2015-01-21 47 views
-1

我試圖執行下面的plsql程序,但是面對錯誤類型的表達式。任何人都可以讓我知道什麼可能是錯誤?錯誤類型的表達式oracle錯誤

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; 
+0

在這裏,你不能像分配'V_TABLE:= L_TGT_TABLE_NAME',這是一個'ROWTYPE'屬性'varchar'是Oracle非法的。這裏不需要動態查詢,除非你的表名是動態的,你可以直接從表中刪除它。 – Exhausted 2015-01-21 12:57:40

回答

0

已經用盡說,你不能指定行變量爲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;