REF CURSOR question
I have a situation where I have to retrieve the records of a table for processing in PL/SQL code. Here is a block annonymous that illustrates the problem that IDECLARE
TYPE crsr_type IS REF CURSOR;
crsr crsr_type;
str VARCHAR2(200);
BEGIN
str := 'SELECT * FROM detail;';
-- Case 1
OPEN crsr FOR str;
--Case 2
OPEN crsr FOR SELECT * FROM detail;
END;
/
Case 2 works fine, however the case 1 generates an error:ORA-00911: "Invalid character".
It seems that the cursor cannot be opened with a variable which is what I have to do because the cursor must be opened in several iterations with different criteria for each iteration.
Is there a way to do this?
Hello
Remove the embedded semicolon:
str := 'SELECT * FROM detail';
Kind regards
Mark
Tags: Database
Similar Questions
-
PL/SQL - Call Out Ref Cursor returned by a stored procedure
Hello
I am creating a procedure where a Ref Cursor is defined as an OUT parameter, my question is how to shout that the Ref Cursor when I run for example here is how I want to call my EXEC sql command:
EXEC film_not_in_stock (2,2,vcur);
Here is the procedure:
CREATE OR REPLACE PROCEDURE film_not_in_stock (p_film_id in NUMBER, p_store_id number, vcur ON SYS_REFCURSOR)
IS
News sys_refcursor;
v_cur inventory.inventory_id%TYPE--ou is the same type of column inventory_id
v_cur sys_refcursor;
BEGIN
Heart OPEN to SELECT inventory_id
INVENTORY
WHERE film_id = p_film_id
AND store_id = p_store_id
AND inventory_id NOT IN (SELECT inventory_in_stock (inventory_id) FROM dual);
News of FETCH in v_cur;
OUTPUT WHEN heart % NOTFOUND;
END;
/
I know there are typos in the procedure, you will appreciate if you can help me to put it right.
Thank you very much!
Tonya.
In fact, based on your previous post, function inventory_in_stock returns 0 or 1. If so, there are:
CREATE OR REPLACE
PROCEDURE film_not_in_stock)
p_film_id in NUMBERS
p_store_id in NUMBERS
p_cur ON SYS_REFCURSOR
)
IS
News sys_refcursor;
v_cur inventory.inventory_id%TYPE--ou is the same type of column inventory_id
v_cur sys_refcursor;
BEGIN
OPEN p_cur
FOR
SELECT inventory_id
INVENTORY
WHERE film_id = p_film_id
AND store_id = p_store_id
AND inventory_in_stock (inventory_id) = 0;
News of FETCH in v_cur;
OUTPUT WHEN heart % NOTFOUND;
END;
/
SY.
-
TYPE V_TYPE IS REF CURSOR
V_CUR V_TYPE;
is that this decalrion is correct or not?
How do decalreuser10447332 wrote:
TYPE V_TYPE IS REF CURSORV_CUR V_TYPE;
is that this decalrion is correct or not?
Not. There is no need of a type defined by the user (unless the definition of type strong ref Cursor - use that is questionable in PL/SQL). Use rather SYS_REFCURSOR .
For example
--// run in SQL*Plus --// define a bind variable var c refcursor declare myCursor sys_refcursor; begin --// create the ref cursor open myCursor for select * from user_objects order by 1; --// pass the ref cursor handle to the client :c := myCursor; end; / --// consume the cursor output in the client print c
-
Ref cursor - result series is not known
Hi all
My requirement is as below
(1) the query to run is stored in a table because the query vary each time
(2) execution of the query and treat it
As the query could be of any table that I'm stuck on go get the query in a variable and treatment. Pls see my example below
CUR cursor is
Select sql_stmt sql1 - extract the sql to run
RTA;
Open p_cursor for sql1; -Open the ref cursor
loop
look for p_cursor in? * -as the result set does not know initially how to declare a variable for it *.
output p_cursor % notfound;
-the results of the process
end loop;
Help, please. Hope I'm clear with my question. If not, please let me knowOracle says:
Hi allMy requirement is as below
(1) the query to run is stored in a table because the query vary each time
(2) execution of the query and treat itAs the query could be of any table that I'm stuck on go get the query in a variable and treatment. Pls see my example below
CUR cursor is
Select sql_stmt sql1 - extract the sql to run
RTA;Open p_cursor for sql1; -Open the ref cursor
loop
look for p_cursor in? * -as the result set does not know initially how to declare a variable for it *.
output p_cursor % notfound;
-the results of the process
end loop;Help, please. Hope I'm clear with my question. If not, please let me know
Storage of queries in a table? This looks like a bad design, not to mention the possibility of SQL injection and causing ALL of your code to be written to be dynamic, where a nightmare to debug. Ouch!
You will not be able to do with a ref cursor if you don't know what to expect as the columns returned.
You can use the DBMS_SQL package and describe the query so that you can find on the columns and data types in the results... example of this package... (my example standard production CSV files)...-----
As user sys:
CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles' / GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser /
As myuser:
CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2 ,p_dir IN VARCHAR2 ,p_header_file IN VARCHAR2 ,p_data_file IN VARCHAR2 := NULL) IS v_finaltxt VARCHAR2(4000); v_v_val VARCHAR2(4000); v_n_val NUMBER; v_d_val DATE; v_ret NUMBER; c NUMBER; d NUMBER; col_cnt INTEGER; f BOOLEAN; rec_tab DBMS_SQL.DESC_TAB; col_num NUMBER; v_fh UTL_FILE.FILE_TYPE; v_samefile BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file); BEGIN c := DBMS_SQL.OPEN_CURSOR; DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE); d := DBMS_SQL.EXECUTE(c); DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab); FOR j in 1..col_cnt LOOP CASE rec_tab(j).col_type WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000); WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val); WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val); ELSE DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000); END CASE; END LOOP; -- This part outputs the HEADER v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767); FOR j in 1..col_cnt LOOP v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),','); END LOOP; -- DBMS_OUTPUT.PUT_LINE(v_finaltxt); UTL_FILE.PUT_LINE(v_fh, v_finaltxt); IF NOT v_samefile THEN UTL_FILE.FCLOSE(v_fh); END IF; -- -- This part outputs the DATA IF NOT v_samefile THEN v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767); END IF; LOOP v_ret := DBMS_SQL.FETCH_ROWS(c); EXIT WHEN v_ret = 0; v_finaltxt := NULL; FOR j in 1..col_cnt LOOP CASE rec_tab(j).col_type WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val); v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',','); WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val); v_finaltxt := ltrim(v_finaltxt||','||v_n_val,','); WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val); v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),','); ELSE v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',','); END CASE; END LOOP; -- DBMS_OUTPUT.PUT_LINE(v_finaltxt); UTL_FILE.PUT_LINE(v_fh, v_finaltxt); END LOOP; UTL_FILE.FCLOSE(v_fh); DBMS_SQL.CLOSE_CURSOR(c); END;
This allows the header line and the data to write into files separate if necessary.
for example
SQL> exec run_query('select * from emp','TEST_DIR','output.txt'); PL/SQL procedure successfully completed.
Output.txt file contains:
empno,ename,job,mgr,hiredate,sal,comm,deptno 7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20 7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30 7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30 7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20 7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30 7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30 7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10 7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20 7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10 7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30 7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20 7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30 7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20 7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10
The procedure allows for the header and the data to separate files if necessary. Just by specifying the file name "header" will put the header and the data in a single file.
Adapt to the exit of styles and different types of data are needed.
-
Packages and poorly Ref Cursor
SQL Server Developer, I fight with Oracle to say the least. I fought with the poor performance of the extraction of data from the database, but also a multitude of other things. The last number I have is a stored procedure in a package that does not work when run from my .NET code. I have many other packages and stored procedures that are working, but this one is a failure. I don't get any errors, just no data when I should be.
I would run the toad package and see if it is the stored Proc and packaging, or if there is a problem in my .NET code. My stored procedure accepts a single PARAMETER of type integer, and has two parameters SYS_RefCursor OUT. My SQL uses the parameter (ID field) to select from a table. If I run the select SQL by itself with the hardcoded value ID, it works fine. I can run too where it uses the SQL for open cursors and inserts the data but I can't determine if it worked.
So, my questions are the following:
Can I select a Ref_Cursor? I'm trying to do something like that.
If I could get the 1st issue a response, I can keep up with my next question.results_cursor SYS_REFCURSOR; OPEN results_cursor FOR SELECT * FROM Person; SELECT * FROM results_cursor;
Thanks in advance.
JeffHello
I don't see an issue of .NET at this point, so you can have the best chance to post in the forum PLSQL, as it seems that if you need help writing a procedure, rather than interacting with a procedure well known in .NET:
SQL and PL/SQLI'm not clear on your question though. Yes, you can read from a slider ref, and you do it by getting him.
SQL > set serveroutput on
SQL > declare
Ref1 2 sys_refcursor;
3 rec1 emp % rowtype;
Number 4 NTC;
5. start
6. open ref1 for select * from emp;
7 LOOP
8 FETCH INTO rec1 ref1;
9 OUTPUT WHEN ref1% NOTFOUND;
10 DBMS_OUTPUT. Put_line (' name = ' | rec1.ename);
11 END OF LOOP;
12 end;
13.
Name = SMITH
Name = ALLEN
Name = WARD
Name = JONES
Name = MARTIN
Name = BLAKE
Name = CLARK
Name = SCOTT
Name = KING
Name = TURNER
Name = ADAMS
Name = JAMES
Name = FORD
Name = MILLERPL/SQL procedure successfully completed.
SQL >
Maybe if clarify what you are trying to do or accomplish in "selecting from a ref cursor" it would be useful.
Greg
-
Return of the ref cursor of procedure where the cursor is defined in the specification
Hello
Here's pseudo-code
create or replace package test
as
cursor c_emp (number cv_emp_id)
is
Select emp_name emp where emp_id = cv_emp_id;
type ref_c is ref cursor;
function get_emp_name (number p_emp_id) return ref_c;
end test;
/
create or replace the test physics package
as
ref_c function get_emp_name (number p_emp_id)
is
ret_val ref_c;
Start
Open c_emp (p_emp_id);
ret_val: = c_emp;
return ret_val;
end get_emp_name;
end test;
/
Returns me "PLS-00382: expression is of the wrong type. I tried to use a strongly typed Ref cursor based on the cursor, but nothing helped.
Clearly, I understand something... and if I can't assign as ' ret_val: = c_emp "and if there is another key way it so please let me know.
Thank you
Ralph
Published by: user13024707 on May 5, 2010 04:43user13024707 wrote:
Clearly the point of my question is being missed.Or maybe the question is not been clearly asked. ;)
I want to set the cursor in the PACKAGE SPECIFICATION, and not in the package body. The issue of the bind variable and the string is neither here nor there because I pass parameters to the cursor.
What you ask is to use a PL/SQL cursor (defined in the specifications of the package or elsewhere) and that convert a Ref Cursor. N ° cannot be done.
PL/SQL cursors should be used in the PL/SQL code. REF CURSOR is primary used to pass back a reference to a cursor (and all queries are cursors) to a layer of application outside of PL/SQL for example .net, java, etc.. Once you start using the ref Cursor only really, you have the choice of opening it based on a (dynamic) or a fixed query string as in the examples given. You cannot open a cursor of a PL/SQL cursor definition Ref.The difference is that when you do:
CURSOR cur_mycursor IS SELECT ...
you declare a cursor in pl/sql definition, not actually a slider itself. The cursor itself is created when you issue an OPENING or a statement FOR etc. So a Ref Cursor (reference to a slider) cannot refer to the definition of the cursor because it is only a definition, not a cursor (i.e. it has not been sent engine sql and instantiated at that time here). Instead the Ref Cursor must reference a cursor (query), itself, and that may be presented as a string or as the query itself that is issued against the sql engine and then the ref cursor points
Thus, slider ref and PL/SQL cursors are different concepts, both designed to manage cursors in a slightly different way of programming. You cannot mix them.
-
How to run the packaged procedure with Ref Cursor
Hello.
The question may be very simple for you... but I was confused how to run
I have the following package
But I want to test (run) this procedure...CREATE OR REPLACE PACKAGE CURSPKG AS TYPE T_CURSOR IS REF CURSOR; PROCEDURE OPEN_ONE_CURSOR (N_EMPNO IN NUMBER, IO_CURSOR IN OUT T_CURSOR); END CURSPKG; / CREATE OR REPLACE PACKAGE BODY CURSPKG AS PROCEDURE OPEN_ONE_CURSOR (N_EMPNO IN NUMBER, IO_CURSOR IN OUT T_CURSOR) IS V_CURSOR T_CURSOR; BEGIN IF N_EMPNO <> 0 THEN OPEN V_CURSOR FOR SELECT EMP.EMPNO, EMP.ENAME, DEPT.DEPTNO, DEPT.DNAME FROM EMP, DEPT WHERE EMP.DEPTNO = DEPT.DEPTNO AND EMP.EMPNO = N_EMPNO; ELSE OPEN V_CURSOR FOR SELECT EMP.EMPNO, EMP.ENAME, DEPT.DEPTNO, DEPT.DNAME FROM EMP, DEPT WHERE EMP.DEPTNO = DEPT.DEPTNO; END IF; IO_CURSOR := V_CURSOR; END OPEN_ONE_CURSOR; END CURSPKG; /
But confused how to have Ref Cursor
Could you help me in this...
Thank youYou must declare a variable of type T_CURSOR and pass it to the procedure like this.
declare lOutCursor CURSPKG.T_CURSOR; begin CURSPKG.OPEN_ONE_CURSOR(
, lOutCursor); end; -
REF CURSOR output and race update
Hello
I have a process where I need to make changes in quantity for the products. I want to these products and the quantity of output in a c# application and also update my table of inventory with the new values.
My question is what is the best way to have a stored procedure out a REF CURSOR (for the purposes of c#) and use the same data that came out in the REF CURSOR to update my table of inventory?
I have this:
-USE IT TO GET MY PRODUCTS-
PROCEDURE sp_get_products)
r_products ON SYS_REFCURSOR
)
IS
BEGIN
Select ProductID, InStock
Products
END sp_get_products;
-USE CE TO OUTPUT REF CURSOR and run - UPDATE
PROCEDURE sp_get_ref_products)
r_ref_products ON SYS_REFCURSOR
)
IS
type ProductID is the Products.ProductID%type table;
QTY type is table of the Products.QTY%type;
l_ProductID ProductID;
l_QTY QTY;
BEGIN
sp_get_products (r_ref_products);
Get the r_ref_products COLLECT in BULK IN l_ProductID, l_QTY;
ForAll indx l_ProductID.first... l_ProductID.Last
Update product p
Set p.QTY = l_QTY (indx)
Where p.ProductID = l_ProductID (indx);
COMMIT;
END sp_get_ref_products;Maybe you're not understanding what is a Ref Cursor. It does not store a result set.
Take a read of this thread:
[PL/SQL 101: understanding Ref Cursor | http://forums.oracle.com/forums/thread.jspa?threadID=886365&tstart=0]
-
2 running, 1 inside and 1 sql external, dynamic queries using loops and ref Cursor
Hi all
I'm under Oracle 10.2.0.2. I'm currently building dynamic sql using external and internal queries ref Cursor. Queries make use of user selected lists of ID, which is stored in a table in memory at run time. My example is as follows. From a list of book_publication_id on a web page, the user selects several books. The same user selects then several maps from a list of map_publication_id on the same web page. A book contains several maps and some of these cards will appear in more than one book (aka many many relationships).
This should then ask the following output to a new web page:
In the example above, the outer loop displays the details of the book for book_publication_id 230 and the inner loop displays all the users selected the maps in book_publication_id 230. Then, it moves on the details of the book for book_publication_id 240 and done the same thing again. Similar in some ways to how break would work in SQL * Plus, even if the table is built like an HTML, the book details must be on a separate line for the card details. However I don't know how I would want it to work.Outer loop: Display book details for book_publication_id 230 Inner loop: Display 1st map details for map_publication_id 340 Inner loop: Display 2nd map details for map_publication_id 346 Inner loop: Display 3rd map details for map_publication_id 350 Outer loop: Display book details for book_publication_id 240 Inner loop: Display 1st map details for map_publication_id 346 Inner loop: Display 2nd map details for map_publication_id 375 Outer loop: Display book details for id 255 and so on.
So far, using loops, I could not show all the details of card for each different book_publication_id, after the details of the book for only 1 book_publication_id are displayed each time. If a loop in a loop. I hope that makes sense. I think this is my internal request that it be built differently. My code for this part of the program, which is currently wrong, is as follows:
If anyone has any ideas or suggestions, I would be grateful. It is an extension of my previous code, I posted a question recently. As I am working and learning a step at a time, I left this idea in my previous question, that I had to make sure I knew that first.--Global variable section contains: var_user_chosen_map_list_ids VARCHAR2(32767); var_details VARCHAR2(32767); ...... PROCEDURE PROCMAPSEARCH (par_user_chosen_map_list_ids PKG_ARR_MAPS.ARR_MAP_LIST) IS BEGIN FOR rec_user_chosen_map_list_ids IN 1 .. par_user_chosen_map_list_ids.count LOOP var_user_chosen_map_list_ids := var_user_chosen_map_list_ids || '''' || par_user_chosen_map_list_ids(rec_user_chosen_map_list_ids) || ''',' ; END LOOP; var_user_chosen_map_list_ids := substr(var_user_chosen_map_list_ids, 1, length(var_user_chosen_map_list_ids)-1); var_details := FUNCMAPDATAFIND (var_user_chosen_map_list_ids); htp.print(var_details); END PROCMAPSEARCH; FUNCTION FUNCMAPDETAILS (par_user_chosen_map_list_ids IN VARCHAR2(32767) RETURN VARCHAR2 AS TYPE cur_type_map IS REF CURSOR; cur_book_search cur_type_map; var_book_date NUMBER(4); var_book_title VARCHAR2(32767); cur_map_search cur_type_map; var_map_date NUMBER(4); var_map_title VARCHAR2(32767); begin: OPEN cur_book_search FOR 'SELECT BI.book_date, BT.book_title FROM BOOK_INFO BI, BOOK_TITLE BT, TABLE (sys.dbms_debug_vc2coll(' || par_user_chosen_book_list_ids || ')) BL_1 WHERE BI.book_title_id = BT.book_title_id AND BI.book_publication_id = BL_1.column_value'; OPEN cur_map_search FOR 'SELECT MI.map_date, MT.map_title FROM map_info MI, map_title MT, TABLE (sys.dbms_debug_vc2coll(' || par_user_chosen_book_list_ids || ')) BL_2 TABLE (sys.dbms_debug_vc2coll(' || par_user_chosen_map_list_ids || ')) ML WHERE MI.map_title_id = MT.map_title_id AND BI.book_publication_id = BL_2.column_value AND BI.book_publication_id = MI.pub_publication_id AND MI.map_publication_id = ML.column_value'; LOOP LOOP FETCH cur_map_compare INTO var_book_date, var_book_title; var_details var_details := var_details || 'Book date: '|| var_book_date || 'Book title: ' || var_book_title; FETCH cur_map_compare INTO var_map_date, var_map_title; var_details := var_details || 'Map date: '|| var_map_date || 'Map title: ' || var_map_title EXIT WHEN cur_book_compare%NOTFOUND; END LOOP; EXIT WHEN cur_map_compare%NOTFOUND; END LOOP; RETURN var_details; END FUNCMAPDETAILS;
Kind regards
TimUsing dynamic SQL
declare dd sys_refcursor; ee sys_refcursor; d dept%rowtype ; e emp%rowtype ; begin open dd for 'select * from dept' ; loop fetch dd into d ; exit when dd%notfound ; dbms_output.put_line('Department:'||d.dname); open ee for 'select * from emp where deptno='||d.deptno ; loop fetch ee into e ; exit when ee%notfound ; dbms_output.put_line('..Employee:'||e.empno||':'||e.ename); end loop; end loop ; end ; / Department:ACCOUNTING ..Employee:7782:CLARK ..Employee:7839:KING ..Employee:7934:MILLER Department:RESEARCH ..Employee:7369:SMITH ..Employee:7566:JONES ..Employee:7788:SCOTT ..Employee:7876:ADAMS ..Employee:7902:FORD Department:SALES ..Employee:7499:ALLEN ..Employee:7521:WARD ..Employee:7654:MARTIN ..Employee:7698:BLAKE ..Employee:7844:TURNER ..Employee:7900:JAMES Department:OPERATIONS PL/SQL procedure successfully completed.
HTH
SS
-
Call a procedure stored via JDBC with a REF CURSOR * input variable.
Hello
S/n of my client has provided me with a stored procedure that I need to call to get information about products prices. Something along the lines of:
some_package.getPrices (products IN OUT csr_type);
where csr_type represents a REF CURSOR. This cursor has a product ID column and a price column. The plan is to move the cursor with the populated product id column and have the routine decorate the slider with the prices.
The setting in this plan is that it seems that it is not possible to go from JDBC REF CURSOR in . However, I'm not sure, since I can only find throw comments on various forums (e.g. http://www.orafaq.com/forum/t/35088/0/), without any reference. If I go back to the client and tell them that their idea will not work, I prefer to be able to point them to a documentation somewhere
So I guess my questions are:
1. it is indeed impossible to pass a REF CURSOR type as a variable input on JDBC to a stored procedure?
2. is there information I can do about my client?
3. am I on the right track thinking I need to go down the path of an array of objects?
Thank you very much to anyone who can help
Peter Svehla.Hi Peter,.
I see it, missed that you actually want to pass in a list of products. Don't think that you can do this with the current procedure. A slider is just a pointer to a result set.
How the result set is created and what it looks like, is determined when the cursor is opened.What does this procedure with the cursor? -It does not have some OPEN
TO ; inside? Or, perhaps, you are supposed to send in an open cursor (does not much sense to me)?
Concerning
Peter -
REP-0737: must be a function of return type 'ref cursor.
Hi all
I have create a ref cursor query in reports 10 g. But it is giving error REP-0737: must be a function of return type 'ref cursor.
Here is my code
function QR_1RefCurDS return sys_refcursor is My_Cur Sys_Refcursor; begin Open My_Cur for select * from scott.emp order by deptno; return My_Cur end;
fate of the screen.
Oracle Forms/Reports has a complete PL/SQL engine and (only) the SQL parser.
However, the engine of forms/States PL / SQL and SQL Analyzer are at a level that was in the Oracle 8.0 database.
So, in the forms/States functions/procedures and forms/States triggers, you can not use SQL commands that did not exist in the 8.0 database.
The predefined SYS_REFCURSOR type is introduced in Oracle 9i.
Use this:
PACKAGE test_rc IS
TYPE of rc_type IS REF CURSOR RETURN emp % ROWTYPE;
END;
FUNCTION RETURN QR_1RefCurDS Test_rc.rc_type IS
test_rc.rc_type RC;
BEGIN
OPEN the RC to SELECT * FROM emp;
RETURN rc;
END;
Kind regards
Zlatko
-
Ref Cursor remote procedure fails
Remote database server Oracle 9iR2 1
Local database server Oracle 10 g 2 2
Remote procedure:
CREATE OR REPLACE PROCEDURE p_get_results ( i_query IN VARCHAR2 , o_refc OUT sys_refcursor ) AS BEGIN IF ( i_query IS NULL ) THEN RAISE_APPLICATION_ERROR(-20001,'The paramter i_query cannot be null') ; END IF ; OPEN o_refc FOR i_query ; EXCEPTION WHEN others THEN RAISE ; END p_get_results ; /
Local PL/SQL block
SQL> var i_query varchar2(100) SQL> var o_refc refcursor SQL> exec :i_query := 'select count(*) from oo_attrs' SQL> exec p_get_results@demo_oo2 (:i_query,:o_refc) ERROR at line 1: ORA-00604: error occurred at recursive SQL level 1 ORA-01001: invalid cursor
Check the link works and request db:
SQL> select count(*) from oo_attrs@demo_oo2; COUNT(*) ---------- 225
Am I missing something here?
Am I missing something here?
Yes - you cannot use REF CURSOR over links to db.
-
Hello expert;
I have a function that returns a ref cursor, but the function may not return anything. I would like to know what is the best way to manage the error message
ORA-06503: PL/SQL: function returned no value - slider Ref
.. Please see below.
function f_de return latest_cur is my_l_cur l_cur; begin open my_l_cur for select max(dateadded) as dateadded from tbl_test; end;
I was wondering what is the best way to manage. I know I could use a count, and if the number is greater than 0, manipulate, but I was looking for the best way to manage it.
user13328581 wrote:
Hello expert;
I have a function that returns a ref cursor, but the function may not return anything. I would like to know what is the best way to manage the error message
ORA-06503: PL/SQL: function returned no value - slider Ref
.. Please see below.
- latest_cur the f_de function return is
- my_l_cur l_cur;
- Start
- Open the my_l_cur for
- Select max (dateadded) as dateadded
- of tbl_test;
- end;
I was wondering what is the best way to manage. I know I could use a count, and if the number is greater than 0, manipulate, but I was looking for the best way to manage it.
by definition a FUNCTION returns a value, but your code isn't working; Therefore, the error is thrown.
RETURN MY_L_CUR;
the top line should take place before the END; statement.
-
Apex and accept Ref Cursor?
Apex and accept Ref Cursor?
Apex and accept objects?
can someone help me please.
Hi Nani4850,
Nani4850 wrote:
Apex and accept Ref Cursor?
Apex and accept objects?
The language of business for APEX is PL/SQL, so yes you can use REF CURSOR and pass objects to you packaged functions/procedures.
How does this relate to Oracle APEX?
Please explain what you plan to use a REF CURSOR in the APEX.
Kind regards
Kiran
-
Hi guys,.
You can develop the ref cursor please. I'm new to the plsql...
Hi Alex,
Introduction to the REF CURSOR
With the help of
REF
CURSOR
s is one of the most powerful, flexible and scalable means to return the query results to an Oracle database to a client application.A
REF
CURSOR
is a PL/SQL data type whose value is the memory address of a workspace of query on the database. In essence, aREF
CURSOR
is a pointer or a handle to a game on the database of results.REF
CURSOR
s are represented by theOracleRefCursor
class ODP.NET.REF
CURSOR
s have the following characteristics:- A
REF
CURSOR
refers to a memory on the database address. Therefore, the client must be connected to the database during the lifetime of theREF
CURSOR
to access. - A
REF
CURSOR
involves a round-trip of additional database. While theREF
CURSOR
is returned to the customer, the actual data is not returned until the customer open itREF
CURSOR
and requests the data. Note that the data are not be retrieved until the user tries to read it. - A
REF
CURSOR
is not editable. The result set represented by theREF
CURSOR
is read-only. You cannot update the database using aREF
CURSOR
. - A
REF
CURSOR
is not back with scroll. The data represented by theREF
CURSOR
is only accessible in a way before and in series. You cannot position a record pointer inside theREF
CURSOR
to point to records in the result set. - A
REF
CURSOR
is a PL/SQL data type. You create and return aREF
CURSOR
within a block of PL/SQL code.
See this link which explained on cursor by Zerathul ref: PL/SQL 101: understanding Ref Cursor
Kind regards
Jitendra
- A
Maybe you are looking for
-
Is there a way to disable Firefox from telling me that Adobe Flash Player is out of date?
We run a program that does not allow students to update programs or make other changes. The problem is that Firefox thinks that it NEED to update Flash Player whenever there is a new version. It is simply not feasible with as many computers as we sup
-
13 "MBP 8.1 died strangely - but battery test as well
Material: MBP 8.1 (early 2011) - dual-core 2.7 GHz i7 / Intel HD Graphics 3000 / 8 GB RAM / 512 GB HD Software: OSX 10.11.5 The battery & Techtool Pro from the current battery to 93% health (max 5368 / 5770 mAh), 408 cycles, cycle of 59.2% of remaini
-
Cannot install Firefox Mobile o my Motorola XOOM. I have download and start editing the page and the page become black and back can not be configured.
-
DVD-RAM UJ-820 s: speed problems
Just wondering if someone has managed to solve the problem with UJ-820 s, i.e. the speed not how it should be for the writing/extraction. I had to use using a USB to get anything above 2 x when the specs say that it should go to 4 x - false advertisi
-
Hello guys... .hope - can someone answer me when we use 850w and that we must use 1125w z820 with 2 x e5-2650 32 GB RAM hard drive 500 GB GTX 780 ti 850 or 1125 w... .will this z820 work with 850w Thanks to you all