Procedure using EXECUTE IMMEDIATE facing error
Hi,
I have a procedure proc_1;
Create or replace proc_1
as
sql_1 varchar2(32767) := 'ANALYZE TABLE INFO COMPUTE STATITICS;';
sql_2 varchar2(32767) := 'ANALYZE TABLE TEST COMPUTE STATITICS;';
Begin
EXECUTE IMMEDIATE sql_1;
EXECUTE IMMEDIATE sql_2;
End;
I get an invalid character error.
How to solve this?
Is the procedure written proper ?
Please guide.
Thanks.
Hi Amm-K!
<pre>
Create or replace proc_1
as
sql_1 varchar2(32767) := 'ANALYZE TABLE INFO COMPUTE STATITICS';
sql_2 varchar2(32767) := 'ANALYZE TABLE TEST COMPUTE STATITICS';
Begin
EXECUTE IMMEDIATE sql_1;
EXECUTE IMMEDIATE sql_2;
End;
</pre>
Remove the ; between STATISTICS and ' like in the above example.
yours sincerely
Similar Messages
-
How to use Execute Immediate to execute a procedure and return a cursor?
The procedure name is unknown until run time so I have to use Execute immediate to execute the procedure, the procedure return a cursor, but I can't figure out the right syntax to pass the cursor out.
To simplify the issue here, I create two procedures as examples.Assume I have a procedure called XDTest:
p_cur OUT SYS_REFCURSOR
IS
BEGIN
OPEN p_cur FOR
Select * from dummy_table;
END XDTest;
In another procedure, I want to use Execute Immediate to execute XDTest and obtain the result that return from the cursor into a local cursor so I can process the records:
p_cur OUT SYS_REFCURSOR
IS
l_cur SYS_REFCURSOR;
BEGIN
execute immediate 'BEGIN XDTest (:1); END;' using OUT l_cur;
END XDTest2;
However, this is not working, I get ORA-03113: end-of-file on communication channel error.
What syntax should I use here?
Cheerswell...
I update the XDTest2 procedure as below but when execute it get exceptions.I think the v_sqlstmt syntax is wrong, but I don't know what meant to be correct, please give some suggestions .
Cheers
-------------------- XDTest procedure --------------------------------------------------
p_cur OUT SYS_REFCURSOR
--AUTHID CURRENT_USER
IS
BEGIN
OPEN p_cur FOR
Select Table_Name from USER_Tables;
END XDTest;
-------------------- XDTest2 procedure --------------------------------------------------
p_cur OUT SYS_REFCURSOR
IS
TYPE T1 IS TABLE OF VARCHAR2(4000) INDEX BY BINARY_INTEGER ;
v_sqlstmt varchar2(1000):=null;
v_cursor number;
x_num number;
LN$Lig number := 0 ;
LN$MaxCol number := 0 ;
t T1 ;
v VARCHAR2(4000) ;
userTb User_Tables%ROWTYPE;
l_cur number;
BEGIN
LN$Lig := 0 ;
LN$MaxCol := 1 ;
--OPEN p_cur FOR
--execute immediate 'BEGIN XDTest (:1); END;' using OUT l_cur;
v_cursor:=dbms_sql.open_cursor;
v_sqlstmt:='begin :p_cur:="XDTest"(); END; ';
dbms_sql.parse(v_cursor,v_sqlstmt,DBMS_SQL.NATIVE);
dbms_sql.bind_variable(v_cursor,':p_cur',l_cur);
dbms_output.put_line('1');
-- Define the columns --
dbms_sql.DEFINE_COLUMN(v_cursor, 1, userTb.Table_Name, 30);
x_num:=dbms_sql.execute(v_cursor);
dbms_output.put_line('2');
-- Fetch the rows from the source query --
LOOP
IF dbms_sql.FETCH_ROWS(v_cursor)>0 THEN
-- get column values of the row --
dbms_sql.COLUMN_VALUE(v_cursor, 1,userTb.Table_Name);
dbms_output.put_line(userTb.Table_Name);
ELSE
-- No more rows --
EXIT;
END IF;
END LOOP;
dbms_sql.close_cursor(v_cursor);
END XDTest2;
---------------------- Error when execute ------------------------------------------------
1
BEGIN DevD0DB.XDTest2(:l_cur); END;
ERROR at line 1:
ORA-01007: variable not in select list
ORA-06512: at "SYS.DBMS_SYS_SQL", line 1010
ORA-06512: at "SYS.DBMS_SQL", line 212
ORA-06512: at "DEVD0DB.XDTEST2", line 35
ORA-06512: at line 1
---------------------------------------------------------------------------------------------------- -
Error while insert data using execute immediate in dynamic table in oracle
Error while insert data using execute immediate in dynamic table created in oracle 11g .
first the dynamic nested table (op_sample) was created using the executed immediate...
object is
CREATE OR REPLACE TYPE ASI.sub_mark AS OBJECT (
mark1 number,
mark2 number
t_sub_mark is a class of type sub_mark
CREATE OR REPLACE TYPE ASI.t_sub_mark is table of sub_mark;
create table sam1(id number,name varchar2(30));
nested table is created below:
begin
EXECUTE IMMEDIATE ' create table '||op_sample||'
(id number,name varchar2(30),subject_obj t_sub_mark) nested table subject_obj store as nest_tab return as value';
end;
now data from sam1 table and object (subject_obj) are inserted into the dynamic table
declare
subject_obj t_sub_mark;
begin
subject_obj:= t_sub_mark();
EXECUTE IMMEDIATE 'insert into op_sample (select id,name,subject_obj from sam1) ';
end;
and got the below error:
ORA-00904: "SUBJECT_OBJ": invalid identifier
ORA-06512: at line 7
then when we tried to insert the data into the dynam_table with the subject_marks object as null,we received the following error..
execute immediate 'insert into '||dynam_table ||'
(SELECT887684 wrote:
ORA-00904: "SUBJECT_OBJ": invalid identifier
ORA-06512: at line 7The problem is that your variable subject_obj is not in scope inside the dynamic SQL you are building. The SQL engine does not know your PL/SQL variable, so it tries to find a column named SUBJECT_OBJ in your SAM1 table.
If you need to use dynamic SQL for this, then you must bind the variable. Something like this:
EXECUTE IMMEDIATE 'insert into op_sample (select id,name,:bind_subject_obj from sam1) ' USING subject_obj;Alternatively you might figure out to use static SQL rather than dynamic SQL (if possible for your project.) In static SQL the PL/SQL engine binds the variables for you automatically. -
Oracle 11G Copying a table using execute immediate
I want to copy the contents of one table into another using execute immediate.
This keeps failing with the following error
ORA-00903: invalid table name
ORA-06512: at "TABLE_COPY", line 6
ORA-06512: at line 8
create or replace
procedure TABLE_COPY(
TABLE1 varchar2,
TABLE2 varchar2)
is
begin
execute immediate 'insert into '||TABLE2||' (select * from '||TABLE1||')';
end;
Edited by: user9213000 on 24-Jan-2013 07:38user9213000 wrote:
I want to copy the contents of one table into another using execute immediate.
This keeps failing with the following error
ORA-00903: invalid table name
ORA-06512: at "TABLE_COPY", line 6
ORA-06512: at line 8
create or replace
procedure TABLE_COPY(
TABLE1 varchar2,
TABLE2 varchar2)
is
begin
execute immediate 'insert into '||TABLE2||' (select * from '||TABLE1||')';
end;
Edited by: user9213000 on 24-Jan-2013 07:38The standard advice when (ab)using EXECUTE IMMEDIATE is to compose the SQL statement in a single VARCHAR2 variable
Then print the variable before passing it to EXECUTE IMMEDIATE.
COPY the statement & PASTE into sqlplus to validate its correctness. -
Using EXECUTE IMMEDIATE with an NVARCHAR2 parameter
Hi everyone,
In the system I'm working on, my stored procedure receives an NVARCHAR2 parameter which contains a complete SQL statement. e.g.
'UPDATE SomeTable SET SomeTable.Value = 0'
I want to be able to execute this dynamically, using EXECUTE IMMEDIATE, but I've encountered a problem where this is apparently not supported (because the string is Unicode).
It is crucial that the string stays as Unicode, because of the data that may possible be baked into the SQL statement, and so casting it off to a VARCHAR2, or changing the parameter type, is not acceptable.
Is there a work-around for this issue? Even if it has a performance hit, it will be better than nothing :)
I've tried something like this;
declare
myVal VARCHAR2(256);
begin
myVal := 'UPDATE SomeTable SET SomeTable.Value = 2';
execute immediate 'BEGIN :x; END;' using myVal;
end;
But I get an error;
"bind variable 'X' not allowed in this context"
Has anyone any ideas?
Thanks for your help,
Chrisuhmm, I'm not sure if this is a valid testcase. the string could still be converted into ascii or we8iso8859p1 or whatever 1byte-character set you want.
What I think you should test is a two-byte character as part of SQL, PL/SQL resp. as in SQL all words are defined you can not enlarge it with a 2byte word. But in PL/SQL you could define your own variable. If this variable name itself contains a 2byte character, I guess it will fail.
(I have used l_vär and l_vér as variable names in my example)
Message was edited by:
Leo Mannhart
According to the PL/SQL Reference Guide PL/SQL consists of:
PL/SQL programs are written as lines of text using a specific set of characters:
Upper- and lower-case letters A .. Z and a .. z
Numerals 0 .. 9
Symbols ( ) + - * / < > = ! ~ ^ ; : . ' @ % , " # $ & _ | { } ? [ ]
Tabs, spaces, and carriage returns
This seems no longer up-to-date as I could define a variable l_vär for instance as long as I use a 1byte char set (like iso8859p1). The same variable name as a n-byte char set like UTF-8 will give an error as my example shows. -
Problem in Update statement using Execute Immediate
Hi All,
I am facing problem in update statement.
I am creating dynamic sql and use "execute immediate" statement to execute a update statement.
But it is not updating any thing there in the table.
I have created a query like :
update_query='Update '|| Table_Name ||' t set t.process_status =''Y'' where t.tid=:A';
Execute immediate update_query using V_Id;
commit;
But it is not updating the table.
I have a question , is execute immediate only does insert and delete?
Thanks
AshokSQL> select * from t;
TID P
101 N
SQL> declare
2 V_Id number := 101;
3 Table_Name varchar2(30) := 'T';
4 update_query varchar2(1000);
5 begin
6 update_query := 'Update '|| Table_Name ||' t set t.process_status =''Y'' where t.tid=:A';
7 Execute immediate update_query using V_Id;
8 commit;
9 end;
10 /
PL/SQL procedure successfully completed.
SQL> select * from t;
TID P
101 Y -
Using execute immediate in form
hi all
how can I use Execute Immediate In form It give me error but In sql no error
thank youThere are two options.
1. FORMS DDL
2. Call a backend function or procedure which has got EXECUTE_IMMEDIATE in it.
Following procedure can be used to execute the dymanic sql in forms.
Create this procedure in backend.
CREATE OR REPLACE PROCEDURE pr_execute_immediate (p_sql_stmt VARCHAR2) IS
BEGIN
EXECUTE_IMMEDIATE(p_sql_stmt );
END pr_execute_immediate;
Edited by: Narayan H on Jun 2, 2010 4:00 AM
Edited by: Narayan H on Jun 2, 2010 4:03 AM
Edited by: Narayan H on Jun 2, 2010 4:05 AM -
Have problem when using EXECUTE IMMEDIATE.
Hi, i'm new here... i having problem when trying to use execute immediate statement... :(
procedure code as below:
create procedure copy_row(
p_table varchar2,
p_key varchar2,
p_keyval varchar2,
p_user varchar2,
p_frmto varchar2 default 'FROM')
IS
V_SQL VARCHAR2(500);
BEGIN
if upper(p_frmto)='FROM' then
V_SQL:='INSERT INTO '||P_TABLE||
' SELECT * FROM '||P_USER||'.'||P_TABLE||' WHERE '||P_KEY||' = '''||P_KEYVAL||'''';
elsif upper(p_frmto)='TO' then
V_SQL:='INSERT INTO '||P_USER||'.'||P_TABLE||
' SELECT * FROM '||P_TABLE||' WHERE '||P_KEY||' = '''||P_KEYVAL||'''';
end if;
EXECUTE IMMEDIATE V_SQL;
exception
when others then
raise_application_error(-20000,'PROCEDURE: COPY_ROW - UNABLE TO COPY ROWS! SQL='||V_SQL,TRUE);
end;
is there any limitation on using EXECUTE IMMEDIATE command? i need to use procedure because i'm using old form builder.... but the database server was 9i which able to use this command, so... i decide to use procedure....
i've done some testing on this.... assume the structure of schema1.table1 and schema2.table1 are same....
SQL> CREATE PROCEDURE TESTING IS
2 BEGIN
3 exeCute IMMEDIATE 'INSERT INTO schema1.table1 SELECT * FROM schema2.table1 WHERE column1 = ''abc''';
4 END;
5 /
Procedure created.
SQL> BEGIN
2 TESTING;
3 END;
4 /
BEGIN
ERROR at line 1:
ORA-00942: table or view does not exist
ORA-06512: at "SCHEMA1.TESTING", line 3
ORA-06512: at line 2
any idea?? or have better solution other than this?
database server:9i
sqlplus:SQL*Plus: Release 8.0.6.0.0Do you have an access to tables you are going to insert into / select from ?
Dynamic SQL checks the access permissions at runtime, not at the compilation stage:
SQL> create user master identified by master default tablespace users temporary
2 tablespace temp;
User created.
SQL> alter user master quota unlimited on users;
User altered.
SQL> grant create session to master;
Grant succeeded.
SQL> grant create table to master;
Grant succeeded.
SQL> grant create procedure to master;
Grant succeeded.
SQL> conn master/master
Connected.
SQL> create procedure wrong_prc
2 is
3 begin
4 execute immediate 'insert into master.t select * from scott.t';
5 end;
6 /
Procedure created.
SQL> create table t (id number);
Table created.
SQL> exec wrong_prc;
BEGIN wrong_prc; END;
ERROR at line 1:
ORA-00942: table or view does not exist
ORA-06512: at "MASTER.WRONG_PRC", line 4
ORA-06512: at line 1
SQL> conn scott/tiger
Connected.
SQL> grant select on t to master;
Grant succeeded.
SQL> conn master/master
Connected.
SQL> exec wrong_prc;
PL/SQL procedure successfully completed.
SQL> select * from t;
ID
1And don't use literals in dynamic SQL - you should use binding variables instead.
Rgds. -
How to use execute immediate for character string value 300
how to use execute immediate for character string value > 300 , the parameter for this would be passed.
Case 1: When length = 300
declare
str1 varchar2(20) := 'select * from dual';
str2 varchar2(20) := ' union ';
result varchar2(300);
begin
result := str1 || str2 ||
str1 || str2 ||
str1 || str2 ||
str1 || str2 ||
str1 || str2 ||
str1 || str2 ||
str1 || str2 ||
str1 || str2 ||
str1 || str2 ||
str1 || str2 ||
str1 || ' ';
dbms_output.put_line('length : '|| length(result));
execute immediate result;
end;
/SQL> 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
length : 300
PL/SQL procedure successfully completed.
Case 2: When length > 300 ( 301)
SQL> set serveroutput on size 2000;
declare
str1 varchar2(20) := 'select * from dual';
str2 varchar2(20) := ' union ';
result varchar2(300);
begin
result := str1 || str2 ||
str1 || str2 ||
str1 || str2 ||
str1 || str2 ||
str1 || str2 ||
str1 || str2 ||
str1 || str2 ||
str1 || str2 ||
str1 || str2 ||
str1 || str2 ||
str1 || ' ';
dbms_output.put_line('length : '|| length(result));
execute immediate result;
end;
/SQL> 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
declare
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 6result varchar2(300);Answer shouldn't be here ? In the greater variable ?
Nicolas. -
Java Stored Procedure in EXECUTE IMMEDIATE
Hi,
I need advice for the following.
I'm on Oracle 11g R2. I'm testing application in Oracle 11gR1 and R2 and Oracle Express.
Purpose is to generate XML reports.
I have PLSQL Stored Procedure which does that, but since there is bug in Oracle11gR2 related to XMLTRANSFORM I have and Java Stored Procedure which is workaround. They are both compiled, valid etc.
Java class is :
import java.io.PrintWriter;
import java.io.Writer;
import oracle.xml.parser.v2.DOMParser;
import oracle.xml.parser.v2.XMLDocument;
import oracle.xml.parser.v2.XSLProcessor;
import oracle.xml.parser.v2.XSLStylesheet;
* This class is used as Java stored procedure
* There is a bug on Oracle11gR2, related to the limitation on the number of style sheet instructions
* This stored procedure is workaround when PLSQL code can not be used.
* File must not have package, otherwise is wrongly compiled in DB
public class JavaXslt {
public static void XMLTtransform(oracle.sql.CLOB xmlInput,oracle.sql.CLOB xslInput,oracle.sql.CLOB output) throws Exception{
DOMParser parser;
XMLDocument xml;
XMLDocument xsldoc;
try{
parser = new DOMParser();
parser.parse(xmlInput.getCharacterStream());
xml = parser.getDocument();
parser.parse(xslInput.getCharacterStream());
xsldoc = parser.getDocument();
XSLProcessor processor = new XSLProcessor();
XSLStylesheet xsl = processor.newXSLStylesheet(xsldoc);
Writer w = output.setCharacterStream(1L);
PrintWriter pw = new PrintWriter(w);
processor.processXSL(xsl, xml, pw);
}catch (Exception ex){
throw ex;
PROCEDURE Java_XmlTransform (xml CLOB, xslt CLOB, output CLOB) AS LANGUAGE JAVA
NAME 'JavaXslt.XMLTtransform(oracle.sql.CLOB, oracle.sql.CLOB, oracle.sql.CLOB)';
I'm calling Java stored procedure from PLSQL Stored procedure (if it is Oracle11gR2) like that :
Java_Proc.Java_XmlTransform(inputXML, xslt, res);
So till here everything works ok. XSLT as applied and output XML (res) is OK.
But when Oracle Express is used Java is out of the question, so there is no Java stored procedure. Howewer PLSQL Stored procedure is still needed.
So I had to put call to Java Stored procedure in EXECUTE IMMEDIATE statement in order to compile to PLSQL package.
But when I do that :
EXECUTE IMMEDIATE 'BEGIN Java_Proc.Java_XmlTransform (:1, :2, :3); END;' USING inputXML, xslt, res;
result value CLOB (res) has zero length...
What am I missing? Should i set return value to Java class?
Hope my explanations are clear though.
ThanksHi odie_63,
Thanks for quick response.
I didn't clearly explained.
When using Oracle 11gR1 and Oracle Express I'm using only PLSQL Procedure.
When using Oracle 11gR2 i have to use Java Stored procedure because there is documented bug in R2.
That's why i have to use EXECUTE IMMEDIATE. I don't know which version is the client DB and whether there is or no Java procedures.
I did tried
EXECUTE IMMEDIATE 'BEGIN Java_Proc.Java_XmlTransform (:1, :2, :3); END;' USING IN inputXML, IN xslt, OUT res; and the result was ORA-06537: OUT bind variable bound to an IN position
When using IN OUT for last parameter i.e.
EXECUTE IMMEDIATE 'BEGIN Java_Proc.Java_XmlTransform (:1, :2, :3); END;' USING IN inputXML, IN xslt, IN OUT res;
there is no exception, but still DBMS_LOB.getlength(res) = 0
Thanks -
Selecting data from a table using Execute Immediate in 9i
Hi,
I was wondering how I would be able to do a SELECT on a table using EXECUTE IMMEDIATE. When I tried it (with the proc below), I got the following below. Can anyone tell me what I am doing wrong?
Using Scott/Tiger I tried this:
SQL> ed
Wrote file afiedt.buf
1 CREATE OR REPLACE PROCEDURE P2
2 IS
3 v_SQL VARCHAR2(100);
4 BEGIN
5 v_SQL := 'Select * from Emp';
6 EXECUTE IMMEDIATE v_SQL;
7* END;
SQL> /
Procedure created.
SQL> exec p2
PL/SQL procedure successfully completed.
SQL> set serveroutput on
SQL> exec p2
PL/SQL procedure successfully completed.
SQL>
Thanks in advance.
Sincerely,
Nikhil Kulkarni1 CREATE OR REPLACE PROCEDURE P2
2 IS
3 v_SQL VARCHAR2(100);
erec emp%rowtype;
4 BEGIN
5 v_SQL := 'Select * from Emp';
6 EXECUTE IMMEDIATE v_SQL into erec;
7* END;
SQL> / -
Using execute immediate creating a table from another
hi friend i wanted to create a table from a select statement in a pl sql procedure. i am using execute immediate but getting problems with it pls can anyone help me.
here is the query i am using
EXECUTE IMMEDIATE 'CREATE TABLE table_name AS (SELECT * FROM a_view WHERE column_name LIKE '%some_string%');
i need to know if this can be done and if yes how. pls help me its bit urgent too. the schema name is same and the privileges are available to create tables too.Your syntax is wrong.
If you would use a syntax higlighted editor, it would show.
Yout try to execute a string where another string is embedded. Please use two times single quote or use the 'q' function:
This one is correct:
EXECUTE IMMEDIATE 'CREATE TABLE table_name AS (SELECT * FROM a_view WHERE column_name LIKE ''%some_string%'')';
or this one:
EXECUTE IMMEDIATE q'|CREATE TABLE table_name AS (SELECT * FROM a_view WHERE column_name LIKE '%some_string%')|';
good luck -
Create temp table using EXECUTE IMMEDIATE
Is there any performance issue in creating globally temp table
using EXECUTE IMMEDIATE or creating globally temp table from
SQL PLUS.
Any response will be greatly appreciated.
nullAnish,
Creating tables is likely to be an expensive operation.
Performance issues can only be considered in comparison to
alternatives.
Alternatives include: PLSQL tables, cursors and/or recoding so
that tmp tables are not required. (One of our consultants reckons
that sqlserver temp tables are usually used to get around
limitations in sqlserver, ie slightly more complicated sql
statements could be used instead of simpler sql and temporary
tables).
I would think creating the temp table once during sqlplus would
be cheaper than creating and deleting it repeatedly at run time.
Note that EXECUTE IMMEDIATE may do an implicit commit (dbms_sql
certainly does). This may be got over my using the PRAGMA
AUTONOMOUS_TRANSACTION; direction which places a
procedure/function in a seperate transaction.
Turloch
P.S. We have some difficulty in getting information back from the
field/customer sites. If you have questions and answers that are
likely to be useful to other Oracle Migration Workbench
users, and migrators in general, please send them in for possible
inclusion in our Frequently Asked Question list.
Oracle Migration Workbench Team
Anish (guest) wrote:
: Is there any performance issue in creating globally temp table
: using EXECUTE IMMEDIATE or creating globally temp table from
: SQL PLUS.
: Any response will be greatly appreciated.
Oracle Technology Network
http://technet.oracle.com
null -
CREATE TEMPORARY TABLE USING EXECUTE IMMEDIATE
Hi All,
i have a question,
how can i create a temporary table using EXECUTE IMMEDIATE ??
Like:
CREATE GLOBAL TEMPORARY table new_table as (Select * from old_table);
Thanks,
Edited by: xDeviates on Jun 11, 2012 3:13 PMIt looks like you are approaching the problem incorrectly. As I suggested in Dynamic Select, it sounds like you, at most, want a function that returns a SYS_REFCURSOR (it's still not obvious to me why you would even want/ need to resort to dynamic SQL in the first place)
CREATE OR REPLACE FUNCTION get_dynamic_cursor( p_table_name IN VARCHAR2 )
RETURN sys_refcursor
IS
l_rc sys_refcursor;
BEGIN
OPEN l_rc FOR 'SELECT * FROM ' || dbms_assert.sql_object_name( p_table_name );
RETURN l_rc;
END;which you can then call from your application
SQL> variable rc refcursor;
SQL> exec :rc := get_dynamic_cursor( 'EMP' );
PL/SQL procedure successfully completed.
SQL> print rc
EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 801
20
7499 ALLEN SALESMAN 7698 20-FEB-81 1601 300
30
7521 WARD SALESMAN 7698 22-FEB-81 1251 500
30
EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO
7566 JONES MANAGER 7839 02-APR-81 2976
20
7654 MARTIN SALESMAN 7698 28-SEP-81 1251 1400
30
7698 BLAKE MANAGER 7839 01-MAY-81 2851
30
EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO
7782 CLARK MANAGER 7839 09-JUN-81 2451
10
7788 SCOTT ANALYST 7566 19-APR-87 3001
20
7839 KING PRESIDENT 17-NOV-81 5001
10
EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO
7844 TURNER SALESMAN 7698 08-SEP-81 1501 0
30
7876 ADAMS CLERK 7788 23-MAY-87 1101
20
7900 JAMES CLERK 7698 03-DEC-81 951
30
EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO
7902 FORD ANALYST 7566 03-DEC-81 3001
20
7934 MILLER CLERK 7782 23-JAN-82 1301
10
14 rows selected.Justin -
Using EXECUTE IMMEDIATE for DML
What benefit is there to use EXECUTE IMMEDIATE for an UPDATE statement like the one below.
EXECUTE IMMEDIATE 'UPDATE mytable SET bonus = v_bonus(i)
WHERE empid =:empid AND sal =:sal'
USING v_empid(n),v_sal(i);This UPDATE sql is not dynamically created. So is there any performance benefit associated with using
EXECUTE IMMEDIATE for this UPDATE? Can't i just use a normal UPDATE without EXECUTE IMMEDIATE?Ran these same tests with SQL_Trace turned on, ran the trace files through tkprof and look at what it tells us:
declare
begin
for i in 1 .. 100000 loop
gso_prueba_a();
end loop;
end;
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.07 0.08 0 0 0 1
Fetch 0 0.00 0.00 0 0 0 0
total 2 0.07 0.08 0 0 0 1Now a slow one
declare
begin
for i in 1 .. 100000 loop
execute immediate 'call gso_prueba_b()';
end loop;
end;
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 36.07 36.54 0 0 0 1
Fetch 0 0.00 0.00 0 0 0 0
total 2 36.07 36.54 0 0 0 1but with this slow one, we see LOTS of recursive SQL - the 'call gso_prueba_b' is getting parsed a gazillion times with the resulting CPU consumption
SQL ID : 1uu09hhqdp1yz
call gso_prueba_b()
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 99989 2.42 2.72 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
total 99990 2.42 2.72 0 0 0 0
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 91 (recursive depth: 1)
SQL ID : dcstr36r0vz0d
select procedure#,procedurename,properties,itypeobj#
from
procedureinfo$ where obj#=:1 order by procedurename desc, overload# desc
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 2 0.00 0.00 0 4 0 1
total 4 0.00 0.00 0 4 0 1Lots, lots more like this last one but having different SQL ID
By wrapping the procedure call in a dynamically created anonymous block, you are incurring LOTS of overhead.
What is it that you are trying to simulate.
What are you trying to do?
Maybe you are looking for
-
Every time a character is made in my app it is saved to an html file named after it in a folder called RpgApp on the sdcard so if the characters name is john smith then there will be a john-smith.htm located in RpgApp folder on the sdcard now that bi
-
I want to see multiple pins on Maps app. Is this possible?
Basically, I would love to be able to click on Maps app on my iphone, and depending on where I am, see the map and any bookmarks I have saved in my phone. For example, if I wanted to pin all my contacts on a map and see pins on where they are, but A
-
My trusty Mac LC no longer boots from the HD
I purchased a new Mac LC many years ago and it has served me well until recently when it would no longer boot from the hard drive. When I boot from a Disk Tools floppy, I get some limited success but do not ever hear the HD spin up. The startup chime
-
Customizing Top level navigation
Hi, I have requirement where in i have to customize the top level navigation. Insted of hyper links display i have to show them like buttons, not exactly buttons but the hyperlinks shown for the navigation should be removed. Is it possible to show wi
-
MDS Schema Configuration Failue during OEM installation
During the OEM installation the set-up stops at MDS Schema Configuration. I see the following exception in the log files :-( emmdscreate_2010_08_25_AD_23_11_09_IST.log* 2010_08_25_AD_23_11_09_IST EMMDSSchemaManager: Info : Oracle Home is C:\Oracle\Mi