function can return multiple value?how give give sample coding

Answer Posted / rahul poptani

Function returns only 1 value
BUT you can return multiple value Indireclty..
1) By returning an result set -

CREATE OR REPLACE FUNCTION GET_DEPT_INFO (P_DEPTNO IN NUMBER) RETURN SYS_REFCURSOR
AS
V_RC SYS_REFCURSOR;
BEGIN
OPEN V_RC FOR SELECT DEPTNO, DNAME, LOC FROM DEPT WHERE DEPTNO = P_DEPTNO;
RETURN V_RC;
END;

SQL> VAR RESULTSET REFCURSOR;
SQL> EXEC :RESULTSET := GET_DEPT_INFO(10)

PL/SQL procedure successfully completed.
SQL> PRINT :RESULTSET

DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK

2)PROVIDING OUT MODE PARAMETERS IN FUNCTION (RARELY USED)

SQL> CREATE OR REPLACE FUNCTION OUTMODE_EXAMPLE (P_DEPTNO NUMBER, P_DNAME OUT VARCHAR2)
2 RETURN NUMBER
3 AS
4 BEGIN
5 SELECT DNAME INTO P_DNAME FROM DEPT WHERE DEPTNO = P_DEPTNO;
6 RETURN NULL;
7 END;
8 /

Function created.

SQL> DECLARE
2 V_DNAME DEPT.DNAME%TYPE;
3 V NUMBER;
4 BEGIN
5 V := OUTMODE_EXAMPLE(10,V_DNAME);
6 DBMS_OUTPUT.PUT_LINE(V_DNAME);
7 END;
8 /
ACCOUNTING

PL/SQL procedure successfully completed.

Is This Answer Correct ?    6 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is msql? : Sql dba

752


Enlist the advantages of sql.

745


What is sqlca in powerbuilder?

746


Which sql statement is used to return only different values?

711


What is sql constant?

677






What is the use of function in sql?

732


How do I run a sql query?

738


How you improve the performance of sql*loader? : aql loader

752


How delete all data from table in sql?

754


what is cursor. write example of it. What are the attributes of cursor.

976


Explain what is a subquery ?

853


Can a table contain multiple primary key’s?

806


What is the function that is used to transfer a pl/sql table log to a database table?

730


what is 'mysqlimport'? : Sql dba

725


How to Declare Fixed Length String Value In PL SQL

843