Avoid calling procedure in cursor loop
Hi all,
The following sample procedure written in cursor loop,The procedure is called each and every time until the cursor loop ends..
procedure proc_main is
DECLARE
cursor c1 is
select e.empno empno
,e.ename ename
,d.dname dname
,d.loc loc
from emp e,dept d
where e.deptno = d.deptno ;
BEGIN
for i in c1 LOOP
proc_test(i.empno,i.ename,i.dname,i.loc) ;
end loop;
END;
PROCEDURE proc_test (p_empno,p_ename,p_dname,p_loc) is
begin
select * into v1,v2,v3 ..
from temp_tab
where col1 =p_empno
end;What would be the alternate methods to write the above procedure instead of calling the procedure inside the cursor for loop
My idea is to use collections ..could you give me the sample code using collections to achieve the above criteria
Thank You
Edited by: smile on Feb 28, 2012 3:45 PM
The ideal would be to gather all of the SQL logic and put as much of it into a single SQL statement as possible. It would also be ideal to determine what the final outcome of the procedure is and use that as a starting point for your SQL. For example, if the desired outcome is to UPDATE employee salaries where they have an entry in table x, you might find that you can avoid needing to split the logic between multiple procedures i.e. instead of
procedure proc_main is
DECLARE
cursor c1 is
select e.empno empno
,e.ename ename
,d.dname dname
,d.loc loc
from emp e,dept d
where e.deptno = d.deptno ;
BEGIN
for i in c1 LOOP
proc_test(i.empno,i.ename,i.dname,i.loc) ;
end loop;
END;
PROCEDURE proc_test (p_empno,p_ename,p_dname,p_loc) is
begin
select * into v1,v2,v3 ..
from temp_tab
where col1 =p_empno
UPDATE
emp e
SET
sal = v2
WHERE
e.empno = p_Empno;
end;You could simply have
procedure proc_main is
BEGIN
UPDATE
emp e
SET
sal = ( SELECT
t.new_sal
FROM
temp_tab t
WHERE
t.empno = e.empno
WHERE
EXISTS
( SELECT
NULL
FROM
temp_tab t
WHERE
t.empno = e.empno
END;Even if your logic is more complex than this, you're likely to find that you can merge together many of the statements that you'd be executing in a loop and replace that loop with a join.
Given the specific structure of what you have posted though, instead of calling the procedure in a loop, you could simply pass the cursor c1 as a parameter to proc_test i.e.
procedure proc_main is
lc_c1 sys_refcursor;
BEGIN
OPEN lc_c1 FOR
select e.empno empno
,e.ename ename
,d.dname dname
,d.loc loc
from emp e,dept d
where e.deptno = d.deptno ;
proc_test(c1) ;
END;
PROCEDURE proc_test (p_Cursor sys_refcursor) is
begin
LOOP
FETCH ....
...DO SOMETHING...
EXIT WHEN p_Cursor%NOTFOUND;
END LOOP;
CLOSE p_Cursor;
END;But I would strongly recommend that you consider trying to merge as much of your SQL together before you consider the cursor approach.
HTH
David
Similar Messages
-
Procedure using cursor loop is taking lot of time!!
Dear All,
I have an existing procedure which works on top of a cursor which fetches around *4,00,000* records.
I have to loop through each record and make it go thru IF..ELSIF block of seven conditions.
And within each IF..ELSIF block condition, i'll have 2-3 select queries on tables accessed via DB links, and then if the values fetched via these queries match certain conditions data willl be inserted into a table and commited.
Running one IF..ELSIF block separately takes around two seconds at the max.
This procedure keeps running for around *4 hrs* and then gives an error as
ERROR at line 1:
ORA-01555: snapshot too old: rollback segment number with name "" too small
ORA-06512: at "<procedure name>", line 47
ORA-06512: at line 1
Then i used BULK COLLECT with limits 2000 and 500, and in both the cases i have never been able to completely run the procedure, as it takes more then 6 hrs and some or the other problem comes up.
And the problem is i cannot run it in a TEST env as the tables are huge, and have no option except to try it in Production environment.
I have a feeling that i have not been able to gather the correct info from the error mentioned above.
DB Version:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for HPUX: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
Thanks in advance!!user11089213 wrote:
Dear All,
I have an existing procedure which works on top of a cursor which fetches around *4,00,000* records.
I have to loop through each record and make it go thru IF..ELSIF block of seven conditions.
And within each IF..ELSIF block condition, i'll have 2-3 select queries on tables accessed via DB links, and then if the values fetched via these queries match certain conditions data willl be inserted into a table and commited.Sounds like it would be better written as one select with joins and case statements and then used within a multi-table insert statement...
e.g.
INSERT ALL
WHEN <condition> THEN
WHEN <condition> THEN
WHEN <condition> THEN
SELECT ...http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_9014.htm#i2121682 -
Need some help on procedure calling procedure using object type reg
dear all,
i need to test one procedure by passing only one value but how do i pass single value. i am showing the details of few section on which i am working on. here is few details about the package.
Description: package pkj_emp contains two procedure pkj_emp and procedure proc_rem.
purpose:based on passing dname values to procedure pkj_emp, cursor cur_emp will fetch empid from emp table and then we are passing 4 empid records to procedure proc_rem using empid object type.Inside the procedure proc_rem it will delete all 4 records of table A,B,C and D at one short.
Requirement:i need to test for only one value that means is it possible i can pass only one value using the cursor cur_emp.
create or replace package pkj_emp
TYPE obj_emp IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
procedure proc_emp(empid obj_emp);
create or replace package body pkj_emp
as
procedure(
dname varchar2;
as
cursor cur_emp is select emp_id from emp a,dept d
where a.deptid=d.deptid
and d.deptname=dname;
begin
count:=0;
for cur_emp_rec in cur_emp LOOP
empid(count) := cur_emp_rec.emp_id;
IF (count = 4) THEN
proc_rem(empid); // calling another procedure
commit;
END IF;
count := count + 1;
END LOOP;
end;
proc_rem(
empid obj_emp;
is
begin
delete from A where emp_id in (empid(0),empid(1),empid(2),empid(3));
delete from B where emp_id in (empid(0),empid(1),empid(2),empid(3));
delete from c where emp_id in (empid(0),empid(1),empid(2),empid(3));
delete from d where emp_id in (empid(0),empid(1),empid(2),empid(3));
end;
regards
LaxmanYou have hardcoded your IN LIST in the REM procedure. I recommend changing the code to take a variable number of inputs. You could do something like the following:
SQL> CREATE TABLE A (ID NUMBER);
Table created.
SQL> CREATE TABLE B (ID NUMBER);
Table created.
SQL> CREATE TABLE C (ID NUMBER);
Table created.
SQL> CREATE TABLE D (ID NUMBER);
Table created.
SQL> INSERT INTO A VALUES(7566);
1 row created.
SQL> INSERT INTO B VALUES(7902);
1 row created.
SQL> INSERT INTO C VALUES(7876);
1 row created.
SQL> INSERT INTO D VALUES(7369);
1 row created.
SQL> CREATE OR REPLACE TYPE EMP_TYPE AS TABLE OF NUMBER(4);
2 /
Type created.
SQL> CREATE OR REPLACE PACKAGE PKJ_EMP
2 AS
3 PROCEDURE PKJ_EMP
4 (
5 DNAME IN SCOTT.EMP.DEPTNO%TYPE
6 );
7
8 PROCEDURE REM
9 (
10 pEMPList IN EMP_TYPE
11 );
12 END PKJ_EMP;
13 /
Package created.
SQL> CREATE OR REPLACE PACKAGE BODY PKJ_EMP
2 AS
3 PROCEDURE PKJ_EMP
4 (
5 DNAME IN SCOTT.EMP.DEPTNO%TYPE
6 )
7 AS
8 pEMPList EMP_TYPE := EMP_TYPE();
9 i NUMBER := 1;
10 BEGIN
11 FOR r IN
12 (
13 SELECT EMPNO
14 FROM SCOTT.EMP
15 WHERE DEPTNO = DNAME
16 )
17 LOOP
18 pEMPList.EXTEND;
19 pEMPList(i) := r.EMPNO;
20
21 i := i + 1;
22 END LOOP;
23
24 REM(pEMPList);
25 END PKJ_EMP;
26
27 PROCEDURE REM
28 (
29 pEMPList IN EMP_TYPE
30 )
31 AS
32 BEGIN
33 DELETE FROM A WHERE ID IN (SELECT COLUMN_VALUE FROM TABLE(pEMPList));
34 DELETE FROM B WHERE ID IN (SELECT COLUMN_VALUE FROM TABLE(pEMPList));
35 DELETE FROM C WHERE ID IN (SELECT COLUMN_VALUE FROM TABLE(pEMPList));
36 DELETE FROM D WHERE ID IN (SELECT COLUMN_VALUE FROM TABLE(pEMPList));
37 END REM;
38 END PKJ_EMP;
39 /
Package body created.
SQL> EXEC PKJ_EMP.PKJ_EMP(20);
PL/SQL procedure successfully completed.
SQL> SELECT * FROM A;
no rows selected
SQL> SELECT * FROM B;
no rows selected
SQL> SELECT * FROM C;
no rows selected
SQL> SELECT * FROM D;
no rows selected
SQL> spool off;HTH! -
Calling procedures from table and apex
Hi
I have a stored procedures and I want to put my stored procedures in table and I want to call store procedure from table in apex. how can I do this?
For example
I have stored procedures like Students(year number,birimno number)
GPA(birimno number,studentno number ) Student Procedure and GPA proecdure retrieve name and lastname
and I want to create a table
table has
Id Package Procedurename Arguments Header
1 GPA birimno, studentno name, lastname
2 Students year, birimno name,lastnameSo how can I do like this ? I want to call storeprocedures on APEX with selectlist. Selectlist will has a storeprocedures .
Edited by: esra aktas on 06.May.2011 01:48
Edited by: esra aktas on 06.May.2011 01:48
Edited by: esra aktas on 06.May.2011 04:08I am beginner pl/sql .
I had searched execute immediate for helping my problem.
My purpose is that I want to collect all of procedures in one table. And I must retrived which I select procedure on APEX Selectlist.
So I started to create a table which name is procedures and I put my procedures names on it.
Now how can I execute to procedures that name is in table?
create or replace
procedure "ISINIF_BASARI"(normalyariyil number,birimno number )
IS
ogrenci_no VARCHAR2(12);
ders_kodu VARCHAR2(12);
ders_adi VARCHAR2(50);
harf_kodu VARCHAR2(4);
CURSOR c_basari IS
select dk.ogrenci_no,da.ders_kodu,da.ders_adi,dk.harf_kodu
into ogrenci_no,ders_kodu,ders_adi,harf_kodu
from ders_aktif da,ders_tanim dt, ders_kayit dk
where da.ders_kodu like birimno ||'%'
and (dt.normal_yariyili=normalyariyil
OR dt.normal_yariyili=normalyariyil+1)
and (da.acildigi_donem='1' or da.acildigi_donem='2')
and dt.ders_kodu = da.ders_kodu
and dk.acilan_ders_no = da.acilan_ders_no
BEGIN
FOR I IN c_basari LOOP
dbms_output.put_line(' OGRENCI NO '||I.OGRENCI_NO||' DERS KODU '|| I.DERS_KODU||' DERS ADI '||I.DERS_ADI||' HARF KODU '||I.HARF_KODU);
end loop;
end;I have procedure like that.
and I have a procedures table. And I put the procedure's name in table.
procedure
id procname
1 ISINIF_BASARI
Now I want to call procedure using this table .
When I call yhe procedures from table I wrote like this. But it has faults.
create or replace
PROCEDURE CALLSPFROMTABLE as
v_sql_exp VARCHAR2(100);
BEGIN
v_sql_exp :='begin'||'select p.procname from procedure p where id=1'||'end;';
end;Edited by: esra aktas on 07.May.2011 02:19 -
Calling procedure in another procedure, how to fetch values
I have couple of procedure in a package and I am trying to call procedurea in procedureb.
TYPE T_CURSOR IS REF CURSOR;
PROCEDURE ProcedureA (acct IN number, o_cur OUT T_CURSOR)
AS
BEGIN
Open o_cur for
SELECT A, B, C, D, E, F FROM DEMO;
END ProcedureA
PROCEDURE ProcedureB (param1 IN number, param2 IN number)
AS
get_cursor T_CURSOR;
BEGIN
ProcedureA(111, get_cursor);
END;How to fetch ProcedureA values in ProcedureB? And also I want to get only columns A and B in ProcedureB.>
How to fetch ProcedureA values in ProcedureB?
>
Try something like this
TYPE rectype IS RECORD (colA demo.a%TYPE, colB demo.b%TYPE );
rec1 rectype;
LOOP
FETCH get_cursor INTO rec1;
EXIT WHEN get_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(rec1.colA);
END LOOP;
DBMS_OUTPUT.PUT_LINE('end test'); -
Trying to pass array to stored procedure in a loop using bind variable
All,
I'm having trouble figuring out if I can do the following:
I have a stored procedure as follows:
create procedure enque_f826_utility_q (inpayload IN f826_utility_payload, msgid out RAW) is
enqopt dbms_aq.enqueue_options_t;
mprop dbms_aq.message_properties_t;
begin
dbms_aq.enqueue(queue_name=>'f826_utility_queue',
enqueue_options=>enqopt,
message_properties=>mprop,
payload=>inpayload,
msgid=>msgid);
end;
The above compiles cleanly.
The first parameter "inpayload" a database type something like the following:
create or replace type f826_utility_payload as object
2 (
3 YEAR NUMBER(4,0),
4 MONTH NUMBER(2,0),
83 MUSTHAVE CHAR(1)
84 );
I'd like to call the stored procedure enque_f826_utility_q in a loop passing to it
each time, new values in the inpayload parameter.
My questions are:
First, I'm not sure in php, how to construct the first parameter which is a database type.
Can I just make an associative array variable with the keys of the array the same as the columns of the database type shown above and then pass that array to the stored procedure?
Second, is it possible to parse a statement that calls the enque_f826_utility_q procedure using bind variables and then execute the call to the stored procedure in a loop passing new bind variables each time?
I've tried something like the following but it's not working:
$conn = oci_pconnect (....);
$stmt = "select * from f826_utility";
$stid = oci_parse($conn, $sqlstmt);
$r = oci_execute($stid, OCI_DEFAULT);
$row = array();
$msgid = "";
$enqstmt = "call enque_f826_utility_q(:RID,:MID)";
$enqstid = oci_parse($conn, $sqlstmt);
oci_bind_by_name($enqstid, ":RID", $row); /* line 57 */
oci_bind_by_name($enqstid, ":MID", $msgid);
while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS+OCI_ASSOC))
++$rowcnt;
if (! oci_execute($enqstid)) /* line 65 */
echo "Error";
exit;
When I run this, I get the following:
PHP Notice: Array to string conversion in C:\Temp\enqueue_f826_utility.php on l
ine 57
Entering loop to process records from F826_UTIITY table
PHP Notice: Array to string conversion in C:\Temp\enqueue_f826_utility.php on l
ine 65
PHP Warning: oci_execute(): ORA-06553: PLS-306: wrong number or types of argume
nts in call to 'ENQUE_F826_UTILITY_Q' in C:\Temp\enqueue_f826_utility.php on lin
e 65
PHP Notice: Undefined variable: msgnum in C:\Temp\enqueue_f826_utility.php on l
ine 68
Error during oci_execute of statement select * from F826_UTILITY
Exiting!Thanks for the reply.
I took a look at this article. What it appears to describe is
a calling a stored procedure that takes a collection type which is an array.
Does anyone from Oracle know if I can pass other database type definitions to a stored procedure from PHP?
I have a type defined in my database similar to the following which is not
an array but a record of various fields. This type corresponds to a payload
of an advanced queue payload type. I have a stored procedure which will take as it's input, a payload type of this structure and then enqueue it to a queue.
So I want to be able to pass a database type similar to the following type definition from within PHP. Can anyone from Oracle verify whether or not this is possible?
create or replace type f826_utility_payload as object
YEAR NUMBER(4,0),
MONTH NUMBER(2,0),
UTILITY_ID NUMBER(10,0),
SUBMIT_FAIL_BY VARCHAR2(30),
MUSTHAVE CHAR(1)
); -
Stored procedure with cursor as out parameter
Can any one help me by showing how to write a procedure with cursor as out parameter and caputuring it in java using jdbc.
Thanks in advance,
shravan bharadwajI know that in the SQLJ distribution (which is also downloadable) there is an example in the demo directory called RefCursDemo that shows the SQL code and how to call it - albeit from SQLJ and not JDBC. There may also be a demo in the JDBC distribution, though I am not sure about that.
-
Getting NLS setting issues when calling procedure
Hi,
Can anybody suggest me what could the problem in the below issue?.
i am invokeing procedure using DBAdapter. My soa version is 11.1.1.5. When i am calling procedure first time it is working fine. But when i am invoke second time
it is showing below error. I observed that i am getting error alternativly. So kinldy advice me what could be the issue.
Error:
Cause: java.sql.SQLException: ORA-20001: Oracle error -20001: ORA-20001: Oracle error -2074: ORA-02074: cannot SET NLS in a distributed transaction has been detected in fnd_global.set_nls.set_parameter('NLS_LANGUAGE','AMERICAN'). has been detected in fnd_global.set_nls. ORA-06512: at "APPS.APP_EXCEPTION", line 72 ORA-06512: at "APPS.FND_GLOBAL", line 240 ORA-06512: at "APPS.FND_GLOBAL", line 1410 ORA-06512: at "APPS.FND_GLOBAL", line 1655 ORA-06512: at "APPS.FND_GLOBAL", line 2171 ORA-06512: at "APPS.FND_GLOBAL", line 2313 ORA-06512: at "APPS.FND_GLOBAL", line 2251 ORA-06512: at
Regards,
AdhiHi:
Another way to avoid this, is to use an Non-XA Datasource.
Hope this helps
best -
Is BC4J a viabl option for database with stored procedure (ref cursor) API?
I'm about to begin a Web application development project. As foundation, we have a (Oracle) database of certain complexity that have a data access API developed with PL/SQL packages.
This API is designed to get data through stored procedures/functions that return REF CURSOR.
Personally I have been investigating about Oracle ADF/JSF, and a number of others J2EE technologies, and at this moment I am doubting if ADF BC are a viable option to my development team.
I think this because I have noticed that one of the great drawback in ADF BC is the lack of simplicity to get data through stored procedures/functions that returns REF CURSORS.
I have been looking for documentation and the only thing that I have found are two examples:
1.- One that really do not work (fails in get data from ref cursor): ADF BC StoredProcedure Sample application.
2.- And other published by Steve Muench in
http://radio.weblogs.com/0118231/stories/2003/03/03/gettingAViewObjectsResultRowsFromARefCursor.html. This sample works fine.
But, the problem with the approach of this last article is the amount (and complexity) of the code necessary to make so basic and recurrent operation as is "obtain data through a stored procedure (ref cursor)".
Below it is the code that I have constructed to call a function that returns a ref cursor (based on steve's article).
If this is the only way to make this (historically so basic and simple) task, then it is obvious that BC is not a viable technology to my (or I am in a mistake?), since we have about 50 stored procedures/functions to access the underlying data; that stored procedures/functions are key to development of the new application (and, still more, currently are used to anothers apps ).
By all this, I would like consult to Oracle's people:
1.- I really must reject BC as technology to implement this project ?
2.- It is possible to access stored procedures in a simpler way using BC?
3.- If the answer to 2 is NOT: in near future, the BC team has plans to give more support to the simple access to stored procedures?
4.- If the answer to 3 is NOT: what another technology you recommend to construct my data access/business tier and still be able to using the others characteristics of ADF?
Thank you very much for your guidelines.
Regards, RL.
** And the code!!!
** ### I am forced to do this for each call to a procedure???? ###
package myrefcursor.model;
import java.math.BigDecimal;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Types;
import oracle.jbo.JboException;
import oracle.jbo.domain.NullValue;
import oracle.jbo.domain.Number;
import oracle.jbo.server.DBTransaction;
import oracle.jbo.server.ViewObjectImpl;
import oracle.jbo.server.ViewRowImpl;
import oracle.jbo.server.ViewRowSetImpl;
import oracle.jdbc.driver.OracleCallableStatement;
import oracle.jdbc.driver.OracleTypes;
public class TraePolizasViewImpl extends ViewObjectImpl {
private static final String SQL = "begin ? := PKG_PRUEBA.trae_polizas(?);end;";
private static final String COUNTSQL = "begin ? := PKG_PRUEBA.count_trae_polizas(?);end;";
public TraePolizasViewImpl() {
protected void executeQueryForCollection(Object qc,Object[] params,int numUserParams) {
BigDecimal rut_contratante = null;
Object[] theUserParam = null;
System.out.println(params);
System.out.println(params[0]);
if (params != null)
theUserParam = (Object[]) params[0];
//if (theUserParam != null && theUserParam.length > 0 )
if (! (theUserParam[1] instanceof NullValue) )
rut_contratante = (BigDecimal)theUserParam[1];
storeNewResultSet(qc ,retrieveRefCursor(qc, rut_contratante));
super.executeQueryForCollection(qc, params, numUserParams);
protected void create() {
getViewDef().setQuery(null);
getViewDef().setSelectClause(null);
setQuery(null);
protected ViewRowImpl createRowFromResultSet(Object qc, ResultSet rs) {
rs = getResultSet(qc);
ViewRowImpl r = createNewRowForCollection(qc);
try {
populateAttributeForRow(r,0, nullOrNewNumber(rs.getBigDecimal(1)));
populateAttributeForRow(r,1, rs.getString(2));
catch (SQLException s) {
throw new JboException(s);
return r;
protected boolean hasNextForCollection(Object qc) {
ResultSet rs = getResultSet(qc);
boolean nextOne = false;
try {
nextOne = rs.next();
if (!nextOne) {
setFetchCompleteForCollection(qc, true);
rs.close();
catch (SQLException s) {
throw new JboException(s);
return nextOne;
protected void releaseUserDataForCollection(Object qc, Object rs) {
ResultSet userDataRS = getResultSet(qc);
if (userDataRS != null) {
try { userDataRS.close(); }
catch (SQLException s) { ; }
super.releaseUserDataForCollection(qc, rs);
public long getQueryHitCount(ViewRowSetImpl viewRowSet) {
return viewRowSet.getRowCount();
private ResultSet retrieveRefCursor(Object qc, BigDecimal rut_contratante) {
CallableStatement st = null;
try {
st = getDBTransaction().createCallableStatement(SQL, DBTransaction.DEFAULT);
st.registerOutParameter(1,OracleTypes.CURSOR);
if (rut_contratante == null)
st.setNull(2, Types.NUMERIC);
else
st.setBigDecimal(2, rut_contratante);
st.execute();
ResultSet rs = ((OracleCallableStatement)st).getCursor(1);
rs.setFetchSize(getFetchSize());
return rs ;
catch (SQLException s) {
throw new JboException(s);
finally {try {st.close();} catch (SQLException s) {;}}
private void storeNewResultSet(Object qc, ResultSet rs) {
ResultSet existingRs = getResultSet(qc);
if (existingRs != null) {
try {existingRs.close();} catch (SQLException s) {;}
setUserDataForCollection(qc,rs);
hasNextForCollection(qc); // Prime the pump with the first row.
private ResultSet getResultSet(Object qc) {
return (ResultSet)getUserDataForCollection(qc);
private static Number nullOrNewNumber(BigDecimal b) {
try {
return b != null ? new Number(b) : null;
catch (SQLException s) { ; }
return null;
public BigDecimal getprutcontratante() {
return (BigDecimal)getNamedWhereClauseParam("prutcontratante");
public void setprutcontratante(BigDecimal value) {
setNamedWhereClauseParam("prutcontratante", value);
}no?
-
Nested table updation in FOR Cursor loop
Hello,
I have nested table as follows:
SQL> desc fp
Name Null? Type
ORDER_NUM NOT NULL VARCHAR2(10)
ORDER_TIE_NUM NOT NULL VARCHAR2(10)
FACILITY NOT NULL VARCHAR2(10)
ON_SHORTS NUMBER(2)
ACTIVE_SHORTS NUMBER(2)
PARTS DPM_TRANSFORM_CODE.FP_SLC_SHORT
FIRST_SHORT DATE
LAST_SHORT DATE
SQL> desc DPM_TRANSFORM_CODE.FP_SLC_SHort
DPM_TRANSFORM_CODE.FP_SLC_SHort TABLE OF DPM_TRANSFORM_CODE.FP_SHORT_INFO
Name Null? Type
PART_NUM VARCHAR2(7)
AREA VARCHAR2(7)
PART_QTY NUMBER(3)
ON_SHORT_CNT NUMBER(4)
OFF_SHORT_CNT NUMBER(4)
FIRST_DATE DATE
LAST_DATE DATE
UPDATE TABLE(SELECT PARTS FROM DPM_REPORTING.FP WHERE ORDER_NUM = P.ORDER_NUM AND ORDER_TIE_NUM = P.ORDER_TIE_NUM) PARTS
SET PARTS.OFF_SHORT_CNT = PARTS.OFF_SHORT_CNT + 1
WHERE PARTS.last_date < SYSDATE - 2/24;
This Update Statement is in FOR Cursor Loop
where select statement for the cursor is
"SELECT ORDER_NUM,ORDER_TIE_NUM,PARTS FROM DPM_REPORTING.FP WHERE FACILITY = 'PN1'"
This select statement generates 20000 records & due to which the Update statement gets executed that many times inside FOR loop.The Procedure has become quite slow due to this.
Please help.
Thanks,
RekhaYou could do it all in one sql update statement, without any pl/sql or cursor or looping:
UPDATE fp t1
SET t1.parts =
CAST (MULTISET (SELECT part_num, area, part_qty, on_short_cnt,
CASE WHEN last_date < SYSDATE - 2/24
THEN off_short_cnt + 1
ELSE off_short_cnt
END,
first_date, last_date
FROM TABLE (SELECT parts
FROM fp
WHERE facility = 'PN1'
AND order_num = t1.order_num
AND order_tie_num = t1.order_tie_num))
AS fp_slc_short)
WHERE t1.facility = 'PN1'
/ -
How to run the cursor loop once even if it is true for many times - urgent
Hi,
Say
loop
tdate='12-JAN-2005'
loop
cursor.......
if '10-JAN-2005'<=tdate then
fetch
end loop
tdate=tdate+1 month
end loop;
in the above query i want my cursor to run the loop only once at the first true of my condition....in the second run the tdate will be = '12-FEB-2005'....but my cursor loop should not go in..it has to comeout....
how to do this....plz help very urgentin the above query i want my cursor to run the loop only once at the first true of
my condition....in the second run the tdate will be = '12-FEB-2005'....but my
cursor loop should not go in..it has to comeout....Simply control has been the cursor processed or not.
Something like that
SQL> declare
2 tdate date := to_date('12-JAN-2005','DD-MON-YYYY');
3 cursor cr is select * from dual;
4 rt dual%rowtype;
5 cursor_has_been_processed boolean := false;
6 begin
7 loop
8 if to_date('10-JAN-2005','DD-MON-YYYY') <=tdate then
9 if not cursor_has_been_processed then
10 open cr;
11 loop
12 fetch cr into rt;
13 exit when cr%notfound;
14 end loop;
15 close cr;
16 cursor_has_been_processed := true;
17 dbms_output.put_line('Cursor has been processed');
18 end if;
19 --DO something
20 null;
21 end if;
22 dbms_output.put_line(tdate);
23 tdate := add_months(tdate,1);
24 exit when tdate >= to_date('12-MAY-2005','DD-MON-YYYY');
25 end loop;
26 end;
27 /
Cursor has been processed
12-JAN-05
12-FEB-05
12-MAR-05
12-APR-05
PL/SQL procedure successfully completed.Rgds. -
How to call procedure from java
My database : oracle xe 10g
I develop my application by use jdeveloper
I call procedure following code :
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection c = (Connection)DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "shm", "shm");
CallableStatement cs = c.prepareCall("begin shm_increase_capital.ins_upd_tb_payment_rec_pc(:1,:2,:3,:4,:5,:6,:7);end;");
cs.setLong(1, shareHolderId);
cs.setString(2, companyCode);
cs.setString(3, lotYear);
cs.setLong(4, seqLot);
cs.setLong(5, allocateId);
cs.setLong(6, originateFrom);
cs.setString(7, curUser);
cs.execute();
cs.close();
c.close();
When I run my application several times I found error :
Exception in thread "main" java.sql.SQLException: Listener refused the connection with the following error:
ORA-12519, TNS:no appropriate service handler found
The Connection descriptor used by the client was:
localhost:1521:XE
Do you have another way for call procedure
Please recommend me
Thank you,
Ja-aeI can call procedure
but when I using my application too long
I found error :
Exception in thread "main" java.sql.SQLException: Listener refused the connection with the following error:
ORA-12519, TNS:no appropriate service handler found
The Connection descriptor used by the client was:
localhost:1521:XE
so, I think perhaps another way to call procedure for avoid this error -
Call procedure within procedure
Hai
I have some question
1)
This below procedure create user at run time
============================================
create or replace procedure new_u1( p_name in varchar2,
p_pw in varchar2,
p_def_tblspace in varchar2 default 'users' )
as
begin
execute immediate 'create user ' || P_name || ' identified by ' ||
p_pw || ' default tablespace ' || p_def_tblspace ||
' temporary tablespace temp';
execute immediate 'grant create session to ' || p_name;
end;
This below procedure create tables at run time
==============================================
create or replace procedure M2 (table_name varchar2) as
cursor1 integer;
begin
cursor1 := dbms_sql.open_cursor;
dbms_sql.parse(cursor1, 'DROP TABLE ' || table_name,
dbms_sql.v7);
dbms_sql.close_cursor(cursor1);
end;
I want ,when first procedure calls ,it calls second procedure and create tables in that schema (call procedure within procedure).How to do that?
2)What is diffrenece between row and statement level trigger?how many types of triggers?
3)what is mutating trigger or table?
4)dbms_stats.gather_table_stats package it collects the statistics about the tables .I want statistics to be collected at every day 9am and 7pm how to do that?
Thanks in advance
MohanYou could use an expression like this, to generate the run times:
SQL> create table times (dt date) ;
Table created.
SQL> BEGIN
2 FOR idx IN 1 .. 24
3 LOOP
4 INSERT INTO times VALUES (trunc(SYSDATE) + (idx / 24));
5 INSERT INTO times VALUES (trunc(SYSDATE) + (idx / 24) + (1 / (24 * 60)));
6 INSERT INTO times VALUES (trunc(SYSDATE) + (idx / 24) + (59 / (24 * 60)));
7 END LOOP;
8 END;
9 /
PL/SQL procedure successfully completed.
SQL>
SQL> SELECT to_char(dt,
2 'dd-mon-yyyy hh:mi:ss AM'),
3 to_char(decode(sign(to_number(to_char(dt,
4 'hh24MI')) - 900),
5 -1,
6 trunc(dt) + (9 / 24),
7 0,
8 trunc(dt) + (9 / 24),
9 decode(sign(to_number(to_char(dt,
10 'hh24MI')) - 1900),
11 -1,
12 trunc(dt) + (19 / 24),
13 0,
14 trunc(dt) + (19 / 24),
15 trunc(dt) + 1 + (9 / 24))),
16 'dd-mon-yyyy hh:mi:ss AM')
17 FROM times
18 ORDER BY dt
19 /
TO_CHAR(DT,'DD-MON-YYYY TO_CHAR(DECODE(SIGN(TO_
01-jan-2004 01:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 01:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 01:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 02:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 02:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 02:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 03:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 03:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 03:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 04:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 04:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 04:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 05:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 05:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 05:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 06:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 06:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 06:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 07:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 07:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 07:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 08:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 08:01:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 08:59:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 09:00:00 AM 01-jan-2004 09:00:00 AM
01-jan-2004 09:01:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 09:59:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 10:00:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 10:01:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 10:59:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 11:00:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 11:01:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 11:59:00 AM 01-jan-2004 07:00:00 PM
01-jan-2004 12:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 12:01:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 12:59:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 01:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 01:01:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 01:59:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 02:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 02:01:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 02:59:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 03:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 03:01:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 03:59:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 04:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 04:01:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 04:59:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 05:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 05:01:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 05:59:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 06:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 06:01:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 06:59:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 07:00:00 PM 01-jan-2004 07:00:00 PM
01-jan-2004 07:01:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 07:59:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 08:00:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 08:01:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 08:59:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 09:00:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 09:01:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 09:59:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 10:00:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 10:01:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 10:59:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 11:00:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 11:01:00 PM 02-jan-2004 09:00:00 AM
01-jan-2004 11:59:00 PM 02-jan-2004 09:00:00 AM
02-jan-2004 12:00:00 AM 02-jan-2004 09:00:00 AM
02-jan-2004 12:01:00 AM 02-jan-2004 09:00:00 AM
02-jan-2004 12:59:00 AM 02-jan-2004 09:00:00 AM
72 rows selected.
SQL> -
Openscript response in SQL Call Procedure
Hi,
How do we get the response data from an SQL Call Procedure, in Openscript?
The SQL Statement is "call pkg_aaa.aaa(?)".
The Details view does not seem to give any results. The procedure is supposed to output a string.
Regards,
Axel
Edited by: ao on 2011-jun-09 10:51Can you help, the solution please. Thanks.
I have this script:
utilities.getSQLService().callProcedure(null,"DESA3",
"Begin\n BMEP_EXECUTA_VALIDACION(?,?,?);\n End;",
utilities.parameters(SQLService.parameter("{{db.par1.10}}", SQLService.SQLParameterType.In),
SQLService.parameter("{{db.par1.10}}", SQLService.SQLParameterType.In),
SQLService.parameter("abc",SQLService.SQLParameterType.Out)))
Error when executing:
Results 05-09-2012 12:26:04 AM 2,007 Failed Failed to execute SQL statement: SQLException occured. ORA-06550: line 1, column 12:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe
The symbol "" was ignored.
ORA-06550: line 2, column 36:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-id
Caused by: SQLException occured. ORA-06550: line 1, column 12:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe
The symbol "" was ignored.
ORA-06550: line 2, column 36:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-id
Script BaseDeDatos1 2,007 Failed Failed to execute SQL statement: SQLException occured. ORA-06550: line 1, column 12:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe
The symbol "" was ignored.
ORA-06550: line 2, column 36:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-id
Caused by: SQLException occured. ORA-06550: line 1, column 12:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe
The symbol "" was ignored.
ORA-06550: line 2, column 36:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-id
Initialize BaseDeDatos1 0,507 Passed
DefineDatabase: DESA3 0,001 Passed
Parameterize SQL: Begin
BMEP_EXECUTA_VALIDACION('20','20',?);
End; 0,001 Passed
Run BaseDeDatos1 - Iteration 1 1,325 Failed Failed to execute SQL statement: SQLException occured. ORA-06550: line 1, column 12:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe
The symbol "" was ignored.
ORA-06550: line 2, column 36:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-id
Caused by: SQLException occured. ORA-06550: line 1, column 12:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe
The symbol "" was ignored.
ORA-06550: line 2, column 36:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-id
GetNextDatabankRecord: par1 0,002 Passed Data Used:[20]
Connect to Database: 'DESA3' 0,787 Passed
Call Procedure DESA3: 'Begin
BMEP_EXECUTA_VALIDACION(?,?,?);
End;' 0,25 Failed Failed to execute SQL statement: SQLException occured. ORA-06550: line 1, column 12:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe
The symbol "" was ignored.
ORA-06550: line 2, column 36:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-id
Caused by: SQLException occured. ORA-06550: line 1, column 12:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe
The symbol "" was ignored.
ORA-06550: line 2, column 36:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-id
Data Used:20
Finish BaseDeDatos1 0,053 Passed
End Script BaseDeDatos1 2,007 Failed Failed to execute SQL statement: SQLException occured. ORA-06550: line 1, column 12:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe
The symbol "" was ignored.
ORA-06550: line 2, column 36:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-id
Caused by: SQLException occured. ORA-06550: line 1, column 12:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare exit for goto if loop mod null pragma
raise return select update while with <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe
The symbol "" was ignored.
ORA-06550: line 2, column 36:
PLS-00103: Encountered the symbol "" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-id
I try, but :(
Edited by: user2810993 on 05-sep-2012 6:03
Edited by: user2810993 on 05-sep-2012 6:07
Edited by: user2810993 on 05-sep-2012 6:07 -
Help!How can I find the name of a calling procedure from within a procedure/function?
Is there anyway to find out the name of calling procedure(database) from within a database stored procedure/function? This is required for creating an auditing module.
Thanks,
Abraham
===========
email:[email protected]You can use this query to get the procedure names that are calling your procedure.
SELECT name FROM all_Dependencies
WHERE upper(referenced_name) = 'YOUR_PROC_NAME'
In your procedure, you can get these values into a cursor and then use them one by one.
Hope this would help.
Faheem
Maybe you are looking for
-
JAVA for BI with Netweaver 7.1
Hello Collegues We have a Netweaver 7.1 Installation, and BI. Does anyone knows how to configure Integrated Planning with this new plataform (7.1). The BI Java Stack is not "available" on the instalation wizard, so de Basis Team, couldn't set up a Ja
-
My Old Classic 1st Gen 10GB doesn't recognize by computer
My cousin gaves me his old iPod Classic 1st gen It's work well...I can listen my foavourite music Because he used windows..so..the format of the iPod is FAT32 And...I'm using Leopard..so...i Format the iPod to become Mac then..the display show the fo
-
How do i recover a ipod 5 generation
HOW DO I RECOVER A IPOD 5 GENERATION
-
I seem to be using gtk 1.5 (even with the latest Arch)
When I check for the gtk version that I am using (#gtk-config --version) I get "1.2.10". How can I switch to gtk2.0?
-
Mac Pro gets stuck on the grey screen and won't finish booting
I have a Mac Pro 1, 1 recently (successfully) upgraded to snow leopard that gets stuck on the grey screen with the spinning rainbow cursor (after the apple logo and brief blue screen) and won't finish booting up. This happened after my computer froze