Query dynamic SQL &; Ref Cursor - debug errors
Hello.
I am trying to execute the query below, but I am getting error for the part highlighted, could you please give some suggestions.
IMMEDIATE EXECUTION
' OPEN SPSN_ECMCODE7_C3 FOR ' |' SELECT OPS_OPTION_NUMBER, OPS_ITEM_PART_NUMBER, OPS_FILE_TYPE, OPS_NOUN_NAME, TO_CHAR(OPS_STOP_DATE,'DD-MON-YYYY') OPS_STOP_DATE
OF T_OPTION_STRUCTURE
WHERE OPS_FILE_TYPE IN '. V3 | »
AND OPS_STOP_DATE > SYSDATE
START BY OPS_STOP_DATE > SYSDATE
AND OPS_ITEM_PART_NUMBER LIKE '. V1 | »
CONNECT OPS_OPTION_NUMBER = PRIOR OPS_ITEM_PART_NUMBER';
Error:
- PLS-00103: encountered the symbol "DD" when expecting one of the following values: * & = +; <>/ to in mod rest not rem return comes back <>or! = or ~ = > = < = <>and or as like2 like4 likec between using | big Member submultiset the symbol ' * ' replaces 'DD' continue.
- PLS-00103: encountered the symbol ") OPS_STOP_DATE" when expecting one of the following values:. ". (* @ % & = - +; <>/ to in mod rest not rem return comes back <>or! = or ~ = > = < = <>and or as like2 like4 likec between using | bulk Member submultiset symbol "("a été substitué pour") OPS_STOP_DATE" to continue.)
- PLS-00103: encountered the symbol ";" when expecting one of the following values :), * & = - + <>/ is mod remains not rem = > <>or! = or ~ = > = < = <>and or as like2 like4 likec in reports between use. Members submultiset symbol ")" has been replaced by a ';' to continue.
Please suggest some possible solutions.
Thank you
open spsn_ecmcode7_c3 for select ops_option_number , ops_item_part_number , ops_file_type , ops_noun_name , to_char(ops_stop_date,'dd-mon-yyyy') ops_stop_date from t_option_structure where ops_file_type in ( select trim(regexp_substr(val, '[^,]+', 1, level)) val from ( select v3 val from dual ) connect by level sysdate start with ops_stop_date > sysdate and ops_item_part_number like case when(instr(1, 1234567890, substr(v_engmonsystem, 1, 1)) > 0) then substr(v_engmonsystem, 1, 7) else substr(v_engmonsystem, 1, 8) end || '%' connect by ops_option_number = prior ops_item_part_number;
Tags: Database
Similar Questions
-
The use of bind variables in dynamic query created for Ref Cursor
Hello
I'm in a situation where there is a Ref cursor to which the query is built execution based on a loop. This is why the number of links would be known until the program runs.
The application is currently using literals instead of bind variables.
code snippet of the above is
strSql: = "select * from emp where 1 = 1 and ().
loop cursor1
If cond is true then
strSql = strSql | "ename = ' |" Cursor1.ColumnName;
end loop;
Open cursor2 for strSql;
How to use links in the example above.sb92075 wrote:
user13019948 wrote:
HelloHere is the code I have my trying to change literal-based link to the base.
What do you mean by "based bind?
who, what, how determines the values to be 'bound '?
He's referring to the coding style. He is currently using concatenated literal, and the goal is to change it to use the bindings.
If I understand this it is known as method 4 dynamic SQL and requires DBMS_SQL. There are examples autour but they vary according to the type of statement being generated - SELECT statements require column lists to be parsed, unlike the INSERT/UPDATE/DELETE.
This came up recently on my current project and I hit a demo. Here a table of names and values accepted procedure and had to build these in a single WHERE clause along the lines of
AND t_names(i) = t_values(i)
for an undetermined number of elements in the array. For this demonstration, I used a table that we called "attribute" (don't ask) which has columns including 'attribute_id' and 'name', and I need to build a query along the lines of
select description from attribute where attribute_id = :b1 and name = :b2
by the way '1012' and 'ISIN' respectively. (I use a table better and after a CREATE statement for her but I have to rush right now, sorry).
declare k_sql_base constant varchar2(500) := 'select description from attribute'; t_names constant varchar2_t := varchar2_t('attribute_id', 'name'); t_values constant varchar2_t := varchar2_t('1012', 'ISIN'); l_sql varchar2(500) := k_sql_base; l_rows_fetched integer := 0; l_value varchar2(4000); l_cursor_handle integer; begin -- Construct the SQL statement with column names and bind variables e.g. -- 'select description from mars.attribute where attribute_id = :b1 and name = :b2' for i in t_names.first .. t_names.last loop l_sql := l_sql || case i when t_names.first then ' where ' else ' and ' end || t_names(i) || ' = :b' || i; end loop; dbms_output.put_line('SQL statment = ' || l_sql); -- Parse the statement we built above (the remaining steps require a parsed cursor): l_cursor_handle := dbms_sql.open_cursor; dbms_sql.parse(l_cursor_handle, l_sql, dbms_sql.native); -- Associate the 1st column of output with variable l_value - required for SELECT statements: -- (actually the 3rd param here 'column' seems to be only used to get a datatype, in this case we want a string - -- dbms_sql.column_value actually extracts the value into a specified variable, which can be different. -- All examples in the documentation pass a local variable without further comment, so not entirely clear what this does other than set the output datatype.) dbms_sql.define_column(l_cursor_handle, 1, l_value, 4000); -- Now go through values array binding actual values to :bn variables in the cursor (similar to USING clause of EXECUTE IMMEDIATE) for i in t_values.first .. t_values.last loop dbms_sql.bind_variable(l_cursor_handle, ':b'||i, t_values(i)); dbms_output.put_line('Bound :b'||i || ' as ' || t_values(i)); end loop; -- Open the cursor and fetch the result (no loop here because we are expecting a single-row result): l_rows_fetched := dbms_sql.execute_and_fetch(l_cursor_handle); -- 'Returns value of the cursor element for a given position in a cursor' -- Copy the value of column 1 to variable l_value (has to match -- dbms_sql.column_value(l_cursor_handle, 1, l_value); dbms_sql.column_value(l_cursor_handle, 1, l_value); dbms_output.put_line('Result = ''' || l_value || ''''); dbms_sql.close_cursor(l_cursor_handle); end;
Hope that helps...
-
wanted to extract data from nested table pl/sql Ref Cursor getting an erro
create or replace type 'DEPT12' as an object (dno number (2), dname varchar2 (30), varchar2 (50)) loc;
create or replace type dept_tab in the table in "DEPT12".
create or replace type 'LOC12' as an object (locno number, loc_name varchar2 (100))
create or replace type loc_tab in the table of "LOC12.
create or replace type dept_loc_rec1 as an object (dept_tab, eno number, loc_dt loc_tab dept_dt);
Create type dept_loc_tb as table of the dept_loc_rec1
create table dept_loc_tb_bk1 (dept_dt dept_tab, eno number, loc_dt loc_tab)
NESTED TABLE dept_dt
STORE AS dept_tab12,
NESTED TABLE loc_dt
STORE AS loc_tab12
insert into dept_loc_tb_bk1 values (dept_tab (dept12(3,'ABD','LOC')
dept12(4,'ABD','LOC')
(, dept12(5,'ABD','LOC')), 3, loc_tab (loc12(21,'AAB'),
loc12(22,'AAB'),
loc12(23,'AAB')));
When I try to extract data from Ref cursor to pl/sql table that I get an error ora-06504: pl/sql: return types of the result set of variables or request do not match.
I created a table nested, as well as the pl/sql nested table object dept_loc_tb and I said the same dept_loc_tb lv_dept_loc_tb, but trying to get in this variable we get an error above.
Please anyone can solve my problem.
-----------------
declare
type cr is ref cursor;
cr_obj cr;
lv_dept_loc_tb dept_loc_tb;
Start
Open cr_obj to select dept_dt, eno, dept_loc_tb_bk1 loc_dt;
collect the fetch cr_obj in bulk in lv_dept_loc_tb;
close cr_obj;
end;Your query selects 3 distinct columns requires so 3 collections of matching types. You want to treat these 3 columns as an object of type DEPT_LOC_REC1:
SQL> declare 2 type cr is ref cursor; 3 cr_obj cr; 4 5 lv_dept_loc_tb dept_loc_tb; 6 7 begin 8 open cr_obj for select dept_dt,eno,loc_dt from dept_loc_tb_bk1; 9 fetch cr_obj bulk collect into lv_dept_loc_tb; 10 close cr_obj; 11 end; 12 / declare * ERROR at line 1: ORA-06504: PL/SQL: Return types of Result Set variables or query do not match ORA-06512: at line 9 SQL> declare 2 type cr is ref cursor; 3 cr_obj cr; 4 5 lv_dept_loc_tb dept_loc_tb; 6 7 begin 8 open cr_obj for select DEPT_LOC_REC1(dept_dt,eno,loc_dt) from dept_loc_tb_bk1; 9 fetch cr_obj bulk collect into lv_dept_loc_tb; 10 close cr_obj; 11 end; 12 / PL/SQL procedure successfully completed. SQL>
SY.
P.S. discover sys_refcursor. -
How to clear the Ref Cursor runtime error
Hello everyone,
the code as follows
When I run this code im gettingcreate or replace procedure Country_sel(key in varchar2) as cc Res_RelcountryLan.countrycode%type; len Res_Language.langname_en%type; lid Res_Language.langid%type; ab Res_Language.Abrivation%type; type refcursorr is ref cursor; cur refcursorr; d_stmt varchar2(100); begin d_stmt := 'select RCL.countrycode,RL.langid,RL.langname_'||key||', RL.Abrivation from Res_RelCountryLan RCL inner join Res_Language RL ON RCL.LangId = RL.LangId'; open cur for d_stmt; loop fetch cur into cc,lid,len,ab; if cur%found then dbms_output.put_line(cc||lid||len||ab); else exit; end if; end loop; close cur; commit; end Country_sel;
can you please help me get rid of this problem.ORA-06502: PL/SQL: numeric or value error: character string buffer too small ORA-06512: at "RASOOL.COUNTRY_SEL", line 11 ORA-06512: at line 6
thanking you,
Prakashd_stmt varchar2(100);
Increase the size of d_stmt. Your an a larger string assignment
d_stmt := 'select RCL.countrycode,RL.langid,RL.langname_'||key||',RL.Abrivation from Res_RelCountryLan RCL inner join Res_Language RL ON RCL.LangId = RL.LangId';
The size of the string above is more than 100 characters.
-
How to create control provided by PL/SQL ref-cursor
Dear valuable experts,
I'm migrating oracle forms10g for JDeveloper. Currently I need a guideline or a reference to create pages of the ADF using the PL/SQL-Refcursor rather then tables or views.
I need help also how can I create using PL/SQL (package) - Refcursor datacontrol.
Please help me.
(!)
Thank you.
Zed
====Zed,
The Fusion developer's Guide has 35.9.4 article titled "How to create a view object on a REF CURSOR" which should help you.
John
-
Zero error of iteration - the treatment of dynamic sql statements in dbms_xmlgen
Hello
I have a procedure that creates a dynamic sql v_sql
cursor v_curr is
Select *.
of btctl_msg_log;
BEGIN
Select count (*) in the v_cnt of btctl_msg_log;
IF v_cnt > 0 THEN
C1 in v_curr
LOOP
v_sql: = "' | ' SELECT * from '. C1.msg_rcrd_src_tbl_nm | |' where rowid = ' | " ' ||'' ' || C1.msg_rcrd_src_tbl_id | " ' ||'' ' ||'' ' ;
Select DBMS_XMLGEN.getXMLtype (v_sql) in the double v_xml;
gives me an error
ORA-19202: an error has occurred in the processing of XML
ORA-24333: zero number of iterations
ORA-06512: at "SYS." DBMS_XMLGEN", line 288
ORA-06512: at line 1
I don't know why is this error happening.
Any help much appreciated.881575 wrote:
HelloI have a procedure that creates a dynamic sql v_sql
cursor v_curr is
Select *.
of btctl_msg_log;BEGIN
Select count (*) in the v_cnt of btctl_msg_log;IF v_cnt > 0 THEN
C1 in v_curr
LOOP
v_sql: = "' | ' SELECT * from '. C1.msg_rcrd_src_tbl_nm | |' where rowid = ' | " ' ||'' ' || C1.msg_rcrd_src_tbl_id | " ' ||'' ' ||'' ' ;
Select DBMS_XMLGEN.getXMLtype (v_sql) in the double v_xml;gives me an error
ORA-19202: an error has occurred in the processing of XML
ORA-24333: zero number of iterations
ORA-06512: at "SYS." DBMS_XMLGEN", line 288
ORA-06512: at line 1I don't know why is this error happening.
Any help much appreciated.Standard when boards (ab) use of EXECUTE IMMEDIATE is to compose the SQL statement in a single VARCHAR2 variable
Then print the variable before passing to EXECUTE IMMEDIATE.
COPY the statement & PASTE in sqlplus to validate its correctness. -
the variable name of database query to SQL Server using the Oracle database link
Hi all
I have an ApEx 4.1 application running on x 64 (11.2.0.1) 11g on Windows Server 2008 x 64, and I have a few points of data integration with SQL (2005 and 2008) server that I need to create. I have configured the database with dg4odbc link and it works perfectly... I can run queries on the SQL Server database without any problem using the database link.
However, there is a scenario where the SQL Server database name is dynamic, and I need to generate on the fly in a PL/SQL block and then use it in a query dynamic SQL (all this in the ApEx). It of wherever I meet problems... when I asked the default database that is based on the ODBC connection and I don't have to specify the name of the database, no problem. But when I need access to one of the several other databases by default, I received the error "invalid table.
It works well:* (note that 'fv' is the name of my database link)
v_query1: = "select 'Release Date' from dbo." Schedules@FV where dbo. Annexes. "" SchedID "=: calendar";
EXECUTE IMMEDIATE v_query1 in rel_date using the grid.
I then take this rel_date variable, convert a varchar2 (rel_date_char), then use it as the name of the database in the following query...
_ It returns an error(error ORA-00903: invalid table name)
v_query2: = "select"PARTNO": rel_date_char.dbo.ProdDetails@fv where 'SchedID' =: calendar and"UnitID"=: unit"
and 'MasterKey' =: master and "ParentKey" =: parent';
EXECUTE IMMEDIATE v_query2 in part_number using planning, master, parent unit;
I also tried using all of the following conditions without result:
"select"PARTNO"of" | : rel_date_char | '.dbo. ProdDetails@fv where 'SchedID '...
"select"PARTNO"of" | rel_date_char | '.dbo. ProdDetails@fv where 'SchedID '...
"select"PARTNO"of" | @rel_date_char | '.dbo. ProdDetails@fv where 'SchedID '...
"select"PARTNO"in @rel_date_char.dbo.ProdDetails @fv where 'SchedID'..."
Is it possible to do it in PL/SQL?
Thanks for any help!
-Ian C.
Published by: 946532 on July 15, 2012 19:45Just did a test using passthrough:
SQL > set serveroutput on
SQL > declare
2 val varchar2 (100);
3 c whole;
4 whole nr;
5. start
c: 6 = dbms_hs_passthrough.open_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3;
7 dbms_hs_passthrough.parse@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, "select count (*) from EMP");
8 LOOP
9 nr: = DBMS_Hs_Passthrough.fetch_row@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
10 output when nr = 0;
11 dbms_hs_passthrough.get_value@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, 1, val);
12 dbms_output.put_line (val);
13 end of loop;
14 dbms_hs_passthrough.close_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
15 end;
16.
24576PL/SQL procedure successfully completed.
SQL > declare
2 val varchar2 (100);
3 c whole;
4 whole nr;
5. start
c: 6 = dbms_hs_passthrough.open_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3;
7 dbms_hs_passthrough.parse@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, ' select count (*) from dbo.) EMP');
8 LOOP
9 nr: = DBMS_Hs_Passthrough.fetch_row@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
10 output when nr = 0;
11 dbms_hs_passthrough.get_value@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, 1, val);
12 dbms_output.put_line (val);
13 end of loop;
14 dbms_hs_passthrough.close_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
15 end;
16.
24576PL/SQL procedure successfully completed.
So all 3 ways work for me.
Published by: kgronau on July 23, 2012 10:08
Now, using the variables to make the selection:
SQL > declare
2 val varchar2 (100);
3 c whole;
4 whole nr;
5 tabname varchar2 (20): = 'EMP ';
6 ownr varchar2 (20): = "dbo."
7 dbname varchar2 (20): = "door";
Start 8
c: 9 = dbms_hs_passthrough.open_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3;
10 dbms_hs_passthrough.parse@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, ' SELECT count (*) FROM ': dbname: '.) ' || ownr | '.'|| tabname | ") ;
11 LOOP
12 nr: = DBMS_Hs_Passthrough.fetch_row@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
13 when the exit nr = 0;
14 dbms_hs_passthrough.get_value@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, 1, val);
15 dbms_output.put_line (val);
16 end loop;
17 dbms_hs_passthrough.close_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
18 end;
19.
24576PL/SQL procedure successfully completed.
=> instead of executing the statement using the "execute Immediate" we use the PASTHROUGH package to pass the statement to SQL Server.
Published by: kgronau on July 23, 2012 10:10
-
Pipelined table vs ref cursor in a function return
Hi gurus,
Everybody has discovered that a (subject) is faster on the other? Data will be primarily consumed from an external application (.net). What are the benefits? I can't decide if that use is
Thank you very much.user12868294 wrote:
Hi gurus,Everybody has discovered that a (subject) is faster on the other? Data will be primarily consumed from an external application (.net). What are the benefits? I can't decide if that use is
Thank you very much.
They are two different things.
A pipeline table acts as an array, but you must always choose in it and so if your consumption that in .net, you would still use a Ref Cursor I guess to query this table in pipeline (I guess .net is not query the tables directly, but must use some sort of slider Ref?)
Tables in pipeline can be fast, but it depends on what you need to. Is there a reason why you really need a feature in pipeline? If this is not the case, just use a normal query with a Ref Cursor, so your .net application only retrieves the data properly.
-
Hello
I have a package that returns a Ref Cursor, in this procedure, I have a dynamic sql code that is built according to certain values, and the query is a select query, is it possible that I can put that dynamic sql in the ref cursor and return of the procedure.
Or y at - it no alternative better workaround.
Thanks in advance.
NaveenYes you can.
Try this...
create or replace package test_pack is type ref_cur is ref cursor; procedure just_print(ref_var ref_cur); end; / create or replace package body test_pack is procedure just_print(ref_var ref_cur) is l_var emp%rowtype; begin loop fetch ref_var into l_var; exit when ref_var%notfound; dbms_output.put_line(l_var.ename); end loop; end; end; / declare cur_var test_pack.ref_cur; dsql varchar2(100); begin dsql := 'select * from emp where deptno=10'; open cur_var for dsql; test_pack.just_print(cur_var); end; / CLARK KING MILLER PL/SQL procedure successfully completed. Elapsed: 00:00:00.00
Kind regards
Prazy -
REF cursor in sql dynamic help to run immediately
Hello
How can we get the Ref cursor out a dynamic sql statement by executing immediate proceedings
for example, immediately run ' open CROR for select * from dynamicTable'
in this area, CROR is a dynamic cursor and table name is dynamic (known at run time), and we can't write static sql statement.
Thank youI don't know what exactly you are after but here is a sample of what can be done.
SQL> VAR r REFCURSOR; SQL> BEGIN 2 OPEN :r FOR 'SELECT * FROM DUAL'; 3 END; 4 / PL/SQL procedure successfully completed. SQL> PRINT r D - X
You can use the OPEN... FOR education with a dynamic string.
-
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
-
I get the following error when you try to select using a ref cursor
SQL error: ORA-06504: PL/SQL: return variables of the game results or the query types do not match
Here are the steps that I have followeed. Can someone tell me what I did wrong.
-CREATE AN OBJECT
create or replace type rsn_rec as object ( rsn_cd varchar2(10), rsn_desc varchar2(30) );
-CREATES A TABLE OF OBJECT
create or replace type rsn_tbl as table of rsn_rec;
PACKAGE/CREATED FUNCTION
create or replace package pkg_rept_test as type refcur is ref cursor; function get_rsn return rsn_tbl pipelined; end pkg_rept_test; create or replace package body pkg_rept_test as function get_rsn return rsn_tbl pipelined is o_cursor refcur; rec rsn%ROWTYPE; begin open o_cursor for select rsn_cd, rsn_desc from rsn; loop fetch o_cursor into rec; exit when (o_cursor%notfound); pipe row(rsn_rec(rec.rsn_cd, rec.rsn_desc) ); end loop; return; end; end pkg_rept_test;
-THE TABLE SELECTION
select * from table(pkg_rept_test.get_rsn)
-ERROR
SQL error: ORA-06504: PL/SQL: return variables of the game results or the query types do not matchYour code works for me just as you posted.
Connected to:
Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production
With partitioning, OLAP, Data Mining and Real Application Testing options
SQL > create table rsn (rsn_cd varchar2 (10), rsn_desc varchar2 (30));
Table created.
SQL > insert into rsn values ("cd test", "test description");
1 line of creation.
SQL > commit;
Validation complete.
SQL > create or replace the rsn_rec as an object type
2 (
3 rsn_cd varchar2 (10),
rsn_desc 4 varchar2 (30)
5 );
6.
Type of creation.
SQL > create or replace type rsn_tbl in the rsn_rec table;
2.
Type of creation.
SQL > create or replace package pkg_rept_test as
2 type refcur is ref cursor;
3 function get_rsn return rsn_tbl in pipeline;
4 end pkg_rept_test;
5.
Package created.
SQL > create or replace package body pkg_rept_test as
2 function get_rsn
3 return rsn_tbl pipeline is
4 o_cursor refcur.
5 rec rsn % ROWTYPE;
6 start
7. open o_cursor for
8. Select
rsn_cd 9,.
10 rsn_desc
11 of rsn;
12 loop
13 extract o_cursor in rec;
When exit 14 (o_cursor % notfound);
line 15 pipe (rsn_rec (rec.rsn_cd, rec.rsn_desc)
16 );
17 end of loop;
18 return;
end 19;
20 end pkg_rept_test;
21.
Package body created.
SQL > select * from table (pkg_rept_test.get_rsn);
RSN_CD RSN_DESC
---------- ------------------------------
tests of cd test description
-
Irregular data loss - function from PL/SQL returning data using Ref Cursor
Database Version: 10.2.0.4.0 (node 2 CARS)
The high-level process flow is as below:
(1) insert records in a few tables & commit the same
(2) call the pl/sql function to extract files (on certain conditions with joins with other tables) of the tables which are filled in step 1.
-> It uses the ORDER BY clause to queries inline & line number 5000 records return for each call.
Sense - if inline query is supposed to return 1,00,000 records then 20 calls to the same function. This, because the application cannot contain records beyond number.
(3) the data returned by the ref cursor is then processed by application (Tibco BW) to generate the flat file.
We are facing the problem of data loss in the file and there is no fixed model. It happens once between 200-300 calls process.
Resolution: When the problem occurs, triggering the process and in almost every time re-outbreak of the process provides required data.
Guidance on what could be the reason?
* Examples of Code for the function:
CREATE OR REPLACE FUNCTION FUNC_GET_HRCH_TOTAL_DATA)
outinstrid in NUMBERS
outinstrkey in NUMBERS
rownumberstart in NUMBERS
rownumbereend in NUMBERS
err_code OUT VARCHAR2,
err_msg OUT VARCHAR2)
RETURN PACK_TYPES. HRCH_TOTAL_CURSOR
IS
REF_HRCH_TOTAL_CURSOR PACK_TYPES. HRCH_TOTAL_CURSOR;
BEGIN
OPEN FOR REF_HRCH_TOTAL_CURSOR
SELECT *.
FROM (SELECT A.HIERARCHY_KEY, B.KEY, B.VAL_KEY, A.KEY_NEW, C.ITEMID, B.VAL_TAG, B.sort_order, ROWNUM ROWNUMBER
OF AOD_HRCH_ITEM A, AOD_HRCH_ATTR B, AOD_HRCH_ITEMS C
WHERE A.outputid = B.outputid
AND A.outputid = C.outputid AND A.outputkey = B.outputkey
AND A.outputkey = C.outputkey AND A.outputid = outinstrid
AND A.outputkey = outinstrkey AND A.ITEM_SEQ = B.ITEM_SEQ
AND A.ITEM_SEQ = C.ITEM_SEQ AND A.HIERARCHY_LEVEL_ORDER = B.SORT_ORDER
ORDER BY A.HIERARCHY_LEVEL_ORDER DESC)
WHERE ROWNUMBER < rownumbereend
AND ROWNUMBER > = rownumberstart;
RETURN REF_HRCH_TOTAL_CURSOR;
EXCEPTION
WHILE OTHERS
THEN
err_code: = x_progress | ' - ' || SQLCODE;
err_msg: = SUBSTR (SQLERRM, 1, 500);
END FUNC_GET_HRCH_TOTAL_DATA;
/
Published by: meet_sanc on February 16, 2013 10:42Your SELECT statement is almost certainly incorrect
SELECT * FROM ( SELECT A.HIERARCHY_KEY, B.KEY, B.VAL_KEY, A.KEY_NEW, C.ITEMID, B.VAL_TAG, B.sort_order,ROWNUM ROWNUMBER FROM AOD_HRCH_ITEM A, AOD_HRCH_ATTR B, AOD_HRCH_ITEMS C WHERE A.outputid = B.outputid AND A.outputid = C.outputid AND A.outputkey = B.outputkey AND A.outputkey = C.outputkey AND A.outputid = outinstrid AND A.outputkey = outinstrkey AND A.ITEM_SEQ = B.ITEM_SEQ AND A.ITEM_SEQ = C.ITEM_SEQ AND A.HIERARCHY_LEVEL_ORDER = B.SORT_ORDER ORDER BY A.HIERARCHY_LEVEL_ORDER DESC) WHERE ROWNUMBER < rownumbereend AND ROWNUMBER >= rownumberstart;
Since the ORDER BY is applied after the ROWNUM is assigned in this case, your query is requested for a period of 5000 lines any arbitrariness. It would be perfectly valid for a single line to return in each of your 200 different calls or for a line to return in any of them.
You definitely want to do something in the sense of the canonical askTom wire
select * from ( select a.*, rownum rnum from ( YOUR_QUERY_GOES_HERE -- including the order by ) a where rownum <= MAX_ROWS ) where rnum >= MIN_ROWS
That said, it seems inconceivable that Tibco is unable to manage a cursor that returns more than a certain number of lines. You do a ton of work to return the data pages that are certainly not necessary. Unless you're saying that you somehow paralyzed your installation of Tibco giving him a ridiculously small amount of memory to process, something doesn't look good. A slider is just a pointer - it holds that no data - so the number of lines that you can extract a slider should have no impact on the amount of memory on the client application needs.
As others have already pointed out, your exception handler is almost certainly do more harm than good. Return the error codes and error messages as from the OUT parameters, instead of simply allowing the exception to propagate deletes a ton of useful information (such as the mistake of the stack) and makes your process much less robust.
Justin
-
How to perform procedures with REF CURSOR &; PLSQL settings table in SQL Dev?
I have 3 SQL Developer. I create a procedure with a set of tables/PL/SQL as an input parameter and a SYS_REFCURSOR as output parameter.
When I press the green arrow (Run button) block the dialog box run PL/SQL PL/SQL has no place at the PL/SQL table with records of entry and also to see the output of the SYS_REFCURSOR.
I get the error ORA-06550 and many other errors when I run the present.
How to do this please?In the debug code, lose the ABS. Prefix the SYS_REFCURSOR QC_SQL_DEVELOPER_TEST.
Also, do not use same name of your settings on your bind variable (so e.g.: OUT_REF_CURSOR).
REF CURSOR is supported output types, so you will get the output of their share in the output tab.
However the output system does not recognize your own types as your PL/SQL table. You need to write an exit procedure yourself, indexing correctly, using the DBMS_OUTPUT.Have fun
K. -
Error when you work with Ref Cursor
Hi, I tried the following, but the err
Error isDECLARE TYPE ref_nm IS REF CURSOR; vref REF_NM; vemp emp%rowtype; BEGIN OPEN vref FOR SELECT ename ,sal FROM EMP; LOOP FETCH vref INTO vemp; EXIT WHEN vref%NOTFOUND; DBMS_OUTPUT.PUT_LINE ( vemp.ename ||','||vemp.sal ); END LOOP; CLOSE vref; END;
ORA-06504: PL/SQL: Return types of Result Set variables or query do not match
Use you this structure as a buffer of extraction:
PEMV emp % rowtype;This structure contains the whole line of EMP - all columns.
That's what you're looking for cursor - 2 columns (not the whole line):
Vref OPEN for SELECT ename, sal of EMP;You can not expect from PL/SQL to find out how to move the 2 column values in a structure that has more than just 2 columns. The error message is quite clear about this - read and think what is transport of the error.
Maybe you are looking for
-
Firefox sometimes I cannot make a purchase online.
I thought it was a problem of Web site, but now wonder if she can relate to Firefox or my Add-ons. I was able to select items and change my "shopping cart" on walmart.com, but when I clicked on "Buy it now" has re-cycled back to the order page. I con
-
Hello A two week ago that Safari does not start at all on my Mac-, it remains open for less than a second and then crashes (farm). It remains not open long enough for me to go on Safari > Preferences to check the settings. When I run the Mac to the g
-
I can't update windows. I get error 0x8024D007
I can't update windows. Under XP. He's trying to download updates but will not continue to the web page. I get error 0x8024D007. What can I do?
-
Vista. 800 70 490 error need help
I can, t update my windows Vista, s corrupted... How can I do it myself with a disc? I need to do it manually
-
screen saver does not lock to protect the password
I don't know how to lock the password protect the screen saver.