Large SQL body for a Cursor
I am trying to build a store procedure to return a rowset from DB. I am using a cursor that I build dynamically based on some input parameters. One of the parameters is actually the where clause of the sql statement and sometimes this can be really big, over 4000 characters. This will end up in having the body of the cursor greater than 4000 characters. As a matter of fact one sql statement I was testing had 16K. I can't get it to work, if the body of the cursor is that big. Same SQL statement runs perfect in SQLDeveloper Worksheet.
So I guess my question is: Is there a limitation in the size of the sql statement inside of a cursor?
This is the code:
Procedure doNothing(cursor1 OUT T_CURSOR, param1 VARCHAR2, param2 VARCHAR2)
IS
aaa VARCHAR2(32000);
BEGIN
aaa:='select f1,f2,f3,f4, ' || param1 ||'
from Table T1
where ' || param2 ||'
group by f1,f2,f3,f4, ' || param1 || ' ';
OPEN cursor1 FOR aaa;
END;
both param1 and param2 are larger than 4000 characters.
The error I am geting is:
Message "[1704] ORA-01704: string literal too long\nORA-06512: at \"XXXXXX.YYYYYYY\", line 75\nORA-06512: at line 1\n" string
Thank you!
Thank you for your answer. I was playing with Bind Variables a bit but unfortunatelly I can't use them.
Procedure doNothing(cursor1 OUT T_CURSOR, param1 VARCHAR2, param2 VARCHAR2)
IS
aaa VARCHAR2(32000);
BEGIN
aaa:='select F1,F2,F3,F4, ' || param1 ||' as F5
from Table T1
where ' || param2 ||'
group by f1,f2,f3,f4, ' || param1 || ' ';
OPEN cursor1 FOR aaa;
END;
In this case param1 is a huge string > 4000. Also I use a group by clause and therefore I need to pass it in the group by clause also.
My where clause is built dynamically and also > 4000 char. I just want somehow to be able to concatenate all these together and run a cursor on the resulted SQL. I am really not worried about SQL injection at this point.
Is there any other way I can return a rowset from an ORACLE stored procedure, without using cursors? Like in SQL Server where you can only provide the SQL Statement?
Thank you!
Similar Messages
-
Hello,
Please help. I am using weblogic 8.1 and MS SQL Server 2000. Using JDBC. I have am calling a stored procedure which outputs a CURSOR. I haveing problems specifying the right java.sql.Type for this. I tried java.sql.Type.OTHER but it fails. The code is as follows
I am planning to return more cursors from the Stored Procedures.
====
Connection conn = null;
CallableStatement stmt = null;
String sqlProc = "{ call GetDocumentDetails(?,?) }";
try {
conn = this.getConnection();
stmt = conn.prepareCall(sqlProc);
stmt.setInt(1, docId);
stmt.registerOutParameter(2,Types.OTHER);
stmt.execute();
ResultSet rs = (ResultSet) stmt.getObject(2);
while(rs.next()) {
The exception that I get is
java.sql.SQLException: [BEA][SQLServer JDBC Driver]The specified SQL type is not supported by this driver.
at weblogic.jdbc.base.BaseExceptions.createException(Unknown Source)
PLEASE HELP.Hello,
Please help. I am using weblogic 8.1 and MS SQL Server 2000. Using JDBC. I have am calling a stored procedure which outputs a CURSOR. I haveing problems specifying the right java.sql.Type for this. I tried java.sql.Type.OTHER but it fails. The code is as follows
I am planning to return more cursors from the Stored Procedures.
====
Connection conn = null;
CallableStatement stmt = null;
String sqlProc = "{ call GetDocumentDetails(?,?) }";
try {
conn = this.getConnection();
stmt = conn.prepareCall(sqlProc);
stmt.setInt(1, docId);
stmt.registerOutParameter(2,Types.OTHER);
stmt.execute();
ResultSet rs = (ResultSet) stmt.getObject(2);
while(rs.next()) {
The exception that I get is
java.sql.SQLException: [BEA][SQLServer JDBC Driver]The specified SQL type is not supported by this driver.
at weblogic.jdbc.base.BaseExceptions.createException(Unknown Source)
PLEASE HELP. -
Hi,
I can see DECLARE_CUSROR < name> in monSysSQLText but unable to see SQL Test used for declare cursor ? Is there any way to trace it ? I am using ASE 12.5.3 .
regards
ManojI have this solved. I needed to turn the implicit cursors inside my procedure into explicit cursors:
-
FOR LOOP cursor that updates table A based on a value in table B
Hi,
I need a FOR LOOP cursor that scans and updates all pro-rata column in table EMPLOYEE(child) based on what pay classification all employees are on in the CLASSIFICATION(parent) table.
DECLARE
BEGIN
IF employee.emp_type = 'FT' THEN
UPDATE employee
SET employee.pro_rata = ((classification.yearly_pay/52)*52)
WHERE employee.empid = v_empid AND classification.class_id = employee.class_id;
END IF;
IF employee.emp_type = 'PT1' THEN
UPDATE employee
SET employee.pro_rata = ((classification.yearly_pay/39)*52)
WHERE employee.empid = v_empid AND classification.class_id = employee.class_id;
END IF;
IF employee.emp_type = 'PT2' THEN
UPDATE employee
SET employee.pro_rata = ((classification.yearly_pay/21)*52)
WHERE employee.empid = v_empid AND classification.class_id = employee.class_id;
END IF;
END;
How do I create a cursor that cuts across these two table
See tables and data
CREATE TABLE CLASSIFICATION(
CLASS_ID VARCHAR2(6) NOT NULL,
CLASS_TYPE VARCHAR2(10),
DESCRIPTION VARCHAR2(30) NOT NULL,
YEARLY_PAY NUMBER(8),
HOURLY_RATE NUMBER,
WEEKDAY_OVER_TIME NUMBER,
WEEKEND_OVER_TIME NUMBER,
CONSTRAINT PK_CLASS_ID PRIMARY KEY (CLASS_ID));
INSERT INTO CLASSIFICATION VALUES('PR1','PERMANENT','MANAGER',45000,'','',NULL);
INSERT INTO CLASSIFICATION VALUES('PR2','PERMANENT','ADMIN ASSISTANT',22000,'',1.5,NULL);
INSERT INTO CLASSIFICATION VALUES('PR3','PERMANENT','CONTROLLER',32000,'',1.5,NULL);
INSERT INTO CLASSIFICATION VALUES('PR4','PERMANENT','CASH OFFICER',22000,'',1.5,NULL);
INSERT INTO CLASSIFICATION VALUES('PR5','PERMANENT','CLEANERS',16000,'',1.5,NULL);
INSERT INTO CLASSIFICATION VALUES('PR6','PERMANENT','ADMIN OFFICER',22000,'',1.5,NULL);
INSERT INTO CLASSIFICATION VALUES('PR7','PERMANENT','WAREHOUSE ATTENDANT',20000,'',1.5,NULL);
INSERT INTO CLASSIFICATION VALUES('PR8','PERMANENT','WINDOWS DRESSER',22000,'',1.5,NULL);
INSERT INTO CLASSIFICATION VALUES('PR9','PERMANENT','DIRECTOR',60000,'','',NULL);
INSERT INTO CLASSIFICATION VALUES('PR10','PERMANENT','DEPUTY DIRECTOR',52000,'','',NULL);
INSERT INTO CLASSIFICATION VALUES('PR11','PERMANENT','SALES ASSISTANT',21000,'',1.5,NULL);
INSERT INTO CLASSIFICATION VALUES('TEMP2','TEMP STAFF','ADMIN ASSISTANT','',16.50,'',NULL);
INSERT INTO CLASSIFICATION VALUES('TEMP3','TEMP STAFF','CONTROLLER','',29.00,'',NULL);
INSERT INTO CLASSIFICATION VALUES('TEMP4','TEMP STAFF','CASH OFFICER','',19.00,'',NULL);
INSERT INTO CLASSIFICATION VALUES('TEMP5','TEMP STAFF','CLEANERS','',10.00,'',NULL);
INSERT INTO CLASSIFICATION VALUES('TEMP6','TEMP STAFF','ADMIN OFFICER','',20.00,'',NULL);
INSERT INTO CLASSIFICATION VALUES('TEMP7','TEMP STAFF','WAREHOUSE ATTENDANT','',18.00,'',NULL);
INSERT INTO CLASSIFICATION VALUES('TEMP8','TEMP STAFF','WINDOWS DRESSER','',18.50,'',NULL);
INSERT INTO CLASSIFICATION VALUES('TEMP11','TEMP STAFF','SALES ASSISTANT','',16.00,'',NULL);
CREATE TABLE EMPLOYEE(
EMPID NUMBER(5) NOT NULL,
SURNAME VARCHAR2(30) NOT NULL,
FNAME VARCHAR2(30) NOT NULL,
GENDER CHAR(1) NOT NULL,
DOB DATE NOT NULL,
EMP_TYPE VARCHAR2(20) NOT NULL,
ANNUAL_WEEKS_REQD NUMBER(2),
PRO_RATA_WAGES NUMBER(7,2),
HOLIDAY_ENTLMENT NUMBER(2),
SICK_LEAVE_ENTLMENT NUMBER(2),
HIRE_DATE DATE NOT NULL,
END_DATE DATE,
ACCNO NUMBER(8) NOT NULL,
BANKNAME VARCHAR2(20) NOT NULL,
BRANCH VARCHAR2(20) NOT NULL,
ACCOUNTNAME VARCHAR2(20),
CLASS_ID VARCHAR2(6),
CONSTRAINT CK_HIRE_END CHECK (HIRE_DATE < END_DATE),
CONSTRAINT CK_HIRE_DOB CHECK (HIRE_DATE >= ADD_MONTHS(DOB, 12 * 18)),
CONSTRAINT CK_EMP_TYPE CHECK (EMP_TYPE IN ('FT','PT1','PT2','PT3','HOURLY')),
CONSTRAINT CK_EMP_GENDER CHECK (GENDER IN ('M','F')),
CONSTRAINT FK_EMP_CLASS FOREIGN KEY (CLASS_ID) REFERENCES CLASSIFICATION(CLASS_ID),
CONSTRAINT PK_EMP PRIMARY KEY (EMPID));
CREATE SEQUENCE SEQ_EMPID START WITH 1;
INSERT INTO EMPLOYEE VALUES(
SEQ_EMPID.NEXTVAL,'RICHARD','BRANDON','M','25-DEC-1966','FT',52,22000.00,28,14,'10-JAN-2005',NULL,90823227,'NATWEST','BROMLEY','DEPOSIT','PR2');
INSERT INTO EMPLOYEE VALUES(
SEQ_EMPID.NEXTVAL,'BOYCE','CODD','M','15-JAN-1972','PT1','','','','','12-JAN-2005',NULL,72444091,'LLOYDS','KENT','CURRENT','PR8');
INSERT INTO EMPLOYEE VALUES(
SEQ_EMPID.NEXTVAL,'ALHAJA','BROWN','F','20-MAY-1970','HOURLY','','','','','21-JUN-2000',NULL,09081900,'ABBEY','ESSEX','CURRENT','TEMP2');
INSERT INTO EMPLOYEE VALUES(
SEQ_EMPID.NEXTVAL,'RON','ATKINSON','M','10-AUG-1955','PT3','','','','','12-JAN-2005','26-MAR-2006',01009921,'HALIFAX','KENT','SAVINGS','PR6');
INSERT INTO EMPLOYEE VALUES(
SEQ_EMPID.NEXTVAL,'CHAMPI','KANE','F','01-JAN-1965','PT2','','','','','12-JAN-2004',NULL,98120989,'HSBC','ILFORD','CURRENT','PR4');
INSERT INTO EMPLOYEE VALUES(
SEQ_EMPID.NEXTVAL,'NED','VED','M','15-JAN-1980','HOURLY','','','','','29-DEC-2005',NULL,90812300,'WOOLWICH','LEWISHAM','CURRENT','TEMP6');
INSERT INTO EMPLOYEE VALUES(
SEQ_EMPID.NEXTVAL,'JILL','SANDER','F','22-MAR-1971','FT','','','','','30-NOV-2003',NULL,23230099,'BARCLAYS','PENGE','DEPOSIT','PR1');
Any contribution would be appreciated
many thanks
Cube60Hi,
I have triede this cursor procedure but I get an compilation error.
See first post for tables and data..
Can someone help me out please.
SQL> CREATE OR REPLACE PROCEDURE update_employee(
2 p_empid employee.empid%type,
3 p_emp_type employee.emp_type%type)
4 IS
5 CURSOR c1 is
6 select e.empid, e.emp_type, c.yearly_pay from employee e, classification c where
7 c.class_id = e.class_id;
8 BEGIN
9 OPEN c1
10 LOOP
11 FETCH c1 INTO p_empid, p_emp_type;
12 exit when c1%notfound;
13
14 IF v_emp_type ='PT1' THEN
15 UPDATE employee SET annual_weeks_reqd = 39, pro_rata_wages = ((v_yearly_pay/52)*39), holiday_en
tlment=21, sick_leave_entlment = 10.5 WHERE c.class_id = e.class_id;
16 END IF;
17 END;
18 /
Warning: Procedure created with compilation errors.
SQL> SHOW ERR;
Errors for PROCEDURE UPDATE_EMPLOYEE:
LINE/COL ERROR
10/1 PLS-00103: Encountered the symbol "LOOP" when expecting one of
the following:
. ( % ; for
The symbol "; was inserted before "LOOP" to continue.
Many thanks -
FOR UPDATE cursor is causing Blocking/ Dead Locking issues
Hi,
I am facing one of the complex issues regarding blocking / dead locking issues. Please find below the details and help / suggest me the best approach to ahead with that.
Its core Investment Banking Domain, in Our Day to day Business we are using many transaction table for processing trades and placing the order. In specific there are two main transaction table
1) Transaction table 1
2) Transaction table 2
These both the tables are having huge amount of data. In one of our application to maintain data integrity (During this process we do not want other users to change these rows), we have placed SELECT …………….. FOR UPDATE CURSOR on these two table and we have locked all the rows during the process. And we have batch jobs (shell scripts ) , calling this procedure , we will be running 9 times per day 1 hrs each start at 7:15AM in the morn finish it up in the eve 5PM . Let’s say. The reason we run the same procedure multiple times is, our business wants to know the voucher before its finalized. Because there is a possibility that order can be placed and will be updated/cancelled several times in a single day. So at the end of the day , we will be sending the finalized update to our client.
20 07 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
20 08 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
20 09 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
20 10 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
20 11 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
20 12 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
20 13 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
20 14 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
20 15 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
20 16 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
20 17 * * 1-5 home/bin/app_process_prc.sh >> home/bin/app1/process.out
Current Program will look like:
App_Prc_1
BEGIN
/***** taking the order details (source) and will be populate into the table ****/
CURSOR Cursor_Upload IS
SELECT col1, col2 … FROM Transaction table1 t 1, Source table 1 s
WHERE t1.id_no = t2.id_no
AND t1.id_flag = ‘N’
FOR UPDATE OF t1.id_flag;
/************* used for inserting the another entry , if theres any updates happened on the source table , for the records inserted using 1st cursor. **************/
CURSOR cursor_update IS
SELECT col1, col2 … FROM transaction table2 t2 , transaction table t1
WHERE t1.id_no = t2.id_no
AND t1.id_flag = ‘Y’
AND t1.DML_ACTION = ‘U’,’D’ -- will retrieve the records which are updated and deleted recently for the inserted records in transaction table 1 for that particular INSERT..
FOR UPDATE OF t1.id_no,t1.id_flag;
BLOCK 1
BEGIN
FOR v_upload IN Cursor_Upload;
LOOP
INSERT INTO transaction table2 ( id_no , dml_action , …. ) VALUES (v_upload.id_no , ‘I’ , … ) RETURNING v_upload.id_no INTO v_no -- I specify for INSERT
/********* Updating the Flag in the source table after the population ( N into Y ) N order is not placed yet , Y order is processed first time )
UPDATE transaction table1
SET id_FLAG = ‘Y’
WHERE id_no = v_no;
END LOOP;
EXCEPTION WHEN OTHER THEN
DBMS_OUTPUT.PUT_LINE( );
END ;
BLOCK 2
BEGIN -- block 2 starts
FOR v_update IN Cursor_Update;
LOOP;
INSERT INTO transaction table2 ( id_no ,id_prev_no, dml_action , …. ) VALUES (v_id_seq_no, v_upload.id_no ,, … ) RETURNING v_upload.id_no INTO v_no
UPDATE transaction table1
SET id_FLAG = ‘Y’
WHERE id_no = v_no;
END LOOP;
EXCEPTION WHEN OTHER THEN
DBMS_OUTPUT.PUT_LINE( );
END; -- block2 end
END app_proc; -- Main block end
Sample output in Transaction table1 :
Id_no | Tax_amt | re_emburse_amt | Activ_DT | Id_Flag | DML_ACTION
01 1,835 4300 12/JUN/2009 N I ( these DML Action will be triggered when ever if theres in any DML operation occurs in this table )
02 1,675 3300 12/JUN/2009 Y U
03 4475 6500 12/JUN/2009 N D
Sample output in Transaction table2 :
Id_no | Prev_id_no Tax_amt | re_emburse_amt | Activ_DT
001 01 1,835 4300 12/JUN/2009 11:34 AM ( 2nd cursor will populate this value , bcoz there s an update happened for the below records , this is 2nd voucher
01 0 1,235 6300 12/JUN/2009 09:15 AM ( 1st cursor will populate this record when job run first time )
02 0 1,675 3300 12/JUN/2009 8:15AM
003 03 4475 6500 12/JUN/2009 11:30 AM
03 0 1,235 4300 12/JUN/2009 10:30 AM
Now the issues is :
When these Process runs, our other application jobs failing, because it also uses these main 2 tranaction table. So dead lock is detecting in these applications.
Solutin Needed :
Can anyone suggest me , like how can rectify this blocking /Locking / Dead lock issues. I wants my other application also will use this tables during these process.
Regards,
Maranhmmm.... this leads to a warning:
SQL> ALTER SESSION SET PLSQL_WARNINGS='ENABLE:ALL';
Session altered.
CREATE OR REPLACE PROCEDURE MYPROCEDURE
AS
MYCOL VARCHAR(10);
BEGIN
SELECT col2
INTO MYCOL
FROM MYTABLE
WHERE col1 = 'ORACLE';
EXCEPTION
WHEN PIERRE THEN
NULL;
END;
SP2-0804: Procedure created with compilation warnings
SQL> show errors
Errors for PROCEDURE MYPROCEDURE:
LINE/COL ERROR
12/9 PLW-06009: procedure “MYPROCEDURE” PIERRE handler does not end in RAISE or RAISE_APPLICATION_ERROR
:) -
Hi,
I need a PL/SQL code for this one...
Let me know if something is not clear...
1) The table CLOB_CLOBJECT_CDA has the columns described below...
Explaining only those fields which are important in this context
-- CDA_STEP_ID : Basically a Sequence
-- CLOBJECT_SOURCE1_ID : Every id has got a set of records
-- CLOBJECT_SOURCE2_ID : Every id has got a set of records
-- LVL : There are total 8 levels..
This is the main aim :
1) There are total 16 million rows..(limited to 10 rows here)
2) We need to go through level by level (LVL column) & insert the intersection records (CLOBJECT_SOURCE1_ID intersect CLOBJECT_SOURCE2_ID)
into another table...but this is how it goes..
Level (LVL column) 3's basically have CLOBJECT_SOURCE1_ID as level (LVL column) 2 CDA_STEP_ID's..
(consider the statement --** where CLOBJECT_SOURCE1_ID = 285 which is same as 1st insert statement step id)..
The above process goes for next levels until 8..(so have to use loops)
So for ex :
We go through the first insert statement and insert the insertion records only when both CLOBJECT_SOURCE1_ID & CLOBJECT_SOURCE2_ID has got records ..
If we don't find any records for both of them we should skip the corresponding step id when we go to the next levels...
Let's go through the 1st insert statement...
-- We have CDA_STEP_ID = 285 & two sources CLOBJECT_SOURCE1_ID as 19 & CLOBJECT_SOURCE2_ID as 74...
-- We see the table CLOBJECT_COUNTS & check whether we have counts for both 19 & 74 ..(In fact we insert counts into this table only if they have records)
-- If so, we insert the intersection records into CDA_MRN_RESULTS ( we do have counts for both of them..) with CDA_STEP_ID 285...
-- Then we insert the step id which is 285 along with the count into CLOBJECT_COUNTS..
Let's go through another insert statement...
-- Consider CDA_STEP_ID = 288 which has two sources CLOBJECT_SOURCE1_ID as 19 & CLOBJECT_SOURCE2_ID as 92...
-- We see the table CLOBJECT_COUNTS & check whether we have counts for both 19 & 92 ..(we have records for 19 but not for 92)
-- So we should not proceed with this..& also skip all those records (future records with increasing levels..basically level 3's) which have got 288 as CLOBJECT_SOURCE1_ID..
(As said earlier that the present CDA_STEP_ID will always be CLOBJECT_SOURCE1_ID in the next level)...
I wrote the following code which is after the statement...
Let me have the create & insert statements here..
create table CLOB_CLOBJECT_CDA
CDA_STEP_ID NUMBER,
CDA_ID NUMBER,
CDA_SEQ_NUMBER NUMBER,
CLOBJECT_SOURCE1_TYPE VARCHAR2(3000),
CLOBJECT_SOURCE1_ID NUMBER,
CLOBJECT_OPERATOR VARCHAR2(3000),
CLOBJECT_SOURCE2_TYPE VARCHAR2(3000),
CLOBJECT_SOURCE2_ID NUMBER,
LVL NUMBER
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (285, 285, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 74, 2);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (286, 286, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 75, 2);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (287, 287, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 91, 2);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (288, 288, 1, 'CLOBJECT', 19, 'INTERSECT', 'CLOBJECT', 92, 2);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4869, 4869, 1, 'CDA_STEP', 285, 'INTERSECT', 'CLOBJECT', 91, 3); -- **
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4870, 4870, 1, 'CDA_STEP', 285, 'INTERSECT', 'CLOBJECT', 92, 3);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4871, 4871, 1, 'CDA_STEP', 285, 'INTERSECT', 'CLOBJECT', 93, 3);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4880, 4880, 1, 'CDA_STEP', 286, 'INTERSECT', 'CLOBJECT', 91, 3);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4881, 4881, 1, 'CDA_STEP', 286, 'INTERSECT', 'CLOBJECT', 92, 3);
insert into clob_clobject_cda (CDA_STEP_ID, CDA_ID, CDA_SEQ_NUMBER, CLOBJECT_SOURCE1_TYPE, CLOBJECT_SOURCE1_ID, CLOBJECT_OPERATOR, CLOBJECT_SOURCE2_TYPE, CLOBJECT_SOURCE2_ID, LVL)
values (4882, 4882, 1, 'CDA_STEP', 286, 'INTERSECT', 'CLOBJECT', 93, 3);
create table CDA_MRN_RESULTS
CDA_STEP_ID NUMBER,
MRN NUMBER,
INSERT_DATE_TIME DATE
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (19, 1, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (19, 2, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (19, 3, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (74, 1, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (74, 2, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (74, 4, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (75, 1, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (75, 2, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (75, 6, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (91, 2, to_date('19-10-2011', 'dd-mm-yyyy'));
insert into cda_mrn_results (CDA_STEP_ID, MRN, INSERT_DATE_TIME)
values (91, 3, to_date('19-10-2011', 'dd-mm-yyyy'));
create table CLOBJECT_COUNTS
CDA_STEP_ID NUMBER,
CLOBJECT_COUNT NUMBER,
DATE_TIME DATE
Insert into CLOBJECT_COUNTS values (19,3, to_date('19-10-2011', 'dd-mm-yyyy'));
Insert into CLOBJECT_COUNTS values (74,3, to_date('19-10-2011', 'dd-mm-yyyy'));
Insert into CLOBJECT_COUNTS values (75,3, to_date('19-10-2011', 'dd-mm-yyyy'));
Insert into CLOBJECT_COUNTS values (91,2, to_date('19-10-2011', 'dd-mm-yyyy'));The output goes into two tables...
CDA_MRN_RESULTS : O/p of intersection records between source1 & source2 id
CLOBJECT_COUNTS : Step id with counts ...(useful for skipping next level step id's if either of source id has "0" counts)
Any help is appreciated..
Thanks..I tried to code this..but looping takes a lot of time..I want to skip certain rows where source1_step_id & source_2_step_id are not in clobject_counts table as we proceed to the next levels..Not sure how to skip the rows..
declare
cursor c1 (p_level varchar2 ) is
Select * from clob_clobject_cda
where lvl = p_level ;
TYPE V_TT IS TABLE OF C1%ROWTYPE INDEX BY PLS_INTEGER;
L_TT V_TT;
v1 number;
v2 number;
v_step_id number;
v_operator varchar2(100) := '';
begin
for i in 2..8 loop
open c1(i);
LOOP
FETCH C1 BULK COLLECT INTO L_TT LIMIT 500;
FOR indx IN 1 .. L_TT.COUNT
LOOP
v1 := L_TT(indx).clobject_source1_id;
v2 := L_TT(indx).clobject_source2_id;
v_step_id := L_TT(indx).cda_step_id;
v_operator := L_TT(indx).clobject_operator;
Execute Immediate ('Insert into cda_mrn_results Select --+ parallel (cm 128)
distinct ' || v_step_id || ', mrn, trunc(sysdate) dt from cda_mrn_results cm
where cda_step_id = ' || v1 || '
and cda_step_id in (Select cda_step_id from clobject_counts) ' ||
v_operator ||
' Select --+ parallel (cm 128)
distinct ' || v_step_id || ', mrn, trunc(sysdate) dt from cda_mrn_results cm
where cda_step_id = ' || v2 || '
and cda_step_id in (Select cda_step_id from clobject_counts) ' );
Insert --+ Append
into clobject_counts Select cda_step_id, count(distinct mrn),
insert_date_time dt from cda_mrn_results where cda_step_id = v_step_id group by cda_step_id,insert_date_time;
COMMIT;
END LOOP;
EXIT WHEN L_TT.COUNT = 0;
END LOOP;
CLOSE C1;
End Loop;
Commit;
End; -
Search Package Body for Keywords
I would like to know if anyone has a query to search a package body for a particular word and then return all of the procedure names where that word (or words) are found. I am in the beginning stages of a 3-5 year upgrade/re-write project and just when I think that I have been given all of the requirements "they" come up with something else. Go figure! For instance I might need to find all of the procedures for a package or packages that contain the word product. Manually searching through all of my packages is very time consuming and I'm sure that someone out there has already written a query to do this.
Any help will be greatly appreciated!
Thanks!
Randy>
I would like to know if anyone has a query to search a package body for a particular word and then return all of the procedure names where that word (or words) are found. I am in the beginning stages of a 3-5 year upgrade/re-write project and just when I think that I have been given all of the requirements "they" come up with something else. Go figure! For instance I might need to find all of the procedures for a package or packages that contain the word product. Manually searching through all of my packages is very time consuming and I'm sure that someone out there has already written a query to do this.
>
A query? No
Would you settle for Oracle supplied functionality that can probably provide all of that cross-reference information for you?
As you can tell from all of the other replies it seems many, if not most, people are not familiar with PL/Scope, which was introduced in version 11.1 (you should always provide your 4 digit Oracle version).
>
PL/Scope is a compiler-driven tool that collects data about identifiers in PL/SQL source code at program-unit compilation time and makes it available in static data dictionary views. The collected data includes information about identifier types, usages (declaration, definition, reference, call, assigment) and the location of each usage in the source code.
PL/Scope enables the development of powerful and effective PL/Scope source code browsers that increase PL/SQL developer productivity by minimizing time spent browsing and understanding source code.
PL/Scope is intended for application developers, and will usually be used in the environment of a development database.
>
See Chapter 8 Using PL/Scope in the Advanced Appication Developer's Guide
http://docs.oracle.com/cd/B28359_01/appdev.111/b28424/adfns_plscope.htm
>
Specifying Identifier Collection
By default, PL/Scope does not collect data for identifiers in the PL/SQL source program. To have PL/Scope collect data for all identifiers in the PL/SQL source program, including identifiers in package bodies, set the PL/SQL compilation parameter PLSCOPE_SETTINGS to 'IDENTIFIERS:ALL'.
>
Without knowing your actual needs or requirements I can't speculate on whether this will give you everything you are looking for.
But don't reinvent the wheel without checking this out first.
Basically just set the compilation parameter and recompile all of the code. Then there will be static dictionary views available with the cross-reference data.
Even if you are not currently using 11g if I were you I would create an 11g sandbox with all of the objects and code (no data needed) just so you could use PL/Scope to get this cross-reference information. -
Hi ,
Can you let me know what happen in this cursoe when we use for update?
CURSOR TRAN_CUR
IS
SELECT TRANSACTION_ID
,YEAR_MONTH_DT
,SOURCE_CD
,INVOICE
FROM
TRANSACTION_CONTROL
WHERE
NEXT_PROCESS = 'MAP'
FOR
UPDATE;
Thanks in advance,Assuming that the cursor is written correctly SQL will lock each row as it is selected. The lock will remain until you do a COMMIT or a ROLLBACK. Normally Oracle will lock rows when you perform DML on them but FOR UPDATE causes the row to be locked when the select occurs.
FOR UPDATE also has the happy side effect of allowing use of the CURRENT OF predicate in select loops simplifying where clauses; when you say "WHERE CURRENT OF cursor_name" for a FOR UPDATE cursor you will only operate on the current row.
Now for the unhappy side effects. FOR UPDATE cursors run more slowly than normal cursors because it takes time and effort to lock the rows. Second (and worse) you are locked into one transaction for the entire cursor execution because performing a SELECT after a commit or rollback results in the FETCH OUT OF SEQUENCE error (this is not usually a problem but could result in running out of rollback segments or undo space for newer databases. Its unlikely these days but can happen). Finally, performing DML in one statement (as in insert into/select from) is often faster than performing the select loops with DML inside them anyway.
I wouldn't use FOR UPDATE unless I really needed the rows locked because of the performance hit. -
Need pl/sql stmnts. for this simple logic
Hi,
I need PL/SQL program for this simple logic i am doing mistake somewhere unbale to trace
out ..
select * from GSR03_PO_DTL;
PO_NUM
L53177000 -- > no changes reqd (only one entry with new format)
L00041677 --> to be updated to L41677000(only one entry with OLD format)
L43677000 -- > no change reqd (exists one row with new format and old format like below)
L00043677 -- > to be deleted this is old format (and new format like above already exists)
EX:
L00012345 --- old format
L12345000 --- new format
Hope question is clear. I written the following program.
update is working fine but delete is not working.
Please help.
Thanks in Advance
Devender
declare
Cursor c_test is
(select po_num from GSR03_PO_DTL);
BEGIN
FOR r_test in c_Test
LOOP
dbms_output.put_line (r_test.po_num);
IF ('L'||substr(r_test.po_num,5,5)) = ('L'||substr(r_test.po_num,2,5)) then
dbms_output.put_line ('delete stmnt');
END IF;
EXIT WHEN c_test%NOTFOUND;
END LOOP;
FOR r_test in c_Test
LOOP
IF r_test.po_num like 'L000%' then
IF ('L'||substr(r_test.po_num,5,5)) is not NULL then
update GSR03_PO_DTL set PO_NUM = 'L'||substr(po_num,5,5)||'000'
where po_num like 'L000%' ;
dbms_output.put_line ('update stmnt');
END IF;
END IF;
END LOOP;
END;
*********************No need for PL/SQL, man.
SQL> SELECT po_no FROM po1
2 /
PO_NO
L53177000
L00041677
L43677000
L00043677
SQL> UPDATE po1 y
2 SET y.po_no = 'L'||substr(y.po_no,5,5)||'000'
3 WHERE y.po_no LIKE 'L000%'
4 AND NOT EXISTS ( SELECT null FROM po1 x
5 WHERE x.po_no = 'L'||substr(y.po_no,5,5)||'000')
6 /
1 row updated.
SQL> DELETE FROM po1 y
2 WHERE y.po_no LIKE 'L000%'
3 AND EXISTS ( SELECT null FROM po1 x
4 WHERE x.po_no = 'L'||substr(y.po_no,5,5)||'000')
5 /
1 row deleted.
SQL> SELECT po_no FROM po1
2 /
PO_NO
L53177000
L41677000
L43677000
SQL> Cheers, APC -
How to get last Record ior Total rows in For Loop Cursor ?
Hi Friends
I would like to know , the last record in for loop cursor, i have the code in following format
cursor c1 is
select * from emp;
begin
for r1 in c1 loop
v_total_rec := ? ( i would like to know total rows in the cursor , say for example if cursor has 10 rows, i want10 into this variable )
v_count := v_count +1;
dbms_output.put_line(r1.emp_name);
end loop;
end;
Hope i am clear
Any suggestions?
Thanks
RaviEven though cursor loops are generally a Bad Idea ^tm^ as Dan says, here's an example of how you can get the information you wanted within the query itself...
SQL> ed
Wrote file afiedt.buf
1 declare
2 cursor c1 is
3 select emp.*
4 ,count(*) over (order by empno) as cnt
5 ,count(*) over () as total_cnt
6 from emp
7 order by empno;
8 begin
9 for r1 in c1 loop
10 dbms_output.put_line(r1.ename||' - row: '||r1.cnt||' of '||r1.total_cnt);
11 end loop;
12* end;
SQL> /
SMITH - row: 1 of 14
ALLEN - row: 2 of 14
WARD - row: 3 of 14
JONES - row: 4 of 14
MARTIN - row: 5 of 14
BLAKE - row: 6 of 14
CLARK - row: 7 of 14
SCOTT - row: 8 of 14
KING - row: 9 of 14
TURNER - row: 10 of 14
ADAMS - row: 11 of 14
JAMES - row: 12 of 14
FORD - row: 13 of 14
MILLER - row: 14 of 14
PL/SQL procedure successfully completed.
SQL> -
How to type cast PL/SQL table to REF cursor?
any one knows how to CAST PL/SQl table to Ref cursor?
eg
procedure some_name(r_out out sys_refcurosr)
IS
type t is table of tab%ROWTYPE;
my_type t;
begin
select * bulk collect into my_type from tab;
r_out := my_type; -- need help here..
end;
it's 10gref cursor is pointer to result set. You can not cast to PL/SQL table.
1 create or replace procedure some_name(r_out out sys_refcursor)
2 IS
3 begin
4 OPEN r_out for select * from emp;
5* end;
SQL> /
Procedure created.
SQL> var mycursor refcursor;
SQL> exec some_name(:mycursor);
PL/SQL procedure successfully completed.
SQL> set linesize 2000
SQL> print :mycursor;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 12/17/80 00:00:00 800 20
7499 ALLEN SALESMAN 7698 02/20/81 00:00:00 1600 300 30
7521 WARD SALESMAN 7698 02/22/81 00:00:00 1250 500 30
7566 JONES MANAGER 7839 04/02/81 00:00:00 2975 20
7654 MARTIN SALESMAN 7698 09/28/81 00:00:00 1250 1400 30
7698 BLAKE MANAGER 7839 05/01/81 00:00:00 2850 30
7782 CLARK MANAGER 7839 06/09/81 00:00:00 2450 10
7788 SCOTT ANALYST 7566 04/19/87 00:00:00 3000 20
7839 KING PRESIDENT 11/17/81 00:00:00 5000 10
7844 TURNER SALESMAN 7698 09/08/81 00:00:00 1500 0 30
7876 ADAMS CLERK 7788 05/23/87 00:00:00 1100 20
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7900 JAMES CLERK 7698 12/03/81 00:00:00 950 30
7902 FORD ANALYST 7566 12/03/81 00:00:00 3000 20
7934 MILLER CLERK 7782 01/23/82 00:00:00 1300 10
14 rows selected. -
Custom PL/SQL servlet for HTTP Listener like HTMLDB
We would like to migrate our applications from apache that use a custom perl application server to the xdb http listener and would need to be able to write a custom pl/sql servlet for the listener
eg
<servlet xmlns="http://xmlns.oracle.com/xdb/xdbconfig.xsd">
<servlet-name>Custom</servlet-name>
<servlet-language>PL/SQL</servlet-language>
Can this be done? (Well obviously, HTMLDB did it.)
Is information available to do this?
Information on the request (url/headers/content) and response (headers/content) objects
of the http listener would be needed.
Our pl/sql applications look like
create package my_app as
procedure my_job (request xmltype);
end;
This is why we need to do the servlet ourselves and why dbms_epg is not suitable.Currently
we don't plan to allow large input to be passed as a
CLOB parameter to the procedure. Is there a use-case
for this?YES ;). I have seen this coming up quite a few times in this forum.
1) we cannot edit sql scripts in Apex directly (>32KB), this is quite inconvenient to download, edit and upload again. If we are talking about sql scripts, they are often larger than 32KB.
2) building an application where the user can directly edit or copy/paste spreadsheet data or xml data. It is quite a restriction to only have 32KB at your hand.
3) the common workaround would be to split the data in 32KB chunks and then reassemble them in the backend. Quite tedious.
4) editing larger HTML texts for a portal application for example.
5) editing larger HTML texts for a forum application for example.
... the list goes on ...
Another argument is that all other major technologies like servlets, jsps, perl, php, python they are all capable of handling this kind of data. I often feel it is too much of a restriction.
What do others in the forum think? Feedback is welcome!!!
Thanks,
~Dietmar. -
I have a 'for update' cursor defined with 'NOWAIT'. When soem of teh records that are supposed to be fetched by teh cursor are locked by another user for update..teh pl?SQL script returns
"ORA-00054: resource busy and acquire with NOWAIT specified" error.
If I declare teh cursor with out 'FOR UPDATE' or did NOT put 'NOWAIT' clause, teh script hangs waiting for teh records to be unlocked.
If the user opens a record in the front end (web app) and does not close it.. i can not run the script. Is theer any way to ignore those records that are locked by other users and query only ones that are available as part of the select statement in the cursor.Optimistic locking implies, essentailly, that you never lock the row. Instead, if you want to update the row, you check all the other columns of the row to see whether they have changed. In other words, you'd do a straight SELECT here and then when you went to UPDATE the data, you'd do
UPDATE <<change some column>>
WHERE col1=<<old col1 value>>
AND col2=<<old col2 value>>
AND ...If the update changed 1 row, you're set. If it changed 0 rows, someone had changed the underlying row since you SELECTED it, so you'd have to handle that condition. If it returned an error indicating that someone else had locked the row, you could handle that situation as well. If you just continue on, however, be sure that you know how to identify that this row wasn't updated so you can try to do the update the next time (assuming that makes sense).
If all your applications take the optimistic locking approach, you're pretty much guaranteed that no one else will have teh row locked, so you don't have to handle that state nearly as robustly.
Justin
Distributed Database Consulting, Inc.
www.ddbcinc.com -
OO4O & VC++ Access Violation with large sql statement
Using Oracle C++ Class Library OO4O for Oracle9i Version 9.0.1.4.3 for
Windows 98/NT/2000/XP.
Open a dynaset with a large sql statemant more then 1000 chars you get
a Access Violation, like below.
szSQL = "select..."
ores = oDyn.Open( odb, szSQL, ODYNASET_READONLY || ODYNASET_NOCACHE);
The same sql query works without any problem in SQL Plus. A simple SQL statement works fine using OO4O.
Any ideas?I am using Jboss 2.44 with tomcat3.2.3, and I get deployment problems when using jdk1.5, I also tried JBoss 4 but I also have lots of problems with that.
I have this huge system developed long time ago. I have problems with printing in jdk1.3 so upgrade to 1.4 or higher will fix the printing. Upgrading to jdk1.5 and JBoss 4 will need lots of rewrite which is not an option.
So to me it seems easier if I keep using jboss2.44 and tomcat 3.2.3 but just upgrade to JDK 1.4. All off this is just because jdk1.3.1 has printing bugs.
Bushwack, I am ding exactly like you are, the only difference is, ResultSet.CONCUR_UPDATABLE and I used , ResultSet.CONCUR_READONLY. But I tried and still the same error.
I will try using a new JDBC driver, hope it works, I am just struggling to find a free one -
OO4O & VC++ Access Violation with large sql statement - REPOST
This is a repost - my email address was incorrect on the previous message
OO4O & VC++ Access Violation with large sql statement
Using Oracle C++ Class Library OO4O for Oracle9i Version 9.0.1.4.3 for
Windows 98/NT/2000/XP.
Open a dynaset with a large sql statemant more then 1000 chars you get
a Access Violation, like below.
szSQL = "select..."
ores = oDyn.Open( odb, szSQL, ODYNASET_READONLY || ODYNASET_NOCACHE);
The same sql query works without any problem in SQL Plus. A simple SQL statement works fine using OO4O.
Any ideas?
[email protected]I am using Jboss 2.44 with tomcat3.2.3, and I get deployment problems when using jdk1.5, I also tried JBoss 4 but I also have lots of problems with that.
I have this huge system developed long time ago. I have problems with printing in jdk1.3 so upgrade to 1.4 or higher will fix the printing. Upgrading to jdk1.5 and JBoss 4 will need lots of rewrite which is not an option.
So to me it seems easier if I keep using jboss2.44 and tomcat 3.2.3 but just upgrade to JDK 1.4. All off this is just because jdk1.3.1 has printing bugs.
Bushwack, I am ding exactly like you are, the only difference is, ResultSet.CONCUR_UPDATABLE and I used , ResultSet.CONCUR_READONLY. But I tried and still the same error.
I will try using a new JDBC driver, hope it works, I am just struggling to find a free one
Maybe you are looking for
-
PO Version not displayed in PO List Displays (ME2L, ME2K, etc)
I have configured PO Version Management. My PO's are working as desired with proper output. However, the PO Version Number is not displayed in my PO List Display tcodes (ME2L, ME2K, etc) nor is it available to add to the layout. I have configured th
-
I have table Like contract_ref_no contract_type realized_internal_gmr_ref_no 53909-P P GMR-3584 102585-S S GMR-3584 51289-p p GMR-1869 104586-S S GMR-1869 57182-P P GMR-2890 102588-S S GMR-2890 I want to display order depending on purchase order(cont
-
No sound in GarageBand for ipad
After uppgrading to iOS 5 on My ipad2 I donet get any sound at all from GarageBand. Not When I start a new project or openig My old ones.Evert Luther application works but not GarageBand. Does anyone have the same problem or a solution to this?
-
Housekeeping of Query Views in Portal
Hi, I am looking to provide housekeeping with Query Views on our Portal. At the moment all Query Views appear when you choose 'Bex Portfolio' and there are a large number in there now - most of which are redundant. At the moment, I have two issues -
-
Hello, when I start sonata in console, I get: Error authenticating audioscrobbler AudioScrobblerHandshakeError: The timestamp provided was not close enough to the current time.