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?
Thanks
And 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.
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 -
Pipelined Function with execute immediate
Hello Experts,
I have created a Pipe lined function with execute immediate, due to below requirement;
1) Columns in where clause is passed dynamically.
2) I want to know the data stored into above dynamic columns.
3) I want to use it in report, so I don't want to insert it into a table.
I have created a TYPE, then through execute immediate i have got the query and result of that query will be stored in TYPE.
But when calling the function i am getting
ORA-00932: inconsistent datatypes: expected - got -
Below is my function and type, let me know i am going wrong, and is my logic correct.
CREATE OR REPLACE TYPE OBJ_FPD AS OBJECT
(LOW_PLAN_NO VARCHAR2 (40),
FPD VARCHAR2 (5),
SERIAL_NO NUMBER,
CEDIA_CODE VARCHAR2 (2),
DT DATE);
CREATE OR REPLACE TYPE FPD_TBL_TYPE AS TABLE OF OBJ_FPD;
CREATE OR REPLACE FUNCTION FUNC_GET_FPD_DATE (P_LOW_PLAN_NO VARCHAR2,
P_CEDIA_CODE VARCHAR2,
P_SERIAL_NO NUMBER)
RETURN FPD_TBL_TYPE
PIPELINED
AS
CURSOR C1
IS
SELECT 'FPD' || LEVEL TBL_COL
FROM DUAL
CONNECT BY LEVEL <= 31;
V_STR VARCHAR2 (5000);
V_TBL_TYPE FPD_TBL_TYPE;
BEGIN
FOR X IN C1
LOOP
V_STR :=
'SELECT A.low_PLAN_NO,
A.FPD,
A.SERIAL_NO,
A.cedia_code,
TO_DATE (
SUBSTR (FPD, 4, 5)
|| ''/''
|| TO_CHAR (C.low_PLAN_PERIOD_FROM, ''MM'')
|| ''/''
|| TO_CHAR (C.low_PLAN_PERIOD_FROM, ''RRRR''),
''DD/MM/RRRR'')
DT FROM ( SELECT low_PLAN_NO, '
|| ''''
|| X.TBL_COL
|| ''''
|| ' FPD, '
|| X.TBL_COL
|| ' SPTS, SERIAL_NO, cedia_code FROM M_low_PLAN_DETAILS WHERE NVL('
|| X.TBL_COL
|| ',0) > 0 AND SERIAL_NO = '
|| P_SERIAL_NO
|| ' AND cedia_code = '
|| ''''
|| P_CEDIA_CODE
|| ''''
|| ' AND low_PLAN_NO = '
|| ''''
|| P_LOW_PLAN_NO
|| ''''
|| ') A,
M_low_PLAN_DETAILS B,
M_low_PLAN_MSTR C
WHERE A.low_PLAN_NO = B.low_PLAN_NO
AND A.cedia_code = B.cedia_code
AND A.SERIAL_NO = B.SERIAL_NO
AND B.low_PLAN_NO = C.low_PLAN_NO
AND B.CLIENT_CODE = C.CLIENT_CODE
AND B.VARIANT_CODE = C.VARIANT_CODE
CONNECT BY LEVEL <= SPTS';
EXECUTE IMMEDIATE V_STR INTO V_TBL_TYPE;
FOR I IN 1 .. V_TBL_TYPE.COUNT
LOOP
PIPE ROW (OBJ_FPD (V_TBL_TYPE (I).LOW_PLAN_NO,
V_TBL_TYPE (I).FPD,
V_TBL_TYPE (I).SERIAL_NO,
V_TBL_TYPE (I).CEDIA_CODE,
V_TBL_TYPE (I).DT));
END LOOP;
END LOOP;
RETURN;
EXCEPTION
WHEN OTHERS
THEN
RAISE_APPLICATION_ERROR (-20000, SQLCODE || ' ' || SQLERRM);
RAISE;
END;Waiting for your views.
Regards,Ora Ash wrote:
Hello Experts,
I have created a Pipe lined function with execute immediate, due to below requirement;
1) Columns in where clause is passed dynamically.No, that's something you've introduced, and is due to poor database design. You appear to have columns on your table called FPD1, FPD2 ... FPD31. The columns do not need to be 'passed dynamically'
2) I want to know the data stored into above dynamic columns.And you can know the data without it being dynamic.
3) I want to use it in report, so I don't want to insert it into a table.That's fine, though there's no reason to use a pipelined function.
You also have an pointless exception handler, which masks any real errors.
I'm not quite sure what the point of your "connect by" is in your query as we don't have your tables or data or know for sure what the expected output is.
However, in terms of handling the 'dynamic' part that you've introduced, then you would be looking at doing something along the following lines, using a static query that requires no poor dynamic code, and no pipelined function...
with x as (select level as dy from dual connect by level <= 31)
select a.low_plan_no
,a.fpd
,a.serial_no
,a.cedia_code
,trunc(c.low_plan_period_from)+a.dy-1 as dt
from (select low_plan_no
,dy
,'FPD'||dy as fpd
,spts
,serial_no
,cedia_code
from (
select low_plan_no
,x.dy
,case x.dy when 1 then fpd1
when 2 then fpd2
when 3 then fpd3
when 4 then fpd4
when 5 then fpd5
when 6 then fpd6
when 7 then fpd7
when 8 then fpd8
when 9 then fpd9
when 10 then fpd10
when 11 then fpd11
when 12 then fpd12
when 13 then fpd13
when 14 then fpd14
when 15 then fpd15
when 16 then fpd16
when 17 then fpd17
when 18 then fpd18
when 19 then fpd19
when 20 then fpd20
when 21 then fpd21
when 22 then fpd22
when 23 then fpd23
when 24 then fpd24
when 25 then fpd25
when 26 then fpd26
when 27 then fpd27
when 28 then fpd28
when 29 then fpd29
when 30 then fpd30
when 31 then fpd31
else null
end as spts
,serial_no
,cedia_code
from x cross join m_low_plan_details
where serial_no = p_serial_no
and cedia_code = p_cedia_code
and low_plan_no = p_low_plan_no
where nvl(spts,0) > 0
) A
join m_low_plan_details B on ( A.low_plan_no = B.low_plan_no
and A.cedia_code = B.cedia_code
and A.serial_no = B.serial_no
join m_low_plan_mstr C on ( B.low_plan_no = C.low_plan_no
and B.client_code = C.client_code
and B.variant_code = C.variant_code
connect by level <= spts;... so just remind us again why you think it needs to be dynamic? -
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 -
Transaction control with execute immediate
Hi, What is the correct way to commit/ rollback transactions when executing a dynamic update statement with execute immediate?
Hi Thanks fo the reply, they don't appear to be. here's my procedure. Is there anything the is obviously wrong?
PROCEDURE p_move_city_numerics ( p_mode IN VARCHAR2,
p_schema IN VARCHAR2,
p_table IN VARCHAR2,
p_destination IN VARCHAR2,
p_city_name IN VARCHAR2,
p_outcome OUT VARCHAR2)
IS
l_valid_object VARCHAR2(200);
l_error_msg VARCHAR2(200);
l_outcome VARCHAR2(2000);
l_sql_count VARCHAR2(2000);
l_sql_update VARCHAR2(2000);
l_record_count NUMBER;
e_object_error EXCEPTION;
BEGIN
l_valid_object := f_is_city_valid (p_schema, p_table, p_destination);
IF l_valid_object != 'VALID' THEN
RAISE e_object_error;
END IF;
l_sql_count := 'SELECT COUNT(*) FROM ' || p_schema || '.' || p_table;
l_sql_count := l_sql_count || ' WHERE UPPER(city) LIKE ' || '''' || '%' || UPPER(p_city_name) || '%' || '''';
l_sql_count := l_sql_count || ' AND ( city LIKE ' || '''' || '%1%' || '''';
l_sql_count := l_sql_count || ' OR city LIKE ' || '''' || '%2%' || '''';
l_sql_count := l_sql_count || ' OR city LIKE ' || '''' || '%3%' || '''';
l_sql_count := l_sql_count || ' OR city LIKE ' || '''' || '%4%' || '''';
l_sql_count := l_sql_count || ' OR city LIKE ' || '''' || '%5%' || '''';
l_sql_count := l_sql_count || ' OR city LIKE ' || '''' || '%6%' || '''';
l_sql_count := l_sql_count || ' OR city LIKE ' || '''' || '%7%' || '''';
l_sql_count := l_sql_count || ' OR city LIKE ' || '''' || '%8%' || '''';
l_sql_count := l_sql_count || ' OR city LIKE ' || '''' || '%9%' || '''';
l_sql_count := l_sql_count || ' OR city LIKE ' || '''' || '%0%' || '''' || ')';
l_sql_update := 'UPDATE ' || p_schema || '.' || p_table;
l_sql_update := l_sql_update || ' SET ' || p_destination || ' = city,';
l_sql_update := l_sql_update || ' city = ' || '''' || p_city_name || '''';
l_sql_update := l_sql_update || ' WHERE UPPER(city) LIKE ' || '''' || '%' || UPPER(p_city_name) || '%' || '''';
l_sql_update := l_sql_update || ' AND ( city LIKE ' || '''' || '%1%' || '''';
l_sql_update := l_sql_update || ' OR ciity LIKE ' || '''' || '%2%' || '''';
l_sql_update := l_sql_update || ' OR city LIKE ' || '''' || '%3%' || '''';
l_sql_update := l_sql_update || ' OR city LIKE ' || '''' || '%4%' || '''';
l_sql_update := l_sql_update || ' OR city LIKE ' || '''' || '%5%' || '''';
l_sql_update := l_sql_update || ' OR city LIKE ' || '''' || '%6%' || '''';
l_sql_update := l_sql_update || ' OR city LIKE ' || '''' || '%7%' || '''';
l_sql_update := l_sql_update || ' OR city LIKE ' || '''' || '%8%' || '''';
l_sql_update := l_sql_update || ' OR city LIKE ' || '''' || '%9%' || '''';
l_sql_update := l_sql_update || ' OR city LIKE ' || '''' || '%0%' || '''' || ')';
IF p_mode = 'SELECT' THEN
EXECUTE IMMEDIATE(l_sql_count) INTO l_record_count;
l_outcome := TO_CHAR(l_record_count) || ' records to be updated!';
ELSIF p_mode = 'UPDATE' THEN
EXECUTE IMMEDIATE(l_sql_count) INTO l_record_count;
EXECUTE IMMEDIATE(l_sql_update);
l_outcome := TO_CHAR(l_record_count) || ' records have been updated!';
COMMIT;
ELSE
l_outcome := ' ERROR - Invalid mode: ' || p_mode || ' has been passed into the function! Valid values are SELECT or UPDATE';
END IF;
EXCEPTION
WHEN e_object_error THEN
IF l_valid_object = 'INVALID_TABLE' THEN
l_outcome := 'ERROR - Not a valid table name: ' || p_schema || '.' || p_table;
ELSIF l_valid_object = 'INVALID_CITY' THEN
l_outcome := 'ERROR - CITY not a valid field in the table: ' || p_schema || '.' || p_table;
ELSIF l_valid_object = 'INVALID_DEST' THEN
l_outcome := 'ERROR - Destination field: ' || p_destination || ' is not a valid field in the table: ' || p_schema || '.' || p_table;
END IF;
WHEN OTHERS THEN
l_error_msg := SQLCODE || '-' || SUBSTR(SQLERRM, 1, 150);
l_outcome := 'ERROR - ' || l_error_msg;
ROLLBACK;
END p_move_city_numerics; -
Disadvantage with 'Execute Immediate'
What is the disadvantage with 'EXECUTE IMMEDIATE'.
I think you guys are missing the point here.
None of the issues listed are 'EXECUTE IMMEDIATE' disadvantages.
'EXECUTE IMMEDIATE' is a tool. Like DMS_SQL. Like ref cursors. Like explicit cursor. Like implicit cursors.
A tool, any tool, needs to be used correctly. If you use a hammer and hit a nail so hard that it bents, causing the hammer to slip doing some serious damage to your thumb... whose fault it is?
Is it The Hammer that is at fault here? Or is the user of that tool?
There are no disadvantages to using 'EXECUTE IMMEDIATE'. It is a tool. But like all tools it needs to be used correctly and safely. Things like excessive hard parsing because of a severe lack of bind variables, or opening a hole for SQL injection, etc.. all these are symptoms of - and let's be blunt here - an ignorant developer. It has nothing to do with the tool 'EXECUTE IMMEDIATE'.
And those same type of errors will be made by Mr Ignorant Developer using other tools in Oracle.
Shoddy workmanship is not because of poor tools. Shoddy code is not because of using a specific feature (like execute immediate).
The proper question to ask is thus not "what are the disadvantages of execute immediate", but rather "where should I typically use execute immediate and how?".
Not every developer will know how to use every single tool in the toolbox (I sure don't know all the tools in the Oracle toolbox). So there is nothing wrong with asking.
But asking what is "wrong" with a tool (aka "what are the disadvantages") is in my view seriously missing the point that a tool is there to solve very specific types of problems...
That is what a developer should be after - How to use the tool correctly. -
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 -
How to decide the limit in bulk collect clause
Hi,
we have got a pl/sql application which is performing mass DML including bulk insert,update and merge over millions of data.Now i am little bit confused in deciding the LIMIT in bulk collect clause.is there any way from which i can decide the optimal limit for my bulk collect clause.and i want to know what are the key factors that affects the limit in bulk collect.
eargerly waiting for ur reply...
thanx
somyHello,
Check this example out and it might help you. All depends how much memory you want to allocate to do this job, you have to experiment to find optimal value (see memory consumption, speed of pl/sql block). There is no formula for finding optimal value as every system is configured differently, so once you have to see how is your oracle parameter (memory related ) configured and monitor system while this is running. I had used 500 for aroun 2.8 million rows.
DECLARE
TYPE array
IS
TABLE OF my_objects%ROWTYPE
INDEX BY BINARY_INTEGER;
data array;
errors NUMBER;
dml_errors exception;
error_count NUMBER := 0;
PRAGMA EXCEPTION_INIT (dml_errors, -24381);
CURSOR mycur
IS
SELECT *
FROM t;
BEGIN
OPEN mycur;
LOOP
FETCH mycur BULK COLLECT INTO data LIMIT 100;
BEGIN
FORALL i IN 1 .. data.COUNT
SAVE EXCEPTIONS
INSERT INTO my_new_objects
VALUES data (i);
EXCEPTION
WHEN dml_errors
THEN
errors := sql%BULK_EXCEPTIONS.COUNT;
error_count := error_count + errors;
FOR i IN 1 .. errors
LOOP
DBMS_OUTPUT.put_line( 'Error occurred during iteration '
|| sql%BULK_EXCEPTIONS(i).ERROR_INDEX
|| ' Oracle error is '
|| sql%BULK_EXCEPTIONS(i).ERROR_CODE);
END LOOP;
END;
EXIT WHEN c%NOTFOUND;
END LOOP;
CLOSE mycur;
DBMS_OUTPUT.put_line (error_count || ' total errors');
END;Regards
OrionNet
Edited by: OrionNet on Dec 17, 2008 12:55 AM -
Please help with an embedded query (INSERT RETURNING BULK COLLECT INTO)
I am trying to write a query inside the C# code where I would insert values into a table in bulk using bind variables. But I also I would like to receive a bulk collection of generated sequence number IDs for the REQUEST_ID. I am trying to use RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs clause where :REQUEST_IDs is another bind variable
Here is a full query that use in the C# code
string sql = "INSERT INTO REQUESTS_TBL(REQUEST_ID, CID, PROVIDER_ID, PROVIDER_NAME, REQUEST_TYPE_ID, REQUEST_METHOD_ID, " +
"SERVICE_START_DT, SERVICE_END_DT, SERVICE_LOCATION_CITY, SERVICE_LOCATION_STATE, " +
"BENEFICIARY_FIRST_NAME, BENEFICIARY_LAST_NAME, BENEFICIARY_DOB, HICNUM, CCN, " +
"CLAIM_RECEIPT_DT, ADMISSION_DT, BILL_TYPE, LANGUAGE_ID, CONTRACTOR_ID, PRIORITY_ID, " +
"UNIVERSE_DT, REQUEST_DT, BENEFICIARY_M_INITIAL, ATTENDING_PROVIDER_NUMBER, " +
"BILLING_NPI, BENE_ZIP_CODE, DRG, FINAL_ALLOWED_AMT, STUDY_ID, REFERRING_NPI) " +
"VALUES " +
"(SQ_CDCDATA.NEXTVAL, :CIDs, :PROVIDER_IDs, :PROVIDER_NAMEs, :REQUEST_TYPE_IDs, :REQUEST_METHOD_IDs, " +
":SERVICE_START_DTs, :SERVICE_END_DTs, :SERVICE_LOCATION_CITYs, :SERVICE_LOCATION_STATEs, " +
":BENEFICIARY_FIRST_NAMEs, :BENEFICIARY_LAST_NAMEs, :BENEFICIARY_DOBs, :HICNUMs, :CCNs, " +
":CLAIM_RECEIPT_DTs, :ADMISSION_DTs, :BILL_TYPEs, :LANGUAGE_IDs, :CONTRACTOR_IDs, :PRIORITY_IDs, " +
":UNIVERSE_DTs, :REQUEST_DTs, :BENEFICIARY_M_INITIALs, :ATTENDING_PROVIDER_NUMBERs, " +
":BILLING_NPIs, :BENE_ZIP_CODEs, :DRGs, :FINAL_ALLOWED_AMTs, :STUDY_IDs, :REFERRING_NPIs) " +
" RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs";
int[] REQUEST_IDs = new int[range];
cmd.Parameters.Add(":REQUEST_IDs", OracleDbType.Int32, REQUEST_IDs, System.Data.ParameterDirection.Output);
However, when I run this query, it gives me a strange error ORA-00925: missing INTO keyword. I am not sure what that error means since I am not missing any INTOs
Please help me resolve this error or I would appreciate a different solution
Thank youIt seems you are not doing a bulk insert but rather an array bind.
(Which you will also find that it is problematic to do an INSERT with a bulk collect returning clause (while this works just fine for update/deletes) :
http://www.oracle-developer.net/display.php?id=413)
But you are using array bind, so you simply just need to use a
... Returning REQUEST_ID INTO :REQUEST_IDand that'll return you a Rquest_ID[]
see below for a working example (I used a procedure but the result is the same)
//Create Table Zzztab(Deptno Number, Deptname Varchar2(50) , Loc Varchar2(50) , State Varchar2(2) , Idno Number(10)) ;
//create sequence zzzseq ;
//CREATE OR REPLACE PROCEDURE ZZZ( P_DEPTNO IN ZZZTAB.DEPTNO%TYPE,
// P_DEPTNAME IN ZZZTAB.DEPTNAME%TYPE,
// P_LOC IN ZZZTAB.LOC%TYPE,
// P_State In Zzztab.State%Type ,
// p_idno out zzztab.idno%type
// IS
//Begin
// Insert Into Zzztab (Deptno, Deptname, Loc, State , Idno)
// Values (P_Deptno, P_Deptname, P_Loc, P_State, Zzzseq.Nextval)
// returning idno into p_idno;
//END ZZZ;
//Drop Procedure Zzz ;
//Drop Sequence Zzzseq ;
//drop Table Zzztab;
class ArrayBind
static void Main(string[] args)
// Connect
string connectStr = GetConnectionString();
// Setup the Tables for sample
Setup(connectStr);
// Initialize array of data
int[] myArrayDeptNo = new int[3]{1, 2, 3};
String[] myArrayDeptName = {"Dev", "QA", "Facility"};
String[] myArrayDeptLoc = {"New York", "Chicago", "Texas"};
String[] state = {"NY","IL","TX"} ;
OracleConnection connection = new OracleConnection(connectStr);
OracleCommand command = new OracleCommand (
"zzz", connection);
command.CommandType = CommandType.StoredProcedure;
// Set the Array Size to 3. This applied to all the parameter in
// associated with this command
command.ArrayBindCount = 3;
command.BindByName = true;
// deptno parameter
OracleParameter deptNoParam = new OracleParameter("p_deptno",OracleDbType.Int32);
deptNoParam.Direction = ParameterDirection.Input;
deptNoParam.Value = myArrayDeptNo;
command.Parameters.Add(deptNoParam);
// deptname parameter
OracleParameter deptNameParam = new OracleParameter("p_deptname", OracleDbType.Varchar2);
deptNameParam.Direction = ParameterDirection.Input;
deptNameParam.Value = myArrayDeptName;
command.Parameters.Add(deptNameParam);
// loc parameter
OracleParameter deptLocParam = new OracleParameter("p_loc", OracleDbType.Varchar2);
deptLocParam.Direction = ParameterDirection.Input;
deptLocParam.Value = myArrayDeptLoc;
command.Parameters.Add(deptLocParam);
//P_STATE -- -ARRAY
OracleParameter stateParam = new OracleParameter("P_STATE", OracleDbType.Varchar2);
stateParam.Direction = ParameterDirection.Input;
stateParam.Value = state;
command.Parameters.Add(stateParam);
//idParam-- ARRAY
OracleParameter idParam = new OracleParameter("p_idno", OracleDbType.Int64 );
idParam.Direction = ParameterDirection.Output ;
idParam.OracleDbTypeEx = OracleDbType.Int64;
command.Parameters.Add(idParam);
try
connection.Open();
command.ExecuteNonQuery ();
Console.WriteLine("{0} Rows Inserted", command.ArrayBindCount);
//now cycle through the output param array
foreach (Int64 i in (Int64[])idParam.Value)
Console.WriteLine(i);
catch (Exception e)
Console.WriteLine("Execution Failed:" + e.Message);
finally
// connection, command used server side resource, dispose them
// asap to conserve resource
connection.Close();
command.Dispose();
connection.Dispose();
Console.WriteLine("Press Enter to finish");
Console.ReadKey();
} -
Please help with the query (INSERT RETURNING BULK COLLECT INTO)
I am trying to write a query inside the C# code where I would insert values into a table in bulk using bind variables. But I also I would like to receive a bulk collection of generated sequence number IDs for the REQUEST_ID. I am trying to use RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs clause where :REQUEST_IDs is another bind variable
Here is a full query that use in the C# code
INSERT INTO REQUESTS_TBL(REQUEST_ID, CID, PROVIDER_ID, PROVIDER_NAME, REQUEST_TYPE_ID, REQUEST_METHOD_ID, SERVICE_START_DT, SERVICE_END_DT, SERVICE_LOCATION_CITY, SERVICE_LOCATION_STATE, BENEFICIARY_FIRST_NAME,
BENEFICIARY_LAST_NAME, BENEFICIARY_DOB, HICNUM, CCN, CLAIM_RECEIPT_DT, ADMISSION_DT, BILL_TYPE,
LANGUAGE_ID, CONTRACTOR_ID, PRIORITY_ID, UNIVERSE_DT, REQUEST_DT, BENEFICIARY_M_INITIAL,
ATTENDING_PROVIDER_NUMBER, BILLING_NPI, BENE_ZIP_CODE, DRG, FINAL_ALLOWED_AMT, STUDY_ID, REFERRING_NPI)
VALUES
(SQ_CDCDATA.NEXTVAL, :CIDs, :PROVIDER_IDs, :PROVIDER_NAMEs, :REQUEST_TYPE_IDs,
:REQUEST_METHOD_IDs, :SERVICE_START_DTs, :SERVICE_END_DTs, :SERVICE_LOCATION_CITYs,
:SERVICE_LOCATION_STATEs, :BENEFICIARY_FIRST_NAMEs, :BENEFICIARY_LAST_NAMEs, :BENEFICIARY_DOBs,
:HICNUMs, :CCNs, :CLAIM_RECEIPT_DTs, :ADMISSION_DTs, :BILL_TYPEs, :LANGUAGE_IDs,
:CONTRACTOR_IDs, :PRIORITY_IDs, :UNIVERSE_DTs, :REQUEST_DTs, :BENEFICIARY_M_INITIALs,
:ATTENDING_PROVIDER_NUMBERs, :BILLING_NPIs, :BENE_ZIP_CODEs, :DRGs, :FINAL_ALLOWED_AMTs,
:STUDY_IDs, :REFERRING_NPIs) RETURNING REQUEST_ID BULK COLLECT INTO :REQUEST_IDs
However, when I run this query, it gives me a strange error ORA-00925: missing INTO keyword. I am not sure what that error means since I am not missing any INTOs
Please help me resolve this error or I would appreciate a different solution
Thank youYou cannot use (and do not want to in this case) the BULK COLLECT.
create table for_testing
the_id number not null primary key,
some_data number
declare
l_return_value for_testing.the_id%type;
begin
4
insert into for_testing
the_id,
some_data
values
1,
5
returning the_id into l_return_value;
dbms_output.put_line('the return values is ' || l_return_value);
end;
20 /
the return values is 1
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.02
TUBBY_TUBBZ?Is a simple example. In the future, please use the tags to preserve formatting on your code like i have so it remains readable . -
Difficulties with execute immediate and 'in' clause
Hello all,
I have some SQL that will have to run dynamically, which I can get to work by building a long statement, then getting it hard-parsed
example:
sql_stmt VARCHAR2(256) :=
'select distinct some_id from table1
where lname = ''Smith''
and fname in(''Joe'', ''Joey'', ''Joseph'')
and ssn = 111223333';
execute immediate sql_stmt into new_id_value;
the above state executes fine and returns the desired result.
HOWEVER, when I try to use bind variables (this statement will be called several million times), I get a no rows returned error.
I use bind variables as follows:
sql_stmt VARCHAR2(256);
vlname VARCHAR2(50) := 'Smith';
vssn NUMBER := 111223333;
vfname VARCHAR2(100) := '''Joe'', ''Joey'', ''Joseph''';
sql_stmt :=
'select distinct some_id from table1
where lname = :vlname
and fname in(:vfname)
and ssn = :vssn;
execute immediate sql_stmt into new_id_value
using vlname, vfname, vssn;
I know the issue involves the 'in' clause because I've substituted hardcoded values in and it has worked.
any suggestions?Well maybe its all a little confusing, does an end to end demo make it any clearer Mr Bidness?
SQL> create or replace type tabstr_t as table of varchar2(4000)
2 /
Type created.
SQL> create or replace function tabstr (
2 p_str in varchar2,
3 p_sep in varchar2 default ','
4 )
5 return tabstr_t
6 is
7 l_str long := p_str || p_sep;
8 l_tabstr tabstr_t := tabstr_t();
9 begin
10 while l_str is not null loop
11 l_tabstr.extend(1);
12 l_tabstr(l_tabstr.count) := rtrim(substr(
13 l_str,1,instr(l_str,p_sep)),p_sep);
14 l_str := substr(l_str,instr(l_str,p_sep)+1);
15 end loop;
16 return l_tabstr;
17 end;
18 /
Function created.
SQL> var s varchar2(100)
SQL> exec :s := 'king,turner,ward'
PL/SQL procedure successfully completed.
SQL> select ename, sal from emp
2 where ename in (
3 select upper(column_value) from
4 table(cast(tabstr(:s) as tabstr_t))
5 );
ENAME SAL
KING 5000
TURNER 1500
WARD 1250
SQL> exec :s := 'jones,blake,clark'
PL/SQL procedure successfully completed.
SQL> /
ENAME SAL
BLAKE 2850
CLARK 2450
JONES 2975 -
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.HalderThatmeans 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. -
Unable to INSERT PL/SQL record with EXECUTE IMMEDIATE
Hi All,
I am selecting data from a source table and after some modification inserting into a target table. Source and target table name are available at run time. You can say only source table structure is fixed.
I have crated a pl/sql table of type source record and inserting record by record in target table using execute immediate. But I am not able to write
EXECUTE IMMEDIATE string USING pl_sql_table(index); and getting error as
PLS-00457: expressions have to be of SQL types
Please see the part of code below. Is it possible to use FORALL with dynamic sql like
FORALL pl_sql_table.FIRST .. pl_sql_table.COUNT
EXECUTE IMMEDIATE .... pl_sql_table(j); -- Like this.
Please suggest why I am not able to write record here. I also want to replace 'INSERT in a loop' with a single INSERT statement out of the loop, to upload whole pl_sql table into target table in one go.
Thanks,
Ravi
DECLARE
TYPE rec_tab_CMP IS RECORD
model_id NUMBER(38),
absolute_rank NUMBER(5)
v_rec_tab_CMP rec_tab_CMP;
TYPE t_rec_tab_CMP IS TABLE OF v_rec_tab_CMP%TYPE INDEX BY BINARY_INTEGER;
v_records_CMP t_rec_tab_CMP;
rc SYS_REFCURSOR;
v_old_table_name VARCHAR2(30); -- passed from parameter
v_new_table_name VARCHAR2(30); -- passed from parameter
dyn_str VARCHAR2(500);
v_columns_str VARCHAR2(200) := ' model_id, absolute_rank ';
BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE '|| v_new_table_name || ' AS SELECT * FROM ' || v_old_table_name ||' WHERE 1 = 2 ' ;
OPEN rc FOR 'SELECT '|| v_columns_str ||' FROM '|| v_old_table_name;
FETCH rc BULK COLLECT INTO v_records_CMP;
FOR j IN 1..v_records_CMP.COUNT
LOOP
v_records_CMP(j).model_id := 1; -- Do someting here, This thing can be performed in SQL stmt directly.
dyn_str := 'INSERT INTO '|| v_new_table_name ||' ( '|| v_columns_str || ' ) VALUES (:1, :2) ';
EXECUTE IMMEDIATE dyn_str USING v_records_CMP(j).model_id ,
v_records_CMP(j).absolute_rank ;
-- Here in place of two columns I want to use one record like
-- EXECUTE IMMEDIATE dyn_str USING v_records_CMP(j);
-- But it is giving me error like
-- EXECUTE IMMEDIATE dyn_str USING v_records_st(j);
-- PLS-00457: expressions have to be of SQL types
END LOOP;
CLOSE rc;
END;
/You cannot bind PL/SQL record types to dynamic SQL.
Possibly you could work around this by declaring the INDEX-BY table of records at package specification level, e.g.
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> CREATE PACKAGE package_name
2 AS
3 TYPE tt_emp IS TABLE OF emp%ROWTYPE;
4 t_emp tt_emp;
5 END package_name;
6 /
Package created.
SQL> CREATE TABLE new_emp
2 AS
3 SELECT *
4 FROM emp
5 WHERE 1 = 0;
Table created.
SQL> DECLARE
2 v_table_name user_tables.table_name%TYPE := 'NEW_EMP';
3 BEGIN
4 SELECT *
5 BULK COLLECT INTO package_name.t_emp
6 FROM emp;
7
8 EXECUTE IMMEDIATE
9 'BEGIN ' ||
10 ' FORALL i IN 1 ..package_name.t_emp.COUNT ' ||
11 ' INSERT INTO ' || v_table_name ||
12 ' VALUES package_name.t_emp (i); ' ||
13 'END;';
14 END;
15 /
PL/SQL procedure successfully completed.
SQL> SELECT empno, ename
2 FROM new_emp;
EMPNO ENAME
7369 SMITH
7499 ALLEN
7521 WARD
7566 JONES
7654 MARTIN
7698 BLAKE
7782 CLARK
7788 SCOTT
7839 KING
7844 TURNER
7876 ADAMS
7900 JAMES
7902 FORD
7934 MILLER
14 rows selected.
SQL> -
Problem with execute immediate
hi,
Oracle gurus,
when i execute the following statement in a procedure it is not getting executed and it is getting strucked,
pls provide me some suggestions.
This is very urgent.
is there any proble with commented lines?
EXECUTE IMMEDIATE 'select
oh.account_no,
p.ord_line_no,
o.ord_no,
p.lot ,
(pr1.each_qty/pr.each_qty),
:p_comp_id ,
p.cube,
sysdate,
SYSDATE,--p.pick_date,
SYSDATE,--pw.date_time_released,
pr.each_qty,
:p_ebiz_appown_no,
p.ord_cntrl_no,
oh.ord_cntrl_no,
nvl(p.prod_no,0),
:p_ebiz_user_no,
nvl(sl.wdth,0) * nvl(sl.dpth,0),
decode(s.haz_mat_class,null,''N'',''Y''),
''N'',
p.ord_line_no,
p.loc,
p.lp,
(nvl(p.qty,0)/nvl(pr.each_qty,1)),
1,
(nvl(p.qty,1)/pr1.each_qty),--ceil(nvl(p.qty,1)/pr1.each_qty),
oh.ord_prio,
oh.ord_type,
o.ord_no ,
nvl(p.pkg_no,0),
:p_task_no,
p.pick_line,
pl.pickline_type,
to_char(nvl(p.transact_id,0)),
p.qty ,
oh.ord_type,
:p_site_id,
nvl(s.sku,''SKU ERROR''),
s.sku_desc1_35 ,
s.prod_fam ,
s.prod_cat,
o.prod_stat,
2 ,
SYSDATE,--nvl(p.pick_date,sysdate),
bt.task_desc ,
bt.task_type,
null,--p.pick_date,
sl.type_stor_equip ,
o.uom,
p.wght
from [email protected] pr,
mast_abbtype bt,
mast_company bc,
[email protected] sl,
sku@'||l_dblink||' s,
picks@'||l_dblink||' p,
ordline'||l_dblink||' o,
ordhead@'||l_dblink||' oh,
prodqty@'||l_dblink||' pr1,
pickwave@'||l_dblink||' pw,
pickline@'||l_dblink||' pl
where decode(bt.comp_id,null,:p_comp_id,bt.comp_id)=:p_comp_id
and decode(bt.site_id,null,:p_site_id,bt.site_id)=:p_site_id
and bt.task_type = ''PICK''--decode(null,''PICK'',''PIK'',''PIK'')
and bc.delete_flag=''N''
and bt.active_flag=''Y''
and bc.active_flag=''Y''
and bt.delete_flag=''N'' --and nvl(bc.ebiz_appown_no,-1) = nvl(bt.ebiz_appown_no,-1)
and nvl(bc.ebiz_appown_no,-1) =1nvl(p_ebiz_appown_no,-1)
and nvl(p.failed_pick_flg,''N'') != ''Y''
and (bt.site_id =:p_site_id or bt.site_id is null)
and p.cmpl_time is not null
and p.wave_no = pw.wave_no
and s.prod_no = p.prod_no
and pr.prod_no = s.prod_no
and pr.pkg_no = p.pkg_no
--and p.ord_cntrl_no in (select ord_cntrl_no from [email protected] where ord_no = nvl(NULL, ord_no))
--nvl(p_ebiz_po_no, p.ord_cntrl_no)
-- and p.ord_cntrl_no = nvl(p_rec_cntrl_no, p.ord_cntrl_no)
and nvl(p.prod_no,0) = nvl(:p_ebiz_sku_no, nvl(p.prod_no,0))
and oh.ord_type = nvl(NULL, oh.ord_type)
and nvl(o.prod_stat, ''~'') = nvl(:p_sku_status, nvl(o.prod_stat, ''~''))
and p.lp = nvl(:p_lp, p.lp)
and nvl(p.lot, ''~'') = nvl(:p_batch_no, nvl(p.lot, ''~''))
and pr.logical_case_flg = ''Y''
--and nvl(bt.site_id,''~'') = nvl(bc.site_id,''~'')
and s.comp_code = p.comp_code
and sl.loc = p.loc
-- and nvl(pick_time,0) != ''9898''
and p.ord_cntrl_no = o.ord_cntrl_no
and p.ord_line_no = o.ord_line_no
and o.ord_cntrl_no = oh.ord_cntrl_no
and trunc(p.pick_date) between trunc(nvl(sysdate-10000,p.pick_date)) and trunc(nvl(sysdate,p.pick_date))
and nvl(p.pick_date,sysdate)<= nvl(bc.effective_date,sysdate)
and p.ord_cntrl_no = decode(null,null,p.ord_cntrl_no,null)
and pr1.pkg_no = pr.pkg_no
and pr1.prod_no = pr.prod_no
and pr1.logical_plt_flg = ''Y'' '
--and p.pick_line = pl.line_id '
Bulk collect into
l_account_no,
l_asn_line_no,
l_asn_no,
l_batch_no,
l_cases_per_pallet,
l_comp_id,
l_cube,
l_currdate,
l_date_time_ended,
l_date_time_started,
l_eachs_per_case,
l_ebiz_appown_no,
l_ebiz_asn_no,
l_ebiz_cntrl_no,
l_ebiz_sku_no,
l_ebiz_user_no,
l_footage,
l_hazmat_flag,
l_intf_conf_flag,
l_line_no,
l_location,
l_lp,
l_no_of_cases,
l_no_of_units,
l_no_plts,
l_order_priority,
l_order_type,
l_ord_no,
l_packcode,
l_parent_task_no,
l_pickline_id,
l_pickline_type,
l_po_no,
l_qty,
l_rcv_type,
l_site_id,
l_sku,
l_skudesc1,
l_skufam,
l_skugroup,
l_sku_status,
l_status_flag,
l_task_date,
l_task_desc,
l_task_type,
l_time,
l_type_stor_equip,
l_uom_id,
l_wght
using p_comp_id,p_ebiz_appown_no,p_ebiz_user_no,p_task_no,
p_site_id,p_comp_id,p_comp_id,p_site_id,p_site_id, p_site_id,p_ebiz_sku_no,p_sku_status,p_lp,p_batch_no;
regards RR.hi,
again iam sending the same query for ur easy reference.
pls treat it urgent.
EXECUTE IMMEDIATE 'select
oh.account_no,p.ord_line_no, o.ord_no, p.lot ,
(pr1.each_qty/pr.each_qty), :p_comp_id ,p.cube,
sysdate, SYSDATE,--p.pick_date, SYSDATE,--pw.date_time_released,
r.each_qty,:p_ebiz_appown_no, p.ord_cntrl_no,oh.ord_cntrl_no,
nvl(p.prod_no,0), :p_ebiz_user_no,nvl(sl.wdth,0) * nvl(sl.dpth,0),
decode(s.haz_mat_class,null,''N'',''Y''),''N'',p.ord_line_no,p.loc,p.lp,
(nvl(p.qty,0)/nvl(pr.each_qty,1)), 1,
(nvl(p.qty,1)/pr1.each_qty),--ceil(nvl(p.qty,1)/pr1.each_qty),
oh.ord_prio, oh.ord_type,o.ord_no ,nvl(p.pkg_no,0),
:p_task_no,p.pick_line,pl.pickline_type, to_char(nvl(p.transact_id,0)),
p.qty , oh.ord_type,:p_site_id, nvl(s.sku,''SKU ERROR''),
s.sku_desc1_35 , s.prod_fam , s.prod_cat,
o.prod_stat, 2 , SYSDATE,--nvl(p.pick_date,sysdate),
bt.task_desc ,bt.task_type, null,--p.pick_date,sl.type_stor_equip ,
o.uom, p.wght
FROM
[email protected] pr,
mast_abbtype bt,
mast_company bc,
[email protected] sl,
sku@'||l_dblink||' s,
picks@'||l_dblink||' p,
ordline'||l_dblink||' o,
ordhead@'||l_dblink||' oh,
prodqty@'||l_dblink||' pr1,
pickwave@'||l_dblink||' pw,
pickline@'||l_dblink||' pl
WHERE
decode(bt.comp_id,null,:p_comp_id,bt.comp_id)=:p_comp_id
and decode(bt.site_id,null,:p_site_id,bt.site_id)=:p_site_id
and bt.task_type = ''PICK''--decode(null,''PICK'',''PIK'',''PIK'')
and bc.delete_flag=''N''
and bt.active_flag=''Y''
and bc.active_flag=''Y''
and bt.delete_flag=''N''
and nvl(p.failed_pick_flg,''N'') != ''Y''
and (bt.site_id =:p_site_id or bt.site_id is null)
and p.cmpl_time is not null
and p.wave_no = pw.wave_no
and s.prod_no = p.prod_no
and pr.prod_no = s.prod_no
and pr.pkg_no = p.pkg_no
and nvl(p.prod_no,0) = nvl(:p_ebiz_sku_no, nvl(p.prod_no,0))
and oh.ord_type = nvl(NULL, oh.ord_type)
and nvl(o.prod_stat, ''~'') = nvl(:p_sku_status, nvl(o.prod_stat, ''~''))
and p.lp = nvl(:p_lp, p.lp)
and nvl(p.lot, ''~'') = nvl(:p_batch_no, nvl(p.lot, ''~''))
and pr.logical_case_flg = ''Y''
and s.comp_code = p.comp_code
and sl.loc = p.loc
and p.ord_cntrl_no = o.ord_cntrl_no
and p.ord_line_no = o.ord_line_no
and o.ord_cntrl_no = oh.ord_cntrl_no
and trunc(p.pick_date) between trunc(nvl(sysdate-10000,p.pick_date)) and trunc(nvlsysdate,p.pick_date))
and nvl(p.pick_date,sysdate)<= nvl(bc.effective_date,sysdate)
and p.ord_cntrl_no = decode(null,null,p.ord_cntrl_no,null)
and pr1.pkg_no = pr.pkg_no
and pr1.prod_no = pr.prod_no
and pr1.logical_plt_flg = ''Y'' '
Bulk collect into
l_account_no,
l_asn_line_no,
l_asn_no,
l_batch_no,
l_cases_per_pallet,
l_comp_id,
l_cube,
l_currdate,
l_date_time_ended,
l_date_time_started,
l_eachs_per_case,
l_ebiz_appown_no,
l_ebiz_asn_no,
l_ebiz_cntrl_no,
l_ebiz_sku_no,
l_ebiz_user_no,
l_footage,
l_hazmat_flag,
l_intf_conf_flag,
l_line_no,
l_location,
l_lp,
l_no_of_cases,
l_no_of_units,
l_no_plts,
l_order_priority,
l_order_type,
l_ord_no,
l_packcode,
l_parent_task_no,
l_pickline_id,
l_pickline_type,
l_po_no,
l_qty,
l_rcv_type,
l_site_id,
l_sku,
l_skudesc1,
l_skufam,
l_skugroup,
l_sku_status,
l_status_flag,
l_task_date,
l_task_desc,
l_task_type,
l_time,
l_type_stor_equip,
l_uom_id,
l_wght
using p_comp_id,p_ebiz_appown_no,p_ebiz_user_no,p_task_no,
p_site_id,p_comp_id,p_comp_id,p_site_id,p_site_id, p_site_id,p_ebiz_sku_no,p_sku_status,p_lp,p_batch_no;
here l_dblink contains database link
regards
RR
Maybe you are looking for
-
The problem is encountered when we try to open the file from external vendor.
We are using Adobe illustrator CS3 with Patch 13.0.2. in MAC PC with OS 10.4.11. We tried to open the file generated from external vendor. This file is made by CS4/CS5 & downgraded to CS3 because we are using different version of CS package. When we
-
What causes itunes application to stop at loading store?
I'm using Win7 with IE8 (32 & 64 Bit). When I launch the iTunes Application all is well. I can go to "View my Apple ID" (which I thnik is in the Apple Store). But when I try to go to the Store, I get the following message. "iTunes has stopped. Window
-
Adapter engine queue monitoring
Hi All, I have one doubt about adapter engine queue. We can see adapter engine queue in RWB->Message Monitoring-> Adapter engine-> Display . Here in queue if one message goes in to system error status, remaining all messages from that queue goes on
-
How i can see the calendar appoinments one year ago.
How i can see the appoinments one year old, thanks.
-
EDI: Partner profile not available for the Ack received
Hi All, All the scenarios are IDOC -->XI --> File We have different scenarios of IDOC to File, where SAP sends IDOC to two (we have 5 here letu2019s say 2) diff FTP locations one say FTP1 and other FTP2 and we used 3 business systems in SLD. 1)