16 Şubat 2010 Salı

PLS-00103: Encountered the symbol "CREATE" hatası ve çözümü

/* PL SQL bloğunun içerisinde DDL komutları kullanılamıyor.ALTER, CREATE, DROP ... komutları bunlardan bazılarıdır. */

***************************************************************************
1 BEGIN
2
3 DBMS_OUTPUT.PUT_LINE('PL SQL kodu içerisinde DDL cümlesi kullanımı');
4
5 CREATE TABLE duser.deneme AS
6 SELECT * FROM dba_tables
7 WHERE ROWNUM <= p_num
8 ORDER BY ROWNUM DESC;
9
10
11 END;
12 /

***************************************************************************

Alınan hata :

BEGIN

DBMS_OUTPUT.PUT_LINE('PL SQL kodu içerisinde DDL cümlesi kullanımı');

CREATE TABLE duser.deneme AS
SELECT * FROM dba_tables
WHERE ROWNUM <= p_num
ORDER BY ROWNUM DESC;


END;
Error at line 1
ORA-06550: line 5, column 6:
PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:

begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<çift tırnaklı sınırlandırılmış belirleyici>
<< close current delete fetch lock
insert open rollback savepoint set sql execute commit forall
merge pipe
The symbol "lock was inserted before "CREATE" to continue.
ORA-06550: line 5, column 32

Script Terminated on line 1.


Çözümü :

*************************************************************************

DECLARE
v_stmt varchar2(200);

BEGIN

DBMS_OUTPUT.PUT_LINE('PL SQL kodu içerisinde DDL cümlesi kullanımı');

v_stmt:='CREATE TABLE duser.deneme AS SELECT * FROM dba_tables WHERE ROWNUM <= 100 ORDER BY ROWNUM DESC';

execute immediate (v_stmt);

END;
/

Hiç yorum yok: