Oracle Procedure returning more number of records

Hi,
I have created an Oracle Procedure which is supposed to fetch a record as per the input parameter passed.
The core query in the procedure is as below -
SELECT DISTINCT col1 FROM my_tab WHERE col2 = 'Input parameter'
Few of the input parms (col2) has more number of records (col1) and so the procedure gives an error like -
'ORA-01422: exact fetch returns more than requested number of rows'
Could you please let me know how can I modify the procedure so that it would return more number of records as the case may be?
Thank you!

It still gives me the same error when it encounters more than one output.Yes, I'm sure it does.
But we can't tell you how to fix it because we don't know what you want.
What's the purpose of the procedure?
Is it to "spell check" the name of an intermediary? If so, you'll need to figure out what to do when you have more then one person with the same name.
You can add AND ROWNUM = 1. Or perhaps you can trap the too_many_rows exception.
Your procedure doesn't return anything (no out variables). Is that correct?
Or is the purpose of the procedure to return the ID of the matching name?

Similar Messages

  • How to return more than one record through OUT parameter in procedure

    Hi,
    I want to create a procedure which accepts one input and returns more than one record as output.
    example:
    Input = DeptNo
    Output= Empno,ename,sal,comm,job
    Scenario:
    There can be more than one employee in department we pass as the IN parameter. OUT parameter has to return all the records of the corresponding employee details in that department.
    Thanks in advance for your help
    Regards,
    K.Vijay

    -- I think you can try something like this using ref cursor:
    -- create a package for the type ref cursor and execute
    CREATE OR REPLACE PACKAGE PACK_REFCURSOR_FOR_TABLES AS
         TYPE DATA_TableRows IS REF CURSOR;
    END;
    -- after executing the package above, create your procedure:
    CREATE OR REPLACE PROCEDURE GET_EMP (
         IN_nDeptNo IN number,
         OUT_Emp OUT PACK_REFCURSOR_FOR_TABLES.DATA_TableRows)
    IS
    BEGIN
    -- leave query open (implicit) as this will return data
         OPEN OUT_Emp FOR
         SELECT *
         FROM tblEmp
         WHERE DeptNo = IN_nDeptNo;
    END;
    --execute the procedure and you're done                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • 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

  • Which system field returns the number of records returned after a select?

    Which system field returns the number of records returned after a select?
    a) sy-index
    b) sy-recno
    c) sy-lncnt
    d) sy-dbcnt
    e) sy-tabix

    Hi,
       SY-DBCNT
    Regards,
    Prashant

  • Extracting more number of records than present number in Infoprovider

    Hi Frnds,
    i have one doubt about data extraction.
    here in my scenario i have one DSO & Infocube in modeling .
    Source DSO for Data extraction :
    DSO is having 10 fields in design .
    2 are Key fields
    8 are Data fields
    & we have enabled some navigation attributes of those key fields in DSO.
    target Infocube for data loading :
    4 keyfigure & rest all are characteristics designed in Dimension properly
    DSO --> Cube loading :
    Source DSO is having 10 records when i triggered loading it is extracting more that 10 records .
    when i check the records in Debugging it is showing more that 10 records because of DSO keyfields & navigation attribute combination .
    it is forming more number records than original 10 records.
    i don't know whether is it right or wrong ?
    example here i am giving:
    if we assume source DSO is having only one record but it is extracting 4 records with the same key.
    0MATERIAL   0PLANT   KEYFIGURE1   KEYFIGURE2
    100                4000       10                     20
    In extraction it is showing as below
    0MATERIAL   0PLANT   0MATERIAL_NAVIGATIONATTRIBUE  KEYFIGURE1  KEYFIGURE2
    100                4000        XXXX                                                     10                    20
    100                4000        YYYY                                                     10                    20
    100                4000        ZZZZ                                                     10                    20
    100                4000        ZYZY                                                     10                    20
    my question is why it is extracing 4 records ? ( why it is taking navigation attribute values in extraction .
    BR
    Ravinder

    Hello,
    Check OSS Note 1145673
    Steps to be performed:
    1. Apply the OSS note in the dev system
    2. OSS note might de-activate the transformation and DTP.
    3. Note down the transformation and DTP which gets de-activated because of this OSS note.
    4. Also send out a mail to BW community saying you are gonna apply this OSS note and ask them to check thier objects whether it is getting impacted by this oss note or not.
    5. Ask everyone to check the data load and the data is getting populated or not.
    6. Apply OSS note in QA and production. Also before applying the OSS in QA and production collect the objects which are getting impacted by this note in dev.
    7. After applying the oss note in QA, send the collected Transforamtions and DTPs to the QA and do a test in QA as well.
    8. Finally apply the oss note in production and transport the impacted transformations and DTP in production.
    Regards,
    Shashank

  • Issue with IN parameter of Oracle Procedure returning two RefCursors...

    Hi all,
    I'm having a nightmare with an Oracle procedure that takes one input parameter and returns two RefCursors as outputs. I recently got help in this forum getting a procedure to work that took no inputs but returned two refcursors and that's still working fine. So, for my current issue I have a procedure defined as follows:
    PROCEDURE getQueueInfo(domainKey char, importQueues OUT ODPNet.refcur, exportQueues OUT ODPNet.refcur) IS
      BEGIN
        OPEN importQueues FOR SELECT
        source_key, source_applid,
        import_status(source_key) as status,
        time_added, time_processed
        FROM wm_import_source_header
        WHERE source_id = domainKey
        ORDER BY source_key DESC;
        OPEN exportQueues FOR SELECT
        h.source_key, d.source_applid,
        export_status(h.source_key) as status,
        d.source_wire_code, d.destination_wire_code, h.time_added,
        h.time_transmitted
        FROM wm_export_source_header h, wm_export_source_data d
        WHERE h.source_key = d.source_key
          and d.source_id = domainKey
        ORDER BY h.source_key DESC;
      END getQueueInfo;This is defined within a package called ODPNet as with my previous procedure and all works fine (I can execute within Oracle SQL Developer and it returns the expected results). Within my .NET application my code is as follows:
                try
                    using (OracleConnection conn = new OracleConnection(connString))
                    using (OracleCommand comm = new OracleCommand())
                        comm.CommandText = "ODPNet.getQueueInfo";
                        comm.CommandType = CommandType.StoredProcedure;
                        comm.Connection = conn;
                        OracleParameter domainKey = new OracleParameter();
                        OracleParameter importQueues = new OracleParameter();
                        OracleParameter exportQueues = new OracleParameter();
                        domainKey.OracleDbType = OracleDbType.Char;
                        importQueues.OracleDbType = OracleDbType.RefCursor;
                        exportQueues.OracleDbType = OracleDbType.RefCursor;
                        domainKey.Value = "UKBD72";
                        domainKey.Direction = ParameterDirection.Input;
                        importQueues.Direction = ParameterDirection.Output;
                        exportQueues.Direction = ParameterDirection.Output;
                        comm.Parameters.Add(domainKey);
                        comm.Parameters.Add(importQueues);
                        comm.Parameters.Add(exportQueues);
                        conn.Open();
                        comm.ExecuteNonQuery();
                        OracleDataReader dr1 = ((OracleRefCursor)importQueues.Value).GetDataReader();
                        OracleDataReader dr2 = ((OracleRefCursor)exportQueues.Value).GetDataReader();
                        if (dr1.HasRows)
                            while (dr1.Read())
                                result6 += dr1["source_applid"].ToString() + "<br>";
                        else
                            result6 += "No Rows";
                        if (dr2.HasRows)
                            while (dr2.Read())
                                result7 += dr2["source_applid"].ToString() + "<br>";
                        else
                            result7 += "No Rows";
                catch (Exception ex)
                    result6 = ex.ToString();
                }The value I want to submit as the IN parameter of the procedure is "UKBD72". but I'm really not sure how to apply this and then return my two refcursors into separate datareaders (except for the input parameter stuff the code above is exactly what I did with the other procedure that returned two ref cursors and still works fine). When I run this code I get no errors, I just get told that each DataReader has no rows returned, which shouldn't be right.
    Any help with this would be hugely appreciated.
    Cheers,
    Seb

    Sorry folks, after staring at this over and over, eventually going to sleep and coming back to it with some fresh eyes I realised I was just being a complete idiot - I was feeding the procedure different data in the .NET app than I was when testing in Oracle SQL Developer. Low and behold once I gave it the right data it worked!
    Silly me...

  • Returning the number of records retrieved by a query

    Hi everyone,
    I did a search on this question, but I'm still unclear as to why it's so difficult to retrieve the number of records returned by a query.
    What is the easiest and most straight-foward way ?
    Thanks,
    Bob

    Shay
    I am confused. I still do not know how to achieve the count of records retrieved in a block. I have viewed the viewlet calculated field demo. I am unclear of what you were refering to when you said use the count as the function.
    I did try setting function to be "get_block_property('myblock',query_hits)", but this always had value of zero. But I do not think this is what you meant.
    Has anybody been able to answer the original question?

  • Create Store Procedure to Count Number of records in Database for each table

    Hello,
    I have created the code which counts the number of records for each table in database. However, I want create store procedure for this code this code that when ever use execute the Store Procedure can provide the database name to execute it and as a result
    table will display number of records in each table.
    Below you will find the code its working:
    CREATE
    TABLE #TEMPCOUNT
    (TABLENAME
    NVARCHAR(128),
    RECORD_COUNT BIGINT)
    -- Creating a TEMP table
    EXEC
    sp_msforeachtable
    'insert #tempcount select ''?'', count(*) from ? with (nolock)'
    SELECT
    * FROM
    #TEMPCOUNT
    ORDER
    BY TABLENAME
    DROP
    TABLE #TEMPCOUNT
    This code need to be convert in store procedure and user can give database name when execute the procedure in order to count the records.
    Looking forward for your support.
    Thanks.
    SharePoint_Consultant_EMEA

    Something like:
    set quoted_identifier off
    go
    create procedure usp_TableCounts
    @DBName as varchar(1000)
    as
    set nocount on
    declare @SQLToExecute varchar(1000)
    CREATE TABLE #TEMPCOUNT (TABLENAME NVARCHAR(128), RECORD_COUNT BIGINT) -- Creating a TEMP table
    set @SQLToExecute = @DBName + ".dbo.sp_msforeachtable 'insert into #tempcount select ''?'', count(*) from ? with (nolock)'"
    print @SQLToExecute
    exec (@SQLToExecute)
    SELECT * FROM #TEMPCOUNT
    ORDER BY TABLENAME
    DROP TABLE #TEMPCOUNT
    GO
    Satish Kartan www.sqlfood.com

  • ABAP query not returning correct number of records

    Hi,
    I have created an ABAP Query using logical database VFV and nodes VBRK, VBUK and VBRP.
    But, after entering values for Sales Organisation ( VBRK-VKORG ), Distribution channel ( VBRK-VTWEG ) and Date ( VBRK-FKDAT), the number of records that I get are very less in number as compared to the actual number in the database.
    Please give some pointers to the reason. I have set Lines 60 and Columns length - 83 and selected ALV List.
    Regards,
    Garima.

    Hi Garima,
    Please Check whether you are selecting all the Key fields in your Query.
    Thanks & Regards,
    Ashok kumar.

  • Query not returning correct number of records

    Hi Guys,
    Can someone please tell me why this query is not retrieving the correct number of records.
    I have a table with six users
    FIRST_NAME          LAST_NAME
    David               Robert
    Martin               Fisher
    Henry               Robert King
    Edmund               Tomkinson
    Williams          Hayes Robert
    Tina               Belkins
    When I run a query, SELECT * FROM USERS WHERE LAST_NAME LIKE 'Robert';
    I only get 1 record back (David Robert). Is the space between the last name
    causing this? If yes, How can I rewite the query?

    show a copy-paste example of your query...
    you need to use a wild card with LIKE, as in
    SQL> create table test
      2  (first_name varchar2(50)
      3  ,last_name varchar2(50)
      4  );
    Table created.
    SQL>
    SQL> insert into test values ('David' , 'Robert'           );
    1 row created.
    SQL> insert into test values ('Martin', 'Fisher'           );
    1 row created.
    SQL> insert into test values ('Henry' , 'Robert King'      );
    1 row created.
    SQL> insert into test values ('Edmund', 'Tomkinson'        );
    1 row created.
    SQL> insert into test values ('Williams',  'Hayes Robert');
    1 row created.
    SQL> insert into test values ('Tina',  'Belkins');
    1 row created.
    SQL>
    SQL> SELECT * FROM test WHERE LAST_NAME LIKE 'Robert';
    FIRST_NAME
    LAST_NAME
    David
    Robert
    SQL>
    SQL> SELECT * FROM test WHERE LAST_NAME LIKE '%Robert%';
    FIRST_NAME
    LAST_NAME
    David
    Robert
    Henry
    Robert King
    Williams
    Hayes Robert

  • Procedure inserting different number of records in GT table

    I have procedure, in the procedure a dynamic query is get created. Then query is open using OPEN for statement into refcusror. Then I'm fetching the data into record type object within a loop..end loop and inserting the records in a GT table.
    But problem is for the same data procedure is inserting less records, when i recomplie the procedure it began to insert correct number of data.
    I wonder whether is environment issue or something else? Please advise if any one faced such type problem.

    Hi upennit. Not much info to go on there.
    Have a read of Re: 2. How do I ask a question on the forums?
    then post back with some relevant info.

  • FOR ALL ENTRIES not returning correct number of records

    Hi,
    I have the following code: -
      SELECT vbelv                                     "Delivery
             posnv                                     "Delivery Item
             rfmng                                     "GR Qty
             plmin                                     "Sign
             INTO TABLE t_gr
             FROM vbfa
             FOR ALL ENTRIES IN t_deliveries
             WHERE vbelv   EQ t_deliveries-vbeln
               AND posnv   EQ t_deliveries-posnr
               AND vbtyp_n EQ c_goods_receipt.
    The internal table t_deliveries has a single entry. The table VBFA has 5 records for the delivery/item.
    When the SQL is executed it returns 4 records. If I amend the code to use the following it returns the 5 records. Has anybody had a similar issue.
      LOOP AT t_deliveries INTO st_deliveries.
        SELECT vbelv                                     "Delivery
               posnv                                     "Delivery Item
               rfmng                                     "GR Qty
               plmin                                     "Sign
               APPENDING TABLE t_gr
               FROM vbfa
               WHERE vbelv   EQ st_deliveries-vbeln
                 AND posnv   EQ st_deliveries-posnr
                 AND vbtyp_n EQ c_goods_receipt.
      ENDLOOP.

    FOR ALL Entries can fatch only the unique rows from the table. So, check in the VBFA for the your inputs and the output fields, you will have only 4 unique records. That's why it is picking up only 4 records.
    Try to include one more fields which makes every row as a unique row.
    Regards,
    Naimesh Patel

  • Oracle  procedures returning table type supported in JDBC

    We have many procedures who return table type return. The JDBC callable statment does not support them.However there is no problem with Ref cursors . How to resolve?.

    Please try searching the JDBC discussion forum or try reposting the question in the JDBC forum. The url is:
    http://forums.oracle.com/forums/forum.jsp?forum=99

  • Query return wrong number of records

    In a function, I use a variable declare as my_var table_name1.column_name%type.
    This variable is used to to a test on a foreign key when I do a query on another table than table_name1 the number of rows return by the query is different than the number of rows return if I do the test directly with the value accorded.
    Ex:
    declare
    my_var table_name1.column_name%type;
    row_num number;
    begin
    my_var := 10;
    select count(1) into row_num
    from table_name2
    where column_name = my_var;
    dbms_output.put_line(row_num);
    select count(1) into row_num
    from table_name2
    where column_name = 10;
    dbms_output.put_line(row_num);
    end;
    the first query will return 2 and the second will return 1.
    Can someone explain me why I have this strange result ?
    Edited by: 897304 on Nov 15, 2011 5:12 AM
    Edited by: 897304 on Nov 15, 2011 5:32 AM

    I cannot put the description of the table :-/
    The type of the field is varchar2(12)
    This is the function the value past to param1 came from oracle 11 and the table tab1 is in oracle10.
    The first query work and return 1 (result expected) and the second return 2.
    FUNCTION getValue(param1 VARCHAR2) RETURN number AS
         var1 VARCHAR2(12 BYTE);
         res1 number;
    BEGIN
    var1 := param1;
    SELECT count(1)
    INTO res1
    FROM tab1
    WHERE col2 = var1;
    SELECT count(1)
    INTO res1
    FROM tab1
    WHERE col2 = param1;     
    RETURN res1;
    END getValue;

  • BAPI returns less number of records when called from WebDynpro

    Hi,
    We have a BAPI which updates some tables and then bring back output in the form of a table.
    When we execute BAPI from R/3 we get all records. When we execute the BAPI using webdynpro, for the same input values, we are always getting 22 records. This count remains same always. 
    When we had put a breakpoint in the BAPI and tested it using webdynpro, we get few more records. Wondering what is the prob?
    Any help?
    regards,
    Shabeer

    Hi,
    Are you using the same user when running the BAPI form R/3 and from the portal?
    We had a similar problem when the user from the portal didn't have the necessary authorizations.
    Adi.

