Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.tools -> Re: HELP! DBMS_SQL.PARSE
In article <3900A515.53A859A0_at_wellesley.edu>,
"John A. Pearson" <jpearson_at_wellesley.edu> wrote:
> Hello,
>
> I have been using this built-in package for a while
> to create and drop tables (DDL's) dynamically.
>
> However, now I want to use DBMS_SQL
> to pass an INSERT statement.
>
> I have had little luck.
>
> v_createstring := 'INSERT INTO TEMP
> ( FIELD_ONE,
> FIELD_TWO)
> VALUES ('||NUM_1||,
> ||NUM_2||' )'
>
> The values are variables within the package the this
> code is in.
>
> I have had luck with inserting only the first column.
>
> When I get the second column into the script
> I get the error message of ORA-00984: column not allowed here.
>
> Any ideas around this? ....
>
> If you do, please forward an example.
>
> Thanks in advance,
>
> john
>
>
You are missing quotes arounds the commas HOWEVER, your approach (concatenating in constants) is the *wrong* way to do this. It will not perform well, character strings will give you problems (quotes), it will not perform well, it is hard to do (the code to build these strings is hard to read), it will not perform well, you will limit the scalability of your application by trashing the shared pool, and lastly -- it will not perform well.
Here is an example showing your method and then an example showing the real way to do it with bind variables.
ops$tkyte_at_8i> create table t ( num1 int, num2 int );
Table created.
ops$tkyte_at_8i> ops$tkyte_at_8i> ops$tkyte_at_8i> declare 2 cursor_name pls_integer default dbms_sql.open_cursor; 3 ignore pls_integer; 4 5 l_num1 int default 5; 6 l_num2 int default 10;
10 ignore := dbms_sql.execute(cursor_name); 11 dbms_sql.close_cursor(cursor_name);12 END;
PL/SQL procedure successfully completed.
ops$tkyte_at_8i> ops$tkyte_at_8i> ops$tkyte_at_8i> ops$tkyte_at_8i> declare 2 cursor_name pls_integer default dbms_sql.open_cursor; 3 ignore pls_integer; 4 5 l_num1 int default 50; 6 l_num2 int default 100;
10 dbms_sql.bind_variable( cursor_name, ':bv1', l_num1 ); 11 dbms_sql.bind_variable( cursor_name, ':bv2', l_num2 ); 12 ignore := dbms_sql.execute(cursor_name); 13 dbms_sql.close_cursor(cursor_name);14 END;
PL/SQL procedure successfully completed.
ops$tkyte_at_8i> select * from t;
NUM1 NUM2
---------- ----------
5 10 50 100 -- Thomas Kyte tkyte_at_us.oracle.comOracle Service Industries
-- Opinions are mine and do not necessarily reflect those of Oracle Corp Sent via Deja.com http://www.deja.com/ Before you buy.Received on Sun Apr 23 2000 - 00:00:00 CDT
![]() |
![]() |