Dynamic Action does not get page item value - Apex 5.1 - oracle

I have a page with 2 date fields and a button. A dynamic action with PLSQL code that references the value from the 2 date fields is created. For some reason, the page item values does not get passed in the dynamic action. When i use constant values, the DA works without any problem, but when i reference the item values, it doesn't work. No idea why. Can somebody please help??
I have included the DA (not working) code and the DA that works.
Not working DA
DECLARE
I_VCNAME VARCHAR2(200);
I_LPARAMS PK_JRXML2PDF_REPGEN.TPARAMLIST;
I_VCDIR VARCHAR2(200);
I_VCFILENAME VARCHAR2(200);
bl BLOB;
BEGIN
I_VCNAME:='Fundraiser_Stats';
I_VCDIR := 'FUNDAMENTAL_FTP';
I_LPARAMS(1).vcName:='date_from';
I_LPARAMS(1).vcValue:=:R1_FROM_DATE;
I_LPARAMS(2).vcName:='date_to';
I_LPARAMS(2).vcValue:=:R1_TO_DATE;
I_LPARAMS(3).vcName:='fundraiser';
FOR fundraiser_name IN (SELECT DISTINCT B.FUNDRAISER fundraiser FROM WAYSACT_SRC_VW A, PLEDGE_EXT B WHERE A.PLEDGE_ID = B.PLEDGE_ID
AND A.PLEDGE_DATE BETWEEN :R1_FROM_DATE AND :R1_TO_DATE)
LOOP
I_LPARAMS(3).vcValue:= fundraiser_name.fundraiser;
I_VCFILENAME := fundraiser_name.fundraiser||'-'||to_char(sysdate,'dd-Mon-yyyy')||'.pdf';
PK_JRXML2PDF_REPGEN.PR_RUN_TO_FILE(I_VCNAME => I_VCNAME, I_LPARAMS => I_LPARAMS, I_VCDIR => I_VCDIR,I_VCFILENAME => I_VCFILENAME);
END LOOP fundraiser_name;
--APEX_APPLICATION.STOP_APEX_ENGINE;
END;
Working DA:
DECLARE
I_VCNAME VARCHAR2(200);
I_LPARAMS PK_JRXML2PDF_REPGEN.TPARAMLIST;
I_VCDIR VARCHAR2(200);
I_VCFILENAME VARCHAR2(200);
bl BLOB;
BEGIN
I_VCNAME:='Fundraiser_Stats';
I_VCDIR := 'FUNDAMENTAL_FTP';
I_LPARAMS(1).vcName:='date_from';
I_LPARAMS(1).vcValue:='02-jun-2018';
I_LPARAMS(2).vcName:='date_to';
I_LPARAMS(2).vcValue:='02-jun-2018';
I_LPARAMS(3).vcName:='fundraiser';
FOR fundraiser_name IN (SELECT DISTINCT B.FUNDRAISER fundraiser FROM WAYSACT_SRC_VW A, PLEDGE_EXT B WHERE A.PLEDGE_ID = B.PLEDGE_ID
AND A.PLEDGE_DATE BETWEEN '02-jun-2018' AND '02-jun-2018')
LOOP
I_LPARAMS(3).vcValue:= fundraiser_name.fundraiser;
I_VCFILENAME := fundraiser_name.fundraiser||'-'||to_char(sysdate,'dd-Mon-yyyy')||'.pdf';
PK_JRXML2PDF_REPGEN.PR_RUN_TO_FILE(I_VCNAME => I_VCNAME, I_LPARAMS => I_LPARAMS, I_VCDIR => I_VCDIR,I_VCFILENAME => I_VCFILENAME);
END LOOP fundraiser_name;
--APEX_APPLICATION.STOP_APEX_ENGINE;
END;

This is the "Execute PL/SQL Code" dynamic action, is it not? Within DA's "Settings" section, there's the "Items to Submit" field - put names of all items you use in that code; I've noticed
R1_FROM_DATE, R1_TO_DATE
You'll know whether there are additional ones. If so, include them into the list.

Related

Error PLS-00428: an INTO clause is expected in this SELECT statement

