Bulk Collect into is storing less no of rows in collection when using LIMIT?
I have written the following anonymous PL SQL Block. However, the line dbms_output.put_line(total_tckt_col.LAST) gives me output as 366 (in DBMS_OUTPUT is SQL Developer) which is correct when no limit is set. If the limit is set to 100 in the FETCH statement then dbms_output.put_line(total_tckt_col.LAST) gives me 66. What I am doing wrong here?
DECLARE
CURSOR cur_total_tckt
is
select t.ticket_id ticket_id, t.created_date created_date, t.created_by created_by, t.ticket_status ticket_status,
t.last_changed last_changed, h.created_date closed_date
from n01.cc_ticket_info t
inner join n01.cc_ticket_status_history h
on (t.ticket_id = h.ticket_id)
where t.last_changed >= '6/28/2012 17:28:59' and t.last_changed < (sysdate + interval '1' day);
type total_tckt_colcn
is
TABLE OF cur_total_tckt%rowtype;
total_tckt_col total_tckt_colcn;
total_coach_col total_tckt_colcn;
begin
total_tckt_col := total_tckt_colcn ();
total_coach_col := total_tckt_colcn ();
OPEN cur_total_tckt;
loop
fetch cur_total_tckt bulk collect into total_tckt_col;
-- fetch cur_total_tckt bulk collect into total_tckt_col limit 100;
EXIT
WHEN (cur_total_tckt%NOTFOUND);
END LOOP ;
CLOSE cur_total_tckt;
dbms_output.put_line(total_tckt_col.LAST);
FOR i IN total_tckt_col.first..total_tckt_col.last
LOOP
dbms_output.put_line(i);
END LOOP;
end;
Ishan wrote:
Here is modified version of your code on standard EMP table in scott schema.
Did you test it? All you demonstrate is last batch has 4 rows. But you print it outsite the loop. This way if last batch is incomplete (has less than limit rows) your loop doesn't process last batch. Assume you want to print enames:
DECLARE
CURSOR cur_total_tckt
IS
select ename
from emp; -- I have a total of 14 records in this table
type total_tckt_colcn
is
TABLE OF cur_total_tckt%rowtype;
total_tckt_col total_tckt_colcn;
BEGIN
total_tckt_col := total_tckt_colcn ();
OPEN cur_total_tckt;
LOOP
fetch cur_total_tckt bulk collect into total_tckt_col limit 5;
EXIT WHEN cur_total_tckt%NOTFOUND;
FOR v_i IN 1..total_tckt_col.count LOOP
dbms_output.put_line(total_tckt_col(v_i).ename);
END LOOP;
END LOOP ;
CLOSE cur_total_tckt;
END;
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
PL/SQL procedure successfully completed.
SQL>
As you can see, it didn't print last batch. Why? Because NOTFOUND is set to true if exact number of rows you asked to fetch was not fetched. So last batch has 4 rows while code asks to fetch 5. Therefore, NOTFOUND is set to true and code exits before processing that last batch. So you have to repeat processing code again outside the loop:
DECLARE
CURSOR cur_total_tckt
IS
select ename
from emp; -- I have a total of 14 records in this table
type total_tckt_colcn
is
TABLE OF cur_total_tckt%rowtype;
total_tckt_col total_tckt_colcn;
BEGIN
total_tckt_col := total_tckt_colcn ();
OPEN cur_total_tckt;
LOOP
fetch cur_total_tckt bulk collect into total_tckt_col limit 5;
EXIT WHEN cur_total_tckt%NOTFOUND;
FOR v_i IN 1..total_tckt_col.count LOOP
dbms_output.put_line(total_tckt_col(v_i).ename);
END LOOP;
END LOOP ;
FOR v_i IN 1..total_tckt_col.count LOOP
dbms_output.put_line(total_tckt_col(v_i).ename);
END LOOP;
CLOSE cur_total_tckt;
END;
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
PL/SQL procedure successfully completed.
SQL>
But you must agree repeating that processing code twice isn't best solution. When using BULK COLLECT LIMIT we should exit not by NOTFOUND but rather by collection.count = 0:
DECLARE
CURSOR cur_total_tckt
IS
select ename
from emp; -- I have a total of 14 records in this table
type total_tckt_colcn
is
TABLE OF cur_total_tckt%rowtype;
total_tckt_col total_tckt_colcn;
BEGIN
total_tckt_col := total_tckt_colcn ();
OPEN cur_total_tckt;
LOOP
fetch cur_total_tckt bulk collect into total_tckt_col limit 6;
EXIT WHEN total_tckt_col.count = 0;
FOR v_i IN 1..total_tckt_col.count LOOP
dbms_output.put_line(total_tckt_col(v_i).ename);
END LOOP;
END LOOP ;
CLOSE cur_total_tckt;
END;
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
PL/SQL procedure successfully completed.
SQL>
SY.
Similar Messages
-
For example access eBay with Firefox and launch a search on the word Frankenstein: you'll get something like 23,671 results (if you search in ''All categories''). Then quit the Firefox browser and load Microsoft Internet Explorer instead; access eBay again and repeat the very same search: this time you'll get 25,383 results. These are reral figures that I tried at 19:21 on March 20, 2014. Why does a search on eBay through Firefox report less hits than the very same search through Internet Explorer? Using Firefox rather than Microsoft Internet Explorer automatically means missing hits/results/items on eBay: that doesn't make sense but it does happen. Why is it so? Thank you, somebody, for shedding light on this problem.
Try this steps and try to load the same once again!!!
Hello,
Many site issues can be caused by corrupt cookies or cache. In order to try to fix these problems, the first step is to clear both cookies and the cache.
Note: ''This will temporarily log you out of all sites you're logged in to.''
To clear cache and cookies do the following:
#Go to Firefox > History > Clear recent history or (if no Firefox button is shown) go to Tools > Clear recent history.
#Under "Time range to clear", select "Everything".
#Now, click the arrow next to Details to toggle the Details list active.
#From the details list, check ''Cache'' and ''Cookies'' and uncheck everything else.
#Now click the ''Clear now'' button.
Further information can be found in the [[Clear your cache, history and other personal information in Firefox]] article.
Did this fix your problems? Please report back to us!
Thank you. -
Stored procedure call returns null result set when using temp table in sp!
Here's a really odd problem...
SQL Server stored procedure called sp_Test takes 1 input INT. Here is the code I call it with
cStmt = connection.prepareCall("{call sp_Test(?)}");
cStmt.setInt(1, 44);
cStmt.execute();
rs = cStmt.getResultSet();When the body of the stored proc is
CREATE PROCEDURE sp_Test(@i_NodeID INT)
AS
BEGIN
SELECT node_id FROM tbl_NavTree
END
GOthe query works and I get all node_id back in rs
BUT when the body of the stored proc is
CREATE PROCEDURE sp_Test(@i_NodeID INT)
AS
BEGIN
CREATE TABLE #Descendants(
descendant_id INT
SELECT node_id FROM tbl_NavTree
DROP TABLE #Descendants
END
GOThe rs comes back as NULL. Really really weird if you ask me. I also tried removing the DROP TABLE line just in case the SELECT had to be the last statement but still NULL.
Final note is that BOTH the above stored proc bodies work when executed within SQL Server query analyser.
Must be JDBC .. what can it be!??DROP TABLE #DescendantsMS SQL Server - right?
Then don't drop the table.
From the MS docs for "create table"
Local temporary tables are visible only in the current session;
A local temporary table created in a stored procedure is dropped automatically when the stored procedure completes. The table can be referenced by any nested stored procedures executed by the stored procedure that created the table. The table cannot be referenced by the process which called the stored procedure that created the table. -
I want to execute a stored procedure using ssis.But the problem I am having is that there is a table with 200 rows with only
single column.Now i want to execute stored procedure using value one by one from table .once the stored procedure is executed with top value from table i also want to delete that topmost column value and execute with next table value.and store the result in
text file.
please help me..or provide a package.If you want to do it in SSIS, a way to do this is by using For Each Loop as mentioned above.
Create 1 OBJECT type variable (list of values) and one STRING type variable (one value at a time)
Use EXE SQL Task with ResultSet = FULL RESULT SET and query = SELECT COL FROM TABLE ORDER BY COL ASC...output this to the OBJECT type variable
Next, a For Each loop container with Foreach ADO Enumerator, ADO object source variable = Object type variable and map that to String type variable with index = 0.
Within your for each loop container, select another EXEC SQL Task and pass in an input parameter (the String type variable) and query = EXEC PROC ? -- WHERE ? = String type variable.
This will execute your store procedure just for that one value out of the whole list.
Now within the same For Each loop, select another EXEC SQL Task and again pass in an input parameter (the same String type variable) and query = DELETE FROM TABLE WHERE COL = ? -- WHERE ? = the current value
The above process should A) get the list of values from the table B) pick one value at a time and execute the proc and delete and right after delete that value from the table.
Hope this helps.
-- some further investigation/tweaking may require but it should help you get started. -
ISSUE: Storing password for FTP account in Keychain when using Finder
Hi,
I recently needed to connect to an FTP server to put some photo files on a server. I found out that you can connect to a FTP server using Finder>Connect to server. I manage to connect to the FTP server by typing <username>@ftp.<anyserver>.<domain> and after it prompted me to enter a password it connects to the server. However, when I check "Store password in keychain" it *does not store the password in keychain*. Each time I want to connect to the server I have to retype the password. I used Keychain first aid to verify the chain, but it reports everything is OK. Even when I manually add a keychain entry using FTP server details and credentials, the challenge window reappears each time I connect to the FTP server.
Any suggestions on how to solve this or is it a bug as I noticed similar problems by other users using other applications (mail, safari)?
Thanks!I am having this exact same issue. I am trying to setup Automator to go out and retrieve files from an FTP folder and everything is working perfectly except for the fact that I have enter my credentials each time even thought I have checked the box to remember the password. I have this issue on multiple ftp servers so I don't think it is something that is "server-specific"
-
Bulk collect into using vector in where clause
Hi,
I have a java stored procedure which takes an array as input and returns an array as output.
I want to select a column in to a collection of array, using array as the select criteria.
For example
create or replace type My_list as table of varchar(20);
create or replace type outarray as table of BLOB;
create or replace function myfunction ( inputlist My_list)
return outarray
AS
o_data := outarray();
BEGIN
SELECT mycolumn from mytable BULK COLLECT INTO o_data where my_creteria=inputlist
retrun o_data;
END;
Unless I use FORALL I can not retrieve the inputlist values. I am not sure how I can use the bulk collect and forall in the same statement?
My data is arranged such that , for each value in the inputlist one row will be fetched. I want to fetch all these rows at one go using the inputlist as select criteria,
I can use the for i in inputlist.first .. inputlist.LAST and iterate the inputlist but that process is quite expensive interms of the latency.
You help in optimizing my query would be highly appreciated.
Regards,
SyamThat only leaves ugly solutions, like:
<ul>
<li>Using dynamic SQL to create a temporary table, doing a bulk insert of the incoming array and then reading the table values using a subquery with the IN opeartor.</li>
<li>Building a dyanmic list, like ('value1','value2', ..) and use it with the IN operator, this is a variable list and requires DBMS_SQL package.</li>
<li>Ignore the bulk operations. :-(</li>
</ul> -
SELECT bulc collect into takes to long
Hi,
by the following statement I get Data from a Remote Database and do a update on a local table via a sql procedure
This part of the proecure takes about 70 seconds.
select /*+ RULE */ id, messaging_state, recipient, messaging_type, manual, node, mess_arch_id, text, alarm_id, time_start, time_end
bulk collect into marcupids, marcstats, marcrecips, marctypes, marcmans, marcnodes, marcmssarc, marctexts, marcalarms, marctstrts, marctends
from m_testdata@Remote_database marcs
where marcs.in_archive = 1 and exists (select id from m_testdata rm where rm.id = marcs.id);
cnt := sql%rowcount;
if cnt > 0 then
forall i in marcupids.first..marcupids.last
update m_testdata set messaging_state = marcstats(i), time_end = marctends(i) where id = marcupids(i);
But if I do just the select like the following without the "bulc collect into" it takes less then a second.
select /*+ RULE */ id, messaging_state, recipient, messaging_type, manual, node, mess_arch_id, text, alarm_id, time_start, time_end
marctexts, marcalarms, marctstrts, marctends
from m_testdata@Remote_database marcs
where marcs.in_archive = 1 and exists (select id from m_testdata rm where rm.id = marcs.id);
Can somebody tell me the reason why it takes so long when executed by a procedure/Job , Strange is that this problem does not appear on all installation with compareable size of m_testdata on the remote and the local database. On Some installations it runs in less than a second with the "bulc collect into" and in some it takes more than 70 seconds:
Any Idea?
Kind Regards
AndreHi,
Have you tried adding the statements in a batch and then executing the batch?
You wouldn't want to add all the records in a batch as it would slow down your client. Instead, experiment to find out what would be the ideal number of records to add in a batch before executing them.
I hope this helps.
Hi, I have an Oracle 8 on a Unix platform which I access with Java 1.3 jdbc code over the network. I write about 9000 records, each record consisting of three fields with respective lengths of 10, 10 and 1. It takes an extremely long time to put these records into the database, for example 20-30 minutes or even more. Is it normal that its taking so long and if not what can I do to speed it? Tx much,
EB -
Use of FOR Cursor and BULK COLLECT INTO
Dear all,
in which case we prefer to use FOR cursor and cursor with BULK COLLECT INTO? The following contains two block that query identically where one is using FOR cursor, the other is using BULK COLLECT INTO . Which one that performs better given in the existing task? How do we measure performance between these two?
I'm using sample HR schema:
declare
l_start number;
BEGIN
l_start:= DBMS_UTILITY.get_time;
dbms_lock.sleep(1);
FOR employee IN (SELECT e.last_name, j.job_title FROM employees e,jobs j
where e.job_id=j.job_id and e.job_id LIKE '%CLERK%' AND e.manager_id > 120 ORDER BY e.last_name)
LOOP
DBMS_OUTPUT.PUT_LINE ('Name = ' || employee.last_name || ', Job = ' || employee.job_title);
END LOOP;
DBMS_OUTPUT.put_line('total time: ' || to_char(DBMS_UTILITY.get_time - l_start) || ' hsecs');
END;
declare
l_start number;
type rec_type is table of varchar2(20);
name_rec rec_type;
job_rec rec_type;
begin
l_start:= DBMS_UTILITY.get_time;
dbms_lock.sleep(1);
SELECT e.last_name, j.job_title bulk collect into name_rec,job_rec FROM employees e,jobs j
where e.job_id=j.job_id and e.job_id LIKE '%CLERK%' AND e.manager_id > 120 ORDER BY e.last_name;
for j in name_rec.first..name_rec.last loop
DBMS_OUTPUT.PUT_LINE ('Name = ' || name_rec(j) || ', Job = ' || job_rec(j));
END LOOP;
DBMS_OUTPUT.put_line('total time: ' || to_char(DBMS_UTILITY.get_time - l_start) || ' hsecs');
end;
/In this code, I put timestamp in each block, but they are useless since they both run virtually instantaneous...
Best regards,
ValIf you want to get 100% benifit of bulk collect then it must be implemented as below
declare
Cursor cur_emp
is
SELECT e.last_name, j.job_title
FROM employees e,jobs j
where e.job_id=j.job_id
and e.job_id LIKE '%CLERK%'
AND e.manager_id > 120
ORDER BY e.last_name;
l_start number;
type rec_type is table of varchar2(20);
name_rec rec_type;
job_rec rec_type;
begin
l_start:= DBMS_UTILITY.get_time;
dbms_lock.sleep(1);
/*SELECT e.last_name, j.job_title bulk collect into name_rec,job_rec FROM employees e,jobs j
where e.job_id=j.job_id and e.job_id LIKE '%CLERK%' AND e.manager_id > 120 ORDER BY e.last_name;
OPEN cur_emp;
LOOP
FETCH cur_emp BULK COLLECT INTO name_rec LIMIT 100;
EXIT WHEN name_rec.COUNT=0;
FOR j in 1..name_rec.COUNT
LOOP
DBMS_OUTPUT.PUT_LINE ('Name = ' || name_rec(j) || ', Job = ' || job_rec(j));
END LOOP;
EXIT WHEN cur_emp%NOTFOUND;
END LOOP;
CLOSE cur_emp;
DBMS_OUTPUT.put_line('total time: ' || to_char(DBMS_UTILITY.get_time - l_start) || ' hsecs');
end;
/ -
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();
} -
Procedure failed while using bulk collect into clause and works with cursor
hi all,
I am using "BULK collect into" clause in my procedure and it is failing after 21 minutes and gives the error "end of file communication channel".
after this error comes when i tried to connect database it is giving following error.
ORA -01034 - Oracle not available.
ORA- 27101 - shared memory realm does not exist.
svr4- error :2 : No such file or directory.
when i use cursor instead of BULK COLLECT INTO clause it is running successful.
Following code is working with cursor.
procedure work_kiosk_full(an_jobid in number ,ac_sqlcode out varchar2 ,ac_sqlerrm out varchar2) is
ld_curr_time Date;
cursor cur_work_kiosk is
select distinct jt.jt_id AS jt_id,
NVL ((ROUND ((jt_date_completed - jt_date_requested) * 24, 2)
0
) AS actual_hrs_to_complete,
NVL ((ROUND ((jt_date_responded - jt_date_requested) * 24, 2)
0
) AS actual_hrs_to_respond,
peo1.peo_name AS agent_name,
peo1.peo_user_name AS asagent_soe_id,
le.lglent_desc AS ap_system,
' ' AS assign_work_request_comment,
DECODE (jt.jt_bill_id,
138802, 'CLIENT BILLABLE',
138803, 'CONTRACTED',
138804, 'INTERNAL BILLABLE',
NULL, ' '
) AS billable,
bl.bldg_name_cc AS building, bl.bldg_id_ls AS building_id,
DECODE (bl.bldg_active_cc,
'Y', 'ACTIVE',
'INACTIVE'
) AS building_status,
DECODE (jt.jt_wrk_cause_id,
141521, 'STANDARD WEAR AND TEAR',
141522, 'NEGLIGENCE',
141523, 'ACCIDENTAL',
141524, 'MECHANICAL MALFUNCTION',
141525, 'OVERSIGHT',
141526, 'VANDAL',
141527, 'STANDARD',
141528, 'PROJECT WORK',
6058229, 'TEST',
NULL, ' '
) AS cause_type,
' ' AS comments, peo3.peo_name AS completed_by,
jt.jt_requestor_email AS contact_email,
jt.jt_requestor_name_first
|| ' '
|| jt.jt_requestor_name_last AS contact_name,
jt.jt_requestor_phone AS contact_phone,
cc.cstctrcd_apcode AS corp_code,
cc.cstctrcd_code AS cost_center,
jt.jt_date_closed AS date_closed,
jt.jt_date_completed AS date_completed,
jt.jt_date_requested AS date_requested,
jt.jt_date_responded AS date_responded,
jt.jt_date_response_ecd AS date_response_ecd,
jt.jt_date_scheduled AS date_scheduled,
DECODE (jt.jt_def_id,
139949, 'WTG VENDOR RESPONSE',
139950, 'WAITING ON PARTS',
139951, 'LABOR AVAILABILITY',
139952, 'DEFERRED- HI PRI WORK',
139953, 'WTG APPROVAL',
139954, 'FUNDING REQUIRED',
139955, 'ACCESS DENIED',
139956, 'WTG MATERIAL',
NULL, ' '
) AS deferral_reason,
jt.jt_description AS description,
jt.jt_date_resched_ecd AS ecd,
fmg.facility_manager AS facility_manager,
fl.floors_text AS FLOOR, gl.genled_desc AS general_ledger,
' ' AS kiosk_date_requested, ' ' AS kiosk_dispatch_confirmed,
' ' AS kiosk_dispatched,
eqp.equip_customer_code AS linked_equipment_alias,
eqp.equip_id AS linked_equipment_id,
eqp.equip_text AS linked_equipment_name,
DECODE (jt_originator_type_id,
1000, 'PROJECT MOVE REQUEST',
138834, 'CUSTOMER INITIATED CORRECTION',
138835, 'CUSTOMER INITIATED REQUEST',
138836, 'CORRECTIVE MAINTENANCE',
138837, 'CONFERENCE ROOM BOOKING',
138838, 'PROJECT INITIATED REQUEST',
138839, 'PLANNED PREVENTIVE MAINTENANCE',
138840, 'SELF INITATED REQUEST',
NULL, ' '
) AS originator_type,
' ' AS payment_terms, priority_text AS priority_code,
swoty.sworktype_text AS problem_type,
prop.property_name_cc AS property,
jt.jt_cost_quote_total AS quote_total,
par.levels_name AS region,
DECODE (jt.jt_repdef_id,
141534, 'ADJUSTED SETTING',
141535, 'TRAINING FOR END',
141536, 'NEW REQUEST',
141537, 'NO REPAIR REQUIR',
141538, 'REPLACED PARTS',
141539, 'REPLACE EQUIPMEN',
1000699, 'NEW REQUEST',
NULL, ' '
) AS repair_definitions,
jt.jt_repairdesc AS repair_description,
jt.jt_requestor AS requestor, ' ' AS requestor_cost_center,
jt.jt_requestor_email AS requestor_email,
jt.jt_requestor_name_first AS requestor_name,
jt.jt_requestor_phone AS requestor_phone,
' ' AS response_time, rm.room_name_cc AS room,
p1.peo_provider_code1 AS service_provider,
p1.peo_address_1 AS service_provider_address,
peocity.city_text service_provider_city,
p1.peo_provider_code1 AS service_provider_code,
peocity.city_country_name AS service_provider_country,
peocur.currency_text AS service_provider_currency,
p1.peo_name AS service_provider_description,
p1.peo_dispatch_method AS serv_prov_dispatc_hmethod,
p1.peo_rate_double AS serv_prov_double_time_rate,
p1.peo_email AS service_provider_email,
p1.peo_emergency_phone AS serv_prov_emergency_phone,
p1.peo_fax AS service_provider_fax_number,
p1.peo_home_phone AS service_provider_home_phone,
p1.peo_rate_hourly AS service_provider_hourly_rate,
p1.peo_title AS service_provider_job_title,
p1.peo_method_id AS service_provider_method,
p1.peo_cell_phone AS service_provider_mobile_phone,
p1.peo_pager AS service_provider_pager,
p1.peo_rate_differential AS service_provider_rates,
p1.peo_rate_differential AS ser_prov_shift_differential,
peocity.city_state_prov_text AS serv_prov_state_province,
DECODE (p1.peo_active,
'Y', 'ACTIVE',
'INACTIVE'
) AS service_provider_status,
p1.peo_url AS serv_prov_web_site_address,
p1.peo_phone AS service_provider_work_phone,
p1.peo_postal_code AS serv_prov_zip_postal_code, ' ' AS shift,
' ' AS skill,
DECODE (jt.jt_bigstatus_id,
138813, 'NEW',
138814, 'PENDING',
138815, 'OPEN',
138816, 'COMPLETED',
138817, 'CLOSED',
138818, 'CANCELLED',
NULL, ' '
) AS status,
lev.levels_name AS subregion, ' ' AS trade,
p1.peo_ls_interface_code1 AS vendor_id,
p1.peo_fax AS vendor_purchasing_fax,
p1.peo_vendor_site_code AS vendor_sitecode,
jt.jt_id AS vendor_ticket, p1.peo_name AS vendor_companyname,
jt.jt_requestor_vip AS vip, wo.wo_id AS work_order_no,
jt.jt_id AS work_request,
jt.jt_class_id AS work_request_class,
woty.worktype_text AS work_type, ' ' AS wr_cost,
jt.jt_description AS wr_description,
' ' AS wr_dispatch_method,
DECODE (jt.jt_bigstatus_id,
138813, 'NEW',
138814, 'PENDING',
138815, 'OPEN',
138816, 'COMPLETED',
138817, 'CLOSED',
138818, 'CANCELLED',
NULL, ' '
) AS wr_status,
ctry.country_name AS country
FROM citi.jobticket jt,
citi.property prop,
citi.bldg bl,
citi.bldg_levels bldglvl,
citi.LEVELS lev,
citi.LEVELS par,
(SELECT crstools.stragg (peo_name) facility_manager,
bldgcon_bldg_id
FROM citi.bldg_contacts, citi.people
WHERE bldgcon_peo_id = peo_id
AND bldgcon_contype_id IN (40181, 10142)
GROUP BY bldgcon_bldg_id) fmg,
citi.floors fl,
citi.room rm,
citi.general_ledger gl,
citi.legal_entity le,
citi.cost_center_codes cc,
citi.equipment eqp,
citi.worktype woty,
citi.subworktype swoty,
citi.work_order wo,
citi.jt_workers jtwo,
citi.priority,
citi.country ctry,
citi.people p1,
citi.people peo3,
citi.people peo1,
citi.city peocity,
citi.currency peocur
WHERE jt.jt_bldg_id = bl.bldg_id
AND bl.bldg_id = bldglvl.bldg_levels_bldg_id
AND bldglvl.bldg_levels_levels_id = lev.levels_id
AND lev.levels_parent = par.levels_id(+)
AND prop.property_id = bl.bldg_property_id
AND bl.bldg_active_ls <> 'N'
AND jt.jt_floors_id = fl.floors_id(+)
AND jt.jt_room_id = rm.room_id(+)
AND jt.jt_bldg_id = fmg.bldgcon_bldg_id(+)
AND jt.jt_genled_id = gl.genled_id(+)
AND gl.genled_lglent_id = le.lglent_id(+)
AND jt.jt_cstctrcd_id = cc.cstctrcd_id(+)
AND jt.jt_equip_id = eqp.equip_id(+)
AND jt.jt_id = jtwo.jtw_jt_id(+)
AND jt.jt_worktype_id = woty.worktype_id(+)
AND jt.jt_sworktype_id = swoty.sworktype_id(+)
AND jt.jt_wo_id = wo.wo_id
AND jt.jt_priority_id = priority_id(+)
--AND jt.jt_date_requested >= ADD_MONTHS (SYSDATE, -12)
AND jt.jt_last_update >= ADD_MONTHS (ld_curr_time, -12)
AND bl.bldg_country_id = ctry.country_id
AND jtwo.jtw_peo_id = p1.peo_id(+)
AND p1.peo_city_id = peocity.city_id(+)
AND jt.jt_completed_by_peo_id = peo3.peo_id(+)
AND p1.peo_rate_currency_id = peocur.currency_id(+)
AND jt.jt_agent_peo_id = peo1.peo_id(+);
BEGIN
execute immediate 'truncate table crstools.drt_bom_work_kiosk';
select sysdate into ld_curr_time from dual;
FOR cur_rec in cur_work_kiosk LOOP
IF MOD(cur_work_kiosk%rowcount,10000 ) = 0 then
COMMIT;
END IF;
INSERT INTO crstools.drt_bom_work_kiosk
( JT_ID
,ACTUAL_HRS_TO_COMPLETE
,ACTUAL_HRS_TO_RESPOND
,AGENT_NAME
,ASAGENT_SOE_ID
,AP_SYSTEM
,ASSIGN_WORK_REQUEST_COMMENT
,BILLABLE
,BUILDING
,BUILDING_ID
,BUILDING_STATUS
,CAUSE_TYPE
,COMMENTS
,COMPLETED_BY
,CONTACT_EMAIL
,CONTACT_NAME
,CONTACT_PHONE
,CORP_CODE
,COST_CENTER
,DATE_CLOSED
,DATE_COMPLETED
,DATE_REQUESTED
,DATE_RESPONDED
,DATE_RESPONSE_ECD
,DATE_SCHEDULED
,DEFERRAL_REASON
,DESCRIPTION
,ECD
,FACILITY_MANAGER
,FLOOR
,GENERAL_LEDGER
,KIOSK_DATE_REQUESTED
,KIOSK_DISPATCH_CONFIRMED
,KIOSK_DISPATCHED
,LINKED_EQUIPMENT_ALIAS
,LINKED_EQUIPMENT_ID
,LINKED_EQUIPMENT_NAME
,ORIGINATOR_TYPE
,PAYMENT_TERMS
,PRIORITY_CODE
,PROBLEM_TYPE
,PROPERTY
,QUOTE_TOTAL
,REGION
,REPAIR_DEFINITIONS
,REPAIR_DESCRIPTION
,REQUESTOR
,REQUESTOR_COST_CENTER
,REQUESTOR_EMAIL
,REQUESTOR_NAME
,REQUESTOR_PHONE
,RESPONSE_TIME
,ROOM
,SERVICE_PROVIDER
,SERVICE_PROVIDER_ADDRESS
,SERVICE_PROVIDER_CITY
,SERVICE_PROVIDER_CODE
,SERVICE_PROVIDER_COUNTRY
,SERVICE_PROVIDER_CURRENCY
,SERVICE_PROVIDER_DESCRIPTION
,SERV_PROV_DISPATC_HMETHOD
,SERV_PROV_DOUBLE_TIME_RATE
,SERVICE_PROVIDER_EMAIL
,SERV_PROV_EMERGENCY_PHONE
,SERVICE_PROVIDER_FAX_NUMBER
,SERVICE_PROVIDER_HOME_PHONE
,SERVICE_PROVIDER_HOURLY_RATE
,SERVICE_PROVIDER_JOB_TITLE
,SERVICE_PROVIDER_METHOD
,SERVICE_PROVIDER_MOBILE_PHONE
,SERVICE_PROVIDER_PAGER
,SERVICE_PROVIDER_RATES
,SER_PROV_SHIFT_DIFFERENTIAL
,SERV_PROV_STATE_PROVINCE
,SERVICE_PROVIDER_STATUS
,SERV_PROV_WEB_SITE_ADDRESS
,SERVICE_PROVIDER_WORK_PHONE
,SERV_PROV_ZIP_POSTAL_CODE
,SHIFT
,SKILL
,STATUS
,SUBREGION
,TRADE
,VENDOR_ID
,VENDOR_PURCHASING_FAX
,VENDOR_SITECODE
,VENDOR_TICKET
,VENDOR_COMPANYNAME
,VIP
,WORK_ORDER_NO
,WORK_REQUEST
,WORK_REQUEST_CLASS
,WORK_TYPE
,WR_COST
,WR_DESCRIPTION
,WR_DISPATCH_METHOD
,WR_STATUS
,COUNTRY
,CREATE_DATE
VALUES
(cur_rec.jt_id
,cur_rec.ACTUAL_HRS_TO_COMPLETE
,cur_rec.ACTUAL_HRS_TO_RESPOND
,cur_rec.AGENT_NAME
,cur_rec.ASAGENT_SOE_ID
,cur_rec.AP_SYSTEM
,cur_rec.ASSIGN_WORK_REQUEST_COMMENT
,cur_rec.BILLABLE
,cur_rec.BUILDING
,cur_rec.BUILDING_ID
,cur_rec.BUILDING_STATUS
,cur_rec.CAUSE_TYPE
,cur_rec.COMMENTS
,cur_rec.COMPLETED_BY
,cur_rec.CONTACT_EMAIL
,cur_rec.CONTACT_NAME
,cur_rec.CONTACT_PHONE
,cur_rec.CORP_CODE
,cur_rec.COST_CENTER
,cur_rec.DATE_CLOSED
,cur_rec.DATE_COMPLETED
,cur_rec.DATE_REQUESTED
,cur_rec.DATE_RESPONDED
,cur_rec.DATE_RESPONSE_ECD
,cur_rec.DATE_SCHEDULED
,cur_rec.DEFERRAL_REASON
,cur_rec.DESCRIPTION
,cur_rec.ECD
,cur_rec.FACILITY_MANAGER
,cur_rec.FLOOR
,cur_rec.GENERAL_LEDGER
,cur_rec.KIOSK_DATE_REQUESTED
,cur_rec.KIOSK_DISPATCH_CONFIRMED
,cur_rec.KIOSK_DISPATCHED
,cur_rec.LINKED_EQUIPMENT_ALIAS
,cur_rec.LINKED_EQUIPMENT_ID
,cur_rec.LINKED_EQUIPMENT_NAME
,cur_rec.ORIGINATOR_TYPE
,cur_rec.PAYMENT_TERMS
,cur_rec.PRIORITY_CODE
,cur_rec.PROBLEM_TYPE
,cur_rec.PROPERTY
,cur_rec.QUOTE_TOTAL
,cur_rec.REGION
,cur_rec.REPAIR_DEFINITIONS
,cur_rec.REPAIR_DESCRIPTION
,cur_rec.REQUESTOR
,cur_rec.REQUESTOR_COST_CENTER
,cur_rec.REQUESTOR_EMAIL
,cur_rec.REQUESTOR_NAME
,cur_rec.REQUESTOR_PHONE
,cur_rec.RESPONSE_TIME
,cur_rec.ROOM
,cur_rec.SERVICE_PROVIDER
,cur_rec.SERVICE_PROVIDER_ADDRESS
,cur_rec.SERVICE_PROVIDER_CITY
,cur_rec.SERVICE_PROVIDER_CODE
,cur_rec.SERVICE_PROVIDER_COUNTRY
,cur_rec.SERVICE_PROVIDER_CURRENCY
,cur_rec.SERVICE_PROVIDER_DESCRIPTION
,cur_rec.SERV_PROV_DISPATC_HMETHOD
,cur_rec.SERV_PROV_DOUBLE_TIME_RATE
,cur_rec.SERVICE_PROVIDER_EMAIL
,cur_rec.SERV_PROV_EMERGENCY_PHONE
,cur_rec.SERVICE_PROVIDER_FAX_NUMBER
,cur_rec.SERVICE_PROVIDER_HOME_PHONE
,cur_rec.SERVICE_PROVIDER_HOURLY_RATE
,cur_rec.SERVICE_PROVIDER_JOB_TITLE
,cur_rec.SERVICE_PROVIDER_METHOD
,cur_rec.SERVICE_PROVIDER_MOBILE_PHONE
,cur_rec.SERVICE_PROVIDER_PAGER
,cur_rec.SERVICE_PROVIDER_RATES
,cur_rec.SER_PROV_SHIFT_DIFFERENTIAL
,cur_rec.SERV_PROV_STATE_PROVINCE
,cur_rec.SERVICE_PROVIDER_STATUS
,cur_rec.SERV_PROV_WEB_SITE_ADDRESS
,cur_rec.SERVICE_PROVIDER_WORK_PHONE
,cur_rec.SERV_PROV_ZIP_POSTAL_CODE
,cur_rec.SHIFT
,cur_rec.SKILL
,cur_rec.STATUS
,cur_rec.SUBREGION
,cur_rec.TRADE
,cur_rec.VENDOR_ID
,cur_rec.VENDOR_PURCHASING_FAX
,cur_rec.VENDOR_SITECODE
,cur_rec.VENDOR_TICKET
,cur_rec.VENDOR_COMPANYNAME
,cur_rec.VIP
,cur_rec.WORK_ORDER_NO
,cur_rec.WORK_REQUEST
,cur_rec.WORK_REQUEST_CLASS
,cur_rec.WORK_TYPE
,cur_rec.WR_COST
,cur_rec.WR_DESCRIPTION
,cur_rec.WR_DISPATCH_METHOD
,cur_rec.WR_STATUS
,cur_rec.COUNTRY
,ld_curr_time
END LOOP;
COMMIT;
exception
when others then
rollback;
dbms_output.put_line('SQLCODE :'||sqlcode ||' Error :'||sqlerrm);
end work_kiosk_full;
Note : total record inserted 849000.
The same code does not work with bulk collect into caluse.
Please help me out why this is happening.
Thanks & regards
shyam~Shyam,
I agree with Billy.
Why are you not using an INSERT..SELECT ?
Also, what are you trying to achieve by
- incremental commits?
- copying data from one table to another (using expensive I/O)?
- using dynamic DML?
Most of these approaches are typically wrong - and not recommended for scalable and performant Oracle applications.I could see you using a CURSOR FOR LOOP if you were changing the data being inserted in such a way that you couldn't encapsulate the changes in a query, but you are doing a straight insert into the table from your Cursor. A much more efficient way would be to use the following modifications I made to your code example:
PROCEDURE WORK_KIOSK_FULL(AN_JOBID IN NUMBER,
AC_SQLCODE OUT VARCHAR2,
AC_SQLERRM OUT VARCHAR2) IS
BEGIN
EXECUTE IMMEDIATE 'truncate table crstools.drt_bom_work_kiosk';
/* Note: The APPEND hint forces a Direct Path INSERT (see Link below code sample) and is combined with the NOLOGGING Hint */
/* To dramtically increase performance. The Direct Path INSERT inserts records above the High-Water Mark on the table. */
INSERT /*+ APPEND NOLOGGING */ INTO CRSTOOLS.DRT_BOM_WORK_KIOSK
(JT_ID
,ACTUAL_HRS_TO_COMPLETE
,ACTUAL_HRS_TO_RESPOND
,AGENT_NAME
,ASAGENT_SOE_ID
,AP_SYSTEM
-- ,ASSIGN_WORK_REQUEST_COMMENT /* I commented out this COLUMN because it doesn't make sense to me to insert */
,BILLABLE /* a couple of space characters into a table. If the intent is to leave the column NULL */
,BUILDING /* don't include it in your INSERT statement and it will be NULL. If there is a valid reason */
,BUILDING_ID /* for inserting the spaces, then remove the "line comments" from the insert and select statments */
,BUILDING_STATUS
,CAUSE_TYPE
-- ,COMMENTS
,COMPLETED_BY
,CONTACT_EMAIL
,CONTACT_NAME
,CONTACT_PHONE
,CORP_CODE
,COST_CENTER
,DATE_CLOSED
,DATE_COMPLETED
,DATE_REQUESTED
,DATE_RESPONDED
,DATE_RESPONSE_ECD
,DATE_SCHEDULED
,DEFERRAL_REASON
,DESCRIPTION
,ECD
,FACILITY_MANAGER
,FLOOR
,GENERAL_LEDGER
-- ,KIOSK_DATE_REQUESTED
-- ,KIOSK_DISPATCH_CONFIRMED
-- ,KIOSK_DISPATCHED
,LINKED_EQUIPMENT_ALIAS
,LINKED_EQUIPMENT_ID
,LINKED_EQUIPMENT_NAME
,ORIGINATOR_TYPE
-- ,PAYMENT_TERMS
,PRIORITY_CODE
,PROBLEM_TYPE
,PROPERTY
,QUOTE_TOTAL
,REGION
,REPAIR_DEFINITIONS
,REPAIR_DESCRIPTION
,REQUESTOR
-- ,REQUESTOR_COST_CENTER
,REQUESTOR_EMAIL
,REQUESTOR_NAME
,REQUESTOR_PHONE
-- ,RESPONSE_TIME
,ROOM
,SERVICE_PROVIDER
,SERVICE_PROVIDER_ADDRESS
,SERVICE_PROVIDER_CITY
,SERVICE_PROVIDER_CODE
,SERVICE_PROVIDER_COUNTRY
,SERVICE_PROVIDER_CURRENCY
,SERVICE_PROVIDER_DESCRIPTION
,SERV_PROV_DISPATC_HMETHOD
,SERV_PROV_DOUBLE_TIME_RATE
,SERVICE_PROVIDER_EMAIL
,SERV_PROV_EMERGENCY_PHONE
,SERVICE_PROVIDER_FAX_NUMBER
,SERVICE_PROVIDER_HOME_PHONE
,SERVICE_PROVIDER_HOURLY_RATE
,SERVICE_PROVIDER_JOB_TITLE
,SERVICE_PROVIDER_METHOD
,SERVICE_PROVIDER_MOBILE_PHONE
,SERVICE_PROVIDER_PAGER
,SERVICE_PROVIDER_RATES
,SER_PROV_SHIFT_DIFFERENTIAL
,SERV_PROV_STATE_PROVINCE
,SERVICE_PROVIDER_STATUS
,SERV_PROV_WEB_SITE_ADDRESS
,SERVICE_PROVIDER_WORK_PHONE
,SERV_PROV_ZIP_POSTAL_CODE
-- ,SHIFT
-- ,SKILL
,STATUS
,SUBREGION
-- ,TRADE
,VENDOR_ID
,VENDOR_PURCHASING_FAX
,VENDOR_SITECODE
,VENDOR_TICKET
,VENDOR_COMPANYNAME
,VIP
,WORK_ORDER_NO
,WORK_REQUEST
,WORK_REQUEST_CLASS
,WORK_TYPE
-- ,WR_COST
,WR_DESCRIPTION
-- ,WR_DISPATCH_METHOD
,WR_STATUS
,COUNTRY
,CREATE_DATE
VALUES
(SELECT DISTINCT
JT.JT_ID AS JT_ID
,NVL((ROUND((JT_DATE_COMPLETED - JT_DATE_REQUESTED) * 24,2)),0) AS ACTUAL_HRS_TO_COMPLETE
,NVL((ROUND((JT_DATE_RESPONDED - JT_DATE_REQUESTED) * 24,2)),0) AS ACTUAL_HRS_TO_RESPOND
,PEO1.PEO_NAME AS AGENT_NAME
,PEO1.PEO_USER_NAME AS ASAGENT_SOE_ID
,LE.LGLENT_DESC AS AP_SYSTEM
-- ,' ' AS ASSIGN_WORK_REQUEST_COMMENT
,DECODE(JT.JT_BILL_ID,138802,'CLIENT BILLABLE'
,138803,'CONTRACTED'
,138804,'INTERNAL BILLABLE',NULL,' ') AS BILLABLE
,BL.BLDG_NAME_CC AS BUILDING
,BL.BLDG_ID_LS AS BUILDING_ID
,DECODE(BL.BLDG_ACTIVE_CC, 'Y', 'ACTIVE', 'INACTIVE') AS BUILDING_STATUS
,DECODE(JT.JT_WRK_CAUSE_ID,141521,'STANDARD WEAR AND TEAR'
,141522,'NEGLIGENCE'
,141523,'ACCIDENTAL'
,141524,'MECHANICAL MALFUNCTION'
,141525,'OVERSIGHT'
,141526,'VANDAL'
,141527,'STANDARD'
,141528,'PROJECT WORK'
,6058229,'TEST',NULL,' ') AS CAUSE_TYPE
-- ,' ' AS COMMENTS
,PEO3.PEO_NAME AS COMPLETED_BY
,JT.JT_REQUESTOR_EMAIL AS CONTACT_EMAIL
,JT.JT_REQUESTOR_NAME_FIRST || ' ' ||JT.JT_REQUESTOR_NAME_LAST AS CONTACT_NAME
,JT.JT_REQUESTOR_PHONE AS CONTACT_PHONE
,CC.CSTCTRCD_APCODE AS CORP_CODE
,CC.CSTCTRCD_CODE AS COST_CENTER
,JT.JT_DATE_CLOSED AS DATE_CLOSED
,JT.JT_DATE_COMPLETED AS DATE_COMPLETED
,JT.JT_DATE_REQUESTED AS DATE_REQUESTED
,JT.JT_DATE_RESPONDED AS DATE_RESPONDED
,JT.JT_DATE_RESPONSE_ECD AS DATE_RESPONSE_ECD
,JT.JT_DATE_SCHEDULED AS DATE_SCHEDULED
,DECODE(JT.JT_DEF_ID,139949,'WTG VENDOR RESPONSE'
,139950,'WAITING ON PARTS'
,139951,'LABOR AVAILABILITY'
,139952,'DEFERRED- HI PRI WORK'
,139953,'WTG APPROVAL'
,139954,'FUNDING REQUIRED'
,139955,'ACCESS DENIED'
,139956,'WTG MATERIAL',NULL,' ') AS DEFERRAL_REASON
,JT.JT_DESCRIPTION AS DESCRIPTION
,JT.JT_DATE_RESCHED_ECD AS ECD
,FMG.FACILITY_MANAGER AS FACILITY_MANAGER
,FL.FLOORS_TEXT AS FLOOR
,GL.GENLED_DESC AS GENERAL_LEDGER
-- ,' ' AS KIOSK_DATE_REQUESTED
-- ,' ' AS KIOSK_DISPATCH_CONFIRMED
-- ,' ' AS KIOSK_DISPATCHED
,EQP.EQUIP_CUSTOMER_CODE AS LINKED_EQUIPMENT_ALIAS
,EQP.EQUIP_ID AS LINKED_EQUIPMENT_ID
,EQP.EQUIP_TEXT AS LINKED_EQUIPMENT_NAME
,DECODE(JT_ORIGINATOR_TYPE_ID,1000,'PROJECT MOVE REQUEST'
,138834,'CUSTOMER INITIATED CORRECTION'
,138835,'CUSTOMER INITIATED REQUEST'
,138836,'CORRECTIVE MAINTENANCE'
,138837,'CONFERENCE ROOM BOOKING'
,138838,'PROJECT INITIATED REQUEST'
,138839,'PLANNED PREVENTIVE MAINTENANCE'
,138840,'SELF INITATED REQUEST',NULL,' ') AS ORIGINATOR_TYPE
-- ,' ' AS PAYMENT_TERMS
,PRIORITY_TEXT AS PRIORITY_CODE
,SWOTY.SWORKTYPE_TEXT AS PROBLEM_TYPE
,PROP.PROPERTY_NAME_CC AS PROPERTY
,JT.JT_COST_QUOTE_TOTAL AS QUOTE_TOTAL
,PAR.LEVELS_NAME AS REGION
,DECODE(JT.JT_REPDEF_ID,141534,'ADJUSTED SETTING'
,141535,'TRAINING FOR END'
,141536,'NEW REQUEST'
,141537,'NO REPAIR REQUIR'
,141538,'REPLACED PARTS'
,141539,'REPLACE EQUIPMEN'
,1000699,'NEW REQUEST',NULL,' ') AS REPAIR_DEFINITIONS
,JT.JT_REPAIRDESC AS REPAIR_DESCRIPTION
,JT.JT_REQUESTOR AS REQUESTOR
-- ,' ' AS REQUESTOR_COST_CENTER
,JT.JT_REQUESTOR_EMAIL AS REQUESTOR_EMAIL
,JT.JT_REQUESTOR_NAME_FIRST AS REQUESTOR_NAME
,JT.JT_REQUESTOR_PHONE AS REQUESTOR_PHONE
-- ,' ' AS RESPONSE_TIME
,RM.ROOM_NAME_CC AS ROOM
,P1.PEO_PROVIDER_CODE1 AS SERVICE_PROVIDER
,P1.PEO_ADDRESS_1 AS SERVICE_PROVIDER_ADDRESS
,PEOCITY.CITY_TEXT SERVICE_PROVIDER_CITY
,P1.PEO_PROVIDER_CODE1 AS SERVICE_PROVIDER_CODE
,PEOCITY.CITY_COUNTRY_NAME AS SERVICE_PROVIDER_COUNTRY
,PEOCUR.CURRENCY_TEXT AS SERVICE_PROVIDER_CURRENCY
,P1.PEO_NAME AS SERVICE_PROVIDER_DESCRIPTION
,P1.PEO_DISPATCH_METHOD AS SERV_PROV_DISPATC_HMETHOD
,P1.PEO_RATE_DOUBLE AS SERV_PROV_DOUBLE_TIME_RATE
,P1.PEO_EMAIL AS SERVICE_PROVIDER_EMAIL
,P1.PEO_EMERGENCY_PHONE AS SERV_PROV_EMERGENCY_PHONE
,P1.PEO_FAX AS SERVICE_PROVIDER_FAX_NUMBER
,P1.PEO_HOME_PHONE AS SERVICE_PROVIDER_HOME_PHONE
,P1.PEO_RATE_HOURLY AS SERVICE_PROVIDER_HOURLY_RATE
,P1.PEO_TITLE AS SERVICE_PROVIDER_JOB_TITLE
,P1.PEO_METHOD_ID AS SERVICE_PROVIDER_METHOD
,P1.PEO_CELL_PHONE AS SERVICE_PROVIDER_MOBILE_PHONE
,P1.PEO_PAGER AS SERVICE_PROVIDER_PAGER
,P1.PEO_RATE_DIFFERENTIAL AS SERVICE_PROVIDER_RATES
,P1.PEO_RATE_DIFFERENTIAL AS SER_PROV_SHIFT_DIFFERENTIAL
,PEOCITY.CITY_STATE_PROV_TEXT AS SERV_PROV_STATE_PROVINCE
,DECODE(P1.PEO_ACTIVE, 'Y', 'ACTIVE', 'INACTIVE') AS SERVICE_PROVIDER_STATUS
,P1.PEO_URL AS SERV_PROV_WEB_SITE_ADDRESS
,P1.PEO_PHONE AS SERVICE_PROVIDER_WORK_PHONE
,P1.PEO_POSTAL_CODE AS SERV_PROV_ZIP_POSTAL_CODE
-- ,' ' AS SHIFT
-- ,' ' AS SKILL
,DECODE(JT.JT_BIGSTATUS_ID,138813,'NEW'
,138814,'PENDING'
,138815,'OPEN'
,138816,'COMPLETED'
,138817,'CLOSED'
,138818,'CANCELLED',NULL,' ') AS STATUS
,LEV.LEVELS_NAME AS SUBREGION
-- ,' ' AS TRADE
,P1.PEO_LS_INTERFACE_CODE1 AS VENDOR_ID
,P1.PEO_FAX AS VENDOR_PURCHASING_FAX
,P1.PEO_VENDOR_SITE_CODE AS VENDOR_SITECODE
,JT.JT_ID AS VENDOR_TICKET
,P1.PEO_NAME AS VENDOR_COMPANYNAME
,JT.JT_REQUESTOR_VIP AS VIP
,WO.WO_ID AS WORK_ORDER_NO
,JT.JT_ID AS WORK_REQUEST
,JT.JT_CLASS_ID AS WORK_REQUEST_CLASS
,WOTY.WORKTYPE_TEXT AS WORK_TYPE
-- ,' ' AS WR_COST
,JT.JT_DESCRIPTION AS WR_DESCRIPTION
-- ,' ' AS WR_DISPATCH_METHOD
,DECODE(JT.JT_BIGSTATUS_ID,138813,'NEW'
,138814,'PENDING'
,138815,'OPEN'
,138816,'COMPLETED'
,138817,'CLOSED'
,138818,'CANCELLED',NULL,' ') AS WR_STATUS
,CTRY.COUNTRY_NAME AS COUNTRY
,SYSDATE --LD_CURR_TIME
FROM CITI.JOBTICKET JT,
CITI.PROPERTY PROP,
CITI.BLDG BL,
CITI.BLDG_LEVELS BLDGLVL,
CITI.LEVELS LEV,
CITI.LEVELS PAR,
(SELECT CRSTOOLS.STRAGG(PEO_NAME) FACILITY_MANAGER,
BLDGCON_BLDG_ID
FROM CITI.BLDG_CONTACTS, CITI.PEOPLE
WHERE BLDGCON_PEO_ID = PEO_ID
AND BLDGCON_CONTYPE_ID IN (40181, 10142)
GROUP BY BLDGCON_BLDG_ID) FMG,
CITI.FLOORS FL,
CITI.ROOM RM,
CITI.GENERAL_LEDGER GL,
CITI.LEGAL_ENTITY LE,
CITI.COST_CENTER_CODES CC,
CITI.EQUIPMENT EQP,
CITI.WORKTYPE WOTY,
CITI.SUBWORKTYPE SWOTY,
CITI.WORK_ORDER WO,
CITI.JT_WORKERS JTWO,
CITI.PRIORITY,
CITI.COUNTRY CTRY,
CITI.PEOPLE P1,
CITI.PEOPLE PEO3,
CITI.PEOPLE PEO1,
CITI.CITY PEOCITY,
CITI.CURRENCY PEOCUR
WHERE JT.JT_BLDG_ID = BL.BLDG_ID
AND BL.BLDG_ID = BLDGLVL.BLDG_LEVELS_BLDG_ID
AND BLDGLVL.BLDG_LEVELS_LEVELS_ID = LEV.LEVELS_ID
AND LEV.LEVELS_PARENT = PAR.LEVELS_ID(+)
AND PROP.PROPERTY_ID = BL.BLDG_PROPERTY_ID
AND BL.BLDG_ACTIVE_LS = 'N'
AND JT.JT_FLOORS_ID = FL.FLOORS_ID(+)
AND JT.JT_ROOM_ID = RM.ROOM_ID(+)
AND JT.JT_BLDG_ID = FMG.BLDGCON_BLDG_ID(+)
AND JT.JT_GENLED_ID = GL.GENLED_ID(+)
AND GL.GENLED_LGLENT_ID = LE.LGLENT_ID(+)
AND JT.JT_CSTCTRCD_ID = CC.CSTCTRCD_ID(+)
AND JT.JT_EQUIP_ID = EQP.EQUIP_ID(+)
AND JT.JT_ID = JTWO.JTW_JT_ID(+)
AND JT.JT_WORKTYPE_ID = WOTY.WORKTYPE_ID(+)
AND JT.JT_SWORKTYPE_ID = SWOTY.SWORKTYPE_ID(+)
AND JT.JT_WO_ID = WO.WO_ID
AND JT.JT_PRIORITY_ID = PRIORITY_ID(+)
--AND jt.jt_date_requested >= ADD_MONTHS (SYSDATE, -12)
AND JT.JT_LAST_UPDATE >= ADD_MONTHS(LD_CURR_TIME, -12)
AND BL.BLDG_COUNTRY_ID = CTRY.COUNTRY_ID
AND JTWO.JTW_PEO_ID = P1.PEO_ID(+)
AND P1.PEO_CITY_ID = PEOCITY.CITY_ID(+)
AND JT.JT_COMPLETED_BY_PEO_ID = PEO3.PEO_ID(+)
AND P1.PEO_RATE_CURRENCY_ID = PEOCUR.CURRENCY_ID(+)
AND JT.JT_AGENT_PEO_ID = PEO1.PEO_ID(+)
COMMIT;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
DBMS_OUTPUT.PUT_LINE('SQLCODE :' || SQLCODE || ' Error :' || SQLERRM);
END WORK_KIOSK_FULL;Here's the link for infor on the [Oracle Direct-Path INSERT |http://download.oracle.com/docs/cd/B10501_01/server.920/a96524/c21dlins.htm#10778].
Also, if you are truly intent on using a CURSOR FOR LOOP with the BULK COLLECT, I suggest you read Steven Feuerstein's article [PL/SQL Practices: On BULK COLLECT |http://www.oracle.com/technology/oramag/oracle/08-mar/o28plsql.html].
Hope this helps.
Craig...
If my response or the response of another was helpful, please mark it accordingly -
Hello All,
I am trying to copy data using database link.
I am using Oracle 11g on Windows.
I check data in source table and it exists. When I execute below block it successfully executes but return no data in target database.
SET SERVEROUTPUT ON
DECLARE
TYPE t_bulk_collect_test_1 IS TABLE OF NT_PROP%ROWTYPE;
l_tab1 t_bulk_collect_test_1;
CURSOR c_data1 IS
SELECT *
FROM NT_PROP@dp_copy;
BEGIN
OPEN c_data1;
LOOP
FETCH c_data1
BULK COLLECT INTO l_tab1 LIMIT 10000;
commit;
EXIT WHEN l_tab1.count = 0;
END LOOP;
CLOSE c_data1;
END;
Could someone please let me know what is the eror in this code.
Thanks in advanceI think you are expecting BULK INSERT using FORALL. Please see below example.
See below link also
http://www.oracle-base.com/articles/9i/bulk-binds-and-record-processing-9i.php#save_exceptions
DECLARE
TYPE t_bulk_collect_test_1 IS TABLE OF NT_PROP%ROWTYPE;
l_tab1 t_bulk_collect_test_1;
CURSOR c_data1 IS
SELECT *
FROM NT_PROP@dp_copy;
ex_dml_errors EXCEPTION;
PRAGMA EXCEPTION_INIT(ex_dml_errors, -24381);
BEGIN
OPEN c_data1;
LOOP
FETCH c_data1
BULK COLLECT INTO l_tab1 LIMIT 10000;
BEGIN
forall i in l_tab1.first..l_tab1.count save exceptions
insert into target_tab values l_tab1(i);
EXCEPTION
WHEN ex_dml_errors THEN
l_error_count := SQL%BULK_EXCEPTIONS.count;
DBMS_OUTPUT.put_line('Number of failures: ' || l_error_count);
FOR i IN 1 .. l_error_count LOOP
DBMS_OUTPUT.put_line('Error: ' || i ||
' Array Index: ' || SQL%BULK_EXCEPTIONS(i).error_index ||
' Message: ' || SQLERRM(-SQL%BULK_EXCEPTIONS(i).ERROR_CODE));
END LOOP;
END;
EXIT WHEN l_tab1.count = 0;
END LOOP;
CLOSE c_data1;
END;
Cheers,
Suri -
Bulk collect into compound array
Hi guys,
just having a bit of an issue here. here's what I've got so far (simplified):
declare
type t_rec is record(foo_rec foo%rowtype,
id number);
type t_tab is table of t_rec index by pls_integer;
w_footab t_tab;
begin
select foo.*,
3
bulk collect into w_footab
from foo;
end;but I get the error pls00597 expression w_footab in the INTO list is of wrong type.
oracle version: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64biHi WhiteHat,
You can't select into a layered PL/SQL structure like this.
SQL> create table foo (col1,col2) as select 1,2 from dual
2 /
Tabel is aangemaakt.
SQL> declare
2 type t_rec is record
3 ( foo_rec foo%rowtype
4 , id number
5 );
6 type t_tab is table of t_rec index by pls_integer;
7 w_footab t_tab;
8 begin
9 select foo.*
10 , 3
11 bulk collect into w_footab
12 from foo
13 ;
14 end;
15 /
bulk collect into w_footab
FOUT in regel 11:
.ORA-06550: line 11, column 28:
PLS-00597: expression 'W_FOOTAB' in the INTO list is of wrong type
ORA-06550: line 12, column 5:
PL/SQL: ORA-00904: : invalid identifier
ORA-06550: line 9, column 3:
PL/SQL: SQL Statement ignoredWhen you flatten it out, it works:
SQL> declare
2 type t_rec is record
3 ( col1 foo.col1%type
4 , col2 foo.col2%type
5 , id number
6 );
7 type t_tab is table of t_rec index by pls_integer;
8 w_footab t_tab;
9 begin
10 select foo.*
11 , 3
12 bulk collect into w_footab
13 from foo
14 ;
15 end;
16 /
PL/SQL-procedure is geslaagd.Or use SQL types, and you can use any structure you want:
SQL> create type foorec is object
2 ( foo_col1 number
3 , foo_col2 number
4 );
5 /
Type is aangemaakt.
SQL> declare
2 type t_rec is record
3 ( foo_rec foorec
4 , id number
5 );
6 type t_tab is table of t_rec index by pls_integer;
7 w_footab t_tab;
8 begin
9 select foorec(foo.col1,foo.col2)
10 , 3
11 bulk collect into w_footab
12 from foo
13 ;
14 end;
15 /
PL/SQL-procedure is geslaagd.Regards,
Rob. -
How to use bulk collect into clause
hi all,
i have requirement like this i want to change the query by passing the different table names in oracle database 10gr2.
like if i use first i pass the scott.emp table name select * from scott.emp;
then i want pass scott.dept table name select * from scott.dept;
using select * option in the select list.
how can i execute it.
give me any solution.
please reply....Hi,
i recently also ran into some serious trouble to make dynamic sql work.
It was about parallel pipelined function with strongly typed cursor (for "partition ... by hash(...)").
But in addition requiring dynamic SQL for the input to this cursor.
I couldn't make it work with execute immediate or something else.
So i used another way - I translated dynamic SQL into dynamically created static SQL:
1. create a base SQL data object type with abstract interface for code (e.g. some Execute() member function).
2. dynamically create a derived SQL data object type with concrete implementation of Execute() holding your "dynamic SQL" "in a static way"
3. delegate to Execute().
Let me quote my example from comp.databases.oracle.server, thread "dynamically created cursor doesn't work for parallel pipelined functions"
- pls. see below (it's an old one - with likely some odd stuff inside).
It might sound some kind of strange for DB programmer.
(I come from C++. Though this is not an excuse smile)
Maybe i just missed another possible option to handle the problem.
And it's a definitely verbose.
But i think it's at least a (last) option.
Actually i would be interested to hear, what others think about it.
best regards,
Frank
--------------- snip -------------------------
drop table parallel_test;
drop type MyDoit;
drop type BaseDoit;
drop type ton;
create type ton as table of number;
CREATE TABLE parallel_test (
id NUMBER(10),
description VARCHAR2(50)
BEGIN
FOR i IN 1 .. 100000 LOOP
INSERT INTO parallel_test (id, description)
VALUES (i, 'Description or ' || i);
END LOOP;
COMMIT;
END;
create or replace type BaseDoit as object (
id number,
static function make(p_id in number)
return BaseDoit,
member procedure doit(
p_sids in out nocopy ton,
p_counts in out nocopy ton)
) not final;
create or replace type body BaseDoit as
static function make(p_id in number)
return BaseDoit
is
begin
return new BaseDoit(p_id);
end;
member procedure doit(
p_sids in out nocopy ton,
p_counts in out nocopy ton)
is
begin
dbms_output.put_line('BaseDoit.doit(' || id || ') invoked...');
end;
end;
-- Define a strongly typed REF CURSOR type.
CREATE OR REPLACE PACKAGE parallel_ptf_api AS
TYPE t_parallel_test_row IS RECORD (
id1 NUMBER(10),
desc1 VARCHAR2(50),
id2 NUMBER(10),
desc2 VARCHAR2(50),
sid NUMBER
TYPE t_parallel_test_tab IS TABLE OF t_parallel_test_row;
TYPE t_parallel_test_ref_cursor IS REF CURSOR RETURN
t_parallel_test_row;
FUNCTION test_ptf (p_cursor IN t_parallel_test_ref_cursor)
RETURN t_parallel_test_tab PIPELINED
PARALLEL_ENABLE(PARTITION p_cursor BY any);
END parallel_ptf_api;
SHOW ERRORS
CREATE OR REPLACE PACKAGE BODY parallel_ptf_api AS
FUNCTION test_ptf (p_cursor IN t_parallel_test_ref_cursor)
RETURN t_parallel_test_tab PIPELINED
PARALLEL_ENABLE(PARTITION p_cursor BY any)
IS
l_row t_parallel_test_row;
BEGIN
LOOP
FETCH p_cursor
INTO l_row;
EXIT WHEN p_cursor%NOTFOUND;
select userenv('SID') into l_row.sid from dual;
PIPE ROW (l_row);
END LOOP;
RETURN;
END test_ptf;
END parallel_ptf_api;
SHOW ERRORS
PROMPT
PROMPT Serial Execution
PROMPT ================
SELECT sid, count(*)
FROM TABLE(parallel_ptf_api.test_ptf(CURSOR(SELECT t1.id,
t1.description, t2.id, t2.description, null
FROM parallel_test t1,
parallel_test t2
where t1.id = t2.id
) t2
GROUP BY sid;
PROMPT
PROMPT Parallel Execution
PROMPT ==================
SELECT sid, count(*)
FROM TABLE(parallel_ptf_api.test_ptf(CURSOR(SELECT /*+
parallel(t1,5) */ t1.id, t1.description, t2.id, t2.description, null
FROM parallel_test t1,
parallel_test t2
where t1.id = t2.id
) t2
GROUP BY sid;
PROMPT
PROMPT Parallel Execution 2
PROMPT ==================
set serveroutput on;
declare
v_sids ton := ton();
v_counts ton := ton();
-- v_cur parallel_ptf_api.t_parallel_test_ref_cursor;
v_cur sys_refcursor;
procedure OpenCursor(p_refCursor out sys_refcursor)
is
begin
open p_refCursor for 'SELECT /*+ parallel(t1,5) */ t1.id,
t1.description, t2.id, t2.description, null
FROM parallel_test t1,
parallel_test t2
where t1.id = t2.id';
end;
begin
OpenCursor(v_cur);
SELECT sid, count(*) bulk collect into v_sids, v_counts
FROM TABLE(parallel_ptf_api.test_ptf(v_cur)) t2
GROUP BY sid;
for i in v_sids.FIRST.. v_sids.LAST loop
dbms_output.put_line (v_sids(i) || ', ' || v_counts(i));
end loop;
end;
PROMPT
PROMPT Parallel Execution 3
PROMPT ==================
set serveroutput on;
declare
instance BaseDoit;
v_sids ton := ton();
v_counts ton := ton();
procedure CreateMyDoit
is
cmd varchar2(4096 char);
begin
cmd := 'create or replace type MyDoit under BaseDoit ( ' ||
' static function make(p_id in number) ' ||
' return MyDoit, ' ||
' overriding member procedure doit( ' ||
' p_sids in out nocopy ton, ' ||
' p_counts in out nocopy ton) ' ||
execute immediate cmd;
cmd := 'create or replace type body MyDoit as ' ||
' static function make(p_id in number) ' ||
' return MyDoit ' ||
' is ' ||
' begin ' ||
' return new MyDoit(p_id); ' ||
' end; ' ||
' ' ||
' overriding member procedure doit( ' ||
' p_sids in out nocopy ton, ' ||
' p_counts in out nocopy ton) ' ||
' is ' ||
' begin ' ||
' dbms_output.put_line(''MyDoit.doit('' || id || '')
invoked...''); ' ||
' SELECT sid, count(*) bulk collect into p_sids, p_counts ' ||
' FROM TABLE(parallel_ptf_api.test_ptf(CURSOR( ' ||
' SELECT /*+ parallel(t1,5) */ t1.id, t1.description,
t2.id, t2.description, null ' ||
' FROM parallel_test t1, parallel_test t2 ' ||
' where t1.id = t2.id ' ||
' ))) ' ||
' GROUP BY sid; ' ||
' end; ' ||
' end; ';
execute immediate cmd;
end;
begin
CreateMyDoit;
execute immediate 'select MyDoit.Make(11) from dual' into instance;
instance.doit(v_sids, v_counts);
if v_sids.COUNT > 0 then
for i in v_sids.FIRST.. v_sids.LAST loop
dbms_output.put_line (v_sids(i) || ', ' || v_counts(i));
end loop;
end if;
end;
--------------- snap ------------------------- -
BULK COLLECT INTO (Oracle 11 G)
ORACLE 11G (The same code works fine in Oracle 9i)
FETCH v_cursor BULK COLLECT INTO AuditData, AuditData1;
the above statement gives me an error:-
ORA-01007: variable not in select list
ORA-06512: at "DEC0512.FCT_AUD_TRAIL_REAL_ENTRY_UPD", line 175
ORA-06512: at line 1
But if the change the statemement to
FETCH v_cursor BULK COLLECT INTO AuditData;
The query works fine.
Any help will be much appreciated.>
ORACLE 11G (The same code works fine in Oracle 9i)
FETCH v_cursor BULK COLLECT INTO AuditData, AuditData1;
the above statement gives me an error:-
ORA-01007: variable not in select list
ORA-06512: at "DEC0512.FCT_AUD_TRAIL_REAL_ENTRY_UPD", line 175
ORA-06512: at line 1
But if the change the statemement to
FETCH v_cursor BULK COLLECT INTO AuditData;
The query works fine.
Any help will be much appreciated.
>
If the second query 'works fine' then your 'AuditData' collection is consuming all of the result set columns and there is nothing to put into the other collection.
So you have a mismatch between the result set your cursor returns and those collections you are trying to put the data into.
This works for me:
DECLARE
CURSOR c1 IS (SELECT empno, deptno FROM emp);
empno_tab dbms_sql.number_table;
deptno_tab dbms_sql.number_table;
BEGIN
OPEN c1;
LOOP --Loop added
FETCH c1 BULK COLLECT INTO empno_tab, deptno_tab LIMIT 3; -- process 3 records at a time
-- process the first 3 records
DBMS_OUTPUT.PUT_LINE('Processing ' || empno_tab.COUNT || ' records.');
FOR i in 1..empno_tab.count loop
dbms_output.put_line('empno is [' || empno_tab(i) || '].');
end loop;
EXIT WHEN c1%NOTFOUND;
END LOOP;
DBMS_OUTPUT.PUT_LINE('All done');
END;
Processing 3 records.
empno is [7369].
empno is [7499].
empno is [7521].
Processing 3 records.
empno is [7566].
empno is [7654].
empno is [7698].
Processing 3 records.
empno is [7782].
empno is [7788].
empno is [7839].
Processing 3 records.
empno is [7844].
empno is [7876].
empno is [7900].
Processing 2 records.
empno is [7902].
empno is [7934].
All done -
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 .
Maybe you are looking for
-
EPay 8.9 vs 9.0 Payroll for NA - PDFs for Payslips & W2s
We are on HCM 8.9 & want to implement the ePay but with the PDF files for payslips and W2s which is not included in ver 8.9 but is in 9.0. Is there a way to either just upgrade ePay to 9.0 without an entire HCM upgrade or a way to implement the PDFs
-
No details, ut thank you a?.
-
What is needed to restore functionality to my CD drives--they do not work with iTunes version 10
I am running Windows 7 on an older computer. Previously, I experienced no difficulty playing iTunes or burning iTunes music to CD. At some point, after downloading newer version of iTunes I lost functionality in both of my disc drives (1 = Liteon D
-
I have just installed Windows 7. With an update to my bios, and newest drivers from both Micorosft and my motherboards website. I installed the newest drivers from Creative for my Sound Blaster X-Fi Xtreme Audio, and installed the Audio Conrol Panel.
-
Standard so10 text in smartform; formatting not used
Hi all, we have a standard text (SO10), where we define the formatting of the text (bold, italic,...). I call this text in the smlartform with 'include text', the text is displayed BUT without the formatting. Is it possible to keep the formatting don