Using a function in a Cursor Definiftion
Hi all,
my problem is to define a curson inside a package, using a function already defined in the function.
My source code is the folowing:
PROCEDURE TEST
IS
CURSOR cursor_test IS
SELECT ID_CUSTOMER
FROM CUSTOMER
WHERE START_VALIDITY_DATE > GET_DATE(DATE_NEW_CUSTOMER, DATE_EXPIRED);
BEGIN
END;
The function Get_date ( a date,b date) is defined in the same package where it is collocated my procedure "Test". The function called "Get date" return a date.
When I compile, I have an error and I don't understand why.
Thank'you in advance
Hi,
To illustrate APC's point with some simple examples:
HR%xe> create or replace package test_pkg
2 as
3 procedure public_proc;
4 end test_pkg;
5 /
Package is aangemaakt.
HR%xe> create or replace package body test_pkg
2 as
3 procedure public_proc
4 is
5 function private_func
6 return date
7 is
8 begin
9 return(sysdate);
10 end private_func;
11 --
12 l_count number := 0;
13 --
14 begin
15 select count(*) into l_count
16 from employees
17 where employees.hire_date < private_func;
18 --
19 dbms_output.put_line(l_count||' employees were counted.');
20 --
21 end;
22 end test_pkg;
23 /
Waarschuwing: package-body is aangemaakt met compilatiefouten.
HR%xe> sho err
Fouten voor PACKAGE BODY TEST_PKG:
LINE/COL ERROR
12/5 PLS-00103: Encountered the symbol "L_COUNT" when expecting one of
the following:
begin function package pragma procedure form
22/5 PLS-00103: Encountered the symbol "TEST_PKG" when expecting one
of the following:
HR%xe> create or replace package test_pkg
2 as
3 /* commented out the declaration in the specification this time
4 function private_func
5 return date;
6 */
7 procedure public_proc;
8 end test_pkg;
9 /
Package is aangemaakt.
HR%xe> create or replace package body test_pkg
2 as
3 function private_func
4 return date
5 is
6 begin
7 return(sysdate);
8 end;
9
10 procedure public_proc
11 is
12 l_count number := 0;
13 begin
14 select count(*) into l_count
15 from employees
16 where employees.hire_date < private_func;
17 --
18 dbms_output.put_line(l_count||' employees were counted.');
19 --
20 end;
21 end test_pkg;
22 /
Waarschuwing: package-body is aangemaakt met compilatiefouten.
HR%xe> sho err
Fouten voor PACKAGE BODY TEST_PKG:
LINE/COL ERROR
14/5 PL/SQL: SQL Statement ignored
16/34 PL/SQL: ORA-00904: "PRIVATE_FUNC": invalid identifier
16/34 PLS-00231: function 'PRIVATE_FUNC' may not be used in SQL
HR%xe> create or replace package test_pkg
2 as
3
4 function private_func
5 return date;
6
7 procedure public_proc;
8 end test_pkg;
9 /
Package is aangemaakt.
HR%xe> create or replace package body test_pkg
2 as
3 function private_func
4 return date
5 is
6 begin
7 return(sysdate);
8 end;
9
10 procedure public_proc
11 is
12 l_count number := 0;
13 begin
14 select count(*) into l_count
15 from employees
16 where employees.hire_date < private_func;
17 --
18 dbms_output.put_line(l_count||' employees were counted.');
19 --
20 end;
21 end test_pkg;
22 /
Package-body is aangemaakt.
HR%xe> exec test_pkg.public_proc
107 employees were counted.
PL/SQL-procedure is geslaagd.Once you declare your function in your package specification as well, you can use your function in your procedure.
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_packages.htm#sthref823
Similar Messages
-
DBMS_XMLQuery behavior when using stored function within cursor select
Consider the following SQL Statement
select t1.id
, t1.name
, cursor ( select t2.id
from tab t2
where t2.t1_id
= t1.id
and validate(t2.xyz,:bd1)
= 1
from tab t1
where t1.id = :bd2
DBMS_XMLQuery is used to create a context and to bind the appropriate values. In this case 'validate' is a stored function. I get the following error message upon execution:
ORA-29532: Java call terminated by uncaught Java exception:
java.sql.SQLException: Missing IN or OUT parameter at index:: 1
Issuing a similar statement in SQL*Plus works fine. I was wondering whether this is a known issue when using a stored function in the cursor select statement in the context of DBMS_XMLQuery or whether I'm doing something wrong.Hi Jan,
This problem has been identified and fixed. The fix should be available in the next release. Thank you for bringing this up to our attention.
visar -
Plsql use a function which returns a ref cursor
Hi
I've been using an function which returns a ref cursor. I've been returning this into a java resultset. Fine!
Now i'm in plsql and want to use the same function. I'm not sure how to get this resultset in plsql.It's not very practical to use a refcursor like you want to, but here you go
create or replace function test_ref
return sys_refcursor
is
v_rc sys_refcursor;
begin
open v_rc for select emp_name from emp ;
return v_rc;
end;
declare
v_rc sys_refcursor;
v_emp_name emp.emp_name%type;
begin
v_rc := test_ref ;
loop
fetch v_rc into v_emp_name ;
exit when v_rc%notfound ;
dbms_output.put_line('Employee Name: '||v_emp_name );
end loop;
end; -
Open Cursor using other function/procedure
Hi
I have a procedure that return a cursor to Java, but if it send a parameter or other I wanted to call a procedure or function and return cursor to java , Is possible it ?
Example
PROCEDURE XYZ ( P_ORD IN NUMBER,
p_CURSOR OUT SYS_REFCURSOR)
IS
BEGIN
IF P_ORD =1 THEN
-- here I want to open cursor from other procedure/function
OPEN P_CURSOR
ELSIF P_ORD = 2 THEN
END IF;
END XYZ;Message was edited by:
muttleychessLooking at your example code, you say you want to open a cursor from another procedure.
I would suggest taking a step back and looking into the basics of procedural programming, especially in the area of variable scopes.
The scope of the cursor declared in another procedure will be that it exists within that procedure only.
In order to use another procedure's cursor you would have to call that procedure and have it return a SYS_REFCURSOR to your first procedure in the same manner you are trying to return a sys_refcursor to your Java code. -
Cursors using a function pointer iterator
I'm implementing an iterator to go over the records from a Berkeley DB. However, it seems I need to set the DB_DBT_USERMEM flag before the call to cursor->get with DB_NEXT. Doing it that way would make my iterator less cohesive and will have to implement multiple iterators for each data type I want to retrieve.
Is there a way to have a generic iterator that can traverse structures w/o pointers, and basic types? Here's what I'm trying to achieve.
#include <stdio.h>
#include <string.h>
#include <db.h>
// let this function handle integers and use DB_DBT_USERMEM for memory alignment
void integer_items(DBT key, DBT data) {
int number = 0;
data.data = &number;
data.flags = DB_DBT_USERMEM;
data.ulen = sizeof(int);
printf("key is: %s, data is: %d\n", (char *) key.data,number);
// let this function handle pointer structs. No need for DB_DBT_USERMEM
void ptr_struct_items(DBT key, DBT data) {
// MY_STRUCT user;
// marshall struct...
// buffsize = sizeof(int) +(strlen(user.familiar_name) + strlen(user.surname) + 2);
// databuff = malloc(buffsize);
// memset(databuff, 0, buffsize);
// printf("key is: %s, data is: %d\n", (char *) key.data,number);
int iterator(DB *database, void(*function)(DBT key, DBT data)) {
DBT key, data;
DBC *cursor;
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
database->cursor(database, NULL, &cursor, 0);
while(cursor->c_get(cursor, &key, &data, DB_NEXT) == 0){
(*function)(key, data);
cursor->c_close(cursor);
return 0;
int main() {
DB_ENV *myEnv;
DB *dbp;
DBT key, data;
int r, v = 10;
char *k = "Test";
db_env_create(&myEnv, 0);
myEnv->open(myEnv, "./", DB_CREATE | DB_INIT_MPOOL, 0);
db_create(&dbp, myEnv, 0);
dbp->open(dbp, NULL, "test.db", NULL, DB_HASH, DB_CREATE, 0664);
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
key.data = k;
key.size = strlen(k) +1;
data.data = &v;
data.size = sizeof(int);
if((r=dbp->put(dbp, NULL, &key, &data, 0)!=0))
fprintf(stderr, "%s\n", db_strerror(r));
iterator(dbp, integer_items);
iterator(dbp, ptr_struct_items);
return 0;Mike, Thanks for your response. From your sample struct, if I normalize my data by using a structure, then I assume I won't need DB_DBT_USERMEM? since all the data would be stored and packed into a single location in memory, i.e. databuff:
buffsize = sizeof(int) + sizeof(int);
char * databuff = malloc(buffsize);
// copy everything to the buffer
memcpy(databuff, &(user.data_type_indicator), sizeof(int));
bufflen = sizeof(int);
memcpy(databuff, &(user.data_size), sizeof(int));
memcpy(databuff + bufflen, user.data_size, sizeof(int));
bufflen += sizeof(int);
data.data = databuff;
data.size = bufflen;
Is that what you are referring to? -
How to use a function PIPELINED in Forms 10g?
Hi guys,
When I tried to use a function PIPELINED in Forms, I received the message:
- PL/SQL function called from SQL must return value of legal SQL Type
FOR rec_dev IN (SELECT *
FROM TABLE(p1196.f_executa('01-aug-2010', -- pdDataInicial
'30-aug-2010', -- pdDataFinal
5, -- pnCodAdm
NULL, -- pnCdsCod
NULL, -- pnAdmsSrvCod
NULL, -- pnAcao
NULL)))
LOOP
vnQtdeEstornos := vnQtdeEstornos + rec_dev.qtde_estornos;
vnVlrTotalCredito := vnVlrTotalCredito + rec_dev.valor_credito;
END LOOP;
Can anyone help me?
CrisYou can't. One option would be to wrap your pipelined function in a view, or you could write a stored procedure which returns a strong ref cursor instead.
cheers -
Using a strongly typed ref cursor doesn't enforce data type
I am trying to enforce the datatypes of the fields coming back from an oracle reference cursor by making it strongly typed. However, there seems to be no warning at compile time on the oracle side or exception in ODP.NET if the datatype coming back in the cursor does not match. For example here is my cursor and proc
create or replace
PACKAGE THIRDPARTY AS
type pricing_record is record
BaseIndexRate number(6,5),
BaseIndexRateType VARCHAR2(1 BYTE)
type cur_pricing2 IS ref CURSOR return pricing_record;
PROCEDURE getpricingbyappidtest(appid IN application.intid%TYPE, pricing OUT cur_pricing2);
END THIRDPARTY;
create or replace
PACKAGE BODY THIRDPARTY AS
PROCEDURE getpricingbyappidtest(appid IN application.appid%TYPE, pricing OUT cur_pricing2)
AS
BEGIN
OPEN pricing FOR
SELECT somevarcharfield, someothervarcharfield
FROM application
WHERE A.appid = appid;
END getpricingbyappidtest;
I would expect this wouldn't compile since i am putting a varchar into a number field. But it does. Also if i check the datatype in the reader on the .net side it also is a string. So odp doesn't seem to care what type the cursor is
here is that code and output
var schemaTable = reader.GetSchemaTable();
using (var file = new System.IO.StreamWriter("c:\\_DefinitionMap_" + cursorName + ".txt"))
file.WriteLine("COLUMN" + "\t" + "DATATYPE");
foreach (DataRow myField in schemaTable.Rows)
file.WriteLine(myField["ColumnName"] + "\t" + myField["DataType"]);
COLUMN DATATYPE
BaseIndexRate System.String
BaseIndexRateType System.String
Does anyone have an approach for enforcing datatypes in a ref cursor? Am I doing something wrong when defining the ref cursor?Hello,
By using a ref cursor you are really using a pointer to a cursor. There is no way I know of to make a compile check of the cursor check unless you want to create a SQL type and cast the cursor to this type and even this wouldn't work in all cases. For instance, I could have function call within my cursor select which could return a varchar (with a number always in the varchar) which would be horribly sloppy but legal and you would expect Oracle to compile it.
If you are worried about this I would suggest not using ref cursors and go to UDT instead, where there will be more checking (because of a C# equivalence generated object). Oh and BTW, yes the cursor will throw an exception if the data is incorrect, but only at runtime - just like normal Oracle PLSQL.
Cheers
Rob.
http://www.scnet.com.au -
Using a function return in an "IN" statement
All,
I need to filter the records in a table based on the return value of a function. The function determines a person's group and then executes 2 separate select statements depending on the group.
CREATE OR REPLACE PACKAGE pkg_rolebased
AS
CURSOR all_dmn_cur
IS
SELECT dmn_id
FROM tomwojeck.pa_domain ;
CURSOR child_dmn_cur (role_id_in IN varchar)
IS
SELECT distinct r.dmn_id
FROM tomwojeck.pa_domain_restriction_domain r
WHERE r.dmn_restriction_id IN (
SELECT DISTINCT a.dmn_restriction_id
FROM tomwojeck.pa_role_wf_entity_fct_access a
WHERE a.role_id = role_id_in
AND a.workflow_entity_fct_id= 'View Student.Student.View'
AND a.dmn_restriction_id IS NOT NULL);
FUNCTION rolelookup (stud_email IN varchar)
RETURN roletable;
END;CREATE OR REPLACE PACKAGE BODY pkg_rolebased
IS
FUNCTION rolelookup (stud_email IN varchar)
RETURN roletable
IS
v_roleid varchar2(200);
v_returnval varchar2(200);
v_data roletable := roletable ();
dmn_rec all_dmn_cur%ROWTYPE;
BEGIN
-- Find out the role of the person
SELECT r.role_id
INTO v_roleid
FROM tomwojeck.pa_user_prfl p, tomwojeck.pa_user_prfl_role r
WHERE p.user_name = r.user_name
AND UPPER (p.email_addr) = UPPER (stud_email);
IF UPPER (v_roleid) = 'ALL'
THEN
OPEN all_dmn_cur;
LOOP
FETCH all_dmn_cur
INTO dmn_rec;
v_data.EXTEND;
v_data (v_data.COUNT) := dmn_rec.dmn_id;
EXIT WHEN all_dmn_cur%NOTFOUND;
END LOOP;
CLOSE all_dmn_cur;
ELSE
OPEN child_dmn_cur (v_roleid);
LOOP
FETCH child_dmn_cur
INTO dmn_rec;
v_data.EXTEND;
v_data (v_data.COUNT) := dmn_rec.dmn_id;
EXIT WHEN child_dmn_cur%NOTFOUND;
END LOOP;
CLOSE child_dmn_cur;
END IF;
RETURN v_data;
END rolelookup;
END;
The select statement to filter on this mess is:
select
lname,
fname,
dmn_id,
stud_id
from tomwojeck.pa_student p
where p.DMN_ID in (select * from table(cast(tomwojeck.pkg_rolebased.rolelookup('[email protected]') as tomwojeck.RoleTable)))
The problemm is this performs horribly! If I enter an email address that causes the first cursor to be used, it runs well, but if I use an email address that causes the second cursor to run, it takes forever.
Is there a better way to do this?
Thanks,
Tom Wojeck<<The version of Oracle is 9i.>>
Could you specify the exact version? For example, 9.2.0.3.0.
<<I'm not sure of the query optimizer version. How do I find that?>>
SQL> show parameter optimizer_mode
NAME TYPE
VALUE
optimizer_mode string
CHOOSE<<The interestin thing is that the function itself runs well; it's when I try to use the function as an "IN" clause that the performance degrades. It almost seems as though the database is retrieving each row from the student table, and then running the function to see if there are any matches. >>
Your query has to be tuned. The execution plan as well as the information on the indexes will certainly help. -
How to use standard function keys as custom keys
how to use standard function keys as custom keys.
i have encountered that problem while developing a screen, there i'm supposed to use standard function key F2 ( which actually meant for choose) for clearing the screen fields where the cursor is present and f1 for saving data that entered in screen fields, etc...
kindly help me out.Hi ,
Solution to use SAP reserve function keys F1 .. F4 (mostly this requirement comes up for RF screens) can be acheived by assigning your new Function code using the Menu path Utilities --> F key Consistency in the Menu Painter (SE41) . Once you assign your cutom function code to the standard Fn keys the only remaining step is to make sure that you set a curson on any of the field on sceen by using the Key Word "SET CURSOR" .
If you dont use the key word SET CURSOR in the PBO of the screen then you might not see any response for F4.
Thanks -
User defined function in a cursor
Hi All,
I need to use a user defined function(which returns a value based on my Procedure's input parameter) in my explicit cursor. Something like
create or replace procedure test(pi_input number)
cursor c1
is
select col1,
col2,
func(pi_input),
col4
from table;
begin
end;
Is this possible? IHi,
User-defined functions can appear in SQL statements, including cursors, if they follow certain rules (e.g., all arguments are IN arguments, in one of the SQL data types).
You really need to post your code. You don't need to post the compete code; a simplified version that gets the same error would serve just as well (actually better). Include CREATE TABLE and INSERT statements for any tables used, the function code, the code that calls the function, and the results you want from that code, given the sample data you posted.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002
Does your function work the way you want when it is not in a cursor? -
Using custom functions in a query
Hi, I have a query in a PLSQL procedure where some of the fields are data retreived from custom functions,
i. e.
select a, b, funcThatNeedsA(a), funcThatNeedsB(b)
from xxxx
where ...
but I also could use those functions by making a loop to a cursor
i. e.
cursor c_data is select a, b from xxxx where ...
for r_data in c_data loop
l_a = funcThatNeedsA(r_data.a);
l_b = funcThatNeedsB(r_data.b);
end loop;
So, my question is: what is more efficient, to use the functions directly in the query or in a loop of a cursor?the overhead of calling your functions will not change based on using them in a loop vs a cursor. the concern is the performance of ANY loop vs not using a loop at all. so what else are you doing in the loop? does it really need to be in a loop? for example, this
insert into a select * from b
is faster than
for rec in (select * from b) loop insert into a values(rec); end loop; -
Returning Mutliple Records using a function
I followed the instructions as per askTom at http://asktom.oracle.com/~tkyte/ResultSets/index.html
Created the package and created a fuction and it works if I do something like
select find_dba_licenses('ALBERTSON') from dual;
Now, the problem is that I want to use the function in the where clause and it's giving me an error.
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected - got CURSER
Does anyone knows what it means?
If I try casting like below I get the same error
select license_id from t_license where license_id = (select cast(oda.find_dba_licenses('ALBERTSON') as number) from dual);
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected NUMBER got CURSER
Thanks
anyhelp will be appreciated.
JuanI thought that using a function will be the easyest Wrong. The easiest is definitely a sub-query:
SELECT * FROM licences
WHERE licence_id IN
( SELECT licence_id FROM table_1
WHERE trading_name = 'ALBERTSON'
UNION ALL
SELECT licence_id FROM table_2
WHERE business_name = 'ALBERTSON')The above is a template, which you will need to tweak to fit your needs.
If you really want to do that in a function you could consider using a PIPELINED function that returns an array of licence IDs and use a TABLE() function on that. But I wouldn't recommend it unless you have additional processing which cannot be done in a SELECT statement.
What does it mean "between program units"?Between two discrete program, er , units. The canonical example is a database accessor for a web application. A Java bean (or whatever) passes parameters to a stored procedure (function) which executes a query and returns a resultset in the form of a ref cursor. Of course the program units can be two PL/SQL procedures but I think that is less common.
Cheers, APC -
Using table function with merge
I wanna use table function on a table type in a merger statement inside a procedure .
1 create or replace procedure fnd_proc as
2 cursor fnd_c is
select * from fnd_columns;
3 type test_t is table of fnd_columns%rowtype;
4 fnd_t test_t;
5 begin
6 merge into sample s using (select * from table (fnd_pkg1.get_records(cursor(select * from fnd_columns)))) f
7 on (s.application_id = f.application_id)
8 when matched then
9 update set last_update_date=sysdate
10 when not matched then
11 insert(APPLICATION_ID,TABLE_ID,COLUMN_ID) values(f.APPLICATION_ID,f.TABLE_ID,f.COLUMN_ID);
12 end;
create or replace package fnd_pkg1 as
type fnd_type is table of fnd_columns%rowtype;
function get_records(p_cursor IN SYS_REFCURSOR) return fnd_type;
end;
create or replace package body fnd_pkg1 as
function get_records(p_cursor IN SYS_REFCURSOR) return fnd_type is
fnd_data fnd_type;
begin
fetch p_cursor bulk collect into fnd_data;
return fnd_data;
end;
end;
/When i compile the procedure fnd_proc I get the following error
LINE/COL ERROR
6/11 PL/SQL: SQL Statement ignored
6/52 PL/SQL: ORA-22905: cannot access rows from a non-nested table
item
6/67 PLS-00642: local collection types not allowed in SQL statements
Let me know what has to be donemichaels> CREATE TABLE fnd_columns (application_id ,table_id ,column_id ,last_update_date )
AS SELECT object_id,data_object_id,ROWNUM,created FROM all_objects
Table created.
michaels> CREATE TABLE SAMPLE (application_id INTEGER,table_id INTEGER,column_id INTEGER,last_update_date DATE)
Table created.
michaels> CREATE OR REPLACE TYPE fnd_obj AS OBJECT (
application_id INTEGER,
table_id INTEGER,
column_id INTEGER,
last_update_date DATE
Type created.
michaels> CREATE OR REPLACE TYPE fnd_type AS TABLE OF fnd_obj
Type created.
michaels> CREATE OR REPLACE PACKAGE fnd_pkg1
AS
FUNCTION get_records (p_cursor IN sys_refcursor)
RETURN fnd_type;
PROCEDURE fnd_proc;
END fnd_pkg1;
Package created.
michaels> CREATE OR REPLACE PACKAGE BODY fnd_pkg1
AS
FUNCTION get_records (p_cursor IN sys_refcursor)
RETURN fnd_type
IS
fnd_data fnd_type;
BEGIN
FETCH p_cursor
BULK COLLECT INTO fnd_data;
RETURN fnd_data;
END get_records;
PROCEDURE fnd_proc
AS
CURSOR fnd_c
IS
SELECT *
FROM fnd_columns;
TYPE test_t IS TABLE OF fnd_columns%ROWTYPE;
fnd_t test_t;
BEGIN
MERGE INTO SAMPLE s
USING (SELECT *
FROM TABLE
(fnd_pkg1.get_records
(CURSOR (SELECT fnd_obj (application_id,
table_id,
column_id,
last_update_date
FROM fnd_columns
)) f
ON (s.application_id = f.application_id)
WHEN MATCHED THEN
UPDATE
SET last_update_date = SYSDATE
WHEN NOT MATCHED THEN
INSERT (application_id, table_id, column_id)
VALUES (f.application_id, f.table_id, f.column_id);
END fnd_proc;
END fnd_pkg1;
Package body created.
michaels> BEGIN
fnd_pkg1.fnd_proc;
END;
PL/SQL procedure successfully completed.
michaels> SELECT COUNT (*)
FROM SAMPLE
COUNT(*)
47469Now I'd like to see the stats and the ferrari too ;-) -
Running a function with a cursor output
Hi All,
It sounds like this should be easy, but I can't get it to work! I'm trying to run or debug a function in JDev. The function simply calls a Java SP that returns a cursor. This all works fine and it runs in SPL Plus with no problems. The problem is that when I try to run it from within JDev I get presented with the PL/SQL block window, and nothing I do will let me view the contents of the cursor returned - mostly I just get errors and the code doesn't run at all.
The default code it generates is:
DECLARE
v_Return NULL;
BEGIN
v_Return := ALISI.POC.POCCALLSP();
-- Modify the code to output the variable
-- DBMS_OUTPUT.PUT_LINE('v_Return = ' || v_Return);
END;
I think this should be modified to say:
DECLARE
v_Return Types.ref_cursor;
BEGIN
v_Return := ALISI.POC.POCCALLSP();
-- Modify the code to output the variable
DBMS_OUTPUT.PUT_LINE('v_Return = ' || v_Return);
END;
But the DBMS_OUTPUT.PUT_LINE is expecting a string, not a cursor, and nothing I've tried (I've tried so many things I can't begin to list them - or remember them) will work.
Can anyone point out the error in my ways? Is it anything to do with the fact that I'm using a function and not a procedure? As you can probably tell I'm new to all this!
Many thanks,
John.With "simple" variables, we are able to display the output using DBMS_OUTPUT. For composite variables (PL/SQL tables, PL/SQL records, cursors, etc), there's no good way for us to directly display the result. DBMS_OUTPUT.PUT_LINE can only take a "String", or something that can be converted to it, and unlike Java, not everything implements a toString method. We would expect in such cases that the user modify the code as desired to output the data.
That being said, you are actually encountering a bug here. With most datatypes that we can't display directly, we generally get enough information that we generate code that at least compiles and runs. I've logged a bug (3124777) to track this.
(For what it's worth, I've tried this in 9.0.5, only to discover that the functionality has regressed a bit to be even less correct than in 9.0.3.)
After the bug is fixed the output should look like this:
DECLARE
v_Return Types.ref_cursor; -- assuming this is the name of your ref cursor type
BEGIN
v_Return := ALISI.POC.POCCALLSP();
-- Modify the code to output the variable
-- DBMS_OUTPUT.PUT_LINE('v_Return = ' || v_Return);
END;The user would then need to modify the part that displays the output. In this example, it might go something like this:
DECLARE
v_Return Types.ref_cursor; -- assuming this is the name of your ref cursor type
v_Record v_Return%ROWTYPE;
BEGIN
v_Return := ALISI.POC.POCCALLSP();
-- Modify the code to output the variable
LOOP
FETCH v_Return INTO v_Record;
EXIT WHEN v_Return%NOTFOUND;
DBMS_OUTPUT.PUT_LINE (v_Record.employee_id || CHR(9) || v_Record.last_name
|| CHR(9) || v_Record.salary); -- replace with your field names
END LOOP;
END;I hope this helps!
-- Brian -
Ora-600 using table function over db link
Hi,
I have a table function n my target schema (OWB 9.2.0.4 on Oracle 9.2.0.5) with the following signature:
function uii_get_exchange_data_tf(
p_input_values in sys_refcursor
) return uii_exchange_table_t pipelined
When I try to use this with a remote table over a db link, e.g.:
=============
select * from table(uii_get_exchange_data_tf(cursor (select sub_zone || '/' || exch_grp_cd exchange_id,
exch_name exchange_name FROM cds_exchange_test@uiid1@uiidraconn order by exchange_id)))
==============
I get this:
================
ORA-00600: internal error code, arguments: [kokbnp2], [942], [], [], [], [], [],
ORA-06512: at "UII_ODS_OWNER_DEV.UII_GET_EXCHANGE_DATA_TF", line 21
=================
However, if I create a local view with the same remote select like this:
===================
CREATE OR REPLACE FORCE VIEW UII_CDS_EXCHANGE_RV
AS SELECT sub_zone || '/' || exch_grp_cd exchange_id,
exch_name exchange_name
FROM cds_css_exch_detail@uiid1@uiidraconn;
====================
Then everything works fine.
Can someone help ? I'm sure I'm dooing something silly, since so many people seem to be using table functions from OWB just fine; but I can't figure out what :-(
Thanks in advance.
Regards,
Biswa.Hello,
Is this query works fine without creating mview
SELECT COL1,COL2, CASE when COL3 = Y then (select X from MASTER2@DBLINK) FROM MASTER1@DBLINK.
try something like this
SELECT col1, col2, CASE
WHEN col3 = y
THEN
(SELECT x
FROM master2@dblink)
END
my
FROM master1@dblinkregards
Maybe you are looking for
-
An editable region, how to keep text formatting?
Hello fellas. Is there any way to keep the text formatting when I paste it into my edible region of the template? Every time I attempt it - dreamweaver gives me message " making this change would require code change which is locked by a template". Th
-
Problem retrieving data that contains special characters in Collections
Hi fellow Apexers, If I load strings that contain characters such as ":" or "," into a collection and then read the data back off the collection into page items via URL e.g. f?p=&APP_ID.:4:&SESSION.::&DEBUG.::P4_INJURED_FIRST_NAME,P4_INJURED_OTHER_NA
-
I cannot download Facebook and I don't have a blackberry world icon
I have just purchased a secondhand blackberry curve 8310 from ebay and I cannot download Facebook and I don't have a blackberry world icon on the home page. When I try to download facebook it says my device does not support this function. I have tri
-
I am running Virus Barrier X6 on my MacBook Pro with OSX 10.8.5. I got a message that a virus was detected and that file ct_scripting.rsrc was infected with the 'OSX/Conduit.A' malware. Virus Barrier appears unable to repair the file and my only op
-
IPhoto slideshow failed to play iTune music
I cannot play my iTune music in iPhoto slideshow after I updated iPhoto to 9.5.1. iPhoto can play theme music during slideshow but not my own iTune music. Please help!