I just want to show USU_USERS table between a declare procedure but it's shows this error when I try to compile
DECLARE
ID_UNICO VARCHAR(200) := 'H3LP';
BEGIN
DECLARE
VID VARCHAR2(200);
VID_USER VARCHAR2(200);
BEGIN
VID := ID_UNICO;
VID_USER := 'SOPORTE';
USR_SP_USERS.CREATE(
VID => VID,
VID_USER => VID_USER,
);
END;
SELECT * from USU_USERS;
END;
NOTE : THIS TABLE HAS MORE THAN ONE ROWS.
PL/SQL is a server-side language only, and as such there's no way to "show" the results of a SELECT statement anywhere. Your SELECT statement needs to put the values it retrieves from the database into a variable or variables. Let's try to give you something which will work:
DECLARE
strID_UNICO VARCHAR(200) := 'H3LP';
strVID VARCHAR2(200);
strVID_USER VARCHAR2(200);
rowUSU_USERS USU_USERS%ROWTYPE;
BEGIN
strVID := strID_UNICO;
strVID_USER := 'SOPORTE';
USR_SP_USERS.CREATE(VID => strVID,
VID_USER => strVID_USER);
SELECT *
INTO rowUSU_USERS
FROM USU_USERS;
END;
Note that if the table USU_USERS has more than one row in it this code will fail. Assuming, though, that USU_USERS has only a single row in it, you could then use DBMS_OUTPUT.PUT_LINE to output the various fields in rowUSU_USERS.

Accessing elements of Oracle PLSQL record type on runtime

