Return a record set from a procedure

I am building an application for my company.
Before oracle I had used MS SQL Server for a long time.
I build a procedure as following
CREATE OR REPLACE PROCEDURE YBP.ReturnSet
-- Return a record set from a procedure
IS
BEGIN
SELECT * FROM fdbase;
END;
But the complier show me a error message:
<font color="#0000FF">PLS-00428     an INTO clause is expected in this SELECT statement</font>
I read the error details
<font color="#0000FF">"In PL/SQL, only a subquery is written without an INTO clause."</font>
But I know that this procedure can run well in <font color="#0000FF">MS SQL Server .</font>
How I can do this thing in Oracle
Any help will be appreciate!

I have a stored proc that is defined as
CREATE or REPLACE
PROCEDURE ABC
(linkid IN CHAR,
Year_in IN DATE,
Method_in IN CHAR,
Date_out OUT DATE,
average_out OUT NUMBER)
is
begin
.. Date_out := ...;
average_out := ...;
end;
another partially completed stored proc that returns a ref
cursor defined as follows:
create or replace package zzz
as
type cursorType is ref cursor;
end;
create or replace function test return zzz.cursortype
as
date_OUT date;
Average_OUT number;
l_cursor zzz.cursorType;
CURSOR temp_cur is
SELECT l.linkid, L.routenumber, ABC(l.linkid,
to_date('01/01/2000', 'mm/dd/yyyy'),
'2',
date_OUT,
average_OUT)
FROM LINK l
WHERE l.LINKID <= '010999';
begin
open temp_cur;
end;
inside test (which I need help completing), how can I refer to
the date_out and the average_out params returned by ABC() so
that these values are in turn passed to the cursortype defined
in package zzz?
Thanks in advance.

