How to use using clause in execute immediate statement??
Hi ALL,
Can u help me ....
This is the code which I have written...
declare
type rec_typ is table of forall_test%rowtype;
v_rectype rec_typ:=rec_typ();
begin
--poputating records
for i in 1..10000 loop
v_rectype.extend;
v_rectype(v_rectype.last).id:=i;
v_rectype(v_rectype.last).code:=to_char(i);
v_rectype(v_rectype.last).description:='Description :'||to_char(i);
end loop;
execute immediate 'truncate table forall_test';
forall i in v_rectype.first..v_rectype.last
execute immediate 'insert into forall_test values :1' using v_rectype(i);
commit;
end;
But I am getting this ERROR....
execute immediate 'insert into forall_test values :1' using v_rectype(i);
ERROR at line 14:
ORA-06550: line 14, column 61:
PLS-00457: expressions have to be of SQL types
ORA-06550: line 14, column 1:
PL/SQL: Statement ignored
Thanks & Regards,
T.Halder
Thatmeans using statement cannot be a non sql type.True: You need an sql type for this:
e.g. with
create or replace type emp_typ
as
object (empno number (4),
ename varchar2 (10 byte),
job varchar2 (9 byte),
mgr number (4),
hiredate date,
sal number (7, 2),
comm number (7, 2),
deptno number (2))
create or replace type emp_tab as table of emp_typ
/you can do
--- an empty test table
SQL> create table emp2
as
select *
from emp
where 1 = 2
Table created.
SQL> declare
emp2_tab emp_tab;
begin
/* fill the collection */
select emp_typ (empno,
ename,
job,
mgr,
hiredate,
sal,
comm,
deptno)
bulk collect into emp2_tab
from emp
where empno like '77%';
-- forall loop
forall c in 1 .. emp2_tab.count
execute immediate 'begin
insert into emp2 select * from table(cast(emp_tab(:1) as emp_tab)) t;
update emp2 set sal = null where empno = (:1).empno and empno = 7788;
end;' using emp2_tab (c);
end;
PL/SQL procedure successfully completed.
SQL> select empno, ename, sal from emp2
EMPNO ENAME SAL
7782 CLARK 2450
7788 SCOTT
2 rows selected.
Similar Messages
-
Using RETURNING clause with Execute Immediate
I wrote a query to update a table and return the column in to a nested table type variable using returning 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 call to '||'
ORA-06550: line 66, column 4:
PL/SQL: Statement ignored
I am getting error in following part of my query
|| 'RETURNING if_row_status bulk collect INTO '
|| v_if_row_status;
v_if_row_status is defined as -
TYPE v_count IS TABLE OF varchar2(50) INDEX BY BINARY_INTEGER;
v_if_row_status v_count;I am trying to update a table for diffrent column if they are null and want no of column updated for each column.
I wrote following query but I am not getting the correct output.
UPDATE
Temp_Bulk_Col_POC
SET if_row_status = 'VALIDATED',
if_row_processed_date = sysdate,
if_row_error_msg =
CASE
WHEN record_type IS NULL
THEN 'RECORD_TYPE is a required column and cannot be NULL'
WHEN source_system IS NULL
THEN 'SOURCE_SYSTEM is a required column and cannot be NULL'
WHEN record_company IS NULL
THEN 'RECORD_COMPANY is a required column and cannot be NULL'
WHEN record_system IS NULL
THEN 'RECORD_SYSTEM is a required column and cannot be NULL'
WHEN txn_flag IS NULL
THEN 'TXN_FLAG is a required column and cannot be NULL'
WHEN create_date IS NULL
THEN 'CREATE_DATE is a required column and cannot be NULL'
WHEN UPDATE_date IS NULL
THEN 'UPDATE_DATE is a required column and cannot be NULL'
WHEN source_customer_id IS NULL
THEN 'SOURCE_CUSTOMER_ID is a required column and cannot be NULL'
WHEN source_product_id IS NULL
THEN 'SOURCE_PRODUCT_ID is a required column and cannot be NULL'
WHEN az_product_id IS NULL
THEN 'AZ_PRODUCT_ID is a required column and cannot be NULL'
WHEN decile IS NULL
THEN 'DECILE is a required column and cannot be NULL'
END
WHERE if_row_status IS NULL
AND (record_type IS NULL
OR source_system IS NULL
OR record_company IS NULL
OR record_system IS NULL
OR txn_flag IS NULL
OR create_date IS NULL
OR UPDATE_date IS NULL
OR source_customer_id IS NULL
OR source_product_id IS NULL
OR az_product_id IS NULL
OR decile IS NULL)
RETURNING if_row_status,record_type,source_system,record_company,record_system,
txn_flag,create_date,UPDATE_date,source_customer_id,source_product_id,az_product_id,
decile
BULK COLLECT INTO
v_if_row_status,v_record_type,v_source_system,
v_record_company,v_record_system,v_txn_flag,v_create_date,v_UPDATE_date,
v_source_customer_id,v_source_product_id,v_az_product_id,v_decile;
its showing same number for all the column.
how I can collect based on the coulmn updated -
How to insert String variables in Execute Immediate Statement
Hi,
I have query
dept varchar2(10);
dept :='electronics'
l_dyn_sql_input600_cbs := 'select EmployeeName,AGE,' || dept ||' from Employee'
EXECUTE immediate l_dyn_sql_input600_cbs;
when i run the query it says "electonics" Invalid identifier.
Can anyone help to rectify the queryWhat are you actually trying to do here:
- Select employee name, age and the string literal 'electronics' from the employee table?
- Select employee name, age and the dept field from the employee table?
- Select employee name, age and dept from the employee table where dept = 'electronics'?
- Something else...?
Doesn't seem to make much sense as it is right now...
cheers,
Anthony -
Pass Pl/sql table into USING clause in EXECUTE IMMEDIATE statment
Getting error when I try to pass the PL/SQL table into USING clause in EXECUTE IMMEDIATE statment:
Declare
result NUMBER;
TYPE values_tab IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
lv_tab values_tab;
lv_exp varchar2(300);
lv_exec varchar2(300);
BEGIN
lv_tab(1) := 5;
lv_tab(2) := 48;
lv_tab(3) := 7;
lv_tab(4) := 6;
lv_exp := ':b1+:b2+(:b3*:b4)';
lv_exec := 'SELECT '||lv_exp ||' FROM DUAL';
EXECUTE IMMEDIATE
lv_exec
INTO
result
USING
lv_tab;
DBMS_OUTPUT.PUT_LINE(result);
END;
Error at line 1
ORA-06550: line 20, column 12:
PLS-00457: expressions have to be of SQL types
ORA-06550: line 15, column 8:
PL/SQL: Statement ignored
I am trying to evaluate the expression ":b1+:b2+(:b3*:b4)" which is stored in table. This table has different expressions (around 300 expressions). I want to use the bind variables in expression because each expression evaluated thousand of time may be more in some case. If I don't use bind variable then it fill shared pool.
Is there any way I can pass the USING (IN) parameters dynamically instead of writing "USING lv_tab(1), lv_tab(2), lv_tab(3), lv_tab(4)"? As number of input parameters change depend on the expression in the table.
If not possible please suggest any other ideas/approches
Please help..
Edited by: satnam on Jun 11, 2009 11:50 AMWell, you keep changing reqs faster I can keep up. Anyway, assuming N-th bind variable (left-to-right) corresponds to collection N-th element:
Declare
result NUMBER;
lv_tab values_tab := values_tab();
lv_exp varchar2(300);
lv_exec varchar2(300);
lv_i number := 0;
BEGIN
lv_tab.extend(4);
lv_tab(1) := 5;
lv_tab(2) := 48;
lv_tab(3) := 7;
lv_tab(4) := 6;
lv_exp := ':5000135+:5403456+(:5900111*:5200456)';
lv_exec := lv_exp;
While regexp_like(lv_exec,':\d+') loop
lv_i := lv_i + 1;
lv_exec := REGEXP_REPLACE(lv_exec,':\d+',':b(' || lv_i || ')',1,1);
end loop;
lv_exec := 'BEGIN :a := ' || lv_exec || '; END;';
DBMS_OUTPUT.PUT_LINE(lv_exec);
EXECUTE IMMEDIATE lv_exec USING OUT result,IN lv_tab;
DBMS_OUTPUT.PUT_LINE(result);
END;
BEGIN :a := :b(1)+:b(2)+(:b(3)*:b(4)); END;
95
PL/SQL procedure successfully completed.
SQL> SY. -
Dynamic USING clause in execute immediate
Hi All,
Is it possible to build a dynamic using clause in execute immediate command.
EXECUTE IMMEDIATE <dynamic query> USING <dynamic clause>;
Rgrds,
Nitin.Hi,
The problem is I have a query in which in some scenarios I want just one column in where clause, in other scenario I need 2 columns in the where clause.
So I would have to write 2 different queries.
execute immediate 'SELECT 1 FROM DUAL WHERE 1 = :bind1' into a using 1;
execute immediate 'SELECT 1 FROM DUAL WHERE 1 = :bind1 AND 2 = :bind2' into a using 1, 2;
Is there any way I can achieve this in a single query like:
dynamic_using_str varchar2(100);
dynamic_using_str := '1';
execute immediate 'SELECT 1 FROM DUAL WHERE 1 = :bind1' into a using dynamic_using_str;
dynamic_using_str := '1, 2';
execute immediate 'SELECT 1 FROM DUAL WHERE 1 = :bind1 AND 2 = :bind2' into a using dynamic_using_str;
~Nitin.
Edited by: user13060845 on Apr 30, 2010 12:29 PM -
Andydata.getObject in piecewise mode using execute immediate statement err
andydata.getObject in piecewise mode using execute immediate statement
will get ora-00600 arguments:[kopuigpfx1], [14] in Oracle 11.1.0.6 and Oralce 10.2.0.2.
andydata.getObject in piecewise mode using execute immediate statement err
andydata.getObject in piecewise mode using execute immediate statement will get ora-00600 arguments:[kopuigpfx1], [14] in Oracle 11.1.0.6 and Oralce 10.2.0.x
The following are test scripts in HR schema.
create type ob_test is object(c1 varchar2(10));
script 1: not using execute immediate statement and works fine.
DECLARE
p_anytype anytype;
p_anydata anydata;
p_value_1 VARCHAR2(4000);
p_value_2 ob_test;
p_result PLS_INTEGER;
BEGIN
anytype.begincreate(dbms_types.typecode_object, p_anytype);
p_anytype.addattr('A1',
dbms_types.typecode_varchar2,
NULL,
NULL,
4000,
NULL,
NULL,
NULL);
p_anytype.addattr('A2',
dbms_types.typecode_object,
NULL,
NULL,
NULL,
NULL,
NULL,
anytype.getpersistent('HR', 'OB_TEST'));
p_anytype.endcreate();
anydata.begincreate(p_anytype, p_anydata);
p_anydata.setvarchar2('abc');
p_anydata.setobject(OB_TEST('abc'));
p_anydata.endcreate;
DECLARE
p_anydata2 anydata := p_anydata;
p_value_1 VARCHAR2(4000);
p_value_2 OB_TEST;
p_result PLS_INTEGER;
BEGIN
p_anydata2.piecewise;
p_result := p_anydata2.getvarchar2(p_value_1);
p_result := p_anydata2.getobject(p_value_2);
END;
END;
script 2: using execute immediate statement will get ora-600
DECLARE
p_anytype anytype;
p_anydata anydata;
p_value_1 VARCHAR2(4000);
p_value_2 ob_test;
p_result PLS_INTEGER;
BEGIN
anytype.begincreate(dbms_types.typecode_object, p_anytype);
p_anytype.addattr('A1',
dbms_types.typecode_varchar2,
NULL,
NULL,
4000,
NULL,
NULL,
NULL);
p_anytype.addattr('A2',
dbms_types.typecode_object,
NULL,
NULL,
NULL,
NULL,
NULL,
anytype.getpersistent('HR', 'OB_TEST'));
p_anytype.endcreate();
anydata.begincreate(p_anytype, p_anydata);
p_anydata.setvarchar2('abc');
p_anydata.setobject(OB_TEST('abc'));
p_anydata.endcreate;
EXECUTE IMMEDIATE 'DECLARE' || chr(10) ||
' p_anydata2 anydata := :1;' || chr(10) ||
' p_value_1 VARCHAR2(4000);' || chr(10) ||
' p_value_2 OB_TEST;' || chr(10) ||
' p_result PLS_INTEGER;' || chr(10) || 'BEGIN' ||
chr(10) || ' p_anydata2.piecewise;' || chr(10) ||
' p_result := p_anydata2.getvarchar2(p_value_1);' ||
chr(10) ||
' p_result := p_anydata2.getobject(p_value_2);' ||
chr(10) || 'END;'
USING p_anydata;
END;
script 3: comment statment "p_result := p_anydata2.getobject(p_value_2);", it works ok.
DECLARE
p_anytype anytype;
p_anydata anydata;
p_value_1 VARCHAR2(4000);
p_value_2 ob_test;
p_result PLS_INTEGER;
BEGIN
anytype.begincreate(dbms_types.typecode_object, p_anytype);
p_anytype.addattr('A1',
dbms_types.typecode_varchar2,
NULL,
NULL,
4000,
NULL,
NULL,
NULL);
p_anytype.addattr('A2',
dbms_types.typecode_object,
NULL,
NULL,
NULL,
NULL,
NULL,
anytype.getpersistent('HR', 'OB_TEST'));
p_anytype.endcreate();
anydata.begincreate(p_anytype, p_anydata);
p_anydata.setvarchar2('abc');
p_anydata.setobject(OB_TEST('abc'));
p_anydata.endcreate;
EXECUTE IMMEDIATE 'DECLARE' || chr(10) ||
' p_anydata2 anydata := :1;' || chr(10) ||
' p_value_1 VARCHAR2(4000);' || chr(10) ||
' p_value_2 OB_TEST;' || chr(10) ||
' p_result PLS_INTEGER;' || chr(10) || 'BEGIN' ||
chr(10) || ' p_anydata2.piecewise;' || chr(10) ||
' p_result := p_anydata2.getvarchar2(p_value_1);' ||
chr(10) ||
' /*p_result := p_anydata2.getobject(p_value_2);*/' ||
chr(10) || 'END;'
USING p_anydata;
END;
Could someone tell me how to solve this problem.
Thanks a lot.
Danielandydata.getObject in piecewise mode using execute immediate statement
will get ora-00600 arguments:[kopuigpfx1], [14] in Oracle 11.1.0.6 and Oralce 10.2.0.2.
andydata.getObject in piecewise mode using execute immediate statement err
andydata.getObject in piecewise mode using execute immediate statement will get ora-00600 arguments:[kopuigpfx1], [14] in Oracle 11.1.0.6 and Oralce 10.2.0.x
The following are test scripts in HR schema.
create type ob_test is object(c1 varchar2(10));
script 1: not using execute immediate statement and works fine.
DECLARE
p_anytype anytype;
p_anydata anydata;
p_value_1 VARCHAR2(4000);
p_value_2 ob_test;
p_result PLS_INTEGER;
BEGIN
anytype.begincreate(dbms_types.typecode_object, p_anytype);
p_anytype.addattr('A1',
dbms_types.typecode_varchar2,
NULL,
NULL,
4000,
NULL,
NULL,
NULL);
p_anytype.addattr('A2',
dbms_types.typecode_object,
NULL,
NULL,
NULL,
NULL,
NULL,
anytype.getpersistent('HR', 'OB_TEST'));
p_anytype.endcreate();
anydata.begincreate(p_anytype, p_anydata);
p_anydata.setvarchar2('abc');
p_anydata.setobject(OB_TEST('abc'));
p_anydata.endcreate;
DECLARE
p_anydata2 anydata := p_anydata;
p_value_1 VARCHAR2(4000);
p_value_2 OB_TEST;
p_result PLS_INTEGER;
BEGIN
p_anydata2.piecewise;
p_result := p_anydata2.getvarchar2(p_value_1);
p_result := p_anydata2.getobject(p_value_2);
END;
END;
script 2: using execute immediate statement will get ora-600
DECLARE
p_anytype anytype;
p_anydata anydata;
p_value_1 VARCHAR2(4000);
p_value_2 ob_test;
p_result PLS_INTEGER;
BEGIN
anytype.begincreate(dbms_types.typecode_object, p_anytype);
p_anytype.addattr('A1',
dbms_types.typecode_varchar2,
NULL,
NULL,
4000,
NULL,
NULL,
NULL);
p_anytype.addattr('A2',
dbms_types.typecode_object,
NULL,
NULL,
NULL,
NULL,
NULL,
anytype.getpersistent('HR', 'OB_TEST'));
p_anytype.endcreate();
anydata.begincreate(p_anytype, p_anydata);
p_anydata.setvarchar2('abc');
p_anydata.setobject(OB_TEST('abc'));
p_anydata.endcreate;
EXECUTE IMMEDIATE 'DECLARE' || chr(10) ||
' p_anydata2 anydata := :1;' || chr(10) ||
' p_value_1 VARCHAR2(4000);' || chr(10) ||
' p_value_2 OB_TEST;' || chr(10) ||
' p_result PLS_INTEGER;' || chr(10) || 'BEGIN' ||
chr(10) || ' p_anydata2.piecewise;' || chr(10) ||
' p_result := p_anydata2.getvarchar2(p_value_1);' ||
chr(10) ||
' p_result := p_anydata2.getobject(p_value_2);' ||
chr(10) || 'END;'
USING p_anydata;
END;
script 3: comment statment "p_result := p_anydata2.getobject(p_value_2);", it works ok.
DECLARE
p_anytype anytype;
p_anydata anydata;
p_value_1 VARCHAR2(4000);
p_value_2 ob_test;
p_result PLS_INTEGER;
BEGIN
anytype.begincreate(dbms_types.typecode_object, p_anytype);
p_anytype.addattr('A1',
dbms_types.typecode_varchar2,
NULL,
NULL,
4000,
NULL,
NULL,
NULL);
p_anytype.addattr('A2',
dbms_types.typecode_object,
NULL,
NULL,
NULL,
NULL,
NULL,
anytype.getpersistent('HR', 'OB_TEST'));
p_anytype.endcreate();
anydata.begincreate(p_anytype, p_anydata);
p_anydata.setvarchar2('abc');
p_anydata.setobject(OB_TEST('abc'));
p_anydata.endcreate;
EXECUTE IMMEDIATE 'DECLARE' || chr(10) ||
' p_anydata2 anydata := :1;' || chr(10) ||
' p_value_1 VARCHAR2(4000);' || chr(10) ||
' p_value_2 OB_TEST;' || chr(10) ||
' p_result PLS_INTEGER;' || chr(10) || 'BEGIN' ||
chr(10) || ' p_anydata2.piecewise;' || chr(10) ||
' p_result := p_anydata2.getvarchar2(p_value_1);' ||
chr(10) ||
' /*p_result := p_anydata2.getobject(p_value_2);*/' ||
chr(10) || 'END;'
USING p_anydata;
END;
Could someone tell me how to solve this problem.
Thanks a lot.
Daniel -
How to make my Execute Immediate statement to work??
Hi, Sir:
I use SQL Oracle 9i,
I have following procedure called by a trigger:
CREATE OR REPLACE PROCEDURE emps_check IS
s_sql VARCHAR2(500);
BEGIN
DBMS_OUTPUT.PUT_LINE('1. Start to Delete all rows in the emps' );
delete from emps;
DBMS_OUTPUT.PUT_LINE('2. Start to insert into emps from emp' );
s_sql:='INSERT INTO Emps(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) select EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO from emp;';
DBMS_OUTPUT.PUT_LINE('3. s_sql= ' || s_sql );
EXECUTE IMMEDIATE s_sql;
DBMS_OUTPUT.PUT_LINE('3. Procedure call OK, Employ Name ' );
EXCEPTION
-- Use this to trap the ORA-00942: table or view does not exist
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Procedure call Exception: Employ Name ' );
end emps_check;
My trigger is:
CREATE OR REPLACE TRIGGER emps_biu_after
after INSERT OR UPDATE or delete on emp
for each row
begin
if TO_CHAR(SYSDate,'DY')= 'SUN'
then
DBMS_OUTPUT.PUT_LINE('Today is holiday, ename =' );
else
DBMS_OUTPUT.PUT_LINE('Today is working Day, ename =');
emps_check();
end if;
end;
When I use following to update emp table:
SQL> UPDATE emp T1
2 SET T1.sal = 200.0
3 WHERE T1.ename like '%SCOTT%';
I got:
Today is working Day, Trigger Call Procedure emps_check()
1. Start to Delete all rows in the emps
2. Start to insert into emps from emp
3. s_sql= INSERT INTO Emps(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) select EMPNO,ENAME,JOB,MGR
Procedure call Exception: Employ Name
Trigger Call Procedure emps_check() Success
Looks like EXECUTE IMMEDIATE s_sql; did not work.
What is wrong??
How to make my Execute Immediate statement to work??
ThanksYou may omit the ';' character...
s_sql:='INSERT INTO
Emps(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
select EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO
from emp';
... and something else
IN PL/SQL when a procedure , function doews not take
any parameter(s) then its call can be made as simply
its name without a pair of parenthesis....(It seems
that you are influenced by Java...:) )
SimThanks Sir:
I remove this ; but still error:
1 UPDATE emp T1
2 SET T1.sal = 768.1
3* wHERE T1.ename like '%SCOTT%'
SQL> /
Today is working Day, Trigger Call Procedure emps_check()
1. Start to Delete all rows in the emps
2. Start to insert into emps from emp
3. s_sql= INSERT INTO Emps(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) select EMPNO,ENAME,JOB,MGR,
Procedure call Exception: Employ Name
Trigger Call Procedure emps_check() Success
My code as follows:
CREATE OR REPLACE PROCEDURE emps_check IS
s_sql VARCHAR2(500);
BEGIN
DBMS_OUTPUT.PUT_LINE('1. Start to Delete all rows in the emps' );
delete from emps;
DBMS_OUTPUT.PUT_LINE('2. Start to insert into emps from emp' );
s_sql:='INSERT INTO Emps(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) select EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO from emp';
DBMS_OUTPUT.PUT_LINE('3. s_sql= ' || s_sql );
EXECUTE IMMEDIATE s_sql;
DBMS_OUTPUT.PUT_LINE('3. Procedure call OK, Employ Name ' );
EXCEPTION
-- Use this to trap the ORA-00942: table or view does not exist
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Procedure call Exception: Employ Name ' );
end emps_check;
what is other wrong??
Yes, I am java guys,
Thanks -
How to run a EXECUTE IMMEDIATE statement in a Interactive Report
Hello all!!
I need to make a dinamic construction of a query to execute in a Interactive Report, but the Region Source only allows simple SELECT statements. There is any way to run a EXECUTE IMMEDIATE statement in a Interactive Report Region Source?
Regards Pedro.Thank you Andy for your reply.
I have been testing for a while the use of a collection in the interactive report but i am unable to load data in the interactive report.
I created the collection successfully in the SQL Commands with the code:
declare
v_sql varchar2(32000);
begin
v_sql:='select ename, job from emp';
APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY('coleccao_emp',v_sql,'NO' );
end;
I tested successfully the creation of the collection with the query:
SELECT c001, c002
FROM APEX_collections
WHERE collection_name = 'COLECCAO_EMP'
My problem is: the data of the collection are returned in the SQL Commands but when i run the query statament in an interactive report, report or even a Pl/Sql region in my application the data aren't displayed, only the message (No data found).
Can someone explain why, besides the collection is populated the interactive can not print the results.
Regards Pedro. -
Execute a DML query its length exceeds 4000 characters with execute immediate statement.
I want to execute a DML query with execute immediate statement. That DML query length exceeds 4000 characters. This query has Xquery related conditions, i can not split the query. when i tried execute it is giving "string literal too long". I tried with DBMS_SQL.Parse() and DBMS_SQL.Execute also, but it is giving same error. I have to execute this DML query inside a Procedure. Please help me to resolve this. We are using oracle 10g version
Thanks & Regards,
K.KedarnadhActually Query is a dynamic query. Query length will exceeds if the no of domains\domain values \products exceeds. Any way Below one is current dynamic query, which is generated within procedure
SELECT
IVT.ID_IVT
,IVT.ID_INS_IVT
,EXTRACTVALUE(IVT.DOCUMENT_IVT,'//productName/text()') AS PRODUCTNAME
,EXTRACTVALUE(IVT.DOCUMENT_IVT,'//elementName/text()') AS INSTANCENAME
,EXTRACTVALUE(IVT.DOCUMENT_IVT,'//elementInternalName/text()') AS INTERNALNAME
,CTG.NAME_CTG
,CTR.NAME_CTR
,MDL.NAME_MDL
,IVT.REEDIT_FLAG_IVT
FROM VARIATION_IVT IVT INNER JOIN CATEGORY_CTG CTG ON CTG.ID_CTG=IVT.ID_CTG_IVT
AND IVT.STATUS_IVT='Active' AND IVT.DELETE_FLAG_IVT=0 AND IVT.ID_PRJ_IVT=1
AND IVT.DOCUMENT_IVT.existsnode('.//domain[domainName="Jurisdictions" and (domainValue="Delhi" or domainValue="Bangladesh" or domainValue="Mumbai" or domainValue="India" or domainValue="Pakistan" or domainValue="Nepal" or domainValue="Maldives" or domainValue="Kolkata" or domainValue="Bhutan" or domainValue="Chennai" or domainValue="ALL")]')=1 AND IVT.DOCUMENT_IVT.existsnode('.//domain[domainName="Channels" and (domainValue="Agents" or domainValue="SBI" or domainValue="Maruti" or domainValue="Direct" or domainValue="CitiFinancial" or domainValue="SCB" or domainValue="BankAssurance" or domainValue="CitiBank" or domainValue="Employees" or domainValue="GE" or domainValue="Brokers" or domainValue="Telemarketing" or domainValue="Agency" or domainValue="ALL")]')=1 AND IVT.DOCUMENT_IVT.existsnode('.//domain[domainName="ModeofDelivery" and (domainValue="Walkin" or domainValue="Internet" or domainValue="ALL")]')=1 AND IVT.DOCUMENT_IVT.existsnode('.//context[(productName="ALL" or productName="A009" or productName="A010" or productName="A046" or productName="AccidentShieldClassic" or productName="AccidentShieldOnline" or productName="AM01" or productName="AM02" or productName="AME_Cancellation" or productName="ARHG" or productName="ARPA" or productName="B003" or productName="B004" or productName="B007" or productName="B008" or productName="B009" or productName="B010" or productName="B012" or productName="B013" or productName="B015" or productName="B016" or productName="B017" or productName="BC04_PA" or productName="BC06_FDP" or productName="BC06_PA" or productName="BC09" or productName="BC10" or productName="BC12" or productName="BC13" or productName="BF03" or productName="BS01" or productName="BS02" or productName="C017" or productName="C035" or productName="C036" or productName="C037" or productName="C038" or productName="C040" or productName="C041" or productName="C041Gold" or productName="C041New" or productName="C045HomeContents" or productName="C048" or productName="C049" or productName="C054" or productName="C057" or productName="C060Building" or productName="C060Contents" or productName="C060FDP" or productName="C061Building" or productName="C061Contents" or productName="C062" or productName="C063" or productName="C067" or productName="C070" or productName="C072" or productName="C074" or productName="C077" or productName="C081" or productName="C082" or productName="C087" or productName="C088" or productName="CITIFOREVER" or productName="CITISECURE" or productName="CITICHILDPLAN" or productName="D001" or productName="DB01" or productName="DD01" or productName="DD02" or productName="DD03" or productName="DD04" or productName="DD09" or productName="DD10" or productName="E005" or productName="E011" or productName="E016" or productName="E020" or productName="E030" or productName="E034" or productName="E040" or productName="E041" or productName="E045HCP" or productName="E045HSP" or productName="E049" or productName="E049New" or productName="E052" or productName="E053" or productName="E054FDP" or productName="E055" or productName="E056" or productName="E057" or productName="E058" or productName="E061" or productName="E061BATCH" or productName="E062" or productName="E063" or productName="E064HCP" or productName="E064HSP" or productName="E066" or productName="E069" or productName="E073" or productName="E075" or productName="E076" or productName="E088" or productName="E090" or productName="E093A" or productName="E093B" or productName="E095" or productName="E099A" or productName="E099B" or productName="E106" or productName="E107" or productName="E110" or productName="E112" or productName="E114" or productName="E115" or productName="E116" or productName="F001" or productName="FamilyHealthInsurance" or productName="FamilyHospitalBenefits" or productName="FamilyHospitalisationCoverBenefit" or productName="G001" or productName="G002" or productName="HealthShieldOnline" or productName="Health_B005" or productName="Health_S057" or productName="HealthSheild" or productName="HealthWalkin" or productName="HomeContentOnline" or productName="HomeShieldOnline" or productName="HomeShieldWalkin" or productName="HospitalCashOnline" or productName="J001" or productName="J008" or productName="K001" or productName="KV02" or productName="LC03" or productName="ML01" or productName="MP02" or productName="MP03" or productName="MR01" or productName="O005" or productName="PO01" or productName="PO02" or productName="PO03" or productName="PO04" or productName="PO05" or productName="PO06" or productName="RR02" or productName="RR03" or productName="RR04" or productName="S006" or productName="S033" or productName="S049" or productName="S051" or productName="S054" or productName="S057" or productName="S060" or productName="S061" or productName="S065" or productName="S065TM" or productName="S068" or productName="S076" or productName="S077" or productName="S079" or productName="S080" or productName="S081" or productName="S084" or productName="S085" or productName="S086" or productName="S087" or productName="S088" or productName="S091" or productName="S092" or productName="S093" or productName="S094" or productName="S095" or productName="S097" or productName="S098" or productName="S099" or productName="S100" or productName="S101" or productName="S102" or productName="S103" or productName="S104" or productName="S106" or productName="S107" or productName="S108" or productName="S109" or productName="S110" or productName="S111" or productName="S113" or productName="SCBNAC" or productName="SF02" or productName="SS01" or productName="SS02" or productName="SUNFHM" or productName="SurgicalShield" or productName="TD01" or productName="TD02" or productName="TP01" or productName="U002Building" or productName="U002Contents" or productName="U004Building" or productName="U007" or productName="U009" or productName="U013" or productName="U014" or productName="U015" or productName="U016" or productName="V001" or productName="V002" or productName="V005" or productName="V006" or productName="V008" or productName="W008" or productName="W020" or productName="W021" or productName="W022" or productName="W023" or productName="W024" or productName="W026" or productName="W027" or productName="W028" or productName="W029" or productName="W105" or productName="W106" or productName="WI01" or productName="WI02" or productName="WI03" or productName="WI07" or productName="WI08" or productName="WI09" or productName="WI10" or productName="WI11" or productName="WI12" or productName="WI13" or productName="WI14" or productName="WI17" or productName="WI20" or productName="WI21" or productName="WI21_Health" or productName="WI23" or productName="WI24" or productName="WI26" or productName="WI30" or productName="WI31" or productName="WI33" or productName="WI34" or productName="X001" or productName="X002" or productName="X003" or productName="X004" or productName="X005" or productName="X008" or productName="Y001" or productName="Y007" or productName="Y009" or productName="Y010" or productName="Y011" or productName="Y011H" or productName="Y020" or productName="Y020N" or productName="Z008" or productName="ZI001")]')=1
INNER JOIN CENTER_CTR CTR ON CTR.ID_CTR=CTG.ID_CTR_CTG
INNER JOIN MODEL_MDL MDL ON MDL.ID_MDL=CTR.ID_MDL_CTR -
Problem in using CREATE TABLE with Execute Immediate
I'm trying to create a table using Native Dynamic SQL. the code of the pl/sql block is
BEGIN
EXECUTE IMMEDIATE 'create table demo (ddate date)';
END;
The problem is that the above block is executed successfully as an anonymous PL/SQL block. The same block when written in a procedure it gives an error
"ORA-01031 Insufficient privelages"
at the time of execution. The procedure is complied successfully.
nullYour user needs direct system privs to create tables. You are receiving your privs properly by the role RESOURCE. Connect as system and grant CREATE TABLE directly to your user - that should do it.
Regards
Peter Larsen -
Update a date field using execute immediate statement..
I need to update a date field dynamically .
Below is the code I have written for the same..
EXECUTE IMMEDIATE
'UPDATE Temp_Emp ' ||
' SET ' || V_Fieldname || ' = ' || D_Value ||
'WHERE Emp_Id = ' || 8447;
I am getting the following error..
ORA-00904: "AUG": invalid identifier
Pls anyone have any ideas..
Thanks,
Xyzput D_Value in single quotes like this
EXECUTE IMMEDIATE
'UPDATE Temp_Emp ' ||
' SET ' || V_Fieldname || ' = ''' || D_Value ||''' WHERE Emp_Id = ' || 8447; -
How how to escape double quation in execute immediate in trigger
Hi all,
please inform me what is the mistake in this procedure.
i think the problem in how to escape double quation.
SQL> create or replace procedure P2
2 is
3 begin
4 execute immediate ' create or replace trigger t2 '
5 ||' before insert '
6 ||' on tb_test'
7 ||' for each row '
8 ||' declare '
9 ||' begin'
*10 ||' execute immediate ''create table t1 as select distinct(NVL(soundex(namess),'''NONE''')) from test';'*
11 ||' end;'
12 end;
13
14 /
Warning: Procedure created with compilation errors.
SQL> show error
Errors for PROCEDURE P2:
LINE/COL ERROR
10/83 PLS-00103: Encountered the symbol "NONE" when expecting one of
the following:
* & = - + ; < / > at in is mod remainder not rem return
returning <an exponent (**)> <> or != or ~= >= <= <> and or
like like2 like4 likec between into using || bulk member
submultiset
SQL>See 'Text Literals' in the SQL Language doc for how to use alternative quoting
http://docs.oracle.com/cd/B28359_01/server.111/b28286/sql_elements003.htm
>
Here are some valid text literals:
'Hello'
'ORACLE.dbs'
'Jackie''s raincoat'
'09-MAR-98'
N'nchar literal'
Here are some valid text literals using the alternative quoting mechanism:
q'!name LIKE '%DBMS_%%'!'
q'<'So,' she said, 'It's finished.'>'
q'{SELECT * FROM employees WHERE last_name = 'Smith';}'
nq'ï Ÿ1234 ï'
q'"name like '['"' -
How can i have '&' in EXECUTE IMMEDIATE statement?
I have PL/SQL procedure, where i will be inserting data to a table. Data which i am inserting is having a '&' value in it. If i use the below statement for insert then sqlplus is prompting for the value '&' like a substitution value while compile this procedure.
EXECUTE IMMEDIATE 'INSERT INTO TABLE_TEST VALUES (:1,:2)' USING 'root/direct/&text', SYSDATE;If i replace the '&' by assigning this value to VARCHAR field then it is working properly. But when i populate an xml from this table using DBMS.XMLGEN, then the value '&' is not entity escaped in the XML which is normally replaced with '&' in XML.
Please help.Vel wrote:
i can't go by both ways because i am using '&' in various files to get some values. Also in this package i am using the '&' to get another substitution variable. Is there any other workaround possible?I prefer not to mess with server-side SQL and PL/SQL code to fix, or work around, a problem on the client-side. Not a very sensible thing IMO.
In such a case as you've described, I would set the substitution character to a character that I'm not using in server-side code. I have done this a couple of times in the past for db create and installation scripts. Oracle uses the same approach for their Apex installation scripts.
I think Oracle uses the +#+ character for their Apex install scripts. E.g.
set define '#'I think I used the tilde (char <i>~</i>) at a stage as substitution char as it is very seldom used in PL/SQL and SQL code.
The bottom line is that you will need to change your code. Set define off and on where needed to ensure substitution only happens where needed. Set the substitution char to a different char and update your substitution variables. Or hack your server-side code (as suggested above) and use the char() function instead. -
Issue while using SUBPARTITION clause in the MERGE statement in PLSQL Code
Hello All,
I am using the below code to update specific sub-partition data using oracle merge statements.
I am getting the sub-partition name and passing this as a string to the sub-partition clause.
The Merge statement is failing stating that the specified sub-partition does not exist. But the sub-partition do exists for the table.
We are using Oracle 11gr2 database.
Below is the code which I am using to populate the data.
declare
ln_min_batchkey PLS_INTEGER;
ln_max_batchkey PLS_INTEGER;
lv_partition_name VARCHAR2 (32767);
lv_subpartition_name VARCHAR2 (32767);
begin
FOR m1 IN ( SELECT (year_val + 1) AS year_val, year_val AS orig_year_val
FROM ( SELECT DISTINCT
TO_CHAR (batch_create_dt, 'YYYY') year_val
FROM stores_comm_mob_sub_temp
ORDER BY 1)
ORDER BY year_val)
LOOP
lv_partition_name :=
scmsa_handset_mobility_data_build.fn_get_partition_name (
p_table_name => 'STORES_COMM_MOB_SUB_INFO',
p_search_string => m1.year_val);
FOR m2
IN (SELECT DISTINCT
'M' || TO_CHAR (batch_create_dt, 'MM') AS month_val
FROM stores_comm_mob_sub_temp
WHERE TO_CHAR (batch_create_dt, 'YYYY') = m1.orig_year_val)
LOOP
lv_subpartition_name :=
scmsa_handset_mobility_data_build.fn_get_subpartition_name (
p_table_name => 'STORES_COMM_MOB_SUB_INFO',
p_partition_name => lv_partition_name,
p_search_string => m2.month_val);
DBMS_OUTPUT.PUT_LINE('The lv_subpartition_name => '||lv_subpartition_name||' and lv_partition_name=> '||lv_partition_name);
IF lv_subpartition_name IS NULL
THEN
DBMS_OUTPUT.PUT_LINE('INSIDE IF => '||m2.month_val);
INSERT INTO STORES_COMM_MOB_SUB_INFO T1 (
t1.ntlogin,
t1.first_name,
t1.last_name,
t1.job_title,
t1.store_id,
t1.batch_create_dt)
SELECT t2.ntlogin,
t2.first_name,
t2.last_name,
t2.job_title,
t2.store_id,
t2.batch_create_dt
FROM stores_comm_mob_sub_temp t2
WHERE TO_CHAR (batch_create_dt, 'YYYY') = m1.orig_year_val
AND 'M' || TO_CHAR (batch_create_dt, 'MM') =
m2.month_val;
ELSIF lv_subpartition_name IS NOT NULL
THEN
DBMS_OUTPUT.PUT_LINE('INSIDE ELSIF => '||m2.month_val);
MERGE INTO (SELECT *
FROM stores_comm_mob_sub_info
SUBPARTITION (lv_subpartition_name)) T1 --> Issue Here
USING (SELECT *
FROM stores_comm_mob_sub_temp
WHERE TO_CHAR (batch_create_dt, 'YYYY') =
m1.orig_year_val
AND 'M' || TO_CHAR (batch_create_dt, 'MM') =
m2.month_val) T2
ON (T1.store_id = T2.store_id
AND T1.ntlogin = T2.ntlogin)
WHEN MATCHED
THEN
UPDATE SET
t1.postpaid_totalqty =
(NVL (t1.postpaid_totalqty, 0)
+ NVL (t2.postpaid_totalqty, 0)),
t1.sales_transaction_dt =
GREATEST (
NVL (t1.sales_transaction_dt,
t2.sales_transaction_dt),
NVL (t2.sales_transaction_dt,
t1.sales_transaction_dt)),
t1.batch_create_dt =
GREATEST (
NVL (t1.batch_create_dt, t2.batch_create_dt),
NVL (t2.batch_create_dt, t1.batch_create_dt))
WHEN NOT MATCHED
THEN
INSERT (t1.ntlogin,
t1.first_name,
t1.last_name,
t1.job_title,
t1.store_id,
t1.batch_create_dt)
VALUES (t2.ntlogin,
t2.first_name,
t2.last_name,
t2.job_title,
t2.store_id,
t2.batch_create_dt);
END IF;
END LOOP;
END LOOP;
COMMIT;
end;
Much appreciate your inputs here.
Thanks,
MK.
(SORRY TO POST THE SAME QUESTION TWICE).
Edited by: Maddy on May 23, 2013 10:20 PMDuplicate question
-
Returning (bulk collect) clause with execute immediate
db version 11.1.0.7
trying to do a returning bulk collect but it is not working:
-- my test table
create table t as
with f as (select rownum rn from dual connect by rownum <= 10)
select
rn,
lpad('x',10,'x') pad
from f;
-- works as expected
declare
type aat is table of t%rowtype;
aay aat;
begin
delete from t returning rn,pad bulk collect into aay;
rollback;
end;
-- but the table I really want to do has many columns so I want to dynamically build list of columns for the
-- returning clause. This way if the table changes the stored proc will not have to be modified
-- fails PLS-00429: unsupported feature with RETURNING clause
declare
type aat is table of t%rowtype;
aay aat;
s varchar2(4000);
begin
s := 'delete from t returning rn,pad into :1';
execute immediate s returning bulk collect into aay;
rollback;
end;
-- tried a few other things:
create or replace type t_obj as object (rn number,pad varchar2(10));
-- PLS-00497: cannot mix between single row and multi-row (BULK) in INTO list
declare
nt t_obj;
s varchar2(4000);
begin
s := 'delete from t returning t_obj(rn,pad) into :1';
execute immediate s returning bulk collect into nt;
rollback;
end;
-- works, but would require store proc changes if the table changes
declare
type t is table of number;
type v is table of varchar2(10);
vt v;
nt t;
s varchar2(4000);
begin
s := 'update t set rn = 10 returning rn,pad into :1,:2';
execute immediate s returning bulk collect into nt,vt;
rollback;
end;
/basically I want to dynamically build the list of columns with all_tab_cols and put the list into the returning clause
but seems like I will have to hard code the column lists. This means whenever the table changes I will have to
modify the store proc .. Any way around this?
ThanksAnd with object type you were almost there. You forgot to create table of objects type:
SQL> create or replace type t_obj as object (rn number,pad varchar2(10));
2 /
Type created.
SQL> declare
2 type aat is table of nt;
3 aay aat;
4 s varchar2(4000);
5 begin
6 s := 'delete from t returning
SQL> declare
2 type aat is table of t_obj;
3 aay aat;
4 s varchar2(4000);
5 begin
6 s := 'delete from t returning t_obj(rn,pad) into :1';
7 execute immediate s returning bulk collect into aay;
8 rollback;
9 end;
10 /
PL/SQL procedure successfully completed.
SQL> SY.
Maybe you are looking for
-
How do I report a bug against Flash Player for Google Chrome?
Flash Player for Google Chrome is currently developed jointly between Adobe and Google. Because of this relationship, we would like to encourage users that are encountering issues with Chrome's Flash Player to report bugs directly to the Chromium da
-
Solaris 10 on Netra T1 install issues....
I have gentoo installed on my netraT1 (which is apparently in the sun4u Platform Group) it has a 500mhz UltraSparc IIe processor and 1Gig of RAM. I decided to try solaris 10 so I downloaded all the cd images to my winows machine and used nero to burn
-
Facing Problem in Batch Job Date
Hi,, I would be great if anyone helps me on this. The background job for invoice printing is taking few days late. Pls check the system background job date. eg. invoice date 17 march, but it only get printed on 19 march. Please doi suggest me the pos
-
5800XM need keyboard to enter data in java app
I have downloaded an app to my 5800 but once in the app i need to enter my account details. There is no keyboard in the app to allow me to enter the details. any ideas please Pat
-
Export Mail inbox and sent mailbox to an Outlook 2003 compatible file
I need to export my Mail inbox and sent mailbox to a file or files that can be imported into MS Outlook 2003 on a PC. I can find menu options for importing files (although no Outlook files) but don't see a menu entry for exporting mailboxes. Anyone k