Open a CURSOR for a CLOB variable in 9i
Hi Friends,
I have a procedure which has a CLOB variable,and a sys_refcursor as inputs.
procedure proc1 ( p_sql clob, cur1 sys_refcursor);
I need to open this cur1 for p_sql clob.
OPEN CUR1 FOR P_SQL;
But it gives an error. I went through webs and found that it is not possible to do it in 9i. Do u know any alternate ? How can I do it ?
vishwa wrote:
Hi Friends,
I have a procedure which has a CLOB variable,and a sys_refcursor as inputs.
procedure proc1 ( p_sql clob, cur1 sys_refcursor);
I need to open this cur1 for p_sql clob.
OPEN CUR1 FOR P_SQL;
But it gives an error. I went through webs and found that it is not possible to do it in 9i. Do u know any alternate ? How can I do it ?Consider upgrading a an Oracle version that has been supported during the current Century.
If you installed a newer version DB, it could be used to access the exist V9 DB;
without any changes to the V9 DB itself.
Similar Messages
-
How can I open a cursor for dynamic sql statement
Hi,
I'm facing issues opening a cursor for dynamic sql statement : PLS-00455: cursor 'RESULT1' cannot be used in dynamic SQL OPEN statement.
CREATE OR REPLACE FUNCTION DEMO
(MN_I in VARCHAR)
return AB_OWNER.ABC_Type.NonCurTyp is
RESULT1 AB_OWNER.ABC_Type.NonCurTyp;
sql_stmt VARCHAR2(4000);
BEGIN
sql_stmt := 'SELECT * FROM AB_OWNER.DUN WHERE JZ_I in ('||mn_i||') ORDER BY app.ACC_I';
OPEN RESULT1 FOR sql_stmt;
END IF;
return RESULT1;
END DEMO;
What changes should I make in the code so that it doesn't fail? I can't change the definition of RESULT1 cursor though.Gangadhar Reddy wrote:
I used SYS REFCURSOR and was able to implement successfully.How many times did you run this successful implementation that does not use bind variables?
Because this is what will happen when it runs a lot.
http://download.oracle.com/docs/cd/E11882_01/server.112/e17766/e2100.htm#sthref1874
http://forums.oracle.com/forums/search.jspa?q=%2BORA-04031%20%2Bbind&objID=c84&dateRange=all&rankBy=10001&start=30
And you will have to regularly restart the server, or possibly slightly less invasive, flush the shared pool.
Flushing Shared Pool regularly
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1516005546092
>
Ok, this is an easy one to diagnose.
You are not using bind variables. This is terrible. Flushing the shared pool is a bad
solution -- you are literally killing the performance on your box by not using them.
If I was to write a book on how to build non scalable applications in Oracle, this
would be the first and last chapter. This is a major cause of performance issues and a
major inhibitor of scalability in Oracle. The way the Oracle shared pool (a very
important shared memory data structure) operates is predicated on developers using bind
variables. If you want to make Oracle run slowly, even grind to a total halt just
refuse to use them.
>
But, please feel free to go ahead with this successful implementation.
I just hope anyone else who reads this doesn't make the same mistake. -
Open cursor for and bind variables
Hello all,
how can I assign values to a bind variable before opening a cursor?
example code:
DECLARE
TYPE ref_cur_t IS REF CURSOR;
l_ref_cur ref_cur_t;
l_query VARCHAR2 (100)
:= 'select * from table t1 where ndx= :var_index' ;
BEGIN
-- assign a value to :var_index
OPEN l_ref_cur FOR l_query;
END;Thanks!Something like this ->
scott@ORCL>
scott@ORCL>DECLARE
2 l_ref_cur sys_refcursor;
3 l_query VARCHAR2 (100) := 'select * from emp where empno = :var_index';
4 l_empno number(4);
5 BEGIN
6 l_empno := &emno;
7 -- assign a value to :var_index
8 OPEN l_ref_cur FOR l_query using l_empno;
9 END;
10 /
Enter value for emno: 7698
old 6: l_empno := &emno;
new 6: l_empno := 7698;
PL/SQL procedure successfully completed.
Elapsed: 00:00:19.78
scott@ORCL>Regards.
Satyaki De. -
ORA-21560: while size is less than 1 GB for a CLOB variable
Hi ,
I use "DBMS_XSLPROCESSOR.CLOB2FILE' to write data from a CLOB variable (Oracle 10g) to TXT file in unix. I assumed that
the clob can collect data of around 4 gb , but it is throwing the "Out of Range" error if the size exceeds
22502381 bytes, which is not at all sufficient to my requirement. I want to collect around 3GB in the variable.
Is it possible ? Please help
2008-12-22 11:08 Error Occurred
ORA-21560: argument 2 is null, invalid, or out of range
Declare
Xfile CLOB ;
v_buffer VARCHAR2(32767);
v_eol VARCHAR2(2);
v_eollen PLS_INTEGER;
c_maxline CONSTANT PLS_INTEGER := 32767;
v_lines PLS_INTEGER := 0;
v_dir VARCHAR2(1000) := 'XXX/YYY' ;
v_data_string VARCHAR2(32767) ;
x integer ;
Begin
v_eol := CASE
WHEN DBMS_UTILITY.PORT_STRING LIKE 'IBMPC%'
THEN CHR(13)||CHR(10)
ELSE CHR(10)
END;
v_eollen := LENGTH(v_eol);
DBMS_LOB.CREATETEMPORARY(Xfile, TRUE);
FOR r in ( Select desc1||'~'||desc2||.....desc30 AS csv from desc_t )
Loop
IF LENGTH(v_buffer) + v_eollen + LENGTH(r.csv) <= c_maxline THEN
v_buffer := v_buffer || v_eol || r.csv;
ELSE
IF v_buffer IS NOT NULL THEN
DBMS_LOB.WRITEAPPEND(
v_file, LENGTH(v_buffer) + v_eollen, v_buffer || v_eol
END IF;
v_buffer := r.csv;
END IF;
v_lines := v_lines + 1;
END LOOP;
IF LENGTH(v_buffer) > 0 THEN
DBMS_LOB.WRITEAPPEND(
v_file, LENGTH(v_buffer) + v_eollen, v_buffer || v_eol
END IF;
DBMS_XSLPROCESSOR.CLOB2FILE(Xfile, v_dir, 'V_DESC,TXT');
DBMS_LOB.FREETEMPORARY(v_file);
Exception
When Others Then
dbms_output.put_line('Error '||v_lines||' --'||SQLERRM) ;
dbms_output.put_line('Error '||dbms_lob.getlength(Xfile)) ;
End ;
ThanksWell, ORA-21560 could indicate file opening issue. Check the file name 'V_DESC,TXT'. Most likely your UNIX either does not allow commas in file name or requires them to be escaped. And anyway, I believe it is a typo and you meant 'V_DESC.TXT'.
SY. -
Carriage Return/Linefeed Character Removal for a CLOB variable
Hi,
Can anyone let me know how I can remove the carriage return from a CLOB variable.
I tried the replace function
REPLACE(D_MessageText, CHR(10)), it doesn't give any error,but the output still has the new line character.
Any help would be really appreciated.
Regards,
Anil.chr(10) takes care of LINEFEED
chr(13) takes care of CARRIAGE RETURN -
Is there a different way to open a cursor for a ref cursor procedure?
hello everybody
i have two cursors, cur_a and cur_b, declared somewhere else in my application.
These two cursors have the same fields, in the same order, and i have to treat both in the same way. So i wrote a routine that gets as input a ref cursor based on the cur_a rowtype, and i am trying to use this routine for both.
The problem is that i am not able to open outside the routine the cursor in a different way than usual...
the common method is :
declare curs ref cursor ...
begin
open curs for (select *...)
end;
instead i would like to obtain something different
declare curs ref cursor ...
begin
open curs for cur_a
end;hi
thanks for answering
i wanted just to give a better idea, anyway you were near to get it.
the only difference is that the two cursors are not written in dynamic sql, just like strings, but are real cursors.
anyway, this is the version of the package i need, but i am not able to compile
(your original code is commented and immediately below there is my code)
CREATE OR REPLACE PACKAGE BODY mytest
IS
--cur_a VARCHAR2(200) := 'SELECT dummy FROM DUAL';
CURSOR cur_a
IS
SELECT dummy
FROM DUAL;
--cur_b VARCHAR2(200) := 'SELECT ''fred'' FROM DUAL';
CURSOR cur_b
IS
SELECT 'fred' fred
FROM DUAL;
TYPE t_cur_a IS REF CURSOR
RETURN cur_a%ROWTYPE
--PROCEDURE routine_a_b (p_cur SYS_REFCURSOR) IS
PROCEDURE routine_a_b (p_cur t_cur_a)
IS
v_x VARCHAR2 (10);
BEGIN
LOOP
FETCH p_cur
INTO v_x;
EXIT WHEN p_cur%NOTFOUND;
DBMS_OUTPUT.put_line (v_x);
END LOOP;
END;
PROCEDURE doit
IS
--v_curs SYS_REFCURSOR;
v_curs t_cur_a;
BEGIN
NULL;
-- open v_curs FOR cur_a;
OPEN v_curs FOR cur_a;
routine_a_b (v_curs);
CLOSE v_curs;
-- open v_curs FOR cur_b;
-- routine_a_b(v_curs);
-- close v_curs;
END;
END;
the error is:
cursor 'V_CURS' cannot be used in dynamic SQL OPEN statement
i did read that if use weak ref cursor, it could work, so i declare the ref cursor type in this way:
TYPE t_cur_a IS REF CURSOR;
instead than
TYPE t_cur_a IS REF CURSOR
RETURN cur_a%ROWTYPE
what i get is another error (in the open cursor command)
PLS-00382: expression is of wrong type....
but if i replace
OPEN v_curs FOR cur_a;
with
OPEN v_curs for select dummy from dual;
it works... but i already knew it.. :-)
anyway, i used a work around to resolve it, so it's just philosophy -
How to Open a cursor for a dynamic page
Hi,
I'm new to portal (we are evaluating the product to give our existing application <which is based heavily on stored procedures> a face-lift) and I am having trouble calling a procedure wich returns a cursor and then looping through that cursor in order to create an HTML report.
The db providor seems to compile but when I try to preview the page I get the following error:
ORA-01001: invalid cursor (WWV-11230)
The preference path does not exist: ORACLE.WEBVIEW.PARAMETERS.1125786214 (WWC-51000)
Here is the pl/sql code from between the ORACLE tags:
<ORACLE>
declare
type datacur is ref cursor;
dcur datacur;
v_CUSTOMER_ID number;
v_NAME varchar2(50);
v_STORE_NAME varchar2(50);
v_STATUS varchar2(50);
v_CREATED date;
begin
FIND_CUSTOMER (
dcur,
'010109_terminated_dhogan',
'Evoke',
71000107 );
loop
fetch dcur into v_CUSTOMER_ID, v_NAME, v_STORE_NAME,v_STATUS, v_CREATED;
exit when dcur%notfound;
htp.print('<tr><td>'||v_NAME ||'</td></tr>');
end loop;
end;
</ORACLE>
When I run the same code (using DBMS_OUTPUT instead of "htp.print") I get output.
Any suggestions?Maybe you should do it.
dcur datacur%rowtype; -
Opening a ref cursor using CLOB variable
Is there any way to open a ref cusor using CLOB variable.
When I am opening on CLOB variable , I am getting an error like 'Missing Expression'
Please help meFor 10g...
SQL> ed
Wrote file afiedt.buf
1 declare
2 v_large_sql CLOB;
3 v_num NUMBER := 0;
4 v_upperbound NUMBER;
5 v_sql DBMS_SQL.VARCHAR2S;
6 v_cur INTEGER;
7 v_ret NUMBER;
8 begin
9 -- Build a very large SQL statement in the CLOB
10 LOOP
11 IF v_num = 0 THEN
12 v_large_sql := 'CREATE VIEW vw_tmp AS SELECT ''The number of this row is : '||to_char(v_num,'fm0999999')||''' as col1 FROM DUAL';
13 ELSE
14 v_large_sql := v_large_sql || ' UNION ALL SELECT ''The number of this row is : '||to_char(v_num,'fm0999999')||''' as col1 FROM DUAL';
15 END IF;
16 v_num := v_num + 1;
17 EXIT WHEN DBMS_LOB.GETLENGTH(v_large_sql) > 40000 OR v_num > 800;
18 END LOOP;
19 DBMS_OUTPUT.PUT_LINE('Length:'||DBMS_LOB.GETLENGTH(v_large_sql));
20 DBMS_OUTPUT.PUT_LINE('Num:'||v_num);
21 --
22 -- Now split that large SQL statement into chunks of 256 characters and put in VARCHAR2S array
23 v_upperbound := CEIL(DBMS_LOB.GETLENGTH(v_large_sql)/256);
24 FOR i IN 1..v_upperbound
25 LOOP
26 v_sql(i) := DBMS_LOB.SUBSTR(v_large_sql
27 ,256 -- amount
28 ,((i-1)*256)+1 -- offset
29 );
30 END LOOP;
31 --
32 -- Now parse and execute the SQL statement
33 v_cur := DBMS_SQL.OPEN_CURSOR;
34 DBMS_SQL.PARSE(v_cur, v_sql, 1, v_upperbound, FALSE, DBMS_SQL.NATIVE);
35 v_ret := DBMS_SQL.EXECUTE(v_cur);
36 DBMS_OUTPUT.PUT_LINE('View Created');
37* end;
SQL> /
Length:40015
Num:548
View Created
PL/SQL procedure successfully completed.
SQL> select count(*) from vw_tmp;
COUNT(*)
548
SQL> select * from vw_tmp where rownum <= 10;
COL1
The number of this row is : 0000000
The number of this row is : 0000001
The number of this row is : 0000002
The number of this row is : 0000003
The number of this row is : 0000004
The number of this row is : 0000005
The number of this row is : 0000006
The number of this row is : 0000007
The number of this row is : 0000008
The number of this row is : 0000009
10 rows selected.
SQL> -
SELECT DISTINCT With OPEN cursor FOR
Hello.
I have the following procedure. All it does is open a cursor for an SQL string passed into it, and return the open cursor.
PROCEDURE sp_execute_dynamic (hold_input_string IN CLOB,
hold_cursor OUT hold_cursor_type) IS
BEGIN
OPEN hold_cursor FOR TO_CHAR(hold_input_string);
END sp_execute_dynamic;
It works fine except when I perform SELECT DISTINCT. I get the following error.
SQL> declare
2 TYPE hold_cursor_type IS REF CURSOR;
3 hold_cursor hold_cursor_type;
4 hold_object_name VARCHAR2(1024);
5 hold_object_type VARCHAR2(1024);
6 begin
7 dynamic_sql_pkg.sp_execute_dynamic('select distinct object_name from user_objects where object_
name in (''PLAN_TABLE'',''DBA_OBJECTS'')',hold_cursor);
8 loop
9 fetch hold_cursor into hold_object_name, hold_object_type;
10 exit when hold_cursor%NOTFOUND;
11 dbms_output.put_line('Object Name = '||hold_object_name||' Object Type = '||hold_object_type);
12 end loop;
13 end;
14 /
declare
ERROR at line 1:
ORA-01007: variable not in select list
ORA-06512: at line 9
It does the same thing with SELECT UNIQUE or SELECT with a GROUP BY. Can anyone tell me why this happens and what I could to to work around it?
Thanks
Chrissee at line 7 you are selecting only one column and at line 9you are fetching into two variables
7 dynamic_sql_pkg.sp_execute_dynamic('select distinct object_name from user_objects where object_
name in (''PLAN_TABLE'',''DBA_OBJECTS'')',hold_cursor);
8 loop
9 fetch hold_cursor into hold_object_name, hold_object_type;
HTH -
Open cursor for internal table
Hi folks,
I have a tricky question concerning the cursor function and internal tables. First of all, it is not possible to create a view. Instead I've to use a function module for extracting some data to the BI system.
Actually most of the time I work with SELECT (for outer joins) and internal tables. At the end I have a internal table and must open an cursor. As fact, I can't open a cursor for an internal table - only database tables are allowed.
OPEN CURSOR WITH HOLD s_cursor FOR SELECT * FROM lt_temp.
Does someone have a clue how to solve my problem? Obviously I have to use a db table for a open cursor statement but on the same way I have to use a internal table for all my previous SELECT-statements.
Thanks in advance for your help.
Regards,
MrclWhy don't you use EXEC and ENDEXEC
Check this link
http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb3b8b358411d1829f0000e829fbfe/content.htm
a® -
Open cursor for PLSQL table of records
Is it possible to open a cursor for all data in a PLSQL table of records?
something like
cursor c (p1 number) is select * from <plsqltab>
where <plsqltab>.col = p1There is no such thing as a PL/SQL table. Yes, I know that many calls this structure in PL/SQL a table. And that is exactly where all this confusion stems from.. and trying to treat such a "table" as an Oracle table using SQL.
The correct terms are dynamic array (indexed by integer) or dynamic associative array (indexed by varchar). And an array is nothing like a table ito RDBMS processing.
Yes, you can run SQLs against arrays. But it is "expensive". Why? Because the data sits inside PL/SQL Engine. Not in the SQL Engine. The data is in a PL/SQL defined structure. Not a SQL defined structure.
So.. the data needs to be shipped from the PL/SQL Engine to the SQL Engine and converted into a format that the SQL Engine can understand and use.
Also, once shipped and converted the SQL structure is not indexed. Which means that the only option is a full table scan of that structure.
So you need to ask yourself why do you want to use SQL against a PL/SQL array? As soon as you do that, you are saying "Hey, this PL/SQL table ain't good enough and I need to process it using SQL".
So why then does that data sit inside a PL/SQL array and not in a SQL table?
Oracle provides you with the ability to create temporary session tables. These can be indexed. SQL can be run against them without all the "expenses" that are associated with running SQL against a PL/SQL array.
PL/SQL arrays is a great tool. But only when it is the right tool to use. When someone says he/she needs SQL to use this tool, then I question the choice of the tool. Make sure you use the right tool for the job. -
OPEN cursor
When you OPEN a cursor for a mult-row query, is there a straightforward way that you can have it only retrieve a limited number of rows at a time and then automatically delete those rows as you do the FETCH against them? I'm thinking of setting up multiple sequential cursors, and opening and closing them as the rows are processed. But I'm hoping there might be a better way.
The problem is that I'm running out of TEMPORARY during the OPEN cursor stage.
The application I am working on needs to work in Standard Edition and Personal Edition versions of Oracle.
Thank you.Thanks - I had read the documentation before, but interpreted it differently.
What I had read was in:
http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14261/sqloperations.htm#i45288
The extract of interest was:
Opening a Cursor
Opening the cursor executes the query and identifies the result set, which consists of all rows that meet the query search criteria. For cursors declared using the FOR UPDATE clause, the OPEN statement also locks those rows. An example of the OPEN statement follows:
DECLARE
CURSOR c1 IS SELECT employee_id, last_name, job_id, salary FROM employees
WHERE salary > 2000;
BEGIN
OPEN C1;
Rows in the result set are retrieved by the FETCH statement, not when the OPEN statement is executed.
My interpretation was that the result of the query was put into the temporary tablespace and then retrieved into the program during the FETCH.
Assuming I was wrong, what I'm wondering now is how I can possibly be running out of temporary space during this OPEN cursor process. -
How to open a cursor based on XML data?
Hello,
I am using Oracle 11g database.
I am required to write a stored procedure accepting an input of XML CLOB.
Upon receiving the CLOB, I'm required to open a cursor for XML tags and then process each 'XML record'.
I am not sure how to achieve this.
Referred to the following link: http://docs.oracle.com/cd/B28359_01/appdev.111/b28369/xdb03usg.htm#CEGDJEEI
But could not meet the requirement.
Appreciate your suggestions.
Amarsomething
create or replace procedure prc (inxml clob, xml_cursor out sys_refcursor)
x xmltype;
begin
select xmltype(inxml) into x from dual;
open xml_cursor for
select extractvalue(x,'/tag') from dual;
...Edited by: AlexAnd on Nov 21, 2011 1:36 AM -
Open ref cursor in a procedure
Hi
I have a procedure which has 3 input parameters and 1 REF CURSOR type OUT parameter.
In the body of the procedure a select query is dynamically being created, and just before the end of the procedure the REF CURSOR is opened for SELECT(dynamic) query
For Ex: Create or replace procedure proc_name(a in number,b in number,c in number,RETVAL OUT REF CURSOR) as
decalre
strQry varchar2(3000);
begin
-- strQry is select query built dynamically
OPEN RETVAL for strQry;
end proc_name;
This procedure is being called by a java application. My question is what the open cursor statement is doing in the procedure?
Any ideas? Thanks!
greddyHi,
As i know, for example if we want to generate a report for some particular records in our project.consider we are using java as front end and oracle as backend. ok. In that case we need to bring the data from backend to front end ,for that in backend (oracle) we can write procedure to perform this task using ref cursors.
Note: ref cursor will provide the most efficient way in bringing the records from back end to front end.
Create or replace procedure proc_name(a in number,b in number,c in number,RETVAL OUT REF CURSOR) as
decalre
strQry varchar2(3000);
begin
-- strQry is select query built dynamically
--if we are using dynamic query, we can filter out the records using id or name or date
once we did, we need to pass the values to calling enviroment, since we declared the ref cursor as out parameter, we can use the ref cursor to pass the values to calling enviroment. Since we are using ref cursor we need to open the cursor for that dynamic query.
OPEN RETVAL for strQry;
end proc_name;
hope this information is some what helpful. if you got any details regarding this please post it..
thanks. -
[Help] statement.executeQuery(query) opens MULTIPLE cursors
Hey everyone,
I'm having a real hard time finding anything about this on the net so I've turned here. When we call:
resultSet = statement.executeQuery(query)
from a servlet for some reason that one executeQuery opens anywhere from 9-12 cursors in our oracle DB. All the executeQuery documentation I could find just said it should open 1 cursor for that particular ResultSet. query is a fairly simple SQL statement, it searches multiple tables but that doesn't explain why it should open so many cursors.
On a side note the resultSet and statement are global to the method and are closed in the finally block, no SQLExceptions are thrown further adding to my confusion.
If anyone has seen something like this where executing 1 query opens multiple cursors please let me know any information you might have.
Thanks in advance
-DaveHi Dave
I had a similar problem using the Oracle 8i, but my query was a more complicated than yours and opened a lot of cursors.
The answer is to close every ResultSet and the Statement:
while (xxResult.next()){ ... }
xxResult.close();
xxResult.getStatement().close();
This worked for me,
Good luck,
Daniel.
Maybe you are looking for
-
1iten have not been activated due to inconsistenant with holding tax inform
Please help in the error message appearing in the clearing of COMPANY CODE *DO53.*Please advise what needs to be done to clear this and why the error occur.
-
WebDynpro Exception: IDs with Namespace Must Have the Format / namespace /
Hi Experts, Can you please help me with this: I get the following error when I execute a webdynpro application. Can you please let me know where do I need to look to verify the <namespace> and <id>. Error when processing your request
-
Integration between WLC 5508 and Microsoft NPS 2008
Hi guys, Any of you, have working guidance for WLC 5508 and Microsoft NPS 2008 integration? I managed to configure Wireless 802.1x feature (PEAP) but it failed. I'm running software ver. 7.0.116.0. Is there any bug related 802.1x on this software ver
-
Jasper reports imtegration in struts2
im new to java. plz help me in integrating jasper reports in struts2,Plz
-
JTable: setSelectionBackground with columnMargin
I have a JTable in which I'm setting a selection background color. objectTable.setSelectionBackground( new Color( 0xCC, 0xCC, 0xFF ) ); I'm also setting a column margin using : DefaultTableColumnModel colModel = (DefaultTableColumnModel) objectTable.