REF Cursor in Forms 4.5
I am using forms 4.5. I have a function whcih returns cursor. I would like to store the return values in Forms cursor variable and iterate thru the result set. When I declare TYPE cname IS REF CUROSOR I get compilation error. Is it possible to declare REF CURSOR in forms 4.5 . Help is greatly appreciated
Thanks. Is there any way I can capture the ref curosr (or resultset) passed from server from the oracle forms. The purpose is to call the function from the forms with a table id which will return a resultset which is the items in the list , which is used to populate list in forms. To have a centralised location for list elements.
Is there any package on forms which can be used to capture the returned resultset, pl. let me know
Similar Messages
-
Opening Ref Cursor in Forms 10
Hi,
I have a procedure test which returns refcursor as out parameter. How can I open and process this refcursor in forms to poulate a non base table block ?
Regards,
RajeshHello
In your forms builder Online help search for 'Creating a Data Block from a Procedure that Uses a Ref Cursor'. It provides a pretty good example.
cheers
Q -
Manipulating data from a ref cursor in the data block of a form
I am using Oracle Forms 10g. I have a ref cursor which returns columns A, B, C, D, E where B, C, D, E are values. The "Query Data Source Name" attribute in the datablock contains "CCTR_Extract_pkg.cctr_refcur". The "Column Name" attribute of item A contains "A", item B contains "B", etc. All of these columns are displayed on the form and it all works perfectly.
I have a new request, the users would like a 6th column displayed - column F - where it equals D - B.
Is there any way of doing this in the form only or do I need to change the ref cursor to accomodate the new column and then the form?
If it can be achieved in the Form (only) - then how do I reference the 2 columns?
Thanks in anticipation
Michael
Edited by: user8897365 on 24-Aug-2011 10:32Is there any way of doing this in the form only or do I need to change the ref cursor to accomodate the new column and then the form? The REF_CURSOR is the data source of your block so you will have to modify the CCTR_Extract_pkg package and cctr_refcur REF_CURSOR.
If it can be achieved in the Form (only) - then how do I reference the 2 columns?After you have modified your database package, I recommend you run the Data Block Wizard on your block and let Forms detect the 2 new columns. You can do this manually, but it is safer to let Forms do it for you. If you want to do it manually, open the Query Data Source Columns property and add your new columns.
Hope this helps,
Craig B-)
If someone's response is helpful or correct, please mark it accordingly. -
Ref Cursor Problem in Oracle Forms 6i
Hi all.
In Oracle Forms 6i, can not I do this?
DECLARE
TYPE CUR_REF IS REF CURSOR;
CUR_PRODUCTS CUR_REF;
VAR_QUERY VARCHAR2(3000) := 'SELECT something FROM table';
BEGIN
OPEN CUR_PRODUCTS FOR VAR_QUERY;
END;
It generates error on opening that it expects a SELECT statement.
How can I open a dynamic ref cursor in Oracle Forms 6i??? The same thing works fine in PL/SQL.
Regards,
Zaaf
Thanks in advance.It could be like this:
PROCEDURE dynamic_cursor ( PC$Clause IN Varchar2 )
IS
cursor_number EXEC_SQL.CursType;
-- Variables for the data to be returned into
LC$ACTYPE Number;
-- Control variables
LN$count Number;
LC$sql_order Varchar2(256);
BEGIN
-- Open the cursor --
cursor_number := Exec_SQL.Open_cursor;
-- build the complete SQL order --
LC$sql_order := PC$clause ;
-- Parse the SQL order --
EXEC_SQL.PARSE(cursor_number, LC$sql_order);
-- Define the columns for the data to be returned --
EXEC_SQL.DEFINE_COLUMN(cursor_number,1,LC$ACTYPE);
-- Execute the Cursor --
LN$count := EXEC_SQL.EXECUTE(cursor_number);
-- Loop and fetch each row from the result set --
While EXEC_SQL.FETCH_ROWS(cursor_number) > 0 Loop
EXEC_SQL.COLUMN_VALUE(cursor_number,1,LC$ACTYPE);
begin
select chqfac, pasfac, indbcr ,
staxfl, excise, incchg, cat001 , trntyp , subtyp
into s_chkbok, s_pasbok, s_intber,
s_staxfl, s_excise, s_incchg, s_cat001 , ss_trntyp , ss_subtyp
from stfeacty
where brancd = s_brancd
and actype = LC$ACTYPE;
s_actype := LC$ACTYPE ;
exception
when no_data_found then
NULL;
when too_many_rows then
NULL;
end;
End Loop ;
-- Close the cursors
EXEC_SQL.CLOSE_CURSOR(cursor_number);
EXCEPTION
When EXEC_SQL.INVALID_CONNECTION Then
message('Unexpected Invalid Connection error from EXEC_SQL');
When EXEC_SQL.PACKAGE_ERROR Then
message('Unexpected error from EXEC_SQL: '||to_char(EXEC_SQL.LAST_ERROR_CODE)|| EXEC_SQL.LAST_ERROR_MESG);
If EXEC_SQL.IS_OPEN(cursor_number) Then
EXEC_SQL.CLOSE_CURSOR(cursor_number);
message('Exception - Cleaned up Cursor');
End if;
END; That you could call with the following:
dynamic_cursor('SELECT ac_type FROM SYSADM.SAVINGS');But, if the query is as simple with only the table name change, you could aslo use a simpliest solution based on a record group.
Francois -
Will REF CURSOR support for Oracle Forms 6i?
Hi,
I need to use ref cursor in my from. My cursor query should be dynamically append the "where clause". Hence I used the dynamic query with ref cursor.
But my problem is , when I compile the form it gives error for the line " OPEN emp_record FOR l_query;"
You need to use "select" statement.
Is there any solution for this in forms?
I know it supports for other PL/SQL areas.
Please help me. below is my code sample,
DECLARE
TYPE emp_refcur IS REF CURSOR;
emp_record emp_refcur;
TYPE rec_emp_data IS RECORD
emp_no VARCHAR2(40),
emp_rec rec_emp_data;
l_query VARCHAR2(4000);
BEGIN
l_query := 'SELECT empno
FROM emp ';
IF :CONTROL.ename IS NOT NULL THEN
l_query := l_query||' AND ename = '''||:CONTROL.ename||''' ';
END IF;
OPEN emp_record FOR l_query;
LOOP
FETCH emp_record INTO emp_rec;
EXIT WHEN emp_record%NOTFOUND;
dbms_output.put_line(emp_rec.emp_no);
END LOOP;
CLOSE emp_record;
END; Thanks
RajeshHi,
It's been a while since I used Forms 6i, but I remember hitting a similar problem. I don't think (and stress think!) that the PLSQL engine that comes with Forms 6i recognises ref_cursors.
The work-around I used was to move the functionality to the database and call it from forms.
Hope this helps.
Regards
Ian -
Using plsql table and ref cursor in oracle forms 10g
Hi all,
Can anyone give me an example of a scenario where we need to create a form manually based on a database stored procedures.
And in that procedure i have created a pl/sql table and a ref cursor in data base level.
CREATE OR REPLACE PACKAGE SCOTT.BONUS_PKG IS TYPE bonus_rec
IS RECORD(
empno bonus_EMP.empno%TYPE,
ename bonus_EMP.ename%TYPE,
job bonus_EMP.job%TYPE,
sal bonus_EMP.sal%TYPE,
comm bonus_EMP.comm%TYPE);
TYPE b_cursor IS REF CURSOR RETURN bonus_rec;
TYPE bontab IS TABLE OF bonus_rec INDEX BY BINARY_INTEGER;
PROCEDURE bonus_refcur(bonus_data IN OUT b_cursor);
PROCEDURE bonus_query(bonus_data IN OUT bontab);
END bonus_pkg;
CREATE OR REPLACE PACKAGE BODY SCOTT.BONUS_PKG IS
PROCEDURE bonus_query(bonus_data IN OUT bontab) IS
ii NUMBER;
CURSOR bonselect IS
SELECT empno, ename, job, sal, comm FROM bonus_EMP ORDER BY empno;
BEGIN
OPEN bonselect;
ii := 1;
LOOP
FETCH bonselect INTO
bonus_data( ii ).empno,
bonus_data( ii ).ename,
bonus_data( ii ).job,
bonus_data( ii ).sal,
bonus_data( ii ).comm;
EXIT WHEN bonselect%NOTFOUND;
ii := ii + 1;
END LOOP;
END bonus_query;
PROCEDURE bonus_refcur(bonus_data IN OUT b_cursor) IS
BEGIN
OPEN bonus_data FOR SELECT empno, ename, job, sal, comm FROM bonus_EMP ORDER BY empno;
END bonus_refcur;
END bonus_pkg;
i want to populate the data in forms manually not using forms data block wizard and programmatically.
please reply...Can anyone give me an example of a scenario where we need to create a form manually based on a database stored procedures.Typically, you would use a procedure based block when you have a collection of data from multiple tables presented in a Form and your user needs to be able to update the information displayed.
From your code example, it looks like you are using Oracle Support document "Basing a Block on a Stored Procedure - Sample Code [ID 66887.1]". If this is the case, keep following the document - it walks you through all of the steps. There is no need to Manually configure things that the Data Block Wizard will perform for you!
i want to populate the data in forms manually not using forms data block wizard and programmatically. Why? Let the Data Block Wizard take care of configuring your block based on a procedure for you. There is no need to manually loop through the data! I've actually done what you are attempting and it was more work than was needed. Let Forms do the work for you. :)
If you absolutely must do things manually, I recommend you use the PROCEDURE bonus_query(bonus_data IN OUT bontab) instead of the bonus_refcur(bonus_data IN OUT b_cursor) . Then, in your code create a variable of type BONTAB and then call the bonus_query procedure. Then it is a simple case of looping through the table of records returned by the bonus_query procedure. For example:
DECLARE
t_bonus bonus_pkb.bontab;
BEGIN
bonus_pkg.bonus_query(t_bonus);
FOR i in 1 .. t_bonus.count LOOP
:YOUR_BLOCK.EMPLOYEE_NUMBER := t_bonus(i).empno;
:YOUR_BLOCK.EMPLOYEE_NAME := t_bonus(i).ename;
:YOUR_BLOCK.EMPLOYEE_JOB := t_bonus(i).job;
:YOUR_BLOCK.EMPLOYEE_SALARY := t_bonus(i).sal;
:YOUR_BLOCK.EMPLOYEE_COMMISSION := t_bonus(i).comm;
END LOOP;
END;This code sample demonstrates the basics, but as it is sample code - you will have to adapt it to your situation.
Also, I strongly recommend you look at the article InoL listed. This is a very comprehensive discussion on REF CURSORs. If you are set on using a procedure based data source - it is more efficient to pass the table of records back to your form than it is to pass a ref cursor. Using a ref cursor, you might as well just using a standard named cursor and loop through your named cursor. The effect is the same (one row returned at a time creating lots of network traffic). Using the table of records is more efficient because the entire data set is returned so network traffic is reduced.
Hope this helps,
Craig B-)
If someone's response is helpful or correct, please mark it accordingly. -
How to out Dynamic ref cursor from Procedure to Forms
Hi
I am trying to out Dynamic ref cursor from Procedure to Forms, But I am unable to do so. however cursor return the value within procedure but I am failed to capture the same in Forms
Pl advice suggestion if any, Here I am attaching full procedure for reference
CREATE PACKAGE winepkg
IS
TYPE wine IS RECORD ( mynumber number);
/* Define the REF CURSOR type. */
TYPE wine_type IS REF CURSOR RETURN wine;
END winepkg;
CREATE procedure find_wine
(col1_in in number,
c1 out winepkg.wine_type) as
vsql varchar2(1000);
cur sys_refcursor;
x number;
BEGIN
vsql:='select bo_id from bo_details where bo_details.bo_id = '||col1_in ;
open cur for vsql;
c1:=cur;
--fetch c1 into x;
--dbms_output.put_line(x);
END find_wine;
In front end forms
Declare
TYPE F is REF CURSOR;
CUR_F F;
rec number;
Begin
break;
find_wine( 1601480000011078,cur_f ) ;
Loop
fetch cur_f into rec ;
Message(rec ) ;pause;
exit when cur_f%notfound ;
End loop ;
exception
when others then
Message(sqlerrm) ;pause;
End ;yo can use
declare
c_cursor EXEC_SQL.CursType;
v_stmt varchar2(2000) = 'select a, b, c from mytab where cond1'; -- you can create this value dynamically
begin
c_cursor := Exec_SQL.Open_cursor;
EXEC_SQL.PARSE(c_articulos, v_stmt);
EXEC_SQL.DEFINE_COLUMN(c_articulos,1, v_colchar1, 30);
EXEC_SQL.DEFINE_COLUMN(c_articulos,2, v_colchar2, 15);
EXEC_SQL.DEFINE_COLUMN(c_articulos,3, v_colchar3, 30);
v_exec := EXEC_SQL.EXECUTE(c_cursor);
WHILE EXEC_SQL.FETCH_ROWS(c_cursor) > 0 LOOP
EXEC_SQL.COLUMN_VALUE(c_cursor,1,v_colchar1);
EXEC_SQL.COLUMN_VALUE(c_c_cursor,2,v_colchar2);
EXEC_SQL.COLUMN_VALUE(c_c_cursor,3,v_colchar3);
assign_values_to_block;
END LOOP;
EXEC_SQL.CLOSE_CURSOR(c_cursor);
end;
and WORKS IN FORMS 6 -
Using ref cursor in after parameter form in reports
hi everyone,
I have problem in usage of ref cursor in after parameter form. My actual requirement is I have user parameter :p_minval, :p_maxval. The values into these user parameters will be coming dynamically using sql_statement as shown below
select min(empid),max(empid) into :p_minval, :p_maxval from emp where empid in (:p_emp);
I will be writing this query in the after parameter form
:p_emp is a lexical parameter as per me but the after parameter form is taking it as a bind variable. so I decided to define a ref cursor and then use it for retrieve. But when I use ref cursor it is returning pl/sql error 591 saying that this is not supported by client side can anyone help me plz..
The following is the code i tried to use in after parameter form
function afterPform return boolean is
type rc is ref cursor;
l_rc rc;
sqlstmt varchar2(512);
begin
sqlstmt:='select min(empid),max(empid) from emp where empid in ('||:p_emp||')';
open l_rc for
select max(empid) from emp where empid in ('||:p_emp||')';
fetch l_rc into :p_maxval;
close l_rc;
return(true);
end;
thanks & regards
venkatI ran into the same problem. any body knows why?
-
hi
i have a stored procedure which accepts deptno and returns the employees from emp as an out parameter of type ref cursor.
if i wish to see that in forms how can i get it?
pls suggest me or if anyone has tried it kindly help with the code
regards
premYou base your block on the procedure instead of a table.
Check "Query Data Source Type" under Database in the Property Palette
for the block. You can select "Procedure".
Then, in "Query Data Source Name" you specify <Package.Procedure>.
(Alternatively you can also fill the block from a trigger by calling the procedure)
The note 66887.1 in Metalink is an excellent cookbook. -
Forms Data-Block based on stored procedures - REF CURSOR feature NOT FUNCTIONING
This topic is related to another topic in this forum titled "FORMS HOW TO SET QUERY SOURCE ARGUMENTS??" I posted my message there as well. I am posting as a NEW TOPIC so that it catches the attention of Oracle Support.
I built a data form based on a stored procedure and REF CURSOR IN OUT parameter.
My procedure takes a IN parameter to fill in the criteria for the OPEN <cursor_variable> select ... where ... statement.
In the Value setting of the Query source Arguments , I set the VALUE to ":BLOCK_NAME.ITEM_NAME" at design time to supply the input value to the procedure. this works to the extent of making available the form item value to the stored procedure parameter. I verified this by doing an insert into some debug table , of the incoming parameter value inside my stored procedure.
The cursor gets opened properly into the REF cursor variable. I verified this by fetching a record into a local variable and inserting the value into a debug table again in the stored procedure.
(I took care to close and re-open the REF cursor variable again - so that the front-end can continue to fetch it from the first record. )
***** PROBLEM **************
But the front end forms runtime is giving me a FRM-40301 - query returned no records even though the REF cursor is returned properly opened.
Did anybody else face the same problem ??
Please post what you found.
Thanks,
Shankaran
nullThis topic is discussed at length in another thread "How Set Value For Query DataSource Arguments?"
But I am posting the findings here as well.
THIS TOPIC IS CLOSED.
My Bad. The problem Cause : I did not include all columns in the
cursor rowtype in the Data-block. In the wizard for the data block , I selected ONLY the columns that I needed. But I was doing a Select * from <my_table> in my open cursor <Cursor-Variable> .... The <Cursor Variable>
itself was declared <my_table>%rowtype
FIX : The Data Block structure (columns included as items) should match the cursor record Structure. One may or may not
display all the columns in the LAYOUT though.
But I don't understand why it gives such a misleading message like FRM-40301 Query retrieved no records. Oracle Team fix it.
Hope this helps people who face the same problem.
Thanks, -
Retrieve to forms 6i a ref cursor from a store procedure
hi, i wanna know how to retrieving to forms 6i a ref cursor or a sys_refcursor from a function or a store procedure.
i`ll be very gradeful if someone send me the code.
sorry about my english, the spanish is my native languaje.I think you can use procedure similar to this one:
example:
My sample table:
SQL> desc small_perf_table1;
Name Null? Type
COL1 NUMBER
COL2 VARCHAR2(10)
COL3 VARCHAR2(1)
Simple data inside:
SQL> select col1 from small_perf_table1
2 where rownum < 10;
COL1
1
2
3
4
5
6
7
8
9
9 rows selected.
Create procedure which return variable sys_refcursor type:
SQL> CREATE OR REPLACE PROCEDURE proc_cursor_test
2 (v_cursor OUT sys_refcursor)
3 IS
4 BEGIN
5 OPEN v_cursor FOR select col1 from small_perf_table1 where rownum < 10;
6 END;
7 /
Procedure created.
And here is code you can write inside forms:
SQL> DECLARE
2 type t_cursor IS REF CURSOR;
3 v_cursor t_cursor;
4 v_col1 NUMBER;
5 BEGIN
6 proc_cursor_test(v_cursor);
7 LOOP
8 FETCH v_cursor INTO v_col1;
9 EXIT WHEN v_cursor%NOTFOUND;
10 -- DBMS_OUTPUT.PUT_LINE(v_col1); This line is only for testing inside SQL*PLUS.
11 END LOOP;
12 END;
13 /
1
2
3
4
5
6
7
8
9
PL/SQL procedure successfully completed.This is just an example.
If this example does not resolve your problems then maybe you should ask your question on forms forum.
Forms
Peter D. -
Ref Cursor closed returning to Form
Hi,
I came across this old thread which seems to be an exact match for my problem.
sys ref cursor is closed
And whereas the solutions do work as stated there is an issue with it that i wonder if anyone here has since got around.
Take those examples and make the sql dynamic. on return to the form the ref cursor is instantaneouly closed for you making the thing unusable.
i.e.
OPEN cur FOR SELECT 'x' from dual
works just fine but
OPEN cur FOR 'SELECT ''X'' from dual'
resutls in an closed cursor the moment the ref cursor parameter returns to the form. I need the dynamic form because my cursor is truly built dynamically.
Any ideas anyone?Hi,
try this :
1. declare in the package specification
TYPE rec_view IS RECORD(
COL1 VARCHAR2(250),
COL2 VARCHAR2(250),
COL3 VARCHAR2(250),
COL4 VARCHAR2(250),
COL5 VARCHAR2(250)
TYPE t_ref_curs IS REF CURSOR RETURN rec_view;
TYPE t_rec_c IS REF CURSOR;
2. define the dynamic sql - procedure
PROCEDURE prc_getdata (p_refcur IN OUT t_ref_curs, p_result OUT VARCHAR2,
p_filter IN varchar2 DEFAULT NULL, p_orderby In VARCHAR2 DEFAULT NULL) IS
BEGIN
-- dyn cursor ! --
EXECUTE IMMEDIATE
'BEGIN
OPEN :a FOR ' ||
' select empno, ename, job, mgr, hiredate, sal from emp'||' '||
p_filter ||' '||
p_orderby ||'; '||
'END;'
USING p_refcur;
END prc_getdata;
3. define in the Form a PL/SQL based block on this procedure.
Hope it helps.
Best regards
Friedhold -
The query below will return values in the form of
bu seq eligible
22 2345 Y
22 2345 N
22 1288 N
22 1458 Y
22 1458 N
22 1234 Y
22 1333 N
What I am trying to accomplish is to loop through the records returned.
for each seq if there is a 'N' in the eligible column return no record for that seq
eg seq 2345 has 'Y' and 'N' thus no record should be returned.
seq 1234 has only a 'Y' then return the record
seq 1333 has 'N' so return no record.
How would I accomplish this with a ref Cursor and pass the values to the front end application.
Procedure InvalidNOs(io_CURSOR OUT T_CURSOR)
IS
v_CURSOR T_CURSOR;
BEGIN
OPEN v_CURSOR FOR
' select bu, seq, eligible ' ||
' from (select bu, seq, po, tunit, tdollar,eligible,max(eligible) over () re ' ||
' from (select bu, seq, po, tunit, tdollar,eligible ' ||
' from ( ' ||
' select bu, seq, po, tunit, tdollar, eligible, sum(qty) qty, sum(price*qty) dollars ' ||
' from ' ||
' ( select /*+ use_nl(t,h,d,s) */ ' ||
' h.business_unit_id bu, h.edi_sequence_id seq, d.edi_det_sequ_id dseq, ' ||
' s.edi_size_sequ_id sseq, h.po_number po, h.total_unit tUnit, h.total_amount tDollar, ' ||
' s.quantity qty, s.unit_price price,' ||
' (select (case when count(*) = 0 then ''Y'' else ''N'' end) ' ||
' from sewn.NT_edii_po_det_error ' ||
' where edi_det_sequ_id = d.edi_det_sequ_id ' ||
' ) eligible ' ||
' from sewn.nt_edii_purchase_size s, sewn.nt_edii_purchase_det d, ' ||
' sewn.nt_edii_purchase_hdr h, sewn.nt_edii_param_temp t ' ||
' where h.business_unit_id = t.business_unit_id ' ||
' and h.edi_sequence_id = t.edi_sequence_id ' ||
' and h.business_unit_id = d.business_unit_id ' ||
' and h.edi_sequence_id = d.edi_sequence_id ' ||
' and d.business_unit_id = s.business_unit_id ' ||
' and d.edi_sequence_id = s.edi_sequence_id ' ||
' and d.edi_det_sequ_id = s.edi_det_sequ_id ' ||
' ) group by bu, seq, po, tunit, tdollar, eligible ' ||
' ) ' ||
' group by bu, seq, po, tunit, tdollar, eligible)) ';
io_CURSOR := v_CURSOR;
END InvalidNOs;One remark why you should not use the assignment between ref cursor
variables.
(I remembered I saw already such thing in your code).
Technically you can do it but it does not make sense and it can confuse your results.
In the opposite to usual variables, when your assignment copies value
from one variable to another, cursor variables are pointers to the memory.
Because of this when you assign one cursor variable to another you just
duplicate memory pointers. You don't copy result sets. What you do for
one pointer is that you do for another and vice versa. They are the same.
I think the below example is self-explained:
SQL> /* usual variables */
SQL> declare
2 a number;
3 b number;
4 begin
5 a := 1;
6 b := a;
7 a := a + 1;
8 dbms_output.put_line('a = ' || a);
9 dbms_output.put_line('b = ' || b);
10 end;
11 /
a = 2
b = 1
PL/SQL procedure successfully completed.
SQL> /* cursor variables */
SQL> declare
2 a sys_refcursor;
3 b sys_refcursor;
4 begin
5 open a for select empno from emp;
6 b := a;
7 close b;
8
9 /* next action is impossible - cursor already closed */
10 /* a and b are the same ! */
11 close a;
12 end;
13 /
declare
ERROR at line 1:
ORA-01001: invalid cursor
ORA-06512: at line 11
SQL> declare
2 a sys_refcursor;
3 b sys_refcursor;
4 vempno emp.empno%type;
5
6 begin
7 open a for select empno from emp;
8 b := a;
9
10 /* Fetch first row from a */
11 fetch a into vempno;
12 dbms_output.put_line(vempno);
13
14 /* Fetch from b gives us SECOND row, not first -
15 a and b are the SAME */
16
17 fetch b into vempno;
18 dbms_output.put_line(vempno);
19
20
21 end;
22 /
7369
7499
PL/SQL procedure successfully completed.Rgds.
Message was edited by:
dnikiforov -
ORA-01008 with ref cursor and dynamic sql
When I run the follwing procedure:
variable x refcursor
set autoprint on
begin
Crosstab.pivot(p_max_cols => 4,
p_query => 'select job, count(*) cnt, deptno, row_number() over (partition by job order by deptno) rn from scott.emp group by job, deptno',
p_anchor => Crosstab.array('JOB'),
p_pivot => Crosstab.array('DEPTNO', 'CNT'),
p_cursor => :x );
end;I get the following error:
^----------------
Statement Ignored
set autoprint on
begin
adsmgr.Crosstab.pivot(p_max_cols => 4,
p_query => 'select job, count(*) cnt, deptno, row_number() over (partition by
p_anchor => adsmgr.Crosstab.array('JOB'),
p_pivot => adsmgr.Crosstab.array('DEPTNO', 'CNT'),
p_cursor => :x );
end;
ORA-01008: not all variables bound
I am running this on a stored procedure as follows:
create or replace package Crosstab
as
type refcursor is ref cursor;
type array is table of varchar2(30);
procedure pivot( p_max_cols in number default null,
p_max_cols_query in varchar2 default null,
p_query in varchar2,
p_anchor in array,
p_pivot in array,
p_cursor in out refcursor );
end;
create or replace package body Crosstab
as
procedure pivot( p_max_cols in number default null,
p_max_cols_query in varchar2 default null,
p_query in varchar2,
p_anchor in array,
p_pivot in array,
p_cursor in out refcursor )
as
l_max_cols number;
l_query long;
l_cnames array;
begin
-- figure out the number of columns we must support
-- we either KNOW this or we have a query that can tell us
if ( p_max_cols is not null )
then
l_max_cols := p_max_cols;
elsif ( p_max_cols_query is not null )
then
execute immediate p_max_cols_query into l_max_cols;
else
RAISE_APPLICATION_ERROR(-20001, 'Cannot figure out max cols');
end if;
-- Now, construct the query that can answer the question for us...
-- start with the C1, C2, ... CX columns:
l_query := 'select ';
for i in 1 .. p_anchor.count
loop
l_query := l_query || p_anchor(i) || ',';
end loop;
-- Now add in the C{x+1}... CN columns to be pivoted:
-- the format is "max(decode(rn,1,C{X+1},null)) cx+1_1"
for i in 1 .. l_max_cols
loop
for j in 1 .. p_pivot.count
loop
l_query := l_query ||
'max(decode(rn,'||i||','||
p_pivot(j)||',null)) ' ||
p_pivot(j) || '_' || i || ',';
end loop;
end loop;
-- Now just add in the original query
l_query := rtrim(l_query,',')||' from ( '||p_query||') group by ';
-- and then the group by columns...
for i in 1 .. p_anchor.count
loop
l_query := l_query || p_anchor(i) || ',';
end loop;
l_query := rtrim(l_query,',');
-- and return it
execute immediate 'alter session set cursor_sharing=force';
open p_cursor for l_query;
execute immediate 'alter session set cursor_sharing=exact';
end;
end;
/I can see from the error message that it is ignoring the x declaration, I assume it is because it does not recognise the type refcursor from the procedure.
How do I get it to recognise this?
Thank you in advanceThank you for your help
This is the version of Oracle I am running, so this may have something to do with that.
Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.8.0 - Production
I found this on Ask Tom (http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:3027089372477)
Hello, Tom.
I have one bind variable in a dynamic SQL expression.
When I open cursor for this sql, it gets me to ora-01008.
Please consider:
Connected to:
Oracle8i Enterprise Edition Release 8.1.7.4.1 - Production
JServer Release 8.1.7.4.1 - Production
SQL> declare
2 type cur is ref cursor;
3 res cur;
4 begin
5 open res for
6 'select * from (select * from dual where :p = 1) connect by 1 = 1'
7 using 1;
8 end;
9 /
declare
ERROR at line 1:
ORA-01008: not all variables bound
ORA-06512: at line 5
SQL> declare
2 type cur is ref cursor;
3 res cur;
4 begin
5 open res for
6 'select * from (select * from dual where :p = 1) connect by 1 = 1'
7 using 1, 2;
8 end;
9 /
PL/SQL procedure successfully completed.
And if I run the same thing on 10g -- all goes conversely. The first part runs ok, and the second
part reports "ORA-01006: bind variable does not exist" (as it should be, I think). Remember, there
is ONE bind variable in sql, not two. Is it a bug in 8i?
What should we do to avoid this error running the same plsql program code on different Oracle
versions?
P.S. Thank you for your invaluable work on this site.
Followup June 9, 2005 - 6pm US/Eastern:
what is the purpose of this query really?
but it would appear to be a bug in 8i (since it should need but one). You will have to work that
via support. I changed the type to tarray to see if the reserved word was causing a problem.
variable v_refcursor refcursor;
set autoprint on;
begin
crosstab.pivot (p_max_cols => 4,
p_query =>
'SELECT job, COUNT (*) cnt, deptno, ' ||
' ROW_NUMBER () OVER ( ' ||
' PARTITION BY job ' ||
' ORDER BY deptno) rn ' ||
'FROM emp ' ||
'GROUP BY job, deptno',
p_anchor => crosstab.tarray ('JOB'),
p_pivot => crosstab.tarray ('DEPTNO', 'CNT'),
p_cursor => :v_refcursor);
end;
/Was going to use this package as a stored procedure in forms but I not sure it's going to work now. -
Hi..
I'm using a ref cursor query to fetch data for a report and works just fine. However i need to use dynamic sql in the query because the columns used in the where condition and for some calculations may change dynamically according to user input from the form that launches the report..
Ideally the query should look like this:
select
a,b,c
from table
where :x = something
and :y = something
and (abs(:x/:y........)
The user should be able to switch between :x and :y
Is there a way to embed dynamic sql in a ref cursor query in Reports 6i?
Reports 6i
Forms 6i
Windows 2000 PROHello Nicola,
You can parameterize your ref cursor by putting the query's select statement in a procedure/function (defined in your report, or in the database), and populating it based on arguments accepted by the procedure.
For example, the following procedure accepts a strongly typed ref cursor and populates it with emp table data based on the value of the 'mydept' input parameter:
Procedure emp_refcursor(emp_data IN OUT emp_rc, mydept number) as
Begin
-- Open emp_data for select all columns from emp where deptno = mydept;
Open emp_data for select * from emp where deptno = mydept;
End;
This procedure/function can then be called from the ref cursor query program unit defined in your report's data model, to return the filled ref cursor to Reports.
Thanks,
The Oracle Reports Team.
Maybe you are looking for
-
How to track the flow of data from R/2 to BI ?
Hi Experts, Question: How to track the flow of data from R/3 to BI ? I want to load master data from R/3 to BI. In BI, i create an infopackage to load data from R/3. Under processing tab i set it as "PSA and then in the InfoObject (package by package
-
Full Qualified Domain Name (FQDN) doesn't work when try to login in portal
I Install a NetWeaver 7.0 with BI JAVA SP15 I try to login in portal with 3 diferent ways: 1) - With IP I can login but I can't see any objects; 2) - With only hostname without domain I can login I see objects, every thing works fine. 3) - With FQDN
-
Getting description of product from another table
Hi, I am getting the level from the user, and based on that creating an internal table. I am getting product code (PRODH) and level (STUFE) from one table (T179), and getting product description (VTEXT) from another table (T179T). I need to create
-
Issue with purchase requisition for third party order (Item category S)
Hello Experts, When I am trying to create purchase requisition with document type NB , item category S (third party) , I am nokt able to assign source of supply as contracts. That means when I click on the assign source of supply
-
I start a task process with multiple people in parallel. I wait for FIRST response. At that time an email is sent to the others saying: "One of your tasks was canceled and deleted. You do not need to take any further action on that task." My users