2016-12-15 44 views
1
CREATE or replace PROCEDURE abc as 

ret number; 
msg varchar2(1000); 
Begin 
execute immediate 'truncate table OBSPROJ'; 
execute immediate 'exec obsproj_full_rebuild(:ret,:msg)'; 

End abc; 

當試圖執行下面的查詢它會導致「無效查詢」試圖執行下面的查詢我收到以下錯誤:「無效查詢」的時候,我認爲這個問題是王氏第二執行查詢

我想問題出在第二個執行查詢。

+0

當我嘗試執行下面得到同樣的錯誤ret數; msg varchar2(1000); 執行'exec obsproj_full_rebuild(:ret,:msg)'; –

回答

2

請參閱下面:在線閱讀評論。

CREATE OR REPLACE PROCEDURE abc 
AS 
    ret NUMBER; 
    msg VARCHAR2 (1000); 
BEGIN 
    EXECUTE IMMEDIATE 'truncate table OBSPROJ'; 
    --This is how you call a procedure inside a procedure. 
    obsproj_full_rebuild(ret,msg); -- I guess your procedure accepts some values. .Here you are just passing the variables you declared. 
END abc; 

執行:

sql> exec abc; 
0

首先:EXEC既不是SQL也不PL/SQL命令 - 這就是爲什麼你所得到的錯誤。如果你仍然想使用動態SQL調用你的程序,你可以在PL/SQL塊和綁定RET和味精變量包裝它:

execute immediate 'begin obsproj_full_rebuild(:ret,:msg); end;' using ret, msg; 

但其實你沒有使用動態SQL執行這個程序。你可以簡單地,調用程序

CREATE OR REPLACE PROCEDURE abc AS 
    ret NUMBER; 
    msg VARCHAR2(1000); 
BEGIN 
    EXECUTE IMMEDIATE 'truncate table OBSPROJ'; 
    obsproj_full_rebuild(ret,msg); 
END abc;