I am using dynamic SQL where I am dynamically using value of column name to bind and its value to be bind
OLD CODE
<Outer Loop>
FOR i IN lvaDBOBJDTLRecTab.FIRST .. lvaDBOBJDTLRecTab.LAST
LOOP
DBMS_SQL.BIND_VARIABLE ( lvnInsertCursorId, ':RTTEXT2VC100',
lvaDBOBJDTLRecTab(i).DBONAME );
DBMS_SQL.BIND_VARIABLE ( lvnInsertCursorId, ':RTTEXT3VC100',
lvaDBOBJDTLRecTab(i).DBOTYPE );
3.
.
.
.
100
END LOOP;
Instead of writing BIND_VARIABLE for 100 times , I want to dynamically access value of collection. I am able to fetch the value of columns dynamically, which need to be bind (lvsColForBinding), however value of lvsColValForBind
is coming as 'lvrCurDBOBJDTL(i).DBONAME' , 'lvrCurDBOBJDTL(i).DBOTYPE'
and same for rest of the 98 columns,
<Inner Loop>
FOR j IN lvaMappingTab.FIRST..lvaMappingTab.LAST
LOOP
lvsColForBinding := ':'||lvaMappingTab(j).MstRptColCds;
lvsColValForBind := 'lvrCurDBOBJDTL(i).'||lvaMappingTab(j).RptColCd;
DBMS_SQL.BIND_VARIABLE ( lvnInsertCursorId,lvsColForBinding, lvsColValForBind);
END LOOP;
when DBMS_SQL.BIND_VARIABLE is run for each row, as mentioned earlier Column to be bind comes correct but value to be bind, instead of coming as
value of 'XYZ' = lvrCurDBOBJDTL(i).DBONAME it comes as this in single quotes 'lvrCurDBOBJDTL(i).DBONAME' same for all columns.
how can we extract the value of each element in inner loop. what step we need to do to fetch the value of lvsColValForBind?
While debugging through SQLDEveloper Watches, I can see the, element name, value and type, when adding and double clicking the plsql record variable,
what is the SQL behind that, can we use that in coding ?
My first recommendation is that you use dynamic SQL to generate lots of dumb code instead of using a small amount of smart PL/SQL. If code generation doesn't work, you can use ANYDATA and ANYTYPE to create PL/SQL reflection to dynamically iterate through the elements of a record at run time.
Code Generation
Don't write BIND_VARIABLE 100 times, but create a small program to generate the 100 lines of code for you. If the data is ultimately coming from one table and going into another table, the input and output may be predictable based on data dictionary views like DBA_TAB_COLUMNS.
Hopefully a small query like this could help generate all the code for a single table:
--Generate PL/SQL statements for binds.
select
'DBMS_SQL.BIND_VARIABLE(lvnInsertCursorId, '':RTTEXT'||column_id||'VC100'', lvaDBOBJDTLRecTab(i).'||column_name||');'
from dba_tab_columns
where owner = 'SOME_OWNER'
and table_name = 'SOME_TABLE'
order by 1;
Then you can copy-and-paste the output into the PL/SQL block. You'll probably also want a warning, like "do not modify, this code is autogenerated by the procedure CODE_TRON_2000".
This approach will only work if the PL/SQL code is predictable, based on the data dictionary or some other metadata.
PL/SQL Reflection
There's no pure PL/SQL reflection for PL/SQL types* but there's a simple workaround if you're willing to create the record types as SQL objects instead. If all your PL/SQL records are based on object types then ANYDATA and ANYTYPE can be used to dynamically access attributes. Object types and PL/SQL record types are pretty similar, it should be relatively painless to convert one to the other.
For example, if you create an object type that contains a number and a string:
create or replace type v_type is object(a number, b varchar2(1));
This (painful) PL/SQL block shows how to iterate through all the records of a collection, and then iterate through all of the attributes in each record. (The code prints the values for, you'll have to add the binding parts yourself.)
declare
type v_nt_type is table of v_type;
v_values v_nt_type := v_nt_type(v_type(1, 'A'), v_type(2, 'B'));
begin
--For each record:
for i in 1 .. v_values.count loop
declare
v_anydata anydata := anydata.ConvertObject(v_values(i));
v_number number;
v_varchar2 varchar2(4000);
v_result pls_integer;
v_anytype anytype;
v_dummy_num pls_integer;
v_dummy_char varchar2(4000);
v_dummy_anytype anytype;
v_number_of_elements number;
begin
--Get the ANYTYPE and the number of elements.
v_result := v_anydata.getType(v_anytype);
v_result := v_anytype.getInfo
(
prec => v_dummy_num,
scale => v_dummy_num,
len => v_dummy_num,
csid => v_dummy_num,
csfrm => v_dummy_num,
schema_name => v_dummy_char,
type_name => v_dummy_char,
version => v_dummy_char,
numelems => v_number_of_elements
);
--For each element in the record:
for i in 1 .. v_number_of_elements loop
--Find the type of the element:
v_anydata.piecewise;
v_result := v_anytype.getAttrElemInfo(
pos => i,
prec => v_dummy_num,
scale => v_dummy_num,
len => v_dummy_num,
csid => v_dummy_num,
csfrm => v_dummy_num,
attr_elt_type => v_dummy_anytype,
aname => v_dummy_char);
--This is where you do something interesting with the values.
--(The same code merely prints the values.)
if v_result = dbms_types.typecode_number then
v_result := v_anydata.getNumber(num => v_number);
dbms_output.put_line(v_number);
elsif v_result = dbms_types.typecode_varchar2 then
v_result := v_anydata.getVarchar2(c => v_varchar2);
dbms_output.put_line(v_varchar2);
--TODO: Add other potential types here.
end if;
end loop;
end;
end loop;
end;
/
Results:
1
A
2
B
* You're right that there must be some way to find this run time information, if the debugger gets it. But as far as I know there is no way for PL/SQL to retrieve that debug information. Maybe it's only available to an OCI(?) interface?
When you call bind_variable, you are binding an actual value to a placeholder. So if you provide a string that is the name of your variable, well, that string is the value bound to the placeholder.
If the array holds those values, then simply reference the array element and not the name of that element, as in:
DBMS_SQL.BIND_VARIABLE (
lvnInsertCursorId,
lvaMappingTab(j).MstRptColCds,
lvrCurDBOBJDTL(i).lvaMappingTab(j).RptColCd);
But I am pretty sure that's not what you've got there. Hope this helps!
#Jon
Thanks for your inputs, that helped. also I am able to iterate cols without creating OBJECTs using DBMS_SQL.DESCRIBE_COLUMNS.
**Below code still need little bit fine tuning, but mostly working :)
BEGIN
COLS_TRAVERSE('SELECT * FROM ALL_OBJECTS WHERE ROWNUM<=100');
END;
create or replace PROCEDURE COLS_TRAVERSE ( p_query in varchar2 )
AS
v_curid NUMBER;
v_desctab DBMS_SQL.DESC_TAB;
v_colcnt NUMBER;
v_RowNumcnt NUMBER := 1;
v_Colname_var VARCHAR2(10000);
v_name_var VARCHAR2(10000);
v_num_var NUMBER;
v_date_var DATE;
v_row_num NUMBER;
p_sql_stmt VARCHAR2(1000);
BEGIN
v_curid := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(v_curid, p_query, DBMS_SQL.NATIVE);
DBMS_SQL.DESCRIBE_COLUMNS(v_curid, v_colcnt, v_desctab);
-- Define columns:
FOR i IN 1 .. v_colcnt LOOP
IF v_desctab(i).col_type = 2 THEN
DBMS_SQL.DEFINE_COLUMN(v_curid, i, v_num_var);
ELSIF v_desctab(i).col_type = 12 THEN
DBMS_SQL.DEFINE_COLUMN(v_curid, i, v_date_var);
ELSE
DBMS_SQL.DEFINE_COLUMN(v_curid, i, v_name_var, 50);
END IF;
END LOOP;
v_row_num := dbms_sql.execute(v_curid);
-- Fetch rows with DBMS_SQL package:
WHILE DBMS_SQL.FETCH_ROWS(v_curid) > 0 LOOP
FOR i IN 1 .. v_colcnt
LOOP
v_Colname_var := v_desctab(i).col_name;
dbms_output.put_line( 'Name:' ||v_Colname_var );
IF (v_desctab(i).col_type = 1) THEN
DBMS_SQL.COLUMN_VALUE(v_curid, i, v_name_var);
dbms_output.put_line( 'String Value:' || v_name_var );
ELSIF (v_desctab(i).col_type = 2) THEN
DBMS_SQL.COLUMN_VALUE(v_curid, i, v_num_var);
dbms_output.put_line( 'Number Value:' || v_num_var);
ELSIF (v_desctab(i).col_type = 12) THEN
DBMS_SQL.COLUMN_VALUE(v_curid, i, v_date_var);
dbms_output.put_line( 'Date Value:' || v_date_var );
END IF;
END LOOP;
dbms_output.put_line( 'End of Row Number # ' ||v_RowNumcnt );
v_RowNumcnt := v_RowNumcnt+1;
END LOOP;
DBMS_SQL.CLOSE_CURSOR(v_curid);
END;
/
DBMS_OUT PUT
Name:OWNER
String Value:SYS
Name:OBJECT_NAME
String Value:ORA$BASE
Name:SUBOBJECT_NAME
String Value:
Name:OBJECT_ID
Number Value:134
Name:DATA_OBJECT_ID
Number Value:
Name:OBJECT_TYPE
String Value:EDITION
Name:CREATED
Date Value:30-03-18
Name:LAST_DDL_TIME
Date Value:30-03-18
Name:TIMESTAMP
String Value:2018-03-30:21:37:22
Name:STATUS
String Value:VALID
Name:TEMPORARY
String Value:N
Name:GENERATED
String Value:N
Name:SECONDARY
String Value:N
Name:NAMESPACE
Number Value:64
Name:EDITION_NAME
String Value:
Name:SHARING
String Value:NONE
Name:EDITIONABLE
String Value:
Name:ORACLE_MAINTAINED
String Value:Y
Name:APPLICATION
String Value:N
Name:DEFAULT_COLLATION
String Value:
Name:DUPLICATED
String Value:N
Name:SHARDED
String Value:N
Name:CREATED_APPID
Number Value:
Name:CREATED_VSNID
Number Value:
Name:MODIFIED_APPID
Number Value:
Name:MODIFIED_VSNID
Number Value:
End of Row Number # 1
Name:OWNER
String Value:SYS
Name:OBJECT_NAME
String Value:DUAL
Name:SUBOBJECT_NAME
String Value:
Name:OBJECT_ID
Number Value:143
Name:DATA_OBJECT_ID
Number Value:143
Name:OBJECT_TYPE
String Value:TABLE
Name:CREATED
Date Value:30-03-18
Name:LAST_DDL_TIME
Date Value:31-03-18
Name:TIMESTAMP
String Value:2018-03-30:21:37:22
Name:STATUS
String Value:VALID
Name:TEMPORARY
String Value:N
Name:GENERATED
String Value:N
Name:SECONDARY
String Value:N
Name:NAMESPACE
Number Value:1
Name:EDITION_NAME
String Value:
Name:SHARING
String Value:METADATA LINK
Name:EDITIONABLE
String Value:
Name:ORACLE_MAINTAINED
String Value:Y
Name:APPLICATION
String Value:N
Name:DEFAULT_COLLATION
String Value:USING_NLS_COMP
Name:DUPLICATED
String Value:N
Name:SHARDED
String Value:N
Name:CREATED_APPID
Number Value:
Name:CREATED_VSNID
Number Value:
Name:MODIFIED_APPID
Number Value:
Name:MODIFIED_VSNID
Number Value:
End of Row Number # 2

