Can a Fn return a recordset?

How do I have oracle store a SQL statement that can have params passed in, and have a recordset returned to user when executed? Is this done w/ a function?
For example, I want to store the following code:
create procedure/function/?? empname
IDNum as number
As
select empid, name
from emp
where empid = IDNum;
In the simple query above, I want to pass in a parameter when executing the above stored sql statement. When executed from the command line the syntax and result should be:
SQL> execute empname '4'
empid name
4 Bill Wojahowitz
Please help, and if possible can you show an example of syntax. Thanks in advance.
ChrisB
null

You can create a procedure like this :
create or replace procedure empname(no in number) is
name varchar2(100);
begin
select ename into name from employee where empno=no;
dbms_output.put_line(no | | ' ' | |name);
end empname;
when u say execute empname(4) it will output the number and name.
set serveroutput on to show the result.
Hope this helps.
Take Care
Chandar

Similar Messages

  • Procedure to return a recordset in ASP.

    I'll admint that my background is with MS SQL and Oracle is a bit different!
    In SQL I can create a stored procedure that will return a recordset, filtered by the parameter that I pass to the procedure. Such as:
    CREATE PROCEDURE sp_DriverList @BusCoID int
    AS
    SELECT DISTINCT ListName, DriverID
    FROM T_Drivers
    WHERE BusCoID = @BusCoID
    ORDER BY ListName
    In ASP I get back a list of all the Drivers for a given company, using the @BusCoID parameter.
    When I try to implement this same method in Oracle 9i, I get an error. Can someone provide an example, comparable to the SQL version above, that would return a recordset?
    Thanks!!!

    Your post will likely get a better response on the ODP.NET forum, but here's how I would do it.
    CREATE OR REPLACE PACKAGE my_package
    IS
    TYPE refc IS REF CURSOR
    RETURN t_drivers%ROWTYPE refc;
    Function fetch_drivers(p_busid_in IN number);
    END my package;
    CREATE OR REPLACE PACKAGE BODY my_package
    IS
    Function fetch_drivers (p_busid_in IN number)
    IS
    l_curser refc;
    BEGIN
    OPEN l_cursor FOR
    SELECT DISTINCT ListName, DriverID
    FROM T_Drivers
    WHERE BusCoID = p_busid_in
    ORDER BY ListName;
    RETURN l_cursor;
    END fetch_drivers;

  • Return a Recordset in a PL/SQL

    Hello All,
    I'm attempting to write a PL/SQL statement over some very large tables. The processing of the statement takes over 45 minutes to complete.
    I've been able to speed up processing by creating a temp table over the largest of the tables, and it truly has speed up processing. The problem is that this statement will be used in a report run from SQL Reporting Services, using PL/SQL. This will be used in various reports and would like to make this an adhoc type of job - launched by executing the report.
    I've tried writing a procedure that returns a recordset, but I'm having no luck. I'm new to writing Stored Procedures, Functions and Packages, and am trying to get my head around the best way to approach this.
    Here is what I have so far - and it's not even close to working, but you can see the logic I'm trying to follow as far was what I need to return.
    CREATE OR REPLACE PACKAGE PKG_BillSegs_ZeroUsage AS
    TYPE cursor_type IS REF CURSOR;
    Procedure GETBILLSEG_ZEROUSAGE (
                   p_RevMth IN bi_bill_segment.rev_month%TYPE,
    p_recordset OUT PKG_BillSegs_ZeroUsage.cursor_type);
    END PKG_BillSegs_ZeroUsage;
    CREATE OR REPLACE PROCEDURE GetBillSeg_ZeroUsage (p_RevMth IN bi_bill_segment.rev_month%TYPE,
    p_recordset OUT PKG_BillSegs_ZeroUsage.cursor_type) AS
    BEGIN
    OPEN p_recordset FOR
    select * from bi_bill_segment where usage_qty = 0 and rev_month = p_RevMth;
    END GetBillSeg_ZeroUsage;
    Any help is greatly appreciated!

    Here's the output from explain plan - sorry for the output, but couldn't get it to be any prettier :
    OPERATION     OPTIONS     OBJECT_NAME     OBJECT_TYPE     OPTIMIZER     SEARCH_COLUMNS     ID     PARENT_ID     POSITION     COST     CARDINALITY     BYTES
    SELECT STATEMENT     REMOTE               CHOOSE          0          91911     91911     2     4902
    TABLE ACCESS     BY INDEX ROWID     BI_BILL_SEGMENT_T          ANALYZED          1     0     1     91911     2     4902
    INDEX     RANGE SCAN     BI_BILL_SEGMENT_IE7     NON-UNIQUE     ANALYZED     1     2     1     1     659     178774

  • Can we use return statement in procedure?

    Can we use return statement in procedure or we can use more than one return statement in procedure?

    HamidHelal wrote:
    NOReally? Did you at least test it? You can use RETURN in procedure or in anonymous PL/SQL block. The only restriction is you can't specify return value:
    SQL> begin
      2      dbms_output.put_line('Before return');
      3      return;
      4      dbms_output.put_line('After return');
      5  end;
      6  /
    Before return
    PL/SQL procedure successfully completed.
    SQL> create or replace
      2    procedure p1
      3      is
      4      begin
      5          dbms_output.put_line('Before return');
      6          return;
      7          dbms_output.put_line('After return');
      8  end;
      9  /
    Procedure created.
    SQL> exec p1;
    Before return
    PL/SQL procedure successfully completed.
    SQL> begin
      2      dbms_output.put_line('Before return');
      3      return 99;
      4          dbms_output.put_line('After return');
      5  end;
      6  /
        return 99;
    ERROR at line 3:
    ORA-06550: line 3, column 5:
    PLS-00372: In a procedure, RETURN statement cannot contain an expression
    ORA-06550: line 3, column 5:
    PL/SQL: Statement ignored
    SQL> create or replace
      2    procedure p1
      3      is
      4      begin
      5          dbms_output.put_line('Before return');
      6          return 99;
      7          dbms_output.put_line('After return');
      8  end;
      9  /
    Warning: Procedure created with compilation errors.
    SQL> show err
    Errors for PROCEDURE P1:
    LINE/COL ERROR
    5/9      PL/SQL: Statement ignored
    5/9      PLS-00372: In a procedure, RETURN statement cannot contain an
             expression
    SQL> SY.

  • How to test a procedure which returns a recordset from pl/sql

    hello,
    Is it possible to test a procedure which returns a recordset from pl/sql?
    Everything I try results in errors like PLS-00382: expression is of wrong type, when I try to open the result cursor
    or PLS-00221: tc is not a procedure or is undefined.
    I created the following procedure:
    CREATE OR REPLACE PACKAGE test AS
    TYPE cursorType is REF CURSOR;
    PROCEDURE test_cursor( tc IN OUT cursorType,
    v_err OUT varchar2,
    v_msg OUT varchar2);
    END;
    CREATE OR REPLACE
    PACKAGE BODY test AS
    PROCEDURE test_cursor
    (tc IN OUT cursorType,
    v_err OUT varchar2,
    v_msg OUT varchar2)
    AS
    BEGIN
    open tc for
    SELECT '1' "number" FROM dual
    union
    select '2' "number" from dual;
    v_msg := 'no errors';
    v_err := 0;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    v_msg := 'no data found';
    v_err := SQLCODE;
    WHEN OTHERS
    THEN
    v_msg := SQLERRM;
    v_err := SQLCODE;
    END;
    END;
    I try to get the output from pl/sql with something like this:
    DECLARE
    TC PROVGRON.TEST.cursorType;
    V_ERR VARCHAR2(200);
    V_MSG VARCHAR2(200);
    BEGIN
    V_ERR := NULL;
    V_MSG := NULL;
    PROVGRON.TEST.TEST_CURSOR ( TC, V_ERR, V_MSG );
    DBMS_OUTPUT.Put_Line('V_ERR = ' || V_ERR);
    DBMS_OUTPUT.Put_Line('V_MSG = ' || V_MSG);
    -- in tc I was hoping to hava a cursor??
    FOR i IN tc
    LOOP
    DBMS_OUTPUT.PUT_LINE (i.number);
    END LOOP;
    END;
    Without the for loop (or open tc) the pl/sql will output:
    V_ERR = 0
    V_MSG = no errors
    PL/SQL procedure successfully completed.
    With anything I try with the cursor I get errors?
    What am I doing wrong?

    http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch5.htm#sthref1122

  • I bought the Adobe Photoshop Classroom in a Book for CS6 by accident and I have CC. I know, stupid mistake. But I can't take return the book. Is is similar enough to CC that I can still get use out of the book? Thank you so much

    I bought the Adobe Photoshop Classroom in a Book for CS6 by accident and I have CC. I know, stupid mistake. But I can't take return the book. Is is similar enough to CC that I can still get use out of the book? Thank you so much

    Each version of Adobe products builds upon the previous ones.  Some things like filters and advanced features may evolve or become deprecated over time, but the basic tools have remained pretty much the same for decades.  As long as you know there are subtle differences between versions, I think you will still get a great deal of value from C in a B for CS6.  
    Also refer to the CC online tuts
    Photoshop CC tutorials | Learn how to use Photoshop CC
    Learn Photoshop CC | Adobe TV
    Nancy O.

  • Can a method return a class ?

    hi,
    i have a simple question.
    can a method return class value ?
    in the below script i did'nt understand the commented line.
    package com.google.gwt.sample.stockwatcher.client;
    import com.google.gwt.user.client.rpc.RemoteService;
    import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
    @RemoteServiceRelativePath("login")
    public interface LoginService extends RemoteService {
      public LoginInfo login(String requestUri);  //What is this ? is this a sample of what i asked ?
    }

    The answer to your question is yes.
    The idea is that an object calls a function of another object (passing in objects to the function as arguments) in which that object returns an object (note the arguments or returned value of the function may alternately be primitive types). Each object typically encapsulates data and provides a rich set of functions to the calling object so that calling object doesn't have to deal with the raw data directly. Therefore, not only does the calling object get the data it wants, but also a rich set of functions that can manipulate that data.
    Example:
    Book book = new Book();
    int characterCount = book.getChapter(3).getParagraph(4).getSentence(12).getWord(8).getCharacterCount();
    In the above, each object (Book, Chapter,Paragraph,Sentence,Word) has a rich set of functions it provides to its caller.
    Example: the Sentence Object has a collection of word objects (raw data). Functions it provides to Paragraph object are:
    Word getWord(int index), Words getWords(), int getWordCount().
    If you haven't already done so, I suggest reading a book on Java from cover to cover to pick up such Object Oriented concepts.

  • How can I get return to 10.6? Uninstall yosemite

    How can I get return to 10.6? Uninstall yosemite

    Clean Install of Snow Leopard
    Be sure to make a backup first because the following procedure will erase
    the drive and everything on it.
         1. Boot the computer using the Snow Leopard Installer Disc or the Disc 1 that came
             with your computer.  Insert the disc into the optical drive and restart the computer.
             After the chime press and hold down the  "C" key.  Release the key when you see
             a small spinning gear appear below the dark gray Apple logo.
         2. After the installer loads select your language and click on the Continue
             button. When the menu bar appears select Disk Utility from the Utilities menu.
             After DU loads select the hard drive entry from the left side list (mfgr.'s ID and drive
             size.)  Click on the Partition tab in the DU main window.  Set the number of
             partitions to one (1) from the Partitions drop down menu, click on Options button
             and select GUID, click on OK, then set the format type to MacOS Extended
             (Journaled, if supported), then click on the Apply button.
         3. When the formatting has completed quit DU and return to the installer.  Proceed
             with the OS X installation and follow the directions included with the installer.
         4. When the installation has completed your computer will Restart into the Setup
             Assistant. After you finish Setup Assistant will complete the installation after which
             you will be running a fresh install of OS X.  You can now begin the update process
             by opening Software Update and installing all recommended updates to bring your
             installation current.
    Download and install Mac OS X 10.6.8 Update Combo v1.1.

  • Can oracle  function return more than one value

    Hi All
    please answer can oracle function return more than one value
    need one schenario
    regards

    Can any function, irrespective of the language, return multiple values?
    OF COURSE NOT!!
    So why do you think Oracle will now suddenly do it differently than all other languages? Never mind that it is impossible for a function (a unit/module of code) returning a memory address, to return multiple memory addresses. The machine code that does that, has not been yet been designed/implemented.
    I am continually amazed that this question is asked. It is about something so fundamental in almost every single 3rd and 4th generation language... something that is taught right at the start... the definition of what a procedure and what a function is.
    Sorry, but I simply cannot pull punches on this subject and smooth it over. There is something fundamentally wrong with your training as a programmer if you have to ask such a question about a function.
    And whatever programming skills you build on such a foundation, will be seriously lacking.
    I kindly suggest that you get back to the very basics of programming - and review and revisit until you fully understand it. There are no shortcuts in becomming a good programmer.
    Message was edited by:
    Billy Verreynne

  • Can a function return two values???

    Hi guys can a function return more than values?

    Or even better return an Object.
    ie
    public class Tester{
         public static Multi getM()
              Multi m=new Multi();
              m.x="testing";
              m.y="new value";
         public static void main(String [] args)
              Multi mt=getM();
              System.out.println(mt.x);
              System.out.println(mt.y);
         class Multi{
              public String x;
              public String y;
    }

  • Can a method return multiple items

    Can a method return more than one thing?
    I want to have a method return a boolean and a String. My method is saying if something is right or wrong, then its saying the reason why.
    help, please.
    Thanx

    Afternoon_Delight wrote:
    My question is:
    Is there a way so that it can be more like this:
    public boolean, String checkValidity (){
    To expand on the previous posts, one way (not saying it's the best one!) is to create an object that combines the information that you want returned:
    public class MyValid
      private boolean valid;
      private String text;
      public MyValid(boolean valid, String text)
        this.valid = valid;
        this.text = text;
      public boolean isValid()
        return valid;
      public String getText()
        return text;
    class DoFoo
      public MyValid checkValidity()
        return new MyValid(false, "Because I said so!");
    }

  • Can PIX 506e return port unreachable

    Hello
    Can PIX 506e return ICMP port unreachable on Linux traceroute with UDP data gram, and if somebody knows how, can you make an example of the access-list how it should be written to allow this response?

    PIX won't return an ICMP port unreachable message and access lists cannot be configured to make PIX to respond a port unreachable.

  • How can I remove the iPhoto upgrade to my iMac OSX 10.2.8? Can the upgrade return my library?

    How can I remove the iPhoto upgrade to my iMac OSX 10.2.8? Can the upgrade return my library?

    With respect, we'll need rather more detail than that.
    In general, you can only roll back an upgrade to a library with a back up. No back up, no roll back.
    Regards
    TD

  • Looking for Rental add-on that can handle flexible return dates

    Hi Forum,
    I am wondering which would be good add-on for rental industry that can handle flexible return dates (without cancelling original contract and creating a new one with actual date).
    I am wondering if Visnova's Rental add-on would handle flexible return dates without actually cancelling original contract and creating a new contract.
    Are there many ways to handle flexible rental return dates?
    Thanks.

    Hi,
    I have moved your thread here because you are looking for partner add-on instead of SAP add-on. Have you searched through this forum and SAP EcoHub ?
    Thanks,
    Gordon

  • Error:  Current provider does not support returning multiple recordsets from a single execution

    Hello,
    The following piece of code which has been working for the
    past five years suddenly started giving me the following error:
    Current provider does not support returning multiple recordsets
    from a single execution
    We have recenlty moved this site to a new server. Could this
    error be related to their CFAdmin settings? Eveything else on the
    site seems to be working fine. Or am I using an outdated tag or
    something?
    Any light in this direction is appreciated, thanks.
    Here's the code:

    There doesn't seem to be anything that seems wrong with the
    code. It might have something to do with the Max Pooled Statements
    or Number of Connections settings in the CF Administrator, but it
    could just as easily have something to do with a setting on the
    database. I would check with your provider.

Maybe you are looking for