2013-11-28 131 views
0

我正在程序中執行這2個語句。Plsql動態sql語句

execute immediate 'create table temp_test(user_state varchar(100), user_goal varchar(100))'; 
     insert into temp_test values('sunil','test'); 

它給我錯誤表未找到。

所以我只是想知道動態sql語句不會立即執行語句。

回答

1

你要做的刀片也是動態:

begin 
    execute immediate 'create table temp_test(user_state varchar(100), user_goal varchar(100))'; 
    execute immediate 'insert into temp_test values('sunil','test');'; 
    COMMIT ; 
end; 
+0

感謝您的回答!我們如何在執行即時語句中插入變量?對不起,我是新的程序寫作:) –

1

應該

begin 
    execute immediate 'create table temp_test(user_state varchar(100), user_goal varchar(100))'; 
    execute immediate 'insert into temp_test values(''sunil'',''test'')'; 
    COMMIT ; 
end; 
+0

感謝您的答案!我們如何在執行即時語句中插入變量?對不起,我是程序撰寫新手:) :) –

+0

您可以使用USING子句。檢查鏈接http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/dynamic.htm –

1

是的,你是對的,動態SQL語句不會立即執行的語句。檢查這個答案execute immediate create table and update table

+0

中的示例7.1感謝您的回答!我們如何在執行即時語句中插入變量?對不起,我是程序寫作的新手:) –