Similar Messages

  • Returning Multiple Record sets to VB.

    Is it possible using an Oracle 7 Driver connecting to a Oracle 9i database to return multiple record sets to screens written in VB? this is all a new area for me and the people I've spoken to so far seem to think it isn't possible - I refuse to believe this - someone must have done this before?!?!? Can someone confirm either way before I go down this path!!!!
    Cheers

    Sounds like you need a join statement in your SQL, is the
    category and field info in different tables, then a join would be
    perfect, also what language are you using. I know another way in
    php you could use a while loop with another RS inside that gets the
    proper field info for each category.
    check out this:
    http://www.w3schools.com/sql/sql_join.asp

  • How to find if certain record exists from stored procedure

    Hello
    I am not an expert in this and am trying simple thing. I want to find if certain record exists in a table and if so set some boolean variable.
    create or replace procedure findit(param)
    AS
    return_group boolean;
    BEGIN
      myflag := false;
    --here goes my question
    -- say I have SELECT WHATEVER FROM TABLE WHERE BLA = param
    --if it returns at least one record set myflag to true;
    END;Any idea?

    THanks Satyaki_De,
    However, when I put simple SELECT statement in the body of my procedure it does not compile. Actually I should have said that before. So here is my code and where it breaks:
    create or replace procedure close_subjects(study_id varchar2)
    AS
    return_group boolean;
    BEGIN
    dbms_output.enable(1000000);
    FOR current_group IN(
       SELECT DISTINCT group_id from groups WHERE study_id=study_id
    ) LOOP
       FOR current_subject IN(
          SELECT individual_id from groups WHERE group_id=current_group.group_id AND study_id=study_id
       ) LOOP
          return_group := true;
          SELECT INDIVIDUAL_ID FROM ASSIGN WHERE DATE_TIME_ASSIGNED = ( SELECT MAX(DATE_TIME_ASSIGNED) FROM ASSIGN WHERE INDIVIDUAL_ID = current_subject.individual_id ) AND                            ASSIGN_STATUS_ID = 'A';
         IF SQL%RowCount = 0 THEN
           return_group := false;
             dbms_output.put_line(current_subject.individual_id);
          END IF;
       END LOOP;
    END LOOP;
    END;
    /If I comment out SELECT statement and leave dbms_output for testing purposes it works well. As I said I am faaaar from expert and seems to me that I cannot have SELECT in procedure BODY?

  • Performance to fetch result set from stored procedure.

    I read some of related threads, but couldn't find any good suggestions about the performance issue to fetch the result set from a stored procedure.
    Here is my case:
    I have a stored procedure which will return 2,030,000 rows. When I run the select part only in the dbartisan, it takes about 3 minutes, so I know it's not query problem. But when I call the stored procedure in DBArtisan in following way:
    declare cr SYS_REFCURSOR;
    firstname char(20);
    lastname char(20);
    street char(40);
    city char(20);
    STATE varchar2(2);
    begin DISPLAY_ADDRESS(cr);
    DBMS_OUTPUT.ENABLE(null);
    LOOP
    FETCH cr INTO firstname,lastname,street, city, state;
    EXIT WHEN cr%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE( firstname||','|| lastname||','|| street||',' ||city||',' ||STATE);
    END LOOP;
    CLOSE cr;
    end;
    It will take about 100 minutes. When I used DBI fetchrow_array in perl code, it took about same amount of time. However, same stored procedure in sybase without using cursor, and same perl code, it only takes 12 minutes to display all results. We assume oracle has better performance. So what could be the problem here?
    The perl code:
    my $dbh = DBI->connect($databaseserver, $dbuser, $dbpassword,
    { 'AutoCommit' => 0,'RaiseError' => 1, 'PrintError' => 0 })
    or die "couldn't connect to database: " . DBI->errstr;
    open OUTPUTFILE, ">$temp_output_path";
    my $rc;
    my $sql="BEGIN DISPLAY_ADDRESS(:rc); END;";
    my $sth = $dbh->prepare($sql) or die "Couldn't prepare statement: " . $dbh->errstr;
    $sth->bind_param_inout(':rc', \$rc, 0, { ora_type=> ORA_RSET });
    $sth->execute() or die "Couldn't execute statement: " . $sth->errstr;
    while($address_info=$rc->fetchrow_arrayref()){
    my ($firstname, $lastname, $street, $city, $STATE) = @$address_info;
    print OUTPUTFILE $firstname."|".$lastname."|".$street."|".$city."|".$STATE;
    $dbh->commit();
    $dbh->disconnect();
    close OUTPUTFILE;
    Thanks!
    rulin

    Thanks for you reply!
    1) The stored procedure has head
    CREATE OR REPLACE PROCEDURE X_OWNER.DISPLAY_ADDRESS
    cv_1 IN OUT SYS_REFCURSOR
    AS
    err_msg VARCHAR2(100);
    BEGIN
    --Adaptive Server has expanded all '*' elements in the following statement
    OPEN cv_1 FOR
    Select ...
    commit;
    EXCEPTION
    WHEN OTHERS THEN
    err_msg := SQLERRM;
    dbms_output.put_line (err_msg);
    ROLLBACK;
    END;
    If I only run select .. in DBArtisan, it display all 2030,000 rows in 3:44 minutes
    2) But when call stored procedure, it will take 80-100 minutes .
    3) The stored procedure is translated from sybase using migration tools, it's very simple, in sybase it just
    CREATE PROCEDURE X_OWNER.DISPLAY_ADDRESS
    AS
    BEGIN
    select ..
    The select part is exact same.
    4) The perl code is almost exact same, except the query sql:
    sybase verson: my $sql ="exec DISPLAY_ADDRESS";
    and no need bind the cursor parameter.
    This is batch job, we create a file with all information, and ftp to clients everynight.
    Thanks!
    Rulin

  • Getting result set from stored procedures in database controls in weblogic

    I am calling a stored procedure from database control which actually returns a result set
    when i call the stored procedure like
    * @jc:sql statement="call PROC4()"
    ResultSet sampleProc() throws SQLException;
    it gives me exception saying
    "weblogic.jws.control.ControlException: Method sampleProc is DML but does not return void or int"
    I would appreciate any help
    Thanks,
    Uma

    Thanks for you reply!
    1) The stored procedure has head
    CREATE OR REPLACE PROCEDURE X_OWNER.DISPLAY_ADDRESS
    cv_1 IN OUT SYS_REFCURSOR
    AS
    err_msg VARCHAR2(100);
    BEGIN
    --Adaptive Server has expanded all '*' elements in the following statement
    OPEN cv_1 FOR
    Select ...
    commit;
    EXCEPTION
    WHEN OTHERS THEN
    err_msg := SQLERRM;
    dbms_output.put_line (err_msg);
    ROLLBACK;
    END;
    If I only run select .. in DBArtisan, it display all 2030,000 rows in 3:44 minutes
    2) But when call stored procedure, it will take 80-100 minutes .
    3) The stored procedure is translated from sybase using migration tools, it's very simple, in sybase it just
    CREATE PROCEDURE X_OWNER.DISPLAY_ADDRESS
    AS
    BEGIN
    select ..
    The select part is exact same.
    4) The perl code is almost exact same, except the query sql:
    sybase verson: my $sql ="exec DISPLAY_ADDRESS";
    and no need bind the cursor parameter.
    This is batch job, we create a file with all information, and ftp to clients everynight.
    Thanks!
    Rulin

  • Multiple result sets from stored procedure into CachedRowSet

    How can you obtain multiple sets of data from a stored procedure that returns multiple result sets, when you'd like to use CachedRowSet rather than ResultSet?
    My database's stored procedures return multiple result sets, but I'm not sure how to manipulate that using CallableStatements and CachedRowSets... I read the RowSet tutorial from java.sun.com but that didn't cover the case of multiple result sets and CallablStatements.
    How might I do this? Thanks a lot.

    SELECT columns..
    FROM table
    FOR XML PATH('NodeName'),('Rootname')
    Thank you for replying.
    I dont have to generate XML from a query. I have to generate from a SP and that too without modifying it.
    Thanks,
    Tauhid
    thats ok you can do like this
    1. Create a table with structure same as SP resultset
    2. Populate table with SP result as per below
    INSERT table
    EXEC SPName param1value,...
    3. Add a query like below
    SELECT columns..
    FROM tablename
    FOR XML PATH('NodeName'),('RootName')
    see
    http://visakhm.blogspot.com/2014/05/t-sql-tips-fun-with-for-xml-path.html
    4. Use sp_send_dbmail to sent it through mail
    http://msdn.microsoft.com/en-IN/library/ms190307.aspx
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • User selection to return filtered record set

    Hi,
    I want to create a JSP which allows a user to enter search criteria for several columns of a table. I will use the entered values to set the sql where clause and produce the filtered record set. (eg the user enters a particular customer code and status code in order to see a list of orders placed by that customer which have the selected status code.)
    The problem I have is this: I want the input fields for the selection criteria to be combo boxes populated with values from the database.
    What is the best way to do this?

    Hi,
    I want to create a JSP which allows a user to enter search criteria for several columns of a table. I will use the entered values to set the sql where clause and produce the filtered record set. (eg the user enters a particular customer code and status code in order to see a list of orders placed by that customer which have the selected status code.)
    The problem I have is this: I want the input fields for the selection criteria to be combo boxes populated with values from the database.
    What is the best way to do this?

  • Return Collection or Set from interface methods?

    When designing abstract entities, like interfaces, abstract classes and utility classes, that hence shouldn't assume too much about neither implementation nor usage, I've been thinking a lot about whether it is better practice to use return types that are as (semantically) specific as possible, or as abstract as possible.
    Consider as an example a method in an interface that returns a set of units. It can be declared at two levels of abstraction - with Collection or Set as the return type.
    public Set getUnits();
    public Collection getUnits();
    The users of the interface instances do not have knowledge of the implementation. The implementations of the interface do not have knowledge of the users.
    That means, some implementations may be utilizing the non-duplicate property of the collection and implement it as a HashSet. Another implementation may also need special ordering and therefore implements it as a LinkedList.
    To specify Set in the interface forces the implementations - either to implement using Sets, or to incur a possibly very significant overhead by converting the internal representation to a Set for the method's return value.
    To specify Collection in the interface does not force anything on the implementations, and the contract that no duplicate elements occur can still be clearly specified (and obvious in the context). On the other hand, the users of the interface lose the Set semantics they might like to make use of, for instance O(1) random access is reasonable to expect from most Set implementations. But this isn't certain, so is it a strong argument?
    Any thoughts?

    Hi,
    I've had to make a similar decision recently, where I'm creating implementations of a generic time-series database, each of which consists of a number of measuring 'stations', which are returned via a method. My initial design of the database interface had the method:
    Set getStationSet();This seemed the most obvious solution, as there would certainly be no duplicate stations defined by a given database. However, I subsequently changed this to
    Collection getStations();for a number of reasons.
    Some databases return the stations in a specified order (the order in which the users of that database are most familar with). If the return type is a Set it forced the use of a TreeSet (assuming I don't write my own SortedSet implementation), which for some (large) databases imposes quite an overhead.
    Also, most database client code just iterates through the returned Set/Collection, sees whether a station meets a certain criteria, and uses it if so. Most code (in my example at least) simply does not need Set behaviour. Any code that does can simply use
    Set s = new HashSet( getStations() );which is hardly a major coding effort for clients using the interface.
    Subsequent coding indicates I've made the right choice. I would definitely say you should return a Collection and simply state in the associated documentation that the collection wont contain any duplicates and it can be put in a Set, or SortedSet, if required.
    In general, I also think it makes sense for interfaces to be as generic (or abstract) as possible.
    Ol.

  • Returning rowcount and resultset from stored procedure

    Hello,
    In SQL Server you can return multiple resultsets from stored procedure by simple SELECT statement. But in Oracle, you have to use SYS_REFCURSOR.
    Sample code:
    CREATE OR REPLACE PROCEDURE sp_resultset_test IS
    t_recordset OUT SYS_REFCURSOR
    BEGIN
    OPEN t_recordset FOR
    SELECT * FROM EMPLOYEE;
    END sp_resultset_test;
    Is there any other way in Oracle 10 or 11 ?
    Thank You.

    What is the requirement? Oracle is far more flexible than SQL-Server... with numerous features that do not exist in SQL-Server. (Fact)
    One of the biggest mistakes you can make is to treat Oracle like SQL-Server... trying to match feature A1 in SQL-Server to feature B3 in Oracle.
    Does not work that way.. rather then stick to SQL-Server as SQL-Server does SQL-Server specific features far better than Oracle.
    So instead of trying to map what a T-SQL stored proc to do to an Oracle ref cursor (even to the extent of using that very silly sp_ prefix to name the proc), tell us the problem and requirements... That way we can tell you what Oracle features and options are best used to solve that problem - instead of competing in some unknown feature comparison event with SQL-Server.

  • Return Values to Block from Insert Procedure

    I have a block with an insert operation performed by a procedure. The insert is working fine.
    However, I was assuming that within the procedure I could modify a value in the record (prior to the insert) and then that new value would be returned to the item in the form so the user can see it. (The procedure allocates a unique reference number from a sequence and I would like to display it back on the screen in the reference number field.)
    Can anyone help or suggest an alternative?
    Thanks
    Lisa Davies
    Durban, South Africa

    I have a block with an insert operation performed by
    a procedure. The insert is working fine.
    However, I was assuming that within the procedure I
    could modify a value in the record (prior to the
    insert) and then that new value would be returned to
    the item in the form so the user can see it. (The
    procedure allocates a unique reference number from a
    sequence and I would like to display it back on the
    screen in the reference number field.)It is really disappointing to me that Oracle cannot handle this simple need by specifying DML Return Value using built-in inserting/updating.
    I had to write a post-insert trigger in the forms to update the field in the data_block with the value generated by the DB-side pre-insert trigger.

  • Returning Oracle Output Parameters from Stored Procedures

    Hi,
    Please forgive my ignorance of Oracle and PL/SQL. I'm trying to get a value out of a stored proc which I've written. The proc takes a username input parameter and returns a user guid through an output parameter. I'm able to print the output parameter to the DBMS Output but can't figure out how to return the thing in a record when calling the proc through a normal sql prompt!
    My call is like so:
    DECLARE
    nGUID NVARCHAR2(255);
    BEGIN
    GETUSER(nGUID, 'WHY-DEV-QSYS-Tim Watson');
    DBMS_OUTPUT.PUT_LINE (nGUID);
    Would like to return the value here; what's the syntax?
    END;
    The signature of the proc is
    CREATE OR REPLACE PROCEDURE GETUSER
    USERGUID OUT NVARCHAR2,
    UNAME IN NVARCHAR2
    IS
    Can anyone assist?
    Thanks in advance!
    Tim

    The easiest way, in my opinion, is to not write a procedure, but a function for this porpose. You would not have to declare an out parameter, but a return value:
    CREATE OR REPLACE FUNCTION GETUSER
    UNAME IN NVARCHAR2
    return nvarchar2
    IS
    From SQL prompt, you can then do
    SQL> select getuser(<input_string>) from dual;
    and get the returnvalue.
    Best regards,
    Gerd

  • Using java beans to return a record set

    Hello,
    I fairly new to JSP and what I'm trying to do is use Beans to connect to a database and then display the result on the JSP page. Can someone please post an example of how I would do this from a JSP page. I already have my JDBC code set up.
    Thanks

    Thanks for the feedback M
    I have added the JSTL 1.1 library and used the Foreach components and data source components which now totally eliminate the need for beans altogether. :P
    <c:forEach var="row" items="${deejays.rows}">
    <tr onmouseover="this.bgColor='gold';"
    onmouseout="this.bgColor='#FFFFFF';">
    <c:forEach var="column" items="${row}">
    <td>
    <c:out value="${column.value}"/>
    </td>
    </c:forEach>
    <td width="24%" align="center">
    <input type="image" src="7af5.jpg" name="test" value="test"/>
    </td>
    <td width="15%">
    <input type="radio" name="book1"/>
    </td>
    </tr>
    </c:forEach>
    </table><p align="left">
    How and where do i add the beans in here now???

  • Return a Result set from a cursor

    Is it necessary to create a temporary table to show the rows I want? there is another way?
    Ex.:
    DECLARE
    CURSOR c1 is
    SELECT ename, empno, sal FROM emp
    ORDER BY sal DESC;
    my_ename VARCHAR2(10);
    my_empno NUMBER(4);
    my_sal NUMBER(7,2);
    BEGIN
    OPEN c1;
    FOR i IN 1..5 LOOP
    FETCH c1 INTO my_ename, my_empno, my_sal;
    EXIT WHEN c1%NOTFOUND;
    INSERT INTO temp VALUES (my_sal, my_empno, my_ename);
    COMMIT;
    END LOOP;
    CLOSE c1;
    END;
    SELECT * FROM temp ORDER BY col1 DESC;

    No cursor or temp table needed. Note the difference between dense_rank() and rank().
    sql>select *
      2    from (select ename, empno, sal, dense_rank() over (order by sal desc) rank
      3            from emp)
      4   where rank <= 5;
    ENAME          EMPNO       SAL      RANK
    KING            7839      5000         1
    SCOTT           7788      3000         2
    FORD            7902      3000         2
    JONES           7566      2975         3
    BLAKE           7698      2850         4
    CLARK           7782      2450         5
    6 rows selected.
    sql>select *
      2    from (select ename, empno, sal, rank() over (order by sal desc) rank
      3            from emp)
      4   where rank <= 5;
    ENAME          EMPNO       SAL      RANK
    KING            7839      5000         1
    SCOTT           7788      3000         2
    FORD            7902      3000         2
    JONES           7566      2975         4
    BLAKE           7698      2850         5
    5 rows selected.
    -- and the non-analytic function approach
    sql>select *
      2    from (select ename, empno, sal
      3            from emp
      4           order by sal desc)
      5   where rownum <= 5;
    ENAME          EMPNO       SAL
    KING            7839      5000
    SCOTT           7788      3000
    FORD            7902      3000
    JONES           7566      2975
    BLAKE           7698      2850
    5 rows selected.

  • Record set

    Hi
    I come from VB background and very new to java.
    Is it possible to return a record set from call method like in VB?
    AP

    Yes.

  • Ora-06550 returning data from Stored Procedure and Entity Data Model

    Hi.
    I'm creating an application that uses a WCF Service to return data. I also created a proyect with the EDMX design and mapped most of my DBModel to a classes context. I have added some of the procedures as well. One of them receive some parameters and return a Sys_RefCursor, that is populated according to the parameters.
    I have declared the "<add >" tags in the Web.Config and imported the function of the Procedure. When I call the Asyncronous function I get different exceptions:
    1. If I call the function, with all of the parameters i get:
    Oracle.DataAccess.Client.OracleException: ORA-06550: línea 1, columna 8:
    PLS-00306: número o tipos de argumentos erróneos al llamar a
    'SP_HECHOSJURITER'
    ORA-06550: línea 1, columna 8:
    (wrong number or types of arguments in call to 'SP_HECHOSJURITER')
    2. If i just set 1 parameter in the SP, returning the same type of data, I get:
    Error al recibir la respuesta HTTP a
    http://localhost/Procalculo.CGFM.SIGOC.DatosServices/ServiceDatos.svc.
    (failed to receive http response. error 12152)
    3. If I don't set any parameters in the procedure, it works fine, and return correct data.
    It exclusively happen with one entity.
    Any clue?
    I appreciate any help.

    When you return result sets from stored procedures to Entity Framework, you are very likely using implicit result sets. Implicit result sets don't need to be declared as a parameter in code, only in the <add> tags to define the metadata in the .NET config file.
    For example, in the EF Oracle By Example, you'll see that the stored procedure in the function import has three parameters, but only two are declared in the code. The third one was defined in the config file.
    http://download.oracle.com/oll/obe/EntityFrameworkOBE/EntityFrameworkOBE.htm

Maybe you are looking for

  • Auto completion of Sales order item after upto 90% delivery

    Hello, Business Requirement: After 90% quantity of an order quantity is delivered, the item should not be considered by MPS planning run and the item should not appear in MD04. Current workaround: Currently, for that item we are setting Partial Deliv

  • Change settings for auto start when logging on?

    How can I change the settings so that when I turn my Macbook Air on it doesent auto open iTunes, Email, ooVoo, and facebook?

  • How to enable a user to change his own password at EP7?

    I want to give the EP7 users the ability to change their own password at EP. Can we do that thru any role assignment or some development is needed? Any detailed help would be appreciated . I'll give points. Thanks!

  • MySQL Date Question

    I have two DATETIME columns in a table. Is it possible to get the difference between the two dates and then format the output as H:M P? I've been trying to get this to work for a while... but now I'm not even sure it's possible.

  • How to place a degree symbol in a JLabel

    I'm trying to place a degree symbol in a JLabel with the following code JLabel label = new JLabel ("<html>&#186</html>");but all I'm getting is the literal, not the degree symbol.