表达错误的类型oracle错误

时间:2015-01-21 12:23:04

标签: oracle stored-procedures plsql plsqldeveloper plsql-psp

我正在尝试执行下面的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;

1 个答案:

答案 0 :(得分: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;