Invalid identifier error when starting plsql block

Since my school does not allow me to publish the code, I had to go back home and give an example to show the problem that I encountered. My school asked me to do my homework on dynamic sql to create a table and then insert one dummy record into it. But doing this, I ran into a problem below. Please find the code below for reference. Thank.

Procedure:

create or replace procedure table_creation(table_name in varchar2,col1  varchar2,col2 varchar2)
is
l_stat varchar2(3000);
v_stat varchar2(1000);
a varchar2(10):='1';
b varchar2(10):='Dummy';
begin
l_stat:='create table '||table_name||' ("'||col1||'"   varchar2(10),"'||col2||'" varchar2(10))';
execute immediate l_stat;
execute immediate 'insert into '||table_name||'('||col1||','||col2||')  values    (:x,:y)' using a,b;
end;
/

Plsql Block for calling the procedure:

set serveroutput on;
declare
a varchar2(10);
b varchar2(10);
c varchar2(10);
begin
a:='Example';
b:='id';
c:='nm';
table_creation(a,b,c);
dbms_output.put_line('Yes');
end;
/

The procedure is created perfectly, and during the execution of the above block I get the following error.

declare
*
ERROR at line 1:
ORA-00904: "NM": invalid identifier
ORA-06512: at "SYS.TABLE_CREATION", line 9
ORA-06512: at line 9

But when I checked the created table. The table exists with 0 records. The structure of the table is as follows.

 Name                                      Null?    Type
 ----------------------------------------- -------- ---------------
 ID                                                 VARCHAR2(10)
 NM                                                 VARCHAR2(10)

Any help from your end is greatly appreciated.

+4
1

, qoutes ( "ID", "NM" ), . , , .

oracle = >

Oracle . . , Oracle , ( CREATE).

:

create or replace procedure table_creation(table_name in varchar2,col1 varchar2,col2 varchar2)
is
l_stat varchar2(3000);
v_stat varchar2(1000);
a varchar2(10):='1';
b varchar2(10):='Dummy';
begin
l_stat:='create table '||table_name||' ('||col1||' varchar2(10),'||col2||' varchar2(10))';
execute immediate l_stat;
execute immediate 'insert into '||table_name||'('||col1||','||col2||') values   (:x,:y)' using a,b;
end;
/

. . , .

:

 l_stat:='create table '||table_name||' ("'||col1||'" varchar2(10),"'||col2||'" varchar2(10))';

to:

 l_stat:='create table '||table_name||' ('||col1||' varchar2(10),'||col2||' varchar2(10))';
+4

Source: https://habr.com/ru/post/1666356/


All Articles