GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  PL/SQL
Go To First  |  Previous Question  |  Next Question 
 PL/SQL  |  Question 205 of 241    Print  
Oracle refcursor and procedure
how to pass result set using refcursor from one package procedure to another package procedure? and code also


  
Total Answers and Comments: 1 Last Update: December 26, 2007     Asked by: sivaprasadpm 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: MAQDOOMAAMER
 
CREATE TABLE employees (
empid   NUMBER(5),
empname VARCHAR2(30));

INSERT INTO employees (empid, empname) VALUES (1, 'Dan Morgan');
INSERT INTO employees (empid, empname) VALUES (2, 'Jack Cline');
INSERT INTO employees (empid, empname) VALUES (3, 'Caleb Small');
COMMIT;
CREATE OR REPLACE PROCEDURE pass_ref_cur(p_cursor SYS_REFCURSOR) IS

TYPE array_t IS TABLE OF VARCHAR2(4000)
INDEX BY BINARY_INTEGER;

rec_array array_t;

BEGIN
  FETCH p_cursor BULK COLLECT INTO rec_array;

  FOR i IN rec_array.FIRST .. rec_array.LAST
  LOOP
    dbms_output.put_line(rec_array(i));
  END LOOP;
END pass_ref_cur;
/

set serveroutput on

DECLARE
 rec_array SYS_REFCURSOR;
BEGIN
  OPEN rec_array FOR
  'SELECT empname FROM employees';

  pass_ref_cur(rec_array);
  CLOSE rec_array;
END;
/


Above answer was rated as good by the following members:
ratna82
December 25, 2007 15:45:43   #1  
MAQDOOMAAMER Member Since: December 2007   Contribution: 1    

RE: Oracle refcursor and procedure
CREATE TABLE employees (
empid NUMBER(5)
empname VARCHAR2(30));

INSERT INTO employees (empid empname) VALUES (1 'Dan Morgan');
INSERT INTO employees (empid empname) VALUES (2 'Jack Cline');
INSERT INTO employees (empid empname) VALUES (3 'Caleb Small');
COMMIT;
CREATE OR REPLACE PROCEDURE pass_ref_cur(p_cursor SYS_REFCURSOR) IS

TYPE array_t IS TABLE OF VARCHAR2(4000)
INDEX BY BINARY_INTEGER;

rec_array array_t;

BEGIN
FETCH p_cursor BULK COLLECT INTO rec_array;

FOR i IN rec_array.FIRST .. rec_array.LAST
LOOP
dbms_output.put_line(rec_array(i));
END LOOP;
END pass_ref_cur;
/

set serveroutput on

DECLARE
rec_array SYS_REFCURSOR;
BEGIN
OPEN rec_array FOR
'SELECT empname FROM employees';

pass_ref_cur(rec_array);
CLOSE rec_array;
END;
/

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    

 Related Questions

What happens if a procedure that updates a column of table X is called in a database trigger of the same table ?
 Mutation of table occurs. 

 The PRAGMA EXECPTION_INIT tells the complier to associate an exception with an oracle error. To get an error message of a specific oracle error.      e.g. PRAGMA EXCEPTION_INIT 
Latest Answer : PRAGMA EXCEPTION_INIT statement associate the declared exception with the standard Oracle server error number. PRAGMA EXCEPTION_INIT tells the compiler to associate an exception name with an Oracle error number. That allows you to refer to any internal ...

 Raise_application_error  is  a  procedure  of  package  DBMS_STANDARD which allows  to  issue an user_defined error messages from stored sub-program or database 
Latest Answer : You can use this procedure to issue user-defined error messages from stored subprograms.You can report errors to your application and avoid returning unhandled exceptions.Syntax: raise_application_error (error_number,message[, {TRUE | FALSE}]); ...

 A  stored  procedure  is  a  sequence  of  statements that perform specific function. 
Latest Answer : A procedure is a named PL/SQL block that can accept parameters (sometimes referred to as arguments), and be invoked. Generally speaking, you use a procedure to perform an action. A procedure has a header, a declaration section, an executable section, ...

 A FUNCTION is always returns a value using the return statement.        A  PROCEDURE   may  return one or more values through parameters or 
Latest Answer : 1. Function is mainly used in the case where it must return a value. Where as a procedure may or may not return a value or may return more than one value using the OUT parameter. 2. Function can be called from SQL statements where as procedure can not ...

 IN,OUT,IN-OUT parameters. 
