-1

我正在尝试执行以下 plsql 程序,但面临错误类型的表达式。谁能让我知道可能是什么错误?

CREATE OR REPLACE PROCEDURE CLN_TBL (CTRLM IN VARCHAR2, CTG IN  VARCHAR,SBCT IN NUMBER, RTDT IN NUMBER )    
AS    
    V_SQL VARCHAR(2000);   
    V_TABLE VARCHAR(30);    
    CURSOR TBL_CUR    
    IS    
    SELECT TGT_TABLE_NAME FROM ODS_USER.CLNP WHERE CONTROLM=CTRLM AND     APPL_CTGY=CTG AND APPL_SUB_CTGY= SBCT;    
    L_TGT_TABLE_NAME TBL_CUR%ROWTYPE;    
BEGIN    
    OPEN TBL_CUR;    
    LOOP    
        FETCH TBL_CUR INTO L_TGT_TABLE_NAME;    
        V_TABLE:= L_TGT_TABLE_NAME ;    
        EXIT WHEN TBL_CUR%NOTFOUND;    
        V_SQL:='DELETE FROM '||V_TABLE||' WHERE RPT_DT_ID'||'=:1';    
        EXECUTE IMMEDIATE V_SQL using RTDT;    
    END LOOP;    
    COMMIT;    
    CLOSE TBL_CUR;   
END;
4

1 回答 1

0

正如 Exhausted 所说,您不能将行变量分配给 varchar,因此您应该从行变量中获取 TGT_TABLE_NAME ,如下所示应该可以;

    CREATE OR REPLACE PROCEDURE CLN_TBL (CTRLM IN VARCHAR2, CTG IN   VARCHAR,SBCT IN NUMBER, RTDT IN NUMBER )    
AS    
V_SQL VARCHAR(2000);   
V_TABLE VARCHAR(30);    
CURSOR TBL_CUR    
IS    
SELECT TGT_TABLE_NAME FROM ODS_USER.CLNP WHERE CONTROLM=CTRLM AND     APPL_CTGY=CTG AND APPL_SUB_CTGY= SBCT;    
L_TGT_TABLE_NAME TBL_CUR%ROWTYPE;    
BEGIN    
OPEN TBL_CUR;    
LOOP    
    FETCH TBL_CUR INTO L_TGT_TABLE_NAME;    
    V_TABLE:= L_TGT_TABLE_NAME.TGT_TABLE_NAME ;    
    EXIT WHEN TBL_CUR%NOTFOUND;    
    V_SQL:='DELETE FROM '||V_TABLE||' WHERE RPT_DT_ID'||'=:1';    
    EXECUTE IMMEDIATE V_SQL using RTDT;    
END LOOP;    
COMMIT;    
CLOSE TBL_CUR;   
END;
于 2015-01-21T13:30:34.370 回答