CURSOR IN IF Statement
HI , I want to write a cursor in IF stmt
IF NOT (( emp_rec.empno IN
(9981, 9980, 9975, 9968)
AND emp_rec.sal< 51))
instead of freezing the values (9981, 9980, 9975, 9968) i have taken them in a table now i want to write a cursor on the table fetching the empno and sal condition
can some one help me
812809 wrote:
HI , I want to write a cursor in IF stmt
IF NOT (( emp_rec.empno IN
(9981, 9980, 9975, 9968)
AND emp_rec.sal< 51))
instead of freezing the values (9981, 9980, 9975, 9968) i have taken them in a table now i want to write a cursor on the table fetching the empno and sal condition
can some one help meHI,
Assuming that you have inserted all your empid in table test
Declare
Cursor C1
IS
Select ...
FROM emp a
where exists (select 1 from test b where a.empno=b.empno);
BEGIN
FOR i in c1 loop
/** Write your logic***/
END LOOP;
END;Hope this helps.
PS-> Mark as COmplete/Answered if it meets your expected Result
Regards,
Achyut
Similar Messages
-
Hi,
Please let me know what is the difference between using OPEN CURSOR and SELECT statement WITH PACAKGE additon.
PraneethHi,
http://wiki.sdn.sap.com/wiki/display/ABAP/SELECTStatementsandCURSORstatement-Performance+Analysis.
and also check
http://help.sap.com/saphelp_46c/helpdata/en/fc/eb3b23358411d1829f0000e829fbfe/content.htm
cheers,
Bhavana -
Using Cursor in Select statements? How to do this?
I am getting an error whilt passing a cursor to a select clause:
SELECT dbms_xmlquery.getXML('select deptno, dname, '||
'cursor(select empno, ename, sal from emp e where e.deptno = d.deptno) employees '||
'from dept d where d.deptno in (10, 20)')
FROM dual;
DBMS_XMLQUERY.GETXML('SELECTDEPTNO'||'CURSORIS(SELECTEMPNOFROMEMPEWHEREE.DEPT=D.
<?xml version = '1.0'?>
<ERROR>oracle.xml.sql.OracleXMLSQLException: ORA-00923
: FROM keyword not found where expected
</ERROR
THIS IS DUE TO THE CURSOR AND ITS FROM STATEMENT?
CAN ANY ONE PLEASE GUIDE AS TO HOW TO USE CURSORS IN A SELECT STATEMENT PLEASE?Another duplicate thread. See my response Select CLAUSE error using CURSORS & XSU.Please SEE..
Cheers, APC -
Cursor - dynamic select statement?
Hello!
I am passing a string into a function, and my string is a sql select statement. Is it possible to create a cursor using the string that is passed to the function?
Ex:
create or replace function "GETCOUNT"
(sqlstring in VARCHAR2)
return NUMBER
is
rec_count NUMBER; --I eventually want to return a count of the rows returned from my sqlstring
cursor c1 is sqlstring <--this is what I'd like to do...but how?
begin
... -- I haven't gotten to this point yet
end;
The error I get says 'Encountered the symbol "sqlstring" when expecting on of the following: ( select '
Thanks in advance!!Something like this ->
create or replace procedure gen_cur(str in varchar2,rc in out sys_refcursor)
is
str1 varchar2(500);
begin
str1 := 'select empno,ename,hiredate,sal
from emp
where '||str;
open rc for str1;
exception
when others then
dbms_output.put_line(sqlerrm);
end;
variable b refcursor
declare
src varchar2(300);
begin
src:= 'sal between 2000 and 7000';
gen_cur(src,:b);
exception
when others then
dbms_output.put_line(sqlerrm);
end;
print bRegards.
Satyaki De. -
Cursor Expression Select Statement
SELECT DNAME, CURSOR(SELECT SAL,COMM FROM EMP E WHERE E.DEPTNO = D.DEPTNO) FROM DEPT D
DNAME CURSOR(SELECTSAL,COM
ACCOUNTING CURSOR STATEMENT : 2
CURSOR STATEMENT : 2
SAL COMM
2450
5000
1300
RESEARCH CURSOR STATEMENT : 2
CURSOR STATEMENT : 2
SAL COMM
800
2975
3000
1100
3000
SALES CURSOR STATEMENT : 2
CURSOR STATEMENT : 2
SAL COMM
1600 300
1250 500
1250 1400
2850
1500 0
950
6 rows selected.
OPERATIONS CURSOR STATEMENT : 2
CURSOR STATEMENT : 2
no rows selected
Can we get rid of "CURSOR STATEMENT : 2"(Also I don't know what is its
significance there) from the output so that the output is in a readable format.
Thanks,
Neeraj GoelI want Data in the Format Like
deptno cnt1
cnt2
cntN
deptno cnt1
cntM
when you have a parent table (dept) and you sometimes
want to see the child rows (emp) but "on demand". For example, you fetch
"select deptno, cursor( from emp ) from dept" and the user says "hmmm, I'd like
to see the emps in deptno 20" -- great, you just fetch that cursor and display
them -- you didn't have to bring everyone else back with that query.
Also useful when you have more then 1:M relationship in a query
Now you can get a result set like:
deptno Sal Comm
Sal Comm
Sal
3 Sal, 2 Comm items and one deptno -- in one "row"
Thats why i used cursor Expression.
Thanks
Neeraj Goel -
Hello All:
Is it possible to have the CASE Statement in the cursor? If so, could you please show me how to use it? I tried to use it as following but it did not work on Form Builder. I tried it on Oracle SQL *Plus and it worked there.
CURSOR tbl_chck_cur IS
SELECT chck_id,
NVL(sup_chck_id,'') sup_chck_id,
(CASE WHEN sup_chck_id = null THEN
(SELECT order_no from tbl_chck_lk where tbl_chck.chck_id = tbl_chck_lk.chck_id ) ELSE
(SELECT order_no from tbl_chck_lk
where tbl_chck.chck_id = tbl_chck_lk.chck_id ) END) order_no,
FROM tbl_chck;
Thanks in advance for any help.
KTFirst, get rid of that NVL on sup_chck_id. It does nothing. What do you want it to do, anyway???
And what is the second table "Tbl_chk_sub" in the from clause?
Ignoring tbl_chk_sub, this might work:SELECT T1.chck_id,
T1.sup_chck_id,
Decode(T1.sup_chck_id, null,LK1.order_no,Lk2.order_no) order_no
FROM tbl_chck T1,
tbl_chck_lk LK1,
tbl_chck_lk LK2
where LK1.chck_id(+) = T1.chck_id
and LK2.sup_chck_id(+) = T1.sup_chck_idIf the above does not work, you will have to find a work-around -- either do the lookup select in the post-query trigger, or create a stored function you can call from the select that returns the correct order_no based on the two columns, sup_chck_id and chck_id.
Do you know if we can use the SELECT statement inside the CASE statement?Sometimes Forms are several steps behind in adapting new sql features. So it looks like you cannot at this time. -
Ref cursor in select statement
I am not sure this is the right forum, but I got no reply from the OTN Sample.
How do I call a function from a select
statement ?
The function returns a ref cursor.
Here is the function definition:
FUNCTION get_priority_code_list
(p_language_id IN VARCHAR2)
RETURN RefCur
IS
rcur RefCur;
BEGIN
OPEN rcur FOR SELECT
priority_code "priority_code_menu",
priority_code_desc "priority_code_menu_desc"
FROM
prio_desc
WHERE
language_id = p_language_id;
RETURN rcur;
END;
I would like to wrap a SELECT statement
around the function and have the same result
as running the SELECT statement directly.
Of course it does not seem logical here to
use a function, but in fact I want the
function to do more than just a select....
I tried the syntax
SELECT package.function(param) FROM dual;
but that does not work...
or
SELECT * FROM package.function(param);
but that does not work either....
any idea ?
Tks.
nullI have a stored function that returns a ref cursor and I want to use it in select
I tried the following code
for example if the ref cursor returned rows of varchar2
I will define an object
CREATE TYPE myType as OBJECT( doc_type VARCHAR2(256));
created a type as a table of myType
create or replace type myTable as table of myType;
If I write a select statement like below
select * from TABLE(CAST(function_name() AS myTable))
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected - got CURSER
I get this error
Can anyone give any clue why this does throw an error or if there is a second way to do this, -
Cursor in if statement with two sql statements
if
:v_project_number ='ALL'
then
cursor c1 is select * from gl_je_lines gjl
where nvl(gjl.attribute10,1) in(select decode(:v_project_number,'ALL',nvl(gjl.attribute10,1),:v_project_number) from dual)
else if
:v_project_number !='ALL'
then
cursor c1 is select * from gl_je_lines gjl
end if;
this is giving error can any one help me to achive above requirementHi,
No need for 'if then' modify your cursor as follows:
cursor c1 is select * from gl_je_lines gjl
where decode(:v_project_number,'ALL','A',nvl(gjl.attribute10,1)) =decode(:v_project_number,'ALL','A',:v_project_number);
if :v_project_number is 'ALL' then it checks the character 'A' in both the side so the query returns all rows. On the other hand if :v_project_number is not equeal to 'ALL' strictly it compares the contents of gjl.attribute10 with :v_project_number. -
CURSOR Inside select statement
Hi,
I am trying to generate reports in XML Publisher using PL/SQL Procedure. Following is my procedure:
PROCEDURE XXDL_PO_VEN_SUMMARY_BY_VEN (ERR_BUFF VARCHAR2,
RETCODE VARCHAR2,
in_vendor_number IN VARCHAR2,
in_start_date IN VARCHAR2,
in_end_date IN VARCHAR2
IS
SQL_STMT VARCHAR2(15000);
result CLOB;
in_vendor_summary_from_date DATE;
in_vendor_summary_to_date DATE;
CURSOR_WHERE_CLAUSE VARCHAR2(1000);
BEGIN
in_vendor_summary_from_date := TO_DATE(in_start_date,'YYYY/MM/DD HH24:MI:SS');
in_vendor_summary_to_date := TO_DATE(in_end_date,'YYYY/MM/DD HH24:MI:SS');
--DBMS_OUTPUT.PUT_LINe('start date object'||in_vendor_summary_from_date);
--DBMS_OUTPUT.PUT_LINe('end date object'||in_vendor_summary_to_date);
IF in_start_date IS NOT NULL AND LENGTH(in_start_date) > 0 AND in_end_date IS NOT NULL AND LENGTH(in_end_date) > 0 THEN
CURSOR_WHERE_CLAUSE := 'AND TO_DATE(CONCAT(CONCAT(SUMMARY_MONTH, ''/''), SUMMARY_YEAR),''MM/YYYY'') BETWEEN'
||' '''||in_vendor_summary_from_date||''' AND '''||in_vendor_summary_to_date||'''';
END IF;
IF in_vendor_number IS NOT NULL AND LENGTH(in_vendor_number)>0 THEN
CURSOR_WHERE_CLAUSE := CURSOR_WHERE_CLAUSE || ' AND UPPER(VENDOR_NUM) LIKE UPPER('''||in_vendor_number||'%'')';
END IF;
--DBMS_OUTPUT.PUT_LINe('cursor where clause : '||CURSOR_WHERE_CLAUSE );
SQL_STMT := 'SELECT VS.VENDOR_NUM,' ||
' VS.VENDOR_NAME,' ||
' VS.SUMMARY_MONTH,' ||
' VS.SUMMARY_YEAR,' ||
' VS.ORD_TOTAL_CNT,' ||
' VS.ORD_DOLLAR_AMT,'||
' VS.RPO_TOTAL_CNT,' ||
' VS.RPO_DOLLAR_AMT,'||
' VS.CWA_TOTAL_CNT,' ||
' VS.CWA_DOLLAR_AMT,'||
' VS.STD_TOTAL_CNT,' ||
' VS.STD_DOLLAR_AMT,'||
' VS.BLM_TOTAL_CNT,' ||
' VS.BLM_DOLLAR_AMT,'||
' VS.INVOICE_TOTAL_CNT,' ||
' VS.INVOICE_DOLLAR_AMT, ' ||
' CURSOR (SELECT nvl(SUM( nvl(VS1.ORD_TOTAL_CNT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS1 '||
' ) TOTAL_ORDERS, ' ||
' CURSOR(SELECT nvl(SUM(nvl(VS2.ORD_DOLLAR_AMT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS2 '||
' ) TOTAL_DOLLARS,' ||
' CURSOR(SELECT nvl(SUM(nvl(VS3.RPO_TOTAL_CNT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS3 '||
' ) RPO_ORDERS,' ||
' CURSOR(SELECT nvl(SUM(nvl(VS4.RPO_DOLLAR_AMT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS4 '||
' ) RPO_DOLLARS,' ||
' CURSOR(SELECT nvl(SUM(nvl(VS5.CWA_TOTAL_CNT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS5 '||
' ) CWA_ORDERS,' ||
' CURSOR(SELECT nvl(SUM(nvl(VS6.CWA_DOLLAR_AMT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS6 '||
' ) CWA_DOLLARS,' ||
' CURSOR(SELECT nvl(SUM(nvl(VS7.STD_TOTAL_CNT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS7 '||
' ) STD_ORDERS,' ||
' CURSOR(SELECT nvl(SUM(nvl(VS8.STD_DOLLAR_AMT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS8 '||
' ) STD_DOLLARS,' ||
' CURSOR(SELECT nvl(SUM(nvl(VS9.BLM_TOTAL_CNT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS9 '||
' ) BLM_ORDERS,' ||
' CURSOR(SELECT nvl(SUM(nvl(VS10.BLM_DOLLAR_AMT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS10 '||
' ) BLM_DOLLARS,' ||
' CURSOR(SELECT nvl(SUM(nvl(VS11.INVOICE_TOTAL_CNT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS11 '||
' ) TOTAL_INVOICES,' ||
' CURSOR(SELECT nvl(SUM(nvl(VS12.INVOICE_DOLLAR_AMT,0)),0) FROM STANPRS.VENDOR_SUMMARY VS12 '||
' ) INVOICE_DOLLARS, ' ||
' CURSOR(SELECT nvl(SUM(nvl(V1.RPO_TOTAL_CNT,0)),0)*100 / decode(SUM(nvl(V1.RPO_TOTAL_CNT,0)),0,1,NULL,1,SUM(nvl(V1.RPO_TOTAL_CNT,0))) FROM '|| ' STANPRS.VENDOR_SUMMARY V1 ) RPO_ORDERS_PER,' ||
' CURSOR(SELECT NVL(SUM(nvl(V2.RPO_DOLLAR_AMT,0)),0)*100 / decode(SUM(nvl(V2.RPO_DOLLAR_AMT,0)),0,1,NULL,1,SUM(nvl(V2.RPO_DOLLAR_AMT,0))) '|| 'FROM STANPRS.VENDOR_SUMMARY V2 ) RPO_DOLLARS_PER,' ||
' CURSOR(SELECT NVL(SUM(nvl(V3.CWA_TOTAL_CNT,0)),0)*100 / decode(SUM(nvl(V3.CWA_TOTAL_CNT,0)),0,1,NULL,1,SUM(nvl(V3.CWA_TOTAL_CNT,0))) FROM '|| 'STANPRS.VENDOR_SUMMARY V3 ) CWA_ORDERS_PER,' ||
' CURSOR(SELECT NVL(SUM(nvl(V4.CWA_DOLLAR_AMT,0)),0)*100 / decode(SUM(nvl(V4.CWA_DOLLAR_AMT,0)),0,1,NULL,1,SUM(nvl(V4.CWA_DOLLAR_AMT,0))) '||
'FROM STANPRS.VENDOR_SUMMARY V4 ) CWA_DOLLARS_PER,' ||
' CURSOR(SELECT NVL(SUM(nvl(V5.STD_TOTAL_CNT,0)),0)*100 / decode(SUM(nvl(V5.STD_TOTAL_CNT,0)),0,1,NULL,1,SUM(nvl(V5.STD_TOTAL_CNT,0))) FROM '|| 'STANPRS.VENDOR_SUMMARY V5 ) STD_ORDERS_PER,' ||
' CURSOR(SELECT NVL(SUM(nvl(V6.STD_DOLLAR_AMT,0)),0)*100 / decode(SUM(nvl(V6.STD_DOLLAR_AMT,0)),0,1,NULL,1,SUM(nvl(V6.STD_DOLLAR_AMT,0))) '||
'FROM STANPRS.VENDOR_SUMMARY V6 ) STD_DOLLARS_PER,' ||
' CURSOR(SELECT NVL(SUM(nvl(V7.BLM_TOTAL_CNT,0)),0)*100 / decode(SUM(nvl(V7.BLM_TOTAL_CNT,0)),0,1,NULL,1,SUM(nvl(V7.BLM_TOTAL_CNT,0))) '||
'FROM STANPRS.VENDOR_SUMMARY V7 ) BLM_ORDERS_PER,' ||
' CURSOR(SELECT NVL(SUM(nvl(V8.BLM_DOLLAR_AMT,0)),0)*100 / decode(SUM(nvl(V8.BLM_DOLLAR_AMT,0)),0,1,NULL,1,SUM(nvl(V8.BLM_DOLLAR_AMT,0))) '||
'FROM STANPRS.VENDOR_SUMMARY V8 ) BLM_DOLLARS_PER,' ||
'CURSOR(SELECT NVL(SUM(nvl(V9.INVOICE_TOTAL_CNT,0)),0)*100 / '||
'decode(SUM(nvl(V9.INVOICE_TOTAL_CNT,0)),0,1,NULL,1,SUM(nvl(V9.INVOICE_TOTAL_CNT,0))) FROM '||
'STANPRS.VENDOR_SUMMARY V9 ) TOTAL_INVOICES_PER, ' ||
'CURSOR(SELECT NVL(SUM(nvl(V10.INVOICE_DOLLAR_AMT,0)),0)*100/ decode(SUM(nvl(V10.INVOICE_DOLLAR_AMT,0)),0,1,NULL,1,SUM(nvl(V10.INVOICE_DOLLAR_AMT,0))) FROM STANPRS.VENDOR_SUMMARY V10 ) INVOICE_DOLLARS_PER' ||
' FROM STANPRS.VENDOR_SUMMARY VS' ||
' WHERE';
--DBMS_OUTPUT.PUT_LINE('STANPRS.VENDOR_SUMMARY V10 WHERE V10.VENDOR_NUM = VS.VENDOR_NUM ') INVOICE_DOLLARS_PER');
IF in_start_date IS NOT NULL AND LENGTH(in_start_date) > 0 AND in_end_date IS NOT NULL AND LENGTH(in_end_date) > 0 THEN
SQL_STMT := SQL_STMT || ' TO_DATE(CONCAT(CONCAT(VS.SUMMARY_MONTH, ''/''), VS.SUMMARY_YEAR),''MM/YYYY'') BETWEEN '
||' '''||in_vendor_summary_from_date||''' AND '''||in_vendor_summary_to_date||'''';
END IF;
IF in_vendor_number IS NOT NULL AND LENGTH(in_vendor_number)>0 THEN
IF SUBSTR(SQL_STMT, LENGTH(SQL_STMT)-4) = 'WHERE' THEN
SQL_STMT := SQL_STMT || ' UPPER(VS.VENDOR_NUM) LIKE UPPER('''||in_vendor_number||'%'')';
ELSE
SQL_STMT := SQL_STMT || ' AND UPPER(VS.VENDOR_NUM) LIKE UPPER('''||in_vendor_number||'%'')';
END IF;
END IF;
IF in_vendor_name IS NOT NULL AND LENGTH(in_vendor_name)>0 THEN
IF SUBSTR(SQL_STMT, LENGTH(SQL_STMT)-4) = 'WHERE' THEN
SQL_STMT := SQL_STMT || ' UPPER(VS.VENDOR_NAME) LIKE UPPER('''||in_vendor_name||'%'')';
ELSE
SQL_STMT := SQL_STMT || ' AND UPPER(VS.VENDOR_NAME) LIKE UPPER('''||in_vendor_name||'%'')';
END IF;
END IF;
IF SUBSTR(SQL_STMT, LENGTH(SQL_STMT)-4) = 'WHERE' THEN
SQL_STMT := SQL_STMT || ' VS.VENDOR_NUM = '''||in_vendor_number||'''';
END IF; */
SQL_STMT := SQL_STMT || ' ORDER BY VS.VENDOR_NUM, VS.VENDOR_NAME ASC';
--insert into XX_ERROR VALUES('Spriha',SQL_STMT);
SELECT DBMS_XMLGEN.GETXML(SQL_STMT) INTO result FROM DUAL;
FND_FILE.PUT_LINE(FND_FILE.OUTPUT, result);
EXCEPTION
WHEN OTHERS THEN
FND_FILE.PUT_LINE(FND_FILE.OUTPUT, SQLERRM);
END XXDL_PO_VEN_SUMMARY_BY_VEN ;
Now u can see in this Procedure that i have created so many cursors. i.e. for one function i have created one cursor. at present thesecursors are working fine. but the time i will put the where clause inside the cursors this will throw an ERROR ' ORA-01460 Unimplemented or Unreasonable Conversion Request'. Also these cursors are working with where clause but they are not working together. i.e when i will remove some cursors then i am not getting any error but at present i.e. without any where clause they all r working fine. Seriously i am not getting anything that what is happening. Can anyone help me? waiting for the reply....
Thanks
SprihaThis is pretty much a poster for ugly code.
Simplify this down to the bare minimum and debug it. Then add back the rest of the functionality.
But I am at a loss, looking at this code, as to why any cursor is either desirable or required. -
Question regarding the execution of cursors and SQL statements
Hi,
I have cursor which fetches results from a table A.
Now, simultaneously, in other session, I ran an update on the table A and commited it.
1) My question is will the cursor keep fetching the old results or the cursor start fetching the new values when the data is committed?
2) I have a similar question in SQL too. We generally write SQL queries which take considerable amount of time- around half an hour. During this time, I ran an update on the table and committed it. Will the result set contain the old values ?
As per my knowledge, both should fetch the old values.
But, I would like to get my beliefs reinforced.
Thanks for your help.
Dondonisback wrote:
Thanks John..
Your post drives me to ask another question. We've been getting the error "Snapshot Too Old" quite frequently.
So, we minimized the SQL and used cursor committing every 10000 records. This prevented the above error.
Is there any other possible reason why we get the error "Snapshot too Old"?
Thanks,
DonDon:
Typically, commiting more frequently increases the likelyhood of 1555, not decreases it. The 1555 error comes when the undo (or rollback in old terms) records that need to be read to support read consistency are no longer available. Simplistically, once a change has been committed, the undo records are marked as available for re-use and could be re-used thereby destroying the information that you need.
Even though ithe initial question is really old, read the Ask Tom thread posted by RPuttagunta. Tom explains it far better than I could, and the basic concepts have not changed.
John
John -
Dashboard cursor cache query statement
hi,
i would like to ask if there is a way to get the query statement that was executed in getting the dashboard result. i'm thinking if it is possible to get this programmatically, like using a session variable.
basically, i would like to replicate the data in the dashboard, and i would like to use the query statement (by another application) to be executed via obiee web service.
thanks.I think you are addressing a common problem in datawarehouses... there are staging tables, some times empty, some times with millions of rows... so, maybe the statistics are not reallistic... What is the result of the following query:
select num_rows, last_analyzed from dba_tables where table_name = '<your_table>';
If this is the problem, you should to consider one of the following strategies:
1) Analize the table when is "full" and assure that never runs an analize table (or a gather_schema_stats) over this table. This strategy works fine if all days the table is populated with similar data... but maybe you need to change a gather_schema_stats job schedule... you should be aware of when and how the statistics are updated
2) Populate the table, then run a gather_table_stats over the table, wait for the completion of the gathertable_stats_, and finally trigger the 6am process... maybe you need to schedule the process before 6am because the statistics gather process
I hope this helps
Regards,
Alfonso -
Cursor or case statement?
PartyTypeID FunctionType
4 Display Name
5 Organization Name
6 Band Name
7 Alias
8 Venue Name
9 Legal Name
10 Abbreviated NameI have table like above in Relational database form, I am working on store PROC. My task is to modify proc in such a way that---One condition if there is existing Organization Namein other reference table then insert as an Alias--another condition if organization nameis noted by venue name, Band Name or Legal name then insert all the records as belowparty Id Function Type
5 Organization Name5 Venue Name5 Band name5 legal Name and so on----- Party Type ID 4 and 5 can not come together combination can be like 4,6,7,8,9 or 5,6,7,8,9 Why 4 and 5 can not come together is both are separate eg Buyer 1 (display name individual person) and Buyer 2 (Org)i.e companyHi Arjunji, I am guessing your buyer table details and the following is the sample code. Please take a look and tweak accordingly
if object_id ('tempdb..#t1',N'U') is not null
drop table #t1
create table #t1 ([BuyerID] int, [BuyerType] tinyint, [FnTypeValue] varchar(50), [partyTypeID] tinyint, [FunctionType] varchar(50))
;with cte1
as
( select 1 as buyerID, 4 as PartyTypeID, 'Display Name1' as FnTypeValue
union all
select 1 as buyerID, 7 as PartyTypeID, 'Alias1' as FnTypeValue
union all
select 1 as buyerID, 9 as PartyTypeID, 'Legal Name1' as FnTypeValue
union all
select 2 as buyerID, 5 as PartyTypeID, 'Organization Name1' as FnTypeValue
union all
select 2 as buyerID, 7 as PartyTypeID, 'Alias2' as FnTypeValue
union all
select 2 as buyerID, 9 as PartyTypeID, 'Legal Name2' as FnTypeValue
union all
select 3 as buyerID, 4 as PartyTypeID, 'Display Name2' as FnTypeValue
union all
select 3 as buyerID, 7 as PartyTypeID, 'Alias3' as FnTypeValue
union all
select 3 as buyerID, 9 as PartyTypeID, 'Legal Name3' as FnTypeValue
union all
select 3 as buyerID, 6 as PartyTypeID, 'Band Name1' as FnTypeValue
union all
select 4 as buyerID, 5 as PartyTypeID, 'Organization Name2' as FnTypeValue
union all
select 4 as buyerID, 9 as PartyTypeID, 'Legal Name4' as FnTypeValue
insert into #t1([BuyerID] , [BuyerType], [FnTypeValue] , [partyTypeID], [FunctionType] )
select
Buyertab.buyerID,
case
when exists( select PartyTypeID from cte1 where PartyTypeID=4 and buyerID=Buyertab.buyerID) then 4
else 5
end as BuyerType,
Buyertab.FnTypeValue,
Reftab.[partyTypeID], Reftab.[FunctionType]
from
cte1 as Buyertab
left join
select 4 as PartyTypeID, 'Display Name' as FunctionType
union all
select 5 as PartyTypeID, 'Organization Name' as FunctionType
union all
select 6 as PartyTypeID, 'Band Name' as FunctionType
union all
select 7 as PartyTypeID, 'Alias' as FunctionType
union all
select 8 as PartyTypeID, 'Venue Name' as FunctionType
union all
select 9 as PartyTypeID, 'Legal Name' as FunctionType
union all
select 10 as PartyTypeID, 'Abbreviated Name' as FunctionType
) as Reftab
on Buyertab.PartyTypeID = Reftab.PartyTypeID
select top 100 * from #t1 -
Oracle and "Maximum open cursors exceeded"
Hi,
I am using Weblogic 7.0sp2 with Oracle 9.2.0. Since we are using manual JTA
transactions and the 9.2 drivers are buggy in that respect, we are using the
9.0.1 thin drivers delivered with weblogic.
The problem I have is that after a while, we get the now classic "Maximum open
cursors exceeded" error on connections from our connection pool (used through
a
TX datasource). I have of course checked all our JDBC code and it is fine. We
do not leave any statement/connection open. In fact, I am certain that the
problem is not caused by our applicative code.
The reason I am so positive is that the numbers of open (cached) cursors is
growing, even though there is no activity on our application (I mean no
activity at all). The number of cursors is regurlarly increasing by one
every 5 minutes until it reaches the maximum allowed for a session.
I have listed the statements corresponding to the opened cursors (they
do not belong to our code, as you might have guessed):
SELECT sysdate, user from dual
select longdbcs from javasnm$ where short = :1
select longname from javasnm$ where short = :1
As you can see, there are only three different statements. You can get
the statements from the system view v$open_cursor for a given session
but it will only give one row per different statement. If you want to know
the # of opened cursors in your cursor, use v$sesstat with statistic# = 3
(opened cursor current).
I suspect something is wrong in the connection testing done by weblogic
for the pool (I have activated test on reserved connections and test table
name is "dual") that leaves a resultset/statement behind. What is weird
though is that the refresh period is still 0 (not 5 minutes as you would
expect from the cursor growth rate...).
I would not say that it is an Oracle bug (as stated in some BEA FAQ I read)
since our application JDBC code does not exhibit the same problem. The
problem appeared with recent version of WebLogic for which the session
cursor cache is enabled, I suppose for performance reasons - this
is set by isssuing "ALTER SESSION SET SESSION_CACHED_CURSORS = ...".
Talking about this, does anybody know to which value WebLogic sets this
parameter when intializing the connection (this is neither
documented/configurable)?
Up to now, I have come up with possibly two workarounds, neither of which
is satisfying:
- resetting the pool from time to time
- issuing "ALTER SESSION SET SESSION_CACHED_CURSORS = 0" when I get a
connection from the pool. I have not tested this one personally (read
in a newsgroup that someone else did successfully) but it is supposed
to reset the cursor cache that is causing the trouble.
Any help will be greatly appreciated,
Regards,
Thierry.Thierry Rouget wrote:
Hi,
I am using Weblogic 7.0sp2 with Oracle 9.2.0. Since we are using manual JTA
transactions and the 9.2 drivers are buggy in that respect, we are using the
9.0.1 thin drivers delivered with weblogic.
The problem I have is that after a while, we get the now classic "Maximum open
cursors exceeded" error on connections from our connection pool (used through
a
TX datasource). I have of course checked all our JDBC code and it is fine. We
do not leave any statement/connection open. In fact, I am certain that the
problem is not caused by our applicative code.
The reason I am so positive is that the numbers of open (cached) cursors is
growing, even though there is no activity on our application (I mean no
activity at all). The number of cursors is regurlarly increasing by one
every 5 minutes until it reaches the maximum allowed for a session.
I have listed the statements corresponding to the opened cursors (they
do not belong to our code, as you might have guessed):
SELECT sysdate, user from dual
select longdbcs from javasnm$ where short = :1
select longname from javasnm$ where short = :1
As you can see, there are only three different statements. You can get
the statements from the system view v$open_cursor for a given session
but it will only give one row per different statement. If you want to know
the # of opened cursors in your cursor, use v$sesstat with statistic# = 3
(opened cursor current).
I suspect something is wrong in the connection testing done by weblogic
for the pool (I have activated test on reserved connections and test table
name is "dual") that leaves a resultset/statement behind. What is weird
though is that the refresh period is still 0 (not 5 minutes as you would
expect from the cursor growth rate...).
I would not say that it is an Oracle bug (as stated in some BEA FAQ I read)
since our application JDBC code does not exhibit the same problem. The
problem appeared with recent version of WebLogic for which the session
cursor cache is enabled, I suppose for performance reasons - this
is set by isssuing "ALTER SESSION SET SESSION_CACHED_CURSORS = ...".
Talking about this, does anybody know to which value WebLogic sets this
parameter when intializing the connection (this is neither
documented/configurable)?
Up to now, I have come up with possibly two workarounds, neither of which
is satisfying:
- resetting the pool from time to time
- issuing "ALTER SESSION SET SESSION_CACHED_CURSORS = 0" when I get a
connection from the pool. I have not tested this one personally (read
in a newsgroup that someone else did successfully) but it is supposed
to reset the cursor cache that is causing the trouble.
Any help will be greatly appreciated,
Regards,
Thierry.Hi. We don't make those queries either. I suspect they are internal to the
oracle driver. One thing you can try is to set the size of the pool's
statement cache to zero. Oracle will retain cursors for every statement we
cache. The alternative is also to tell the DBMS to allow a given session
more cursors.
Joe -
Cannot figure out why "ORA-01000 Maximum open cursors" is shown...
Hello there ...
I am programming a PL/SQL Code that is throwing 0RA-01000 Maximum Open Cursors Exceeded.
Having already read quite a lot about ORA-01000 errors, I know I should be closing cursors, and have already tried setting OPEN_CURSORS parameter to a high number (1000).
I declared a lot of procedures in my pl/sql, each of which uses one cursor since i am working with a non-Oracle table linked by ODBC ... and each procedure sometimes does thousands of inserts -- but all WITHIN the explicit cursors. The explicit cursors are not declared within each loop.
I already checked the code many times, and made sure all open cursors are closed. In addition, I also verified the numberopen cursors generated by the PL/SQL by running the following SQL after every procedure i run... and outputting it... and it appears the value just keeps on increasing, even though I had explicitly closed all the cursors in all the earlier procedures.
What is funny is that the most number of cursors reported by the code below only hits 150+ cursors. Nowhere near the 1000 open_cursors limit per session.
select a.value into strtxt --, b.name
from v$mystat a, v$statname b
where a.statistic# = b.statistic#
and a.statistic#= 3;When I run the procedures separately though, all the procedures run smoothly (even when I had not yet updated the open_cursors parameter).
I was thinking of the following, but maybe you have some other ideas?
Does this have anything to do with my procedures not being stored procedures?
Or should i be committing records within my procedures instead of out of it?
I really have run into a wall and would really appreciate any tips or helps on this. Thanks in advance!
My basic pl/sql code looks like below. I did not give the actual details cause it will be too long (up to 5000 lines).
DECLARE
PROCEDURE proc1
IS
CURSOR cur_hca
is
select ...from..where;
TYPE cur_hca_fetch
Is TABLE OF cur_hca%ROWTYPE
INDEX BY PLS_INTEGER;
temp_collect cur_hca_fetch;
BEGIN
open cur_hca; --cur_hca is the cursor name.
--i use exactly the same cursor name in the other procedures
loop
fetch cur_hca bulk collect into temp_collect LIMIT 1000;
exit when temp_collect.count=0
for indx in 1 .. temp_collect.count
loop
...run some sql
end loop;
end loop;
close cur_hca;
END proc1;
PROCEDURE proc2 --almost the same as above the only changes are the query for the
-- cursor and the sql that happens for each record
IS
BEGIN
open cur_hca; --cur_hca is my cursor name
loop
end loop;
close cur_hca;
END proc2;
... up to 40 other very similar procedures
BEGIN
proc1;
commit;
select a.value into strtxt
from v$mystat a, v$statname b
where a.statistic# = b.statistic#
and a.statistic#= 3;
DBMS_OUTPUT.PUT_LINE('Number of Cursors After STATUSproc1: ' || strtxt);
proc2;
commit;
select a.value into strtxt
from v$mystat a, v$statname b
where a.statistic# = b.statistic#
and a.statistic#= 3;
DBMS_OUTPUT.PUT_LINE('Number of Cursors After STATUSproc2: ' || strtxt);
... 40 other procedures
END;Edited by: user4872285 on May 6, 2013 6:49 PM
Edited by: user4872285 on May 6, 2013 7:01 PM
Edited by: user4872285 on May 6, 2013 8:02 PM
Edited by: user4872285 on May 6, 2013 8:03 PMPL/SQL code usually leaks reference cursors and DBMS_SQL cursors - as the ref cursor/DBMS_SQL interface used has a global (session static) scope.
PL/SQL has an intelligent garbage collector that will close local implicit and explicit cursors, when the cursor variable goes out of scope.
If you define an explicit cursor globally (package interface), then it can only be opened once. The 2nd attempt results in a ORA-06511: PL/SQL: cursor already open exception. So code cannot leak explicit cursors as code cannot reopen an existing opened explicit cursor.
I have never seen Oracle leaking cursors internally. So I would be hesitant to call what you are seeing, a bug. If your code is using explicit cursors (even static/global ones), your code cannot leak these cursors, even if your code does not close them. Worse case - the cursor remains open, however new copies cannot be created while it is open.
So I think your are looking at the wrong thing - explicit cursors. These are not the cursors that are leaking in my view (simply because code cannot reuse and open an already opened explicit cursor). Here is an example:
SQL> show parameter cursors
NAME TYPE VALUE
open_cursors integer 300
session_cached_cursors integer 50
// procedure that seems to "leak" an explicit cursor handle
// as it does not explicitly closes the handle
SQL> create or replace procedure CursorUse is
2 cursor c is select e.* from emp e;
3 empRow emp%RowType;
4 begin
5 open c;
6 fetch c into empRow;
7 --// not closing explicit cursor handle
8 --// and going out-of-scope
9 end;
10 /
Procedure created.
// current session stats
SQL> select b.name, a.value from v$mystat a, v$statname b where a.statistic# = b.statistic# and b.name like '%open%cursor%';
NAME VALUE
opened cursors cumulative 91
opened cursors current 2
// execute proc that "leaks" a cursor, 10000 times
SQL> begin
2 for i in 1..10000 loop
3 CursorUse;
4 end loop;
5 end;
6 /
PL/SQL procedure successfully completed.
// no errors due to cursor leakage
// session stats: no cursor leakage occurred as
// PL/SQL's garbage collector cleaned (and closed)
// cursor handles when these became out-of-scope
SQL> select b.name, a.value from v$mystat a, v$statname b where a.statistic# = b.statistic# and b.name like '%open%cursor%';
NAME VALUE
opened cursors cumulative 10,095
opened cursors current 2
SQL> So the cursor leakage you are seeing is caused by something else... so what else is part of the code, or the session, that you have not yet mentioned? -
Please reply:how to avoid extra trailing spaces while using cursor sharing
i am using cursor sharing with FORCE or SIMILAR.
what is the solution to avoid extra trailing spaces without any java code change.
do we have any option in oracle to avoid extra trailing spaces during the query processing ?
I am using Oracle 10g
CURSOR SHARING is a feature in which multiple sql statements
which are same will have a shared cursor (in the library cache) for an oracle session,
i.e, the first three steps of the sql processing (hard parse, soft parse, optimization)
will be done only the first time that kind of statement is executed.
There are two ways in which similar SQL statements with different condition values can be made to "SHARE" cursor during execution:
1. Writing SQLs with Bind Variables: SQLs having no hard coded literals in them
For e.g., the query below
SELECT node.emp_name AS configid
FROM emp node
WHERE emp_no = :1
AND dept_no =
DECODE (SUBSTR (:2, 1, 3),
:3, :4,
(SELECT MAX (dept_no)
FROM emp
WHERE emp_no = :5 AND dept_no <= :6)
AND node.dept_type = :7
ORDER BY node.emp_name
Here all the variables are dynamically bound during the execution. The ":X" represents BIND Variable and the actual values are bound to the SQL only at the 4th step of the execution of the SQL.
In applications: The queries written with "?" as bind variables will be converted into ":X" and are sqls with Bind Variables.
2. The CURSOR_SHARING parameter: Only Useful for SQL statements containing literals:
For eg., the query below:
SELECT node.emp_name AS configid
FROM emp node
WHERE emp_no = 'H200'
AND dept_no =
DECODE (SUBSTR (:1, 1, 3),
'PLN', :2,
(SELECT MAX (dept_no)
FROM emp
WHERE emp_no = :3 AND dept_no <= :4)
AND node.dept_type = :5
ORDER BY node.emp_name
In the query above, there are two hard coded literals H200 , PLN. In this case when the same SQL executed with different values like (H2003 , PLN), oracle will create a new cursor for this statement and all the first three steps ( hard & soft parse and optimization plan) needs to be done again.
This can be avoided by changing the CURSOR_SHARING parameter which can be set to any of three values:
1. EXACT: Causes the mechanism not be used, i.e. no cursor sharing for statements with different literals. This is the default value.
2. FORCE: Causes unconditional sharing of SQL statements that only differ in literals.
3. SIMILAR: Causes cursor sharing to take place when this is known not to have any impact on optimization.
So, FORCE and SIMILAR values of the parameter will be helping in cursor sharing and improve the performance of the SQLs having literals.
But here the problem arises if we use the FORCE and SIMILAR other than EXACT.
alter session set cursor_sharing ='EXACT'
select 1 from dual;
'1'
1
alter session set curson_sharing='FORCE'
select 2 from dual;
'2'
2
alter session set curson_sharing='SIMILAR'
select 3 from dual;
'3'
3
So, this will give extra trailing spaces in when we retrieve from java method and any
further java processing based on the hardcoded literal values will fail. this needs lot of
effort in remodifying the existing millions of lines of code.
My question is i have to use cursor sharing with FORCE or SIMILAR and can't we do the trimming
from the oracle query processing level ?
please help me on this ?
Message was edited by:
Leeladhar
Message was edited by:
LeeladharPlease reply to this thread
How to avoid extr trailing spaces using Cursor sharing opton FORCE, SIMILAR
Maybe you are looking for
-
Hi friends, I used list view or datagrid in .net , I dnt know how to implement in forms 6i. In my module, I have to enter sales items ..it will come like this:(it will come from textbox to listview) item_name qty price x 1 23.00 y 2 34.00 z 1 23.00 f
-
Vendor returns with delivery(new delivery type)
Hi, I configured vendor return process with delivery. it's working fine with delivery type RLL but when I try to copy "RLL" and create new delivery type it's still picking delivery type "RLL" and not the new delivery type. My configurations 1. Create
-
Error while deploying inbound java server proxy on PI7.1....
Check this link: https://wiki.sdn.sap.com/wiki/display/JSTSG/(JSTSG)(TG)Q1127 Regards, Ravi
-
Multiple Midi Keyboards in Mainstage 1
Hi all I am currently running mainstage with a Novation Remote SL61. I want to also connect an Novation Remote SL25 to the set up, so I am running 2 Midi Controllers within Mainstage. Does anyone know if this is possible? Many thanks, Steve
-
Hi, How to find out, a machine is got internet conection or not? Using Java. Please Help me, Thanks