2011-10-22 92 views
3
declare 
type yy is table of t12.name%type index by binary_integer; 
y yy; 
n number:=1; 
begin 
execute immediate 'create table rat1 (name varchar2(10))'; 
commit; 

select name bulk collect into y from t12; 
for i in (select id,name from t12) 
loop 
dbms_output.put_line(y(n)); 
n:=n+1; 
end loop; 
forall i in y.first..y.last 
insert into rat1 values(y(i)); 
end; 

其給出ora-00942。 我檢查一下吧......在一些網站有人提的是,你必須給下面的privilages ...無法使用pl/sql創建表格

grant select on sys.v_$paramenter to abc 

我無法做到這一點also..Can任何機構幫我這個

+0

加..我不想在這裏使用任何程序或遊標的概念..... – Tarun

回答

11
所以,它是在2層連續的步驟執行

改變它(NOT在一個PL/SQL匿名塊像它是現在):

首先這個

begin 
execute immediate 'create table rat1 (name varchar2(10))'; 
commit; 
end; 

THEN作爲第二阻止這種

declare 
type yy is table of t12.name%type index by binary_integer; 
y yy; 
n number:=1; 
begin 

select name bulk collect into y from t12; 
for i in (select id,name from t12) 
loop 
dbms_output.put_line(y(n)); 
n:=n+1; 
end loop; 
forall i in y.first..y.last 
insert into rat1 values(y(i)); 
end; 

編輯 - 按評論:

執行前整個PL/SQL塊進行解析, - 在PL/SQL塊中使用的所有對象必須存在的PL/SQL塊之前執行...

+0

Thanx ....如果我理解它正確..然後。 任何DDl在pl/sql成功執行1個塊之前不會生效 – Tarun

+0

目標:沒什麼我只是在學習PL/SQL的過程中所做的一切。 – Tarun

+2

否 - 它會生效,但在執行之前整個PL/SQL塊將被解析 - 所以在PL/SQL塊中使用的所有對象必須存在之前執行PL/SQL塊...請不要忘記upvote /標記爲接受任何答案是有幫助的... – Yahia

3

你應該在兩個獨立的塊中完成。

第一塊:

begin 
... 
end; 
/

斜槓表示您的緩衝區應該被髮送到DBMS和評估。它表明你的PL/SQL代碼結束並可以開始評估。

那麼接下來:

declare 
... 
begin 
... 
end; 
/

因此,你必須:

begin 
... 
end; 
/
declare 
... 
begin 
... 
end; 
/

它工作在SQL * Plus和的SQLDeveloper。