Maybe you are looking for

  • Why can't I install the 10.5.8 Leopard Combo Update??

    I've had the Leopoard 10.5.8 combo update on my computer for a while now, but I haven't been able to install it successfully after at least 5 attempts. Usually, when I restart my computer to install it, the installation remains stuck in "configuring

  • IMAP server times out, Why?

    For 6 days now I have been having a problem acesssing my sites and email accounts. Finally the hosting company has found that it is the number of email accounts (49) trying to access the IMAP mail server at the same time? I have disable automatic "ch

  • I am trying to upgrade from OS X 10.5.8 to latest version- any recommendations?

    Hello, I am trying to upgrade my iMAC to latest OS and keep running into issues. First issue is that I need to be on a later version in order to upgrade and not sure how to do that. Any suggestions would be appreciated. TIA

  • Creating JVM to Make JNI calls

    I am trying to create a JVM to make JNI calls to Java. When I try to link my C++ program with jvm.lib, I am getting following error. Please advise. "fatal error LNK1106: invalid file or disk full" I am sure the disk is not full.

  • SW_MATM-4-MACFLAP_NOTIF due to wifi devices

    we see sometimes on a 3750switch SW_MATM-4-MACFLAP_NOTIF: Host 000b.xxxx.xxxx in vlan 5 is flapping between port Gi2/0/42 and port Po7 looking up the MAC we found wifi devices like a pc and handscanner which move to the building thereby changing from