Latest Answer : IN (default): Passes a constant value from the calling environment into the procedureOUT     :Passes a value from the procedure to the calling environmentIN OUT  :Passes a value from the calling environment into the ...

 Procedure Specification and Procedure Body. 
Latest Answer : This is from Oracle PL/SQL DocumentationA procedure has two parts: the specification (spec for short) and the body.The procedure spec begins with the keyword PROCEDURE and ends with the procedurename or a parameter listThe procedure body begins with the ...

       PROCEDURE name (parameter list.....)     is     local variable declarations      BEGIN      
Latest Answer : [CREATE [OR REPLACE]] PROCEDURE procedure_name[(Optional Parameters)] {IS | AS} [PRAGMA AUTONOMOUS_TRANSACTION;] [local declarations] BEGIN executable statements [EXCEPTION exception handlers] END [name]; ...

 Function is called as part of an expression.   sal := calculate_sal ('a822');   procedure is called as a PL/SQL statement   calculate_bonus ('A822'); 
Latest Answer : Procedure can be called in the following waysa) CALL direcb) EXCECUTE from calling environmentc) from other procedures or functions or packagesFunctions can be called in the following ...

The Same procedure name is repeated with parameters of different datatypes and  parameters  in  different  positions,  varying number of parameters is called overloading of 
Latest Answer : Definining two or more procedures with same name is called overloading of procedures. But they must differ in no or order or datatype family of formal arguments. ...


 Sponsored Links

 
Related Articles

Querying Data with Oracle XQuery

Querying Data with Oracle XQuery Starting with Oracle Database 10g Release 2 you can take advantage of a full featured native XQuery engine integrated with the database With Oracle XQuery you can accomplish various tasks involved in developing PHP Oracle XML applications operating on any kind of dat
 

Using Oracle XML DB Repository

Using Oracle XML DB Repository Another variation on accessing and manipulating XML content stored in Oracle database is provided by Oracle XML DB repository which is an essential component of Oracle XML DB mosgoogle NOTE Oracle XML DB repository also known as XML repository is a hierarchically organ
 

Using Oracle Database for Storing, Modifying, and Retrieving XML Data

Using Oracle Database for Storing Modifying and Retrieving XML Data With Oracle XML DB you have various XML storage and XML processing options allowing you to achieve the required level of performance and scalability One of the most interesting things about Oracle XML DB is that it allows you to per
 

XML Processing in PHP and Oracle Applications

Processing XML in PHP Oracle Applications As mentioned there are two alternatives when it comes to performing XML processing in your PHP Oracle application You can perform any required XML processing using either PHP s XML extensions or PEAR XML packages or Oracle s XML features mosgoogle In the fol
 

PHP Oracle Web Development

PHP Oracle Web Development Data processing Security Caching XML Web Services and Ajax The book is written by Yuli Vaseliev a well known author of different web development and programming books PHP Oracle Web Development Data processing Security Caching XML Web Services and Ajax is a good starting b
 

Getting Started with Oracle and ODP.NET

ODP NET Developer’ s Guide by Jagadish Chatarji Pulakhandam Sunitha Paruchuri A practical guide for developers working with the Oracle Data Provider for NET and the Oracle Developer Tools for Visual Studio 2005 Application development with ODP NET Dealing with XML DB using ODP NET Oracle
 

PHP Oracle Web Development Review

PHP Oracle Web Development Data processing Security Caching XML Web Services and Ajax The book is written by Yuli Vaseliev a well known author of different web development and programming books The author is also an expert in open source technologies and SOA Service Oriented Architecture But besides
 

Step by Step Oracle PL-SQL Tutorial

This introductory tutorial to PL SQL will help you to understand the basic concepts of PL SQL Please review the following tutorials and practice the sample SQL Statements on your local Oracle Database Please note that you must learn these basic things before we actually start getting in to Advanced
 

Working with XML in Oracle

Working with XML in Oracle Introduction to XML Extensive markup language is the language which presents data in a human readable form of text The data can be anything from a purchase order or a stock quote or weather radar or a flight schedule it can be represented using XML XML is very similar to H
 

What is Oracle Net Service

Oracle Net Services provides enterprise-wide connectivity solutions in distributed, heterogeneous computing environments. Oracle Net Services eases the complexities of network configuration and management, maximizes performance, and improves network diagnostic capabilities. Oracle Net, a component
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape