FORALL with EXECUTE IMMEDIATE
Hi allI'm using Oracle 11 g Release2.
I need to use the forall with EXECUTE IMMEDIATE statement and the content of string inside EXECUTE IMMEDIATE is a SELECT instead of the usual DML statement.
Objective: In this SELECT statement, I'll be passing of data using the "USING" clause in FORALL statement
When I try to use it, am getting error found "no DATA".
Please advice if I use FORALL and EXECUTE IMMEDIATE on a SELECT statement?
I can share the scenario...
Thank you!
>
Please advice if I use FORALL and EXECUTE IMMEDIATE on a SELECT statement?
>
No - you can't. See the specifications of the PL/SQL language
http://docs.Oracle.com/CD/E14072_01/AppDev.112/e10472/forall_statement.htm
>
dml_statement
An INSERT, UPDATE, or DELETE static or dynamic statement making reference at least a collection in its VALUES or the WHERE clause. Performance benefits apply only to references to the collection that use as an index index_name.
Tags: Database
Similar Questions
-
How to create and insert data with Execute Immediate?
Hi guys
Am stuck on a procedure of formatting in a package... script works okay however integrating a module turns out to be difficult!
Am not used to oracle... I have the script runs, but not in the package... Well not all that... Drop Table worked
CREATE or REPLACE PACKAGE BODY is
PROCEDURE DropTable1 IS
BEGIN
run immediately ("DROP TABLE mytable1");
END;
PROCEDURE PopulateTable1 IS
BEGIN
immediately execute ('CREATE TABLE mytable1 )
AS LONG AS)
Select
substr (T1.genarea, 3, 3) as M_Class,
substr (T1.genarea, 6, 30) as M_Description,
substr (T1.genarea, 36, 3) as M_Class,
substr (T1.genarea, 39, 30) as M_Description,
substr (T1. ItemItem, 1, 3) as product_code,.
T3. CHANNEL_NUM as SALES_CHANNEL,
to_date(''t2.time_id'',''dd-mon-yyyy'') as mis_date,
Sum (T2.ap_cw_cfi_irp + T2.ap_cw_issues_irp) as ap_gross,
sum (t2. Ap_Cw_Cfi_Irp + t2. Ap_Revivals_Irp) as ap_net,
Sum (T2.sp_inc_irp + T2.sp_issues_irp) as sp_gross,
Sum (T2.sp_dec_irp + T2.sp_fs_irp) as sp_net
Of
d_pr t1, t2 age_map t3 law
where
T1.pfx = "WE"and t1.coy ="1" and t1.tabl = "T81" and substr (t1.itemitem, 1, 3) = t2.product_id and t3. AGE_NUM = t2.age_id
Group
substr (T1.genarea, 3, 3),
substr (T1.genarea, 6, 30),
substr (T1.genarea, 36, 3),
substr (T1.genarea, 39, 30),
substr (T1. ItemItem, 1, 3).
T3. CHANNEL_NUM,
to_date(''t2.time_id'',''dd-mon-yyyy'')
)');
COMMIT;
END PopulateTable1;
END test;
/
Thank you
Hello
a few notes.
1. to_date(t2.time_id,'dd-mon-yyyy')
New York T2.Time_ID Cis the varchar2 data type that contains values to JJ-me-YYYY format?
And if, in which language is used for the names of the months? Conversions are point impossible to solve in reasonable time limits without logging of dml errors and unique failure on charges of staging nightly!
2 single quote escaping "alternative in string literals.You can use Q or q to escape single quotes in strings.
http://docs.Oracle.com/database/121/SQLRF/sql_elements003.htm#SQLRF00218
3. validation
Not required because the DDL commands commit implied.
In general I recommend you write commit clauses only in calling script rather than in the code unless it connects with an autonomous transaction.
You end up with a lot of validation of code here and there and you don't know where it is and where it isn't. That is, your process may have more than one appeal process and commit the middle of the process, it is not atomic processes.
Here's the demo although I recommend also using the static table and truncate to efficiency. ETG is good choice for the purpose of maintenance table.
create or replace package testing is procedure staging_one; end; / create or replace package body testing is -- procedure staging_one is -- procedure drop_staging_one is table_does_not_exist exception; pragma exception_init(table_does_not_exist, -00942); begin execute immediate q'{ drop table staging_one purge }'; exception when table_does_not_exist then return; -- fine end; -- procedure create_staging_one is begin execute immediate q'{ -- remove >>> create table staging_one nologging as select * from dual -- <<< remove /* uncomment >>> create table staging_one nologging as select substr(t1.genarea,3,3) as m_class, substr(t1.genarea,6,30) as m_description, substr(t1.genarea,36,3) as m_class, substr(t1.genarea,39,30) as m_description, substr(t1.itemitem,1,3) as product_code, t3.channel_num as sales_channel, to_date(t2.time_id,'dd-mon-yyyy') as mis_date, sum(t2.ap_cw_cfi_irp+t2.ap_cw_issues_irp) as ap_gross, sum(t2.ap_cw_cfi_irp+t2.ap_revivals_irp) as ap_net, sum(t2.sp_inc_irp +t2.sp_issues_irp) as sp_gross, sum(t2.sp_dec_irp +t2.sp_fs_irp) as sp_net from d_pr t1, act t2, age_map t3 where t1.pfx = 'IT' and t1.coy = '1' and t1.tabl = 'T81' and substr(t1.itemitem,1,3) = t2.product_id and t3.age_num = t2.age_id group by substr(t1.genarea,3,3), substr(t1.genarea,6,30), substr(t1.genarea,36,3), substr(t1.genarea,39,30), substr(t1.itemitem,1,3), t3.channel_num, to_date(t2.time_id,'dd-mon-yyyy') <<< uncomment */ }'; -- end; -- main begin drop_staging_one; create_staging_one; end; end; / set serveroutput on exec testing.staging_one; select * from staging_one ; commit ; PACKAGE TESTING compiled PACKAGE BODY TESTING compiled anonymous block completed DUMMY ----- X committed.
-
ORA-01031 on create sequence with Execute Immediate
I have the following statement in a procedure:
When the statement is executed, I get an ORA-01031: insufficient privileges error.EXECUTE IMMEDIATE ' CREATE SEQUENCE my_seq INCREMENT BY 1 START WITH 130224 NOMINVALUE NOMAXVALUE NOCYCLE NOCACHE';
I can run the CREATE statement in sqlplus. The schema from which I executed the CREATE statement is the same as that under which the procedure is run. In addition, the procedure is also created in the same schema.
What a privilege I'm missing?Your privilege CREATE SEQUENCE given to you through a role.
Roles are not considered in the stored procedures, you must have the privilege granted directly to your user name.
-
Need help with EXECUTE IMMEDIATE
I'm tring to issue an EXECUTE IMMEDIATE to create a DIRECTORY. My problem is that I'm in the "'... ''...'' '...'' ' mess!
source_instance VARCHAR2 (30);
Select sys_context ('USERENV', 'DB_NAME') in the double source_instance;
IMMEDIATE EXECUTION
' CREATE OR REPLACE DIRECTORY "DATA_HUB_". source_instance LIKE "/ mnt/smb/share/layout scene/DataHub /" | source_instance';
I am hopeing to get:
CREATE or REPLACE DIRECTORY DATA_HUB_MYDB AS ' / mnt/smb/share/layout DataHub/scene/MYDB ";
I'm on Oracle 11.1
Thank you!I wonder why people do not use q' syntax. It was introduced in 10g
EXECUTE IMMEDIATE q'#CREATE OR REPLACE DIRECTORY DATA_HUB_#' || source_instance || q'# AS '/mnt/smb/share/Staging/DataHub/#' || source_instance || q'#'#';
Concerning
Pavol Babel
-
With the help of the POLL with Execute Immediate clause
I wrote a query to update a table and return the column in a variable of type table nested using the return clause but its not working, I am getting error like
ORA-06550: line 66, column 22:
PLS-00306: wrong number or types of arguments in the call to ' |'
ORA-06550: line 66, column 4:
PL/SQL: Statement ignored
I get the error message in part of my request to the suite
|| "RETURN If_row_status in bulk collect INTO"
|| v_if_row_status;
Referred to as v_if_row_status-
TYPE v_count IS the TABLE OF varchar2 (50) INDEX directory.
v_if_row_status v_count;The original message listed error about concatenation, but the code in response to scott.wesley had no concatenation. Have you tried to revise the update process? What is a different issue, unrelated to the first?
The best thing to do would be to create a cursor, loop through it and use a simple update for each row. Updates complex as the one you are trying to use are very difficult to manage. By using a loop to insert/update, you can have control over the process and have access to all values, you must use more later in advance instead of having to use the RETURN clause.
Insert bulk can be more effective, but is difficult to manage for the great updates.
-
Execute Immediate is not working well
We need to find tables with the same name and columns but these columns whose data type is different. The SQL below detects the difference.
Based on the SQL above, I created the procedure mentioned below which takes a base as input parameter schema and find these tables with the same name but have different data type columns. It generates dynamic SQL code properly (you can see in DBMS_OUTPUT) but for some reason, the INSERT is not the case with EXECUTE IMMEDIATE. No idea why?select a.table_name, a.column_name, a.data_type ||'---> '||a.owner BASE_SCHEMA_TYPE, b.data_type ||'---> '||B.owner COMPARED_SCHEMA_TYPE from all_tab_columns a, all_tab_columns b where a.owner = 'SCOTT' and b.owner = 'HR' and a.table_name=b.table_name and a.column_name=b.column_name and a.data_type!=b.data_type
Structure of the table being INSERT edcreate or replace procedure admin.compare_data_types (p_baseschema in varchar2) is v_sql varchar2(2000); begin delete from admin.differences; commit; for rec in (select username from dba_users where Username IN ( 'HR')) loop v_sql := 'insert into admin.differences select a.table_name, a.column_name, a.data_type ||''---> ''||a.owner BASE_SCHEMA_TYPE, b.data_type ||''---> ''||B.owner COMPARED_SCHEMA_TYPE from all_tab_columns a, all_tab_columns b where a.owner = '''||p_baseschema||''' and b.owner = '''||rec.username||''' and a.table_name=b.table_name and a.column_name=b.column_name and a.data_type!=b.data_type'; dbms_output.put_line (v_sql); execute immediate v_sql; --commit; -- Doesn't make any difference --v_sql := null; -- Doesn't make any difference end loop; commit; end compare_data_types;
create table admin.DIFFERENCES ( TABLE_NAME VARCHAR2(200), COLUMN_NAME VARCHAR2(200), BASE_SCHEMA_TYPE VARCHAR2(100), COMPARED_SCHEMA_TYPE VARCHAR2(100) )
How about putting in a debug message to see what he does...
(don't forget to ' set serveroutput we "before...)
create or replace procedure admin.compare_data_types (p_baseschema in varchar2) is v_sql varchar2(2000); begin delete from admin.differences; commit; for rec in (select username from dba_users where Username IN ( 'HR')) loop insert into admin.differences select a.table_name ,a.column_name ,a.data_type ||'---> '||a.owner BASE_SCHEMA_TYPE ,b.data_type ||'---> '||B.owner COMPARED_SCHEMA_TYPE from all_tab_columns a ,all_tab_columns b where a.owner = p_baseschema -- Procedure Paramater and b.owner = rec.username and a.table_name = b.table_name and a.column_name = b.column_name and a.data_type!=b.data_type; dbms_output.put_line('Rows Inserted for '||rec.username||': '||sql%rowcount); end loop; commit; end compare_data_types;
And see if it is one) enter the loop and b) the number of rows is inserted during the process.
If it displays 0 rows inserted, then there's something of logically wrong with your select statement, as is return nothing.
-
EXECUTE IMMEDIATE or DBMS_UTILITY. EXEC_DDL_STATEMENT
Hello
I recently became aware of DBMS_UTILITY. EXEC_DDL_STATEMENT and I was wondering if it works in pretty much the same way as EXECUTE IMMEDIATE. I'm guessing that EXECUtE IMMEDIATE offers more flexibility when putting together the command you want to run, but you are the only real difference? All opinions accepted with gratitude,
Kind regards
Kevin.This isn't an exact answer to your question, but it may be useful.
Execute Immediate is the approach privileged 9i or higher. If you decide which to use, go with EXECUTE IMMEDIATE. You never know when the other dynamic SQL methods will be deprecated. In addition, EXECUTE IMMEDIATE has also been optimized (and will continue to be optimized), so you can usually expect better performance during use.
The exact differences between EXECUTE IMMEDIATE and DBMS_UTILITY. EXEC_DDL_STATEMENT go, I can't give you an exact answer. (Also the fact that DBMS_UTILITY. EXEC_DDL_STATEMENT DDL is, of course).
You may or may not find this article helpful: http://okjsp.pe.kr/seq/9789. He did a good job to compare the differences between EXECUTE IMMEDIATE and another way inherited to the dynamic SQL statements (DBMS_SQL. RUN)
Bob
-
use of execute immediate with variables
Hello
I want to update a table with immediate execution, but I need to use the variable to run immediately. I typed a code, but the code below does not work and I m getting the error ORA-00936. Something wrong with this code?
WHILE v_acu_payment_amount > 0
LOOP
BEGIN
SELECT emplid, amount_past_due
IN v_emplid, v_vade_tutari
OF vade_temp
WHERE the sira = v_sirano AND emplid IN (r1.emplid);
END;
v_acu_payment_amount: = v_acu_payment_amount - v_vade_tutari;
Dbms_output.put_line ('paymentamount2' | v_acu_payment_amount);
IF v_acu_payment_amount > 0
THEN
EXECUTE IMMEDIATE "update vade_temp set AMOUNT_PAST_DUE = to_number('||) 0
|| ') where sira = to_number (')
|| v_sirano
|| ')';
ON THE OTHER
Temp: = v_acu_payment_amount * (-1);
Dbms_output.put_line (temp);
EXECUTE IMMEDIATE "update vade_temp set AMOUNT_PAST_DUE = to_number (')"
|| Temp
|| ') where sira = to_number (')
|| v_sirano
|| ')';
END IF;
COMMIT;
v_sirano: = v_sirano + 1;
END LOOP;
Kind regards
Gunce
In addition, you have no dynamic SQL for this
[code]
WHILE v_acu_payment_amount > 0
LOOP
BEGIN
SELECT emplid, amount_past_due
IN v_emplid, v_vade_tutari
OF vade_temp
WHERE the sira = v_sirano AND emplid IN (r1.emplid);
END;
v_acu_payment_amount: = v_acu_payment_amount - v_vade_tutari;
Dbms_output.put_line ('paymentamount2' | v_acu_payment_amount);
IF v_acu_payment_amount > 0
THEN
UPDATE vade_temp
SET amount_past_due = 0
WHERE the sira = v_sirano;
ON THE OTHER
Temp: = v_acu_payment_amount * (-1);
Dbms_output.put_line (temp);
UPDATE vade_temp
SET AMOUNT_PAST_DUE = temp
where sira = v_sirano;
END IF;
COMMIT;
v_sirano: = v_sirano + 1;
END LOOP;
[/ code]
But if you need dynamic sql statements, then you should use bind variables as
...
EXECUTE IMMEDIATE "UPDATE vade_temp SET amount_past_due =: b1 WHERE sira =: b2' using 0, v_sirano;"
...
HTH
-
Execute Immediate with DOF and TABLE() - error ORA-22905
Hello
I have a problem trying to use a user defined the Type of the Table in a statement Execute Immediate containing a CREATE TABLE statement.
Is there no work around for this problem?
The actual code for the SELECT * OF TABLE(:T) is dynamic and slow. That's why I try to avoid to create/fill the table in two steps (as does with MY_TABLE1). Also, in this case, I can't use SELECT * but must specify all the columns (amount variable and over 100 columns).
CREATE TYPE MY_TABLE_TYPE AS TABLE OF VARCHAR2(30); / DECLARE MT MY_TABLE_TYPE; BEGIN SELECT * BULK COLLECT INTO MT FROM DUAL; -- Two steps EXECUTE IMMEDIATE 'CREATE TABLE MY_TABLE1 (A VARCHAR2(30))'; EXECUTE IMMEDIATE 'INSERT INTO MY_TABLE1 SELECT * FROM TABLE(:T)' USING MT; -- OK -- One step EXECUTE IMMEDIATE 'CREATE TABLE MY_TABLE2 AS SELECT * FROM TABLE(:T)' USING MT; -- ERROR ORA-22905 END; /
byee
Andrea
In my view, the error message is incorrect or the less misleading. Bind variables cannot be used in DDL:
SQL > declare
2 number of v_var: = 99;
3. start
4 run immediately "' create the my_table2 in select table: double T" using v_var; "
5 end;
6.
declare
*
ERROR on line 1:
ORA-01027: bind variable not allowed for data definition operations
ORA-06512: at line 4 levelSQL >
What you could do is use the package variable:
SQL > CREATE OR REPLACE
2 PACKAGE PKG1
3 EAST
4 MT MY_TABLE_TYPE;
5 FUNCTION GET_MT
6 RETURN MY_TABLE_TYPE;
7 END;
8.Package created.
SQL > CREATE OR REPLACE
PACKAGE 2 BODY PKG1
3 EAST
4 GET_MT FUNCTION
5 RETURN MY_TABLE_TYPE
6 EAST
7. START
8 RETURN MT;
9 END;
10 END;
11.Package body created.
SQL > DROP TABLE MY_TABLE1 PURGE
2.Deleted table.
SQL > DROP TABLE MY_TABLE2 PURGE
2.
DROP TABLE MY_TABLE2 PURGE
*
ERROR on line 1:
ORA-00942: table or view does not existSQL > START
2. SELECT * BULK COLLECT INTO PKG1.MT FROM DUAL;
3 - two steps
4 RUN IMMEDIATELY "CREATE TABLE MY_TABLE1 (A VARCHAR2 (30))';"
5 IMMEDIATELY EXECUTE "INSERT INTO MY_TABLE1 SELECT * FROM TABLE (PKG1." GET_MT)';
6 - one step
7 IMMEDIATE EXECUTION "CREATE TABLE MY_TABLE2 AS SELECT * FROM TABLE (PKG1." GET_MT)';
8 END;
9.PL/SQL procedure successfully completed.
SQL > select * from my_table1;
A
------------------------------
XSQL > select * from my_table2;
COLUMN_VALUE
------------------------------
XSQL >
SY.
-
How to run execute immediate with variables
Hi friends,
How to run execute immediate with variables in v_stmt below?
I don't know how to declare value I have here.
Regds,Set serveroutput on; DECLARE i VARCHAR (20); v_stmt VARCHAR2 (100); CURSOR c IS SELECT sqlid FROM temp1; BEGIN OPEN c; LOOP FETCH c INTO i; EXIT WHEN c%NOTFOUND; DBMS_OUTPUT.put_line (i); v_stmt := 'select * from table(dbms_xplan.display_cursor('&i',null))' execute immediate v_stmt; END LOOP; CLOSE c; END; /
Kunwar.You must first use a variable binding (named ': v' in the SQL statement in my example):
set serveroutput on; DECLARE i VARCHAR (20); v_stmt VARCHAR2 (100); CURSOR c IS -- modified for a quick test SELECT sql_id FROM v$sql where child_number > 2; BEGIN OPEN c; LOOP FETCH c INTO i; EXIT WHEN c%NOTFOUND; DBMS_OUTPUT.put_line (i); v_stmt := 'select * from table(dbms_xplan.display_cursor(:v,null))'; execute immediate v_stmt using i; END LOOP; CLOSE c; END; /
However because your SELECT statement returns multiple lines, you need to adapt your code to process all rows returned (as already suggested in first response to your message).
Instead of using the PL/SQL, I recommend you to generate a SQL file using only SQL, and then run the generated SQL file.
For example:spool edx.sql set serveroutput on declare v_stmt varchar2(100); v_q char(1):=''''; begin dbms_output.put_line('spool edx.log'); for s in (select sql_id from v$sql where child_number >2) loop dbms_output.put_line('select * from table(dbms_xplan.display_cursor(' || v_q || s.sql_id || v_q || ',null));'); end loop; dbms_output.put_line('exit'); end; / spool of
This generates a file similar to:
spool edx.log select * from table(dbms_xplan.display_cursor('5rygsj4dbw6jt',null)); select * from table(dbms_xplan.display_cursor('5rygsj4dbw6jt',null)); select * from table(dbms_xplan.display_cursor('5rygsj4dbw6jt',null)); select * from table(dbms_xplan.display_cursor('fsbqktj5vw6n9',null)); select * from table(dbms_xplan.display_cursor('6q42j0018w7t8',null)); select * from table(dbms_xplan.display_cursor('a5mmhrrnpwjsc',null)); select * from table(dbms_xplan.display_cursor('3c1kubcdjnppq',null)); select * from table(dbms_xplan.display_cursor('3c1kubcdjnppq',null)); select * from table(dbms_xplan.display_cursor('9gkq7rruycsjp',null)); select * from table(dbms_xplan.display_cursor('f0wj261bm8snd',null)); select * from table(dbms_xplan.display_cursor('ab3swhv5g138y',null)); select * from table(dbms_xplan.display_cursor('6vgvyh4xw9c5g',null)); select * from table(dbms_xplan.display_cursor('ak5crjygnpk60',null)); select * from table(dbms_xplan.display_cursor('9p6bq1v54k13j',null)); select * from table(dbms_xplan.display_cursor('19x1189chq3xd',null)); select * from table(dbms_xplan.display_cursor('7sx5p1ug5ag12',null)); select * from table(dbms_xplan.display_cursor('730vdzhng6m6g',null)); select * from table(dbms_xplan.display_cursor('730vdzhng6m6g',null)); select * from table(dbms_xplan.display_cursor('0v3dvmc22qnam',null)); select * from table(dbms_xplan.display_cursor('0v3dvmc22qnam',null)); select * from table(dbms_xplan.display_cursor('a1zv6wju3ftgv',null)); select * from table(dbms_xplan.display_cursor('7ng34ruy5awxq',null)); select * from table(dbms_xplan.display_cursor('7ng34ruy5awxq',null)); select * from table(dbms_xplan.display_cursor('b2gnxm5z6r51n',null)); select * from table(dbms_xplan.display_cursor('b2gnxm5z6r51n',null)); select * from table(dbms_xplan.display_cursor('g4gp07gt2z920',null)); select * from table(dbms_xplan.display_cursor('1gu8t96d0bdmu',null)); select * from table(dbms_xplan.display_cursor('g00cj285jmgsw',null)); select * from table(dbms_xplan.display_cursor('g00cj285jmgsw',null)); select * from table(dbms_xplan.display_cursor('g00cj285jmgsw',null)); select * from table(dbms_xplan.display_cursor('bn4b3vjw2mj3u',null)); select * from table(dbms_xplan.display_cursor('38243c4tqrkxm',null)); select * from table(dbms_xplan.display_cursor('2abjfnvy5rkyg',null)); select * from table(dbms_xplan.display_cursor('350f5yrnnmshs',null)); select * from table(dbms_xplan.display_cursor('350f5yrnnmshs',null)); select * from table(dbms_xplan.display_cursor('3s1yukp05bzg6',null)); select * from table(dbms_xplan.display_cursor('3s1yukp05bzg6',null)); select * from table(dbms_xplan.display_cursor('1tgukkrqj3zhw',null)); exit PL/SQL procedure successfully completed.
Edited by: P. Forstmann March 20, 2013 19:06
Edited by: P. Forstmann March 20, 2013 19:33
-
Problem with bind in Execute Immediate
Hi all
Scenario 1:
It works very well.
Scenario 2:DECLARE V VARCHAR2(20) := ':X'; X VARCHAR2(20) := 'Hello World'; RES VARCHAR2(20); QRY VARCHAR2(100); BEGIN QRY := 'SELECT '||V||' FROM DUAL'; EXECUTE IMMEDIATE QRY INTO RES USING X; DBMS_OUTPUT.PUT_LINE(RES); END;
Necessary 'X' as the output.DECLARE V VARCHAR2(20) := 'X'; X VARCHAR2(20) := 'Hello World'; RES VARCHAR2(20); QRY VARCHAR2(100); BEGIN QRY := 'SELECT '||V||' FROM DUAL'; EXECUTE IMMEDIATE QRY INTO RES USING X; DBMS_OUTPUT.PUT_LINE(RES); END; Error: X invalid identifier.
I could do to make it works very well for both scenarios with small changes in the code?My code can't handle scenario 2.
You can change to sth as follows:
SQL> declare v varchar2 (20) := 'X'; x varchar2 (20) := 'Hello World'; res varchar2 (20); qry varchar2 (100); begin qry := 'SELECT ' || case when v not like ':%' then ':' end || v || ' FROM DUAL'; execute immediate qry into res using case when v not like ':%' then v else x end; dbms_output.put_line (res); end; / X PL/SQL procedure successfully completed. SQL> declare v varchar2 (20) := ':X'; x varchar2 (20) := 'Hello World'; res varchar2 (20); qry varchar2 (100); begin qry := 'SELECT ' || case when v not like ':%' then ':' end || v || ' FROM DUAL'; execute immediate qry into res using case when v not like ':%' then v else x end; dbms_output.put_line (res); end; / Hello World PL/SQL procedure successfully completed.
-
dml execution 2 statements at a time with the help of execute immediate
I would like to run 2 DML statements at a time with the help of execute immediate usefulness,.
ex:
update employee set ename = 'Chantal' where eno = 123;
Update dept set dname = 'IT' where dno = 345;
I want the two statement to execute at a time, but I don't want to use any loop as well.
Thanks in advanceYou can use:
execute immediate 'begin update employee set ename='jagadeesh' where eno=123; update dept set dname='IT' where dno=345; end;';
Although updates will always run one after the other.
If you want the simultaneous treatment, then you need to use DBMS_JOB and DBMS_SCHEDULER to plan both work to run to run each of the statements independently.
-
EXECUTE IMMEDIATE - problem with log file
Hello
In pl/sql Script, create tables, I used EXECUTE IMMEDIATE. problem is when I try to display the Table name in the LOG file, I can not display the Table name in the LOG file.
When it comes to output file, I can able to display the name of the table in the OUTPUT file.
What could be the problem?
Thank you.Hi user;
Please check:
How to use "Run immediately" in Oracle reports [ID 196813.1]
How to use Execute Immediate with the data of DBMS_METADATA. [285403.1 ID]It may be useful
Respect of
HELIOS -
Use of EXECUTE IMMEDIATE with XML
Database version: 10.2.0.3.0 - 64bi
Hi all
I have an xml that is stored in a table, xmltype column.
I target insert tables including column names and xml nodes are the same.
using the table of all_tab_columns I will generate columns must be passed to xmltable.
all these data, I'll store them in variables and finally proceed to xmltable as below
I just want to know using execute immediate is good to use XML?
SQL_STMT: = 'insert'. table_name | ' ( '|| V_COLUMN_NAME |') ' ;
SQL_STMT: = SQL_STMT | ' SELECT '. V_XTAB_COLUMN_NAME |
"FOR TO_XML,
XMLTABLE(' || v_xpath ||)
"PASSAGE XML_VALUE
columns | V_COLUMNS_DATA_TYPE
||') XTAB
WHERE Seq_NO = ' | P_SEQUENCE_NO;
RUN IMMEDIATELY SQL_STMT;
Thank you and best regards,
RubyHi Ruby,
I just want to know using execute immediate is good to use XML?
Sorry, but this question does not make much sense.
Whether or not dynamic SQL means XML is not relevant, the statement will end up as a cursor in the shared pool independently and be executed or retrieved as any other.If I were you, I'd be worried on the statement do not use bind variables, or the need for dynamic SQL in the first place.
Why should you use dynamic SQL?
If it's laziness, because there are a lot of columns to write down, then it is a bad reason. -
I'm trying to write a script that will perform the synchronization between two databases, sequence numbers. The only way I know to update the nextval is to change the INCREMENT value, take the nextval, then together, the return to 1 INCREMENT value. If there is an easier way, I'd be interested to hear about it too.
However, my current problem is the following. Once I determine dynamically what should be the value to INCREMENT BY, I have run this...
{color: #808080} declare {color}
{color: #808080} v_idDiff number: = 1; {color}
{color: #808080} begin {color}
{color: #808080} run immediately "ALTER SEQUENCE SPHRSBILLING. WORK_UNIT_ID INCREMENT BY: 1 MINVALUE MAXVALUE 999999999999999999999999999 NOCACHE NOCYCLE ALL 0'{color}
{color: #808080} using v_idDiff;
{color} {color: #999999} {color: #808080} end; {color}
{color}
And I get this...
{color: #999999} {color: #808080} ORA-01722: invalid number
ORA-06512: at line 5
{color}
{color} If I simplify things for tests and only try to run this...
{color: #808080} run immediately "ALTER SEQUENCE SPHRSBILLING. WORK_UNIT_ID INCREMENT OF 100 MINVALUE MAXVALUE 999999999999999999999999999 NOCACHE NOCYCLE ALL 0';
{color}
Can I get this...
{color: #808080} ORA-06550: line 1, column 17:
PLS-00103: encountered the symbol "ALTER SEQUENCE SPHRSBILLING. WORK_UNIT_ID INCREASE OF 100 DIGRAPH"when expecting one of the following values:
{color}
{color: #808080}: =. ( @ % ;
The symbol ': = ' was replaced by 'ALTER SEQUENCE SPHRSBILLING. WORK_UNIT_ID INCREASE OF 100 MINVAL' to continue.
{color}
{color: #000000} If I run the ALTAR without being in an EXECUTE IMMEDIATE then it works fine. Ideally, I would like to just pass v_idDiff as a parameter in the ALTAR without the EXECUTE IMMEDIATE, but it does not seem to allow this.
Can someone help me?
Thank you
Ian {color}
Published by: user7808064 on December 3, 2008 11:06Use it and please cache sequence as they are expensive generate
DECLARE
v_sql VARCHAR2 (200);
BEGIN
v_sql: =.
'ALTER SEQUENCE SPHRSBILLING. WORK_UNIT_ID INCREMENT OF 100 MINVALUE MAXVALUE 999999999999999999999999999 NOCACHE NOCYCLE ALL 0';EXECUTE IMMEDIATE v_sql;
END;Published by: OrionNet on December 3, 2008 14:27
Maybe you are looking for
-
24.0 Firefox crashes when closing
Since I installed Firefox 24.0 on my computer, it crashes when I close it, either using X or file-> exit. The only way to stop him is to use the Task Manager to kill the process. Windows is trying to find a solution to the problem and it crashes too,
-
Downloads of E-mail will be not open
I am running FF 17.0.1 on a Sony Vaio laptop with an Intel P7350 under Windows 7 Home Premium. I use Yahoo for my customer e-mail and until recently, when I received an email with a PDF attachment I could save or open attachments. Recently, as a week
-
Satellite M55 is extremely slow
Hello worldI need help with the following:I own a * Toshiba Satellite M55 *. I bought it a few years ago and so far it worked great, but recently (since 3 days ago).It works really SLOW, with about 5 minutes loading screen and things like that. Spywa
-
Equium A100-147: cannot install Vista because of startup configuration problem
Equium A100-147 (Windows MCE) bought compatible Vista and bought my promised copy of Vista... used Toshiba step by step DVD ROM upgrade and also updated the Bios. Tried to load Vista Home Premium and after going through all the steps, it came with th
-
CD/dvd hardware with windows vista problem
I have a code 10 when I search for a solution to my problem. I tried the solution in the Ant, and that's what came. After clicking the regetit in programs, then the only option that appears next to what you say, it's this 'HKEY_LOCAL_MACHINE' when