Oracle PL/SQL dynamic if statement global vars

I'm having trouble with dynamic sql, Issue is (I think) reading and setting global variable. Here's what I have and any help at all is greatly appreciated. Please let me know if you need table data too although I have included the data in comments.
CREATE OR REPLACE PACKAGE data_load
IS
curr_rec NUMBER;
curr_rule VARCHAR2(200);
curr_sql VARCHAR2(4000);
curr_sql_two VARCHAR2(4000);
curr_data_element VARCHAR2 (200);
curr_rule_text VARCHAR2(200);
curr_error_code VARCHAR2(10);
curr_error_flag VARCHAR2(10);
curr_flag_val NUMBER;
v_check NUMBER;
v_ID NUMBER;
cur_hdl INT ;
rows_processed NUMBER;
PROCEDURE check_rules;
END data_load;
The package body:
create or replace PACKAGE BODY data_load IS
PROCEDURE check_rules IS
CURSOR c1
IS
SELECT * FROM STAGING_TABLE where rownum < 3;
CURSOR c2
IS
SELECT * FROM ERROR_CODES WHERE rule_text IS NOT NULL AND status =1;
BEGIN
FOR rec1 IN c1
LOOP
FOR rec2 IN c2
LOOP
curr_data_element := 'rec1.'||rec2.data_element; --- this results in value "rec1.SHIP_FROM_ACCOUNT_ORG_CODE" without quotes
curr_rule_text := rec2.rule_text; --- this value is "is not null" without quotes
curr_error_flag := rec2.error_flag; --this value is "FLAG_03" without quotes
curr_flag_val := to_number(rec2.error_code); --- this value is 31
curr_sql :='begin if :curr_data_element '||curr_rule_text||' then update table_with_column_FLAG_03 set '||curr_error_flag ||' = 0; else update table_with_column_FLAG_03 set '||curr_error_flag ||' = '||curr_flag_val||'; end if; end;';
dbms_output.put_line(curr_sql); -- results in "begin if :curr_data_element is null then update table_with_column_FLAG_03 set FLAG_03 = 0; else update table_with_column_FLAG_03 set FLAG_03 = 31; end if; end;"
EXECUTE IMMEDIATE curr_sql USING curr_data_element ; -- this always updates the column with 31 even when curr_data_element/ rec1.SHIP_FROM_ACCOUNT_ORG_CODE is null and that's the problem
COMMIT;
END LOOP;
curr_rec := curr_rec+1;
END LOOP;
dbms_output.put_line(curr_rec);
END check_rules;
END data_load;
You've already highlighted the problem really:
curr_data_element := 'rec1.'||rec2.data_element; --- this results in value "rec1.SHIP_FROM_ACCOUNT_ORG_CODE" without quotes
You can't refer to cursor columns dynamically. You are creating a string with value 'rec1.SHIP_FROM_ACCOUNT_ORG_CODE'; there is no mechanism to evaluate what that represents. You can't, for instance, try to dynamically select that from dual because the rec1 is not in scope for a SQL call, even dynamically.
When you bind that string value it is never going to be null. You are using that string, not the value in the outer cursor that it represents, and essentially you cannot do that.
The simplest way to deal with this, if you have a reasonably small number of columns in your staging table that might appear as the rec2.data_element value, is to use a case expression to assign the appropriate actual rec1 column value to the curr_data_element variable, based on the rec2.data_element value:
...
BEGIN
FOR rec1 IN c1
LOOP
FOR rec2 IN c2
LOOP
curr_data_element :=
case rec2.data_element
when 'SHIP_FROM_ACCOUNT_ORG_CODE' then rec1.SHIP_FROM_ACCOUNT_ORG_CODE
when 'ANOTHER_COLUMN' then rec1.ANOTHER_COLUMN
-- when ... -- repeat for all possible columns
end;
curr_rule_text := rec2.rule_text;
...
If you have a lot of columns you could potentially do that via a collection but it may not be worth the extra effort.
The curr_sql string stays the same, all that's changing is that you're binding the actual value from the relevant rec1 column, rather than never-null string you were forming.

