Function returning cursor..
i have written a function which returns me a cursor ...
CREATE OR REPLACE function getAdvisorInfo(advID IN char)
RETURN types.ref_cursor
AS
atp_cursor types.ref_cursor;
BEGIN
OPEN atp_cursor FOR
select ad.Advisor_id, ad.Bundle_code, bd.bundle_name, ad.platform,ad.position_code,ad.advisor_first_name,ad.advisor_last_name,ad.date_bundle_changed,ad.status from advisor_details ad,bundle_details bd where ad.bundle_code = bd.bundle_code and ad.advisor_id=advID;
return atp_cursor;
end getAdvisorInfo;it reads 2 tables as of now...
1. advisor_details and values it reads from this table are ...
a. advisor_id,
b. bundle_code,
c. platofmr,
d. position_code,
e. advisor_first_name,
f. advisor_last_name,
g. date_bundle_changed,
h. status
2. bundle_details ...and values it readds from this table are ...
a. bundle_name.
it works absolutely fine...
now the value date_bundle_changed from advisor_details has to be read from a third table ...and to read that value i need a select query which is like ...
SQL> select max(date_timestamp-0) from advisor_details_history where advisor_id=advID and date_timestamp between systimestamp-30 and systimestamp and change_reason='Bundle Selection';
so in the query "select ad.Advisor_id, ad.Bundle_code, bd.bundle_name, ad.platform,ad.position_code,ad.advisor_first_name,ad.advisor_last_name,ad.date_bundle_changed,ad.status from advisor_details ad,bundle_details bd where ad.bundle_code = bd.bundle_code and ad.advisor_id=advID;" i need to replace that ad.date_bundle_changed with the above query ....which reads date_timestamp from a third table and then sets the value in this query itself...
can some1 tell me how can i do this...or i need to use union only....:(
is there any other way then union...
please let me know..
thank you..
regards,
chintan..
let me know if i am not soo clear in conveying my problem...
can some1 give me hint on how to do this..
even with union i m struggling a bit... :(
here is my function with union....but facing problems to form the query...
CREATE OR REPLACE function getAdvisorInfo(advID IN char)
RETURN types.ref_cursor
AS
atp_cursor types.ref_cursor;
sqlQuery VARCHAR2(1000);
changeReason VARCHAR2(30);
BEGIN
changeReason := 'Bundle Selection';
sqlQuery := 'select ad.Advisor_id, ad.Bundle_code, bd.bundle_name, ad.platform,
ad.position_code,ad.advisor_first_name,ad.advisor_last_name,
ad.status, ad.date_bundle_changed from advisor_details ad,bundle_details bd where
ad.bundle_code = bd.bundle_code and ad.advisor_id=';
sqlQuery := sqlQuery || 'advisor_id = '||CHR(39)||advID||CHR(39);
sqlQuery := sqlQuery || 'UNION
select ad.advisor_id, ad.bundle_code, bd.bundle_name, ad.platform,
ad.position_code, ad.advisor_first_name, ad.advisor_last_name,
ad.status, max(ad.date_timestamp-0) from advisor_details_history ad,
bundle_details bd where ';
sqlQuery := sqlQuery || 'advisor_id = ' ||CHR(39)||advID||CHR(39) and ';
sqlQuery := sqlQuery || 'date_timestamp between systimestamp-30 and systimestamp and ';
sqlQuery := sqlQuery || 'change_reason = '||CHR(39)||changeReason||CHR(39);
OPEN atp_cursor FOR
sqlQuery;
return atp_cursor;
end getAdvisorInfo;
ERROR:
20/26 PLS-00103: Encountered the symbol "DATE_TIMESTAMP" when expecting
one of the following:
. ( * @ % & = - + ; < / > at in is mod not rem
<an exponent (**)> <> or != or ~= >= <= <> and or like
between ||
The symbol "." was substituted for "DATE_TIMESTAMP" to continue.
21/26 PLS-00103: Encountered the symbol "CHANGE_REASON" when expecting
one of the following:
. ( * @ % & = - + ; < / > at in is mod not rem
<an exponent (**)> <> or != or ~= >= <= <> and or like
LINE/COL ERROR
between ||can some1 tell me what is the problem with the query ... ???
thank you,
Regards,
Chintan
Similar Messages
-
Custom report based on function returning cursor
Hi,
I'm trying to create a generic function that will be the basis of a custom report in Grid Control.
The idea is to pass in a database link name, then the function builds a cursor to select using that name, and returns the result to Grid control to render.
At the moment all I get is an empty table.
My function is defined as follows:
create or replace function list_databases(p_dblink varchar2) return sys_refcursor
is
db_name varchar2(40);
c_cursor sys_refcursor;
v_query varchar2(100);
begin
v_query := 'select name from rc_database@'||p_dblink;
open c_cursor for v_query;
return c_cursor;
end;
The custom report contains a 'Table from SQL' type, with the following sql statement:
select sysman.list_databases('rmancat_test') from dual
I've tried playing around with the ??EMIP_BIND_RESULTS_CURSOR?? bind variable but it only seems to work if I write the pl/sql block in the custom report, rather than going for a generic function.
Any ideas are most welcome.
ChrisWhy not use a simple procedure to achieve the same thing?
-
Function returning cursor to be used in select statement
I have written a function which returns a cursor. I want to use this in a select statement to display rows. How to do this.
Eg : function - test_fn return sys_refcursor. (returns empno, empname, deptname)
select test_fn from dual
This should return
empno empname deptno
1 name1 dept1
2 name 2 dept2
....Try This::
SCOTT@xe_144>variable c refcursor
SCOTT@xe_144>CREATE OR REPLACE FUNCTION get_nm
2 RETURN sys_refcursor
3 AS
4
5 c sys_refcursor;
6 BEGIN
7
8 open c for 'SELECT ENAME , SAL FROM EMP';
9
10 RETURN c;
11 END;
12 /
Function created.
SCOTT@xe_144>select get_nm into :c from dual;
GET_NM
CURSOR STATEMENT : 1
CURSOR STATEMENT : 1
ENAME SAL
SMITH 800
ALLEN 1600
WARD 1250
JONES 2975
BLAKE 2850
CLARK 2450
KING 3000
AKASH2 5000
TURNER 1500
ADAMS 1100
JAMES 950
MILLER 1300
ABC 2000
13 rows selected.Let me know if its works for you. -
Returning Cursor from Function
I have been struggling all afternoon to get a package function
to return a cursor. Following some advice from the forums, I
think I'm getting close. <vbg> But am getting a compile error
on my RETURN statement. Can someone please help or post a
working example of how to do this. Thanks!
-- IN PACKAGE HEADER
type package_cursor is ref cursor;
function testfunction (p_system_date in date)
return package_cursor;
-- IN PACKAGE BODY
function testfunction (p_system_date in date)
return package_cursor is
cursor c1 is
select columns from tables where mydate = p_system_date;
begin
open c1;
return c1;
end testfunction;Nevermind, I figured it out by using Barbara Boehmer example in
the "function returning record or table" thread.
function testfunction (
p_system_date in date)
return package_cursor is
vret package_cursor;
begin
open vret for
select columns from tables where mydate = p_system_date;
return vret;
end testfunction; -
How to get a stored function return value (which is not a cursor)?
I want to do so with ADO inside Visual Basic. I know how to call a stored procedure, but nothing I tried could help me in calling a stored function and getting its return code. Note that the function has no cursors within its argument or return code.
Your quick response would be appreciated
EyalEyal,
A stored function returns a value. You need to have the first parameter (of correct data type) for the returned value. The parameter binding is pretty much the same as you would do with stored procedures.
e.g. "begin :1= proc(....); end;"
Sinclair -
How to execute function having return cursor
hi all
Please tell me
How to execute function having return cursor
regardsCREATE OR REPLACE FUNCTION sp_get_stocks(v_price IN NUMBER)
RETURN types.ref_cursor
AS
stock_cursor types.ref_cursor;
BEGIN
OPEN stock_cursor FOR
SELECT ric,price,updated FROM stock_prices
WHERE price < v_price;
RETURN stock_cursor;
END;
SQL> exec :results := sp_get_stocks(20.0)
PL/SQL procedure successfully completed.
Message was edited by:
chenks -
Function returning error - change notification
I have a function returning error text. When error occurs I get the message
'xx error has occurred' on the screen (in notification). Is there a way to control the message text so I can display different text?It's something like this:
DECLARE l_code zip.code%TYPE;
got_error varchar2(1) := 'N';
l_check_fld varchar2(30000);
l_error_fld varchar2(32000);
vErrorFields varchar2(1000);
CURSOR check_zip IS
select ''
from zip
where code = l_code;
BEGIN
apex_collection.create_or_truncate_collection('ZIP');
FOR i IN 1 .. apex_application.g_f03.COUNT LOOP
vErrorFields := '';
/* Code MUST be entered */
if (apex_application.g_f03(i) is null and
(apex_application.g_f04(i) is not null or
apex_application.g_f05(i) is not null))then
got_error := 'Y';
vErrorFields := vErrorFields || ',f03';
l_error_fld := l_error_fld || 'Row ' || to_char(i) || ':' ||' <span style="color: red">Code cannot be <strong>blank.</strong></span><br>';
end if;
END LOOP;
if got_error = 'N' then
apex_collection.delete_collection('ZIP');
end if;
RETURN l_error_fld;
END; -
Can Function Return more than One Values ??
Hi Experts,
I would like to ask you Can Function Return more than one values. I Used Function with Out and In out parameter and its working Fine..
1. what is harm using Out and In out parameter in function
2. if we can use Out and In out parameter in Function so what is deffernce between procedure and Function.
3. Is there any Other Way Though which we can return more the One values in Function.
Please advice me...
Thanks
Umesh GoelYes/No.
You can return multiple value from function. But, in PL/SQL and not in a SQL.
The following examples demonstrate that -
SQL*Plus: Release 9.2.0.1.0 - Production on Wed Mar 28 17:41:15 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> create or replace package glob
2 as
3 b varchar2(20);
4 c varchar2(20);
5 end;
6 /
Package created.
SQL>
SQL> create or replace function test_mul_out(a in number)
2 return number
3 is
4 cursor c1(eno in number)
5 is
6 select ename,job,sal
7 from emp
8 where empno = eno;
9
10 rec c1%rowtype;
11 d number(10);
12 begin
13 open c1(a);
14 loop
15 fetch c1 into rec;
16 exit when c1%notfound;
17 glob.b:= rec.ename;
18 glob.c:= rec.job;
19 d:= rec.sal;
20 end loop;
21 close c1;
22 return d;
23 end;
24 /
Function created.
SQL> set serveroutput on
SQL>
SQL> declare
2 zz number(10);
3 begin
4 select test_mul_out(7777)
5 into zz
6 from dual;
7
8 dbms_output.put_line('Ename: '||glob.b);
9 dbms_output.put_line('Job: '||glob.c);
10 dbms_output.put_line('Sal: '||zz);
11 end;
12 /
Ename: Avik
Job: CLERK
Sal: 3456
PL/SQL procedure successfully completed.
SQL> Regards.
Satyaki De. -
OCI8: returning cursors from stored procedures
The short version of my question is:
In OCI8, how do open a cursor from the database stored procedure, return it to my C++ program and fetch from it, given that in OCI8 cursors and cursor functions are becoming obsoleted?
The long version of the same question is:
I am converting my C++ code from the Oracle 7.3 OCI driver to the Oracle8 OCI driver. One thing I did very frequently in Oracle 7.3 OCI code is open a multi-row select cursor within a stored procedure and return that cursor to my program. In the program, I would then do the fetching with the returned cursor. This was very useful, as it allows me to change the queries in the stored procedure (for example, to append information to certain columns or make some data in all uppercase) without recompiling the application due to a changed SQL string.
My 7.3 psuedocode is as follows:
stored procedure def:
TYPE refCurTyp IS REF CURSOR;
FUNCTION LoadEmployeeData RETURN refCurTyp;
stored procedure body:
FUNCTION LoadEmployeeData RETURN refCurTyp IS
aCur refCurTyp;
BEGIN
OPEN aCur FOR
SELECT emp_id, emp_name
FROM employee_table
ORDER BY emp_name;
return aCur;
END;
OCI code: // all functions are simplified, not actual parameter listing
// declare main cursor variable #1 and return cursor variable #2
Cda_Def m_CDAstmt, m_CDAfunction;
// open both cursors
oopen(m_CDAstmt, ...);
oopen(m_CDAfunction, ...);
// bind cursor variable to cursor #2
oparse(&m_CDAstmt, "BEGIN :CUR := MYPACKAGE.LoadEmployeeData; END;");
obindps(&m_CDAstmt, SQLT_CUR, ":CUR", &m_CDAfunction);
// run cursor #1
oexn(&m_CDAstmt);
// bind variables from cursor #2, and fetch
odefineps(&m_CDAfunction, 1, SQLT_INT, &m_iEmpId);
odefineps(&m_CDAfunction, 2, SQLT_CHAR, &m_pEmpName);
while (!ofen(&m_CDAfunction))
// loop: do something with fetch
// values placed in m_iEmpID and m_pEmpName
This works perfectly, and has really helped to make my code more maintainable. Problem is, in Oracle 8 OCI both cursors and the cursor functions (such as oopen()) are becoming obsoleted. Now it uses statement and environment handles. I know I can still use Cda_Def and cursors--for a while--within OCI8, but I need to know the official up-to-date method of returning a cursor from the database and fetching within my C++ code. Any code fragment, or explanation of what I need to do in OCI8 would be appreciated (perhaps I need to bind to a statement handle instead? But the stored procedure still returns a cursor.)
The Oracle8 OCI has a new SQLT_ type, SQLT_RSET, which the header file defines as "result set type". Unfortunately, it's almost completely undocumented in the official documentation. Am I supposed to use this instead of the obsolete SQLT_CUR?
Thanks,
Glen MazzaEmail me diorectly and I will get you some code that might help. I fail to see the relevance of posting this type of information in the JDeveloper forum.
-
How to migrate sql server 2000 user defined function returns table
Hi,
How do I capture the SQL Server 200 user defined function that returns table? Is this supported in the current version of Oracle Migration Workbench? I am using the latest version - Release 9.2.0.1.0 with SQL SERVER 2000 plug-in.
I was able to capture the SQL Server 2000 user defined function that returns string and smalldatetime but not the functions return table during the migrate data source stage.
Thanks in Advance,
SusanSusan,
This is not currently supported. The next release of the Oracle Migration Workbench (due very soon), will do a better job of catching this mad reporting an error. We are looking into a suitable mapping and have created bug # 2355073 - TABLE DEFINITIONS NOT ACCEPTED FOR TABLE FUNCTIONS to track this issue.
Once possible solution we are looking into is using the object type to emulate. Here is an example from the bug:
Original table
SQL> create table tabela (a number, b number, c number, d number);
SQL> insert some values...
SQL> select * from tabela;
A B C D
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
SQL Server 2000 code
CREATE FUNCTION FUNCRETORNATABELA()
RETURNS TABLE
AS
RETURN SELECT A,B,C,D FROM TABELA
SELECT A,B,C,D
FROM FUNCRETORNATABELA()
ORDER BY A
Oracle code (workaround)
SQL> create or replace type MyObjType as object (
2 a number, b number, c number, d number);
3 /
Type created.
SQL> create or replace type MyTabType as table of MyObjType;
2 /
Type created.
SQL> create or replace function teste return Mytabtype pipelined as
2 aa MyObjType := MyObjType(null, null, null, null);
3 cursor c1 is select a,b,c,d from tabela;
4 begin
5 open c1;
6 loop
7 fetch c1 into aa.a, aa.b, aa.c, aa.d;
8 exit when c1%NOTFOUND;
9 pipe row (aa);
10 end loop;
11 close c1;
12 return;
13 end;
14 /
Function created.
SQL> select * from table(teste);
A B C D
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
SQL> select a, c from table(teste) order by c desc;
A C
4 4
3 3
2 2
1 1
Donal -
ORA-06503: PL/SQL: Function returned without value
Hello
Having a bit of a problem with piplined functions.
Why does this work :
SET SERVEROUTPUT ON
DECLARE
TYPE SARRAY IS TABLE OF VARCHAR2(4000);
CURSOR CU IS SELECT * FROM DX_XML_ATTENDANCE WHERE STUD_ID = 107777 AND BASE_ID = 94;
T_STUD NUMBER(10);
T_BASE NUMBER(10);
T_DATE DATE;
T_MARKS VARCHAR2(1000);
LEN_MARKS NUMBER;
PDATE DATE;
SDATE DATE;
EDATE DATE;
SLEN NUMBER;
WEEKLEN NUMBER;
INIPOS NUMBER;
MARRAY VARCHAR2(1000);
SUBARRAY SARRAY := SARRAY();
SFILL VARCHAR2(14) := '--------------';
EPOS NUMBER;
MY_REC DX_XML_ATTENDANCE%ROWTYPE;
BEGIN
SUBARRAY.EXTEND(17);
DBMS_OUTPUT.ENABLE(100000000);
--FOR MY_REC IN CU
OPEN CU;
LOOP
FETCH CU INTO MY_REC;
EXIT WHEN (CU%NOTFOUND);
T_STUD := MY_REC.STUD_ID;
T_BASE := MY_REC.BASE_ID;
T_DATE := TO_DATE(MY_REC.START_DATE, 'DD/MM/YYYY');
T_MARKS := MY_REC.MARKS;
LEN_MARKS := LENGTH(T_MARKS);
EPOS := LEN_MARKS / 2;
SDATE := ROUND(TO_DATE(T_DATE), 'W') - 1;
INIPOS := TO_NUMBER(TO_CHAR(T_DATE, 'D'));
SLEN := INIPOS + 3;
PDATE := SDATE;
EDATE := SDATE + EPOS;
MARRAY := SUBSTR(T_MARKS, 1, SLEN);
WEEKLEN := LENGTH(MARRAY);
IF WEEKLEN < 14 THEN
MARRAY := SUBSTR(SFILL, 1, 14 - WEEKLEN) || MARRAY;
END IF;
SUBARRAY(1) := T_STUD;
SUBARRAY(2) := T_BASE;
SUBARRAY(3) := PDATE;
FOR i IN 4 .. 17 LOOP
SUBARRAY(i) := SUBSTR(MARRAY, i - 3, 1);
END LOOP;
DBMS_OUTPUT.PUT_LINE(SUBARRAY(1)||' '||SUBARRAY(2)||' '||SUBARRAY(3)||' '||SUBARRAY(4)||' '||
SUBARRAY(5)||' '||SUBARRAY(6)||' '||SUBARRAY(7)||' '||SUBARRAY(8)||' '||SUBARRAY(9)||' '||
SUBARRAY(10)||' '||SUBARRAY(11)||' '||SUBARRAY(12)||' '||SUBARRAY(13)||' '||SUBARRAY(14)||' '||
SUBARRAY(15)||' '||SUBARRAY(16)||' '||SUBARRAY(17));
WHILE PDATE < EDATE LOOP
PDATE := PDATE + 7;
MARRAY := SUBSTR(T_MARKS, SLEN + 1, 14);
WEEKLEN := LENGTH(MARRAY);
IF WEEKLEN < 14 THEN
MARRAY := MARRAY || SUBSTR(SFILL, 1, 14 - WEEKLEN);
END IF;
FOR i IN 4 .. 17 LOOP
SUBARRAY(i) := SUBSTR(MARRAY, i - 3, 1);
END LOOP;
SUBARRAY(3) := PDATE;
DBMS_OUTPUT.PUT_LINE(SUBARRAY(1)||' '||SUBARRAY(2)||' '||SUBARRAY(3)||' '||SUBARRAY(4)||' '||
SUBARRAY(5)||' '||SUBARRAY(6)||' '||SUBARRAY(7)||' '||SUBARRAY(8)||' '||SUBARRAY(9)||' '||
SUBARRAY(10)||' '||SUBARRAY(11)||' '||SUBARRAY(12)||' '||SUBARRAY(13)||' '||SUBARRAY(14)||' '||
SUBARRAY(15)||' '||SUBARRAY(16)||' '||SUBARRAY(17));
PDATE := PDATE + 7;
SLEN := SLEN + 14;
END LOOP;
END LOOP;
END;
and this does not :
CREATE OR REPLACE PACKAGE BODY PARSE_ATTENDANCE AS
FUNCTION ENUM_MARKS(SEL_SQL IN VARCHAR2)
RETURN TMP_ATT_DATA_TBL PIPELINED
IS
V_SQL VARCHAR(1000):= SEL_SQL;
V_CURSOR SYS_REFCURSOR;
V_ROW TMP_ATT_HOLDING:=TMP_ATT_HOLDING(NULL, NULL, NULL, NULL);
T_STUD NUMBER(10);
T_BASE NUMBER(10);
T_DATE DATE;
T_MARKS VARCHAR2(1000);
LEN_MARKS NUMBER;
PDATE DATE;
SDATE DATE;
EDATE DATE;
SLEN NUMBER;
WEEKLEN NUMBER;
INIPOS NUMBER;
MARRAY VARCHAR2(1000);
SUBARRAY SARRAY := SARRAY();
SFILL VARCHAR2(14) := '--------------';
EPOS NUMBER;
BEGIN
SUBARRAY.EXTEND(17);
OPEN V_CURSOR FOR V_SQL;
LOOP
FETCH V_CURSOR INTO V_ROW.STUD_ID, V_ROW.BASE_ID, V_ROW.START_DATE, V_ROW.MARKS;
EXIT WHEN V_CURSOR%NOTFOUND;
T_STUD := V_ROW.STUD_ID;
T_BASE := V_ROW.BASE_ID;
T_DATE := TO_DATE(V_ROW.START_DATE, 'DD/MM/YYYY');
T_MARKS := V_ROW.MARKS;
LEN_MARKS := LENGTH(T_MARKS);
EPOS := LEN_MARKS / 2;
SDATE := ROUND(TO_DATE(T_DATE), 'W') - 1;
INIPOS := TO_NUMBER(TO_CHAR(T_DATE, 'D'));
SLEN := INIPOS + 3;
PDATE := SDATE;
EDATE := SDATE + EPOS;
MARRAY := SUBSTR(T_MARKS, 1, SLEN);
WEEKLEN := LENGTH(MARRAY);
IF WEEKLEN < 14 THEN
MARRAY := SUBSTR(SFILL, 1, 14 - WEEKLEN) || MARRAY;
END IF;
SUBARRAY(1) := T_STUD;
SUBARRAY(2) := T_BASE;
SUBARRAY(3) := PDATE;
FOR i IN 4 .. 17 LOOP
SUBARRAY(i) := SUBSTR(MARRAY, i - 3, 1);
END LOOP;
PIPE ROW(TMP_ATT_DATA_OBJ(SUBARRAY(1),SUBARRAY(2),SUBARRAY(3),SUBARRAY(4),
SUBARRAY(5),SUBARRAY(6),SUBARRAY(7),SUBARRAY(8),SUBARRAY(9),
SUBARRAY(10),SUBARRAY(11),SUBARRAY(12),SUBARRAY(13),SUBARRAY(14),
SUBARRAY(15),SUBARRAY(16),SUBARRAY(17)));
WHILE PDATE < EDATE LOOP
PDATE := PDATE + 7;
MARRAY := SUBSTR(T_MARKS, SLEN + 1, 14);
WEEKLEN := LENGTH(MARRAY);
IF WEEKLEN < 14 THEN
MARRAY := MARRAY || SUBSTR(SFILL, 1, 14 - WEEKLEN);
END IF;
FOR i IN 4 .. 17 LOOP
SUBARRAY(i) := SUBSTR(MARRAY, i - 3, 1);
END LOOP;
SUBARRAY(3) := PDATE;
PIPE ROW(TMP_ATT_DATA_OBJ(SUBARRAY(1),SUBARRAY(2),SUBARRAY(3),SUBARRAY(4),
SUBARRAY(5),SUBARRAY(6),SUBARRAY(7),SUBARRAY(8),SUBARRAY(9),
SUBARRAY(10),SUBARRAY(11),SUBARRAY(12),SUBARRAY(13),SUBARRAY(14),
SUBARRAY(15),SUBARRAY(16),SUBARRAY(17)));
PDATE := PDATE + 7;
SLEN := SLEN + 14;
END LOOP;
END LOOP;
END ENUM_MARKS;
END PARSE_ATTENDANCE;
(This is then called like SELECT * FROM
TABLE(
PARSE_ATTENDANCE.ENUM_MARKS(
'SELECT STUD_ID, BASE_ID, START_DATE, MARKS
FROM DX_XML_ATTENDANCE WHERE STUD_ID = 107777
AND BASE_ID = 94'))
I get the same error, around this section near the bottom :
PDATE := PDATE + 7;
SLEN := SLEN + 14;
Can any one help?Here is an example. you are missing an return statement.
SQL> create or replace type varchar2_table is table of varchar2(10) ;
2 /
Type created.
SQL> show errors
No errors.
SQL> create or replace function get_data return varchar2_table pipelined is
2 begin
3 pipe row(('Test')) ;
4 end ;
5 /
Function created.
SQL> show errors
No errors.
SQL> select * from table(get_data) ;
ERROR:
ORA-06503: PL/SQL: Function returned without value
ORA-06512: at "KKISHORE.GET_DATA", line 3
no rows selected
SQL> create or replace function get_data return varchar2_table pipelined is
2 begin
3 pipe row(('Test')) ;
4 return ;
5 end ;
6 /
Function created.
SQL> show errors
No errors.
SQL> select * from table(get_data) ;
COLUMN_VAL
Test
SQL> -
Call stored function return array
Hi all,
I have a function as follow:
create or replace TYPE string_table IS TABLE OF VARCHAR2(2000);
create or replace TYPE ARRAYTYPE is VARRAY(20) OF VARCHAR2(30);
create or replace FUNCTION getEmpArray(s varchar2, t varchar2, st string_table) RETURN ARRAYTYPE AS
l_data ARRAYTYPE := ARRAYTYPE();
BEGIN
l_data.extend; l_data(l_data.count) := s; l_data.extend; l_data(l_data.count) := t; l_data.extend; l_data(l_data.count) := st(1); RETURN l_data;
END;
I want to call this function by StoredFunctionCall
code:
StoredFunctionCall fun = new StoredFunctionCall();
fun.setProcedureName("getEmpArray".toUpperCase());
Object[] arr = new Object[]{"aa", "fgfg", "bbb"};
ArrayDescriptor arrDescriptor =
ArrayDescriptor.createDescriptor("string_table".toUpperCase(),
connection);
ARRAY arrayToPass = new ARRAY(arrDescriptor, connection, arr);
fun.addUnamedArgumentValue("a");
fun.addUnamedArgumentValue("b");
fun.addUnamedArgumentValue(arrayToPass);
fun.setResult("FUNCTION_RESULT"); // for get result by this name
Vector<DatabaseRecord> list = session.executeSelectingCall(fun);
But Exception
PLS-00382: expression is of wrong type
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
Error Code: 6550
Call: BEGIN ? := GETEMPARRAY(?, ?, ?); END;
bind => [=> FUNCTION_RESULT, a, b, oracle.sql.ARRAY@21fbc01]
Please help me
Edited by: fbg on 21:52 26-04-2010A few issues,
1 - JDBC does not support the PLSQL TABLE type, you must use a VARRAY type, or wrap the TABLE function call in a function that takes a VARRAY.
TopLink also has support for PLSQL types in its PLSQLStoredProcedureCall class, but no support is currently offered for StoredFunctions.
You can't pass the VARRAY type for the TABLE argument.
2 - Your function returns a VARRAY, so you need to define this type in the StoredFunctionCall result.
We don't currently expose the API to set a Array type for the result, so you would need to access the call's first parameter directly, or use a StoredProcedureCall (and convert your function to a procedure).
You may also wish to investigate returning a cursor from a stored procedure instead of the varray.
You could also access the JDBC connection directly and perform the call using JDBC code.
Feel free to log these issues in EclipseLink.
James : www.eclipselink.org -
create or replace function etest
(dep in number)
return varchar2
is
dept number:= 0;
cursor c1 is
select deptno
into dept
from emp
where deptno = dep;
begin
open c1;
loop
fetch c1 into dept;
exit when c1%notfound;
end loop;
close c1;
return dept;
end;
Dear all
the above function return only one return ,,,but i want to display all record that belong to department 10
it just i idea that what i want to do....!
and Secondly
how i fetch multiple column like i enter department 10 and it give output like
empno ename sal
7782 CLARK 2450
7739 KING 5000
7934 MILLER 13000
Thanks to allYou could use a REF CURSOR:
PL/SQL 101 : Understanding Ref Cursors
http://www.oracle-base.com/articles/misc/UsingRefCursorsToReturnRecordsets.php
or maybe a pipelined function....
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:19481671347143
http://www.oracle-base.com/articles/9i/PipelinedTableFunctions9i.php
depending on what client is fetching. -
Hi,
I am having function returning ref cursor.I am assigning all the output values into ref cursor but getting error while returning cursor.
When I am trying to print value in a loop its showing correct output but while returning the cursor giving error.
Please guide us on this issue.
Regards..Hi,
set serveroutput on;and again run the function.
Thanks -
Function Returning Object
Hi Experts,
Here is my code,
-- DROP TYPE TYP_EMP;
-- DROP TYPE TYP_EMP_OBJ;
CREATE OR REPLACE TYPE TYP_EMP_OBJ AS OBJECT
TOTAL NUMBER,
ROWINDEX NUMBER,
EMPNO NUMBER,
ENAME VARCHAR2(50),
LOC VARCHAR2(100)
CREATE OR REPLACE TYPE TYP_EMP AS TABLE OF TYP_EMP_OBJ;
CREATE OR REPLACE FUNCTION FUN_GETEMP_LOCATION(pmDeptno IN NUMBER) RETURN VARCHAR2
AS
vLocation DEPT.LOC%TYPE;
BEGIN
SELECT LOC INTO vLocation FROM DEPT WHERE DEPTNO=pmDeptno;
RETURN vLocation;
END;
CREATE OR REPLACE FUNCTION FUN_GET_EMP_DETAILS
pmType IN NUMBER,
pmStartPage IN NUMBER,
pmEndPage IN NUMBER,
pmOrderBy IN VARCHAR2
RETURN TYP_EMP PIPELINED
AS
vString VARCHAR2(100);
TYPE vRefCursor IS REF CURSOR;
Cur vRefCursor;
Rec TYP_EMP_OBJ := TYP_EMP_OBJ(NULL,NULL,NULL,NULL,NULL);
BEGIN
IF pmType IS NULL THEN
SELECT 0,NULL,NULL,NULL,NULL INTO Rec.TOTAL,Rec.ROWINDEX,Rec.EMPNO,Rec.ENAME,Rec.LOC FROM DUAL;
RETURN;
END IF;
IF pmType =1 THEN
OPEN Cur FOR
'SELECT * FROM(
SELECT
COUNT(*) OVER(),
ROW_NUMBER() OVER('||pmOrderBy||') ROW_INDEX,
EMPNO,
ENAME,
FUN_GETEMP_LOCATION(EMP.DEPTNO) LOC
FROM EMP)T
WHERE T.ROW_INDEX BETWEEN '||pmStartPage||' AND '||pmEndPage;
ELSE
OPEN Cur FOR
'SELECT * FROM(
SELECT
COUNT(*) OVER(),
ROW_NUMBER() OVER('||pmOrderBy||') ROW_INDEX,
2,
ENAME,
FUN_GETEMP_LOCATION(EMP.DEPTNO) LOC
FROM EMP)T
WHERE T.ROW_INDEX BETWEEN '||pmStartPage||' AND '||pmEndPage;
END IF;
LOOP
FETCH Cur INTO Rec.TOTAL,Rec.ROWINDEX,Rec.EMPNO,Rec.ENAME,Rec.LOC;
EXIT WHEN Cur%NOTFOUND;
PIPE ROW(Rec);
END LOOP;
CLOSE Cur;
RETURN;
END;
SELECT * FROM TABLE(FUN_GET_EMP_DETAILS(NULL,1,10,'ORDER BY EMPNO DESC'));
SELECT * FROM TABLE(FUN_GET_EMP_DETAILS(1,1,10,'ORDER BY EMPNO DESC'));
SELECT * FROM TABLE(FUN_GET_EMP_DETAILS(2,1,10,'ORDER BY EMPNO DESC'));
Executing First Query
Actually Whats happening on Executing first Query, it does not return as specified
SELECT 0,NULL,NULL,NULL,NULL INTO Rec.TOTAL,Rec.ROWINDEX,Rec.EMPNO,Rec.ENAME,Rec.LOC FROM DUAL;
It just returning null;
Executing Second Query
It return correctly.
Executing Third Query
It return correctly.
Can anyone suggest how to work out like this?
Thanks,
Dharan VYou dint pipe the row if pmType is NULL
CREATE OR REPLACE FUNCTION FUN_GET_EMP_DETAILS
pmType IN NUMBER,
pmStartPage IN NUMBER,
pmEndPage IN NUMBER,
pmOrderBy IN VARCHAR2
RETURN TYP_EMP PIPELINED
AS
vString VARCHAR2(100);
TYPE vRefCursor IS REF CURSOR;
Cur vRefCursor;
Rec TYP_EMP_OBJ := TYP_EMP_OBJ(NULL,NULL,NULL,NULL,NULL);
BEGIN
IF pmType IS NULL THEN
SELECT 0,NULL,NULL,NULL,NULL INTO Rec.TOTAL,Rec.ROWINDEX,Rec.EMPNO,Rec.ENAME,Rec.LOC FROM DUAL;
pipe row(rec); ----------------<<<<----------------- This is required
RETURN;
END IF;
IF pmType =1 THEN
OPEN Cur FOR
'SELECT * FROM(
SELECT
COUNT(*) OVER(),
ROW_NUMBER() OVER('||pmOrderBy||') ROW_INDEX,
EMPNO,
ENAME,
FUN_GETEMP_LOCATION(EMP.DEPTNO) LOC
FROM EMP)T
WHERE T.ROW_INDEX BETWEEN '||pmStartPage||' AND '||pmEndPage;
ELSE
OPEN Cur FOR
'SELECT * FROM(
SELECT
COUNT(*) OVER(),
ROW_NUMBER() OVER('||pmOrderBy||') ROW_INDEX,
2,
ENAME,
FUN_GETEMP_LOCATION(EMP.DEPTNO) LOC
FROM EMP)T
WHERE T.ROW_INDEX BETWEEN '||pmStartPage||' AND '||pmEndPage;
END IF;
LOOP
FETCH Cur INTO Rec.TOTAL,Rec.ROWINDEX,Rec.EMPNO,Rec.ENAME,Rec.LOC;
EXIT WHEN Cur%NOTFOUND;
PIPE ROW(Rec);
END LOOP;
CLOSE Cur;
RETURN;
END;Edited by: Karthick_Arp on Dec 24, 2009 2:12 AM
Maybe you are looking for
-
Error while updating customer data through IDOC.
hi all, I am using the function module "IDOC_INPUT_DEBITOR" to update the customer master data but i was getting an error "editing was terminated".Please help to solve this problem. regards, Suresh.
-
My ipodshuffle g2 recognized as unknown device
when i connect my ipod with my pc(win7) ,the shuffle(G2,1g)is not recognized by itunes or windows,An error box states :usb device not recognized"
-
JMicron + x58 Platinum + windows 7 64 bit = no go
Hi all, I have an MSI x58 platinum running bios 3.7. (ive also got a core i7 930 (3 x 2 GIG ram)) My issue is Ive just rebuilt it and i have just acquired 2 x 36GIG 10000RPM Raptors. Ive done as per the manual said and stuck them on SATA 7/8 made a
-
My apple TV is not working. The light blinks but the TV only shows the apple picture and nothing happens. Any idea why?
-
Error while trying to import using OdiImportObject
When trying to import project using OdiImportObject from command prompt the following error is encountered... E:\ODIHome\oracledi\bin>startcmd.bat OdiImportObject -FILE_NAME=E:\slot\ego\patch\115\odi\US\mode\MFOL_PIM.xml -IMPORT_MODE=SYNONYM_INSERT_U