Output results of Oracle stored proc from SQL Developer

I'm trying to call an Oracle stored proc using SQL Developer. The proc outputs results using a sys_refcursor. I right click in the proc window which brings up the Run PL/SQL window. When I choose the proc I want it creates all the input params etc for me. Below is the code I'm using to try and loop through the sys_refcursor and output the results, but I'm getting an error on the 'v_rec v_Return%rowtype;' line :
ORA-06550: line 6 column 9:
PLS-00320: the declaration of the type of this expression is incomplete or malformed.
ORA-06550: line 6 column 9:
PL/SQL: Item ignored
vendor code 6550
I found the looping code on a couple of other websites and it seems to be the way to do it but it's not working for me no matter what I try. Another question - on the DBMS_OUTPUT.PUT_LINE('name = ' || v_rec.ADM) am I referencing the v_rec correctly i.e. is v_rec."column_name" the correct way??
I'm not that used to Oracle and have never used SQL plus. Any suggestions appreciated.
DECLARE
P_CAE_SEC_ID_N NUMBER;
P_PAGE_INDEX NUMBER;
P_PAGE_SIZE NUMBER;
v_Return sys_refcursor;
v_rec v_Return%rowtype;
BEGIN
P_CAE_SEC_ID_N := NULL;
P_PAGE_INDEX := 0;
P_PAGE_SIZE := 25;
CAE_FOF_SECURITY_PKG.GET_LIST_FOF_SECURITY(
P_CAE_SEC_ID_N => P_CAE_SEC_ID_N,
P_PAGE_INDEX => P_PAGE_INDEX,
P_PAGE_SIZE => P_PAGE_SIZE,
P_FOF_SEC_REFCUR => v_Return
);
-- Modify the code to output the variable
-- DBMS_OUTPUT.PUT_LINE('P_FOF_SEC_REFCUR = ');
loop
fetch v_Return into v_rec;
exit when v_Return%notfound;
DBMS_OUTPUT.PUT_LINE('name = ' || v_rec.ADM);
end loop;
END;
Your problem is here:
v_Return sys_refcursor;
v_rec v_Return%rowtype;
v_Return is a cursor variable and has no specific structure (list of columns), so v_Return%rowtype is not a valid record structure to declare v_rec. It is even possible for different calls to the procedure to return cursors with different structures.
You know what you are expecting the structure of the returned cursor to be (but Oracle doesn't) so you need to explicitly define the appropriate record structure e.g.
type t_row is record (empno number, ename varchar2(30));
v_rec t_row;
You need a strongly typed ref cursor to be able to define it as a %ROWTYPE.
Example here
#Tony Andrews thanks for this it gave me a better idea where I was going wrong. Still having problems though - here's a shortened version of my proc. It's a bit complex in that it's selecting all fields from a subquery and 2 other values:
open p_fof_sec_refcur for
SELECT *
FROM(
SELECT securities.*, rownum rnum, v_total_count
FROM
(
SELECT
CFS.CAE_SEC_ID,
CFS.FM_SEC_CODE,
...
FROM
CAEDBO.CAE_FOF_SECURITY CFS
INNER JOIN caedbo.CAE_DATA_SET_ELEMENT CDSE_STAT
ON (CDSE_STAT.DATA_SET_ELEMENT_ID = CFS.APPR_STATUS)
...
WHERE APPR_STATUS = NVL(p_appr_status, APPR_STATUS)
...
)securities
)
WHERE rnum between v_pgStart and v_pgEnd;
I explicitly defined the output structure as below to match the return fields from the proc but I'm still getting an error:
v_Return sys_refcursor;
type t_row is record (CAE_SEC_ID NUMBER,FM_SEC_CODE VARCHAR2(7),...rnum number, v_total_count number);
v_rec t_row;
The error I get is
ORA-06504: PL/SQL: Return types of Result Set variables or query do not match
ORA-06512: at line 45
I'm just wondering is the "rownum rnum, v_total_count" part tripping me up. I'm pretty sure I have all the other fields in the output structure correct as I copied them directly from the proc.

Oracle SQL Developer: how to view results from a ref cursor?

If I have a function which returns a reference cursor for a query, how can I view the result set of this in SQL Developer? Toad has a special tab for viewing the results of a reference cursor, this is the functionality I would like to find.
SET SERVEROUTPUT ON;
VARIABLE X REFCURSOR;
EXEC PROCEDURE_WITH_OUTPUT_SYS_REFCURSOR(:X);
PRINT X;
Double click the cursor fields in your result record. On the right side there is a "..." icon. Click this and you'll see the contents
Hi I know this was asked a while ago but I've just figured this out and it might help someone else. Not sure if this is exactly what you're looking for but this is how I call a stored proc and view the output in SQL Developer.
In SQL Developer when viewing the proc, right click and choose 'Run' or select Ctrl+F11 to bring up the Run PL/SQL window. This creates a template with the input and output params which you need to modify. To return the results of a sys_refcursor you then need to declare a row type that is exactly equivalent to the select stmt / sys_refcursor being returned by the proc. Below I declare "type t_row" which matches my output fields, then loop through the returned sys_refcursor. If t_row matches my sys_refcursor then it gets populated with each row of the sys_refcursor:
DECLARE
P_CAE_SEC_ID_N NUMBER;
P_FM_SEC_CODE_C VARCHAR2(200);
P_PAGE_INDEX NUMBER;
P_PAGE_SIZE NUMBER;
v_Return sys_refcursor;
type t_row is record (CAE_SEC_ID NUMBER,FM_SEC_CODE VARCHAR2(7),rownum number, v_total_count number);
v_rec t_row;
BEGIN
P_CAE_SEC_ID_N := NULL;
P_FM_SEC_CODE_C := NULL;
P_PAGE_INDEX := 0;
P_PAGE_SIZE := 25;
CAE_FOF_SECURITY_PKG.GET_LIST_FOF_SECURITY(
P_CAE_SEC_ID_N => P_CAE_SEC_ID_N,
P_FM_SEC_CODE_C => P_FM_SEC_CODE_C,
P_PAGE_INDEX => P_PAGE_INDEX,
P_PAGE_SIZE => P_PAGE_SIZE,
P_FOF_SEC_REFCUR => v_Return
);
-- Modify the code to output the variable
-- DBMS_OUTPUT.PUT_LINE('P_FOF_SEC_REFCUR = ');
loop
fetch v_Return into v_rec;
exit when v_Return%notfound;
DBMS_OUTPUT.PUT_LINE('sec_id = ' || v_rec.CAE_SEC_ID || 'sec code = ' ||v_rec.FM_SEC_CODE);
end loop;
END;
there are no way to display a refcursor in datagrid in sqldeveloper.
we can define a refcursor,call SP,then print refcursor,then data will be printed in Script output window in a plane text mode,but not in Query Result window.

Resources