Return Set Amount Of Rows

Hello All,
Quick question I hope... How do I request a set amount of terms and have the Oracle Agent stop, once the amount of rows has been reached.
I am not looking for (example):
select * from
(SELECT rownum ROW_NUM, empID, empName FROM employees)
where empName like '%SM%'
AND
ROW_NUM <= 10
This works in most cases, but Oracle is still evaluating all results, and only returning rows where the ROW_NUM meets the criteria. If I have a million rows with matching empName , and only want to return 10 results it still evaluates all million rows. and break the query, this does not work...

Statement 1 is faster - rownum criteria is used along with the last_name
Statement 2 is slower - rownum criteria is used after all the last names are fetched.
--#1
SQL> select first_name, last_name from emp2 where last_name like 'W%' and rownum < 10 ;
FIRST_NAME           LAST_NAME
Alana                Walsh
Alana                Walsh
Alana                Walsh
Alana                Walsh
Alana                Walsh
Alana                Walsh
Alana                Walsh
Alana                Walsh
Alana                Walsh
9 rows selected.
Execution Plan
Plan hash value: 3151743630
| Id  | Operation                    | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT             |       |    "9"|   234 |    13   (0)| 00:00:01 |
|*  1 |  COUNT STOPKEY               |       |       |       |            |          |
|   2 |   TABLE ACCESS BY INDEX ROWID| EMP2  |  5145 |   130K|    13   (0)| 00:00:01 |
|*  3 |    INDEX RANGE SCAN          | EMP2X |       |       |     3   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   1 - filter(ROWNUM<10)
   3 - access("LAST_NAME" LIKE 'W%')
       filter("LAST_NAME" LIKE 'W%')
Note
   - dynamic sampling used for this statement
Statistics
         15  recursive calls
          0  db block gets
        157  consistent gets
          8  physical reads
          0  redo size
        552  bytes sent via SQL*Net to client
        380  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          9  rows processed
--#2
SQL> select * from ( select first_name, last_name, rownum rn from emp2 where last_name like 'W%'  ) where  rn< 10 ;
FIRST_NAME           LAST_NAME                         RN
Matthew              Weiss                              1
Alana                Walsh                              2
Jennifer             Whalen                             3
Matthew              Weiss                              4
Alana                Walsh                              5
Jennifer             Whalen                             6
Matthew              Weiss                              7
Alana                Walsh                              8
Jennifer             Whalen                             9
9 rows selected.
Execution Plan
Plan hash value: 2594185790
| Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT    |      | "5145"|   195K|   619   (3)| 00:00:08 |
|*  1 |  VIEW               |      |  5145 |   195K|   619   (3)| 00:00:08 |
|   2 |   COUNT             |      |       |       |            |          |
|*  3 |    TABLE ACCESS FULL| EMP2 |  5145 |   130K|   619   (3)| 00:00:08 |
Predicate Information (identified by operation id):
   1 - filter("RN"<10)
   3 - filter("LAST_NAME" LIKE 'W%')
Note
   - dynamic sampling used for this statement
Statistics
         13  recursive calls
          0  db block gets
       2371  consistent gets
          0  physical reads
          0  redo size
        745  bytes sent via SQL*Net to client
        380  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          9  rows processed

Similar Messages

  • JTextArea - set specific amount of rows, or characters...

    I'm working on a Applet which handles text according to given parameters. One of these parameters sets a JTextArea to the horizontal size of, lets say: 5 rows. What i want is that once this TextArea is set to a specific number of rows no text beyond those rows can be inserted. 5 rows, or a specific amount of characters are allowed.
    My problem is that the TextArea wont stop allowing text vertically. The TextArea is visibly set to 5 rows, which doesnt change. But how can i stop text from being inserted beyond row 5?
    We have tried a number of different approaches, from trying to set TextArea's size with invisible scrollbars to overriding invalidate()...

    I never understand why people want to limit the number of rows in a JTextArea. Add the text area to a scroll pane and scroll bars will appear when the number of rows exceed the display area. The point of using a text area is to allow the user to enter data in a flexible format. If the format is not flexible then maybe you should be using another component or combination of combination of components.
    Setting a maximum character size is valid if you intend to store the data on a database with a fixed size field. It is easy to do this by using a custom Document with you JTextArea. Read this section from the Swing tutorial on "General Rules for Using Text Components" for example code on how to do this:
    http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html
    Note, if you really want to limit the text area to 5 lines then count the number of new line characters in the document and don't allow them to enter more than 4.

  • How can you set the max row for a 'open cursor' in a stored proc?

    I would like to know how can you set the maximum amount of row returned in a resultset coming from a stored proc?
    You can do it via JDBC with cStatement.setMaxRows(10); but it works only for select that you do via JDBC...
    I would like the same functionality using open cursor inside a stored proc...
    Thanks...

    is "where ROWNUM <= 10" the equivalent of "cStatement.setMaxRows(10);" because the ROWNUM as problem with the ORDER BY clause and the setMaxRows() as no problem...

  • How to set number of rows in filters?

    Hi, we need to set another number of rows which is displayed in filters on bex or web template?
    Thanks for advice

    Hi Pavel,
    can you please specify your question more clearly. If you are on NW 7.0 you can determine a number of colums for your filter item with following command:
    COLUMNS
    http://help.sap.com/saphelp_nw70ehp1/helpdata/en/85/08e241aa8e9d39e10000000a155106/content.htm
    If you meant the amount of rows within the analysis item you can use following command within your analysis item:
    BLOCK_ROWS_SIZE   (numbers of rows displayed at once)
    BLOCK_ROWS_STEP_SIZE  (numbers of rows to be scrolled for one step)
    http://help.sap.com/saphelp_nw70ehp1/helpdata/en/76/489d39d342de00e10000000a11402f/content.htm
    Brgds,
    Marcel
    Edited by: Marcel Landsfried on Feb 10, 2009 7:45 PM
    Edited due to wrong url

  • How to set number of rows in "Rows Per Page Selector" in Interactive Report

    Hi Guys,
    Is there any way to set the number of rows in "Rows Per Page Selector" in Interactive Report. By default it is set to 15.
    I know one way is to change the number of rows when you are running the report and then set that as 'Default Report Setting'.
    If anybody is aware of any other way, please let me know.
    Cheers,
    Ashish Agarwal
    http://www.dbcon.com.sg

    Hi Pavel,
    can you please specify your question more clearly. If you are on NW 7.0 you can determine a number of colums for your filter item with following command:
    COLUMNS
    http://help.sap.com/saphelp_nw70ehp1/helpdata/en/85/08e241aa8e9d39e10000000a155106/content.htm
    If you meant the amount of rows within the analysis item you can use following command within your analysis item:
    BLOCK_ROWS_SIZE   (numbers of rows displayed at once)
    BLOCK_ROWS_STEP_SIZE  (numbers of rows to be scrolled for one step)
    http://help.sap.com/saphelp_nw70ehp1/helpdata/en/76/489d39d342de00e10000000a11402f/content.htm
    Brgds,
    Marcel
    Edited by: Marcel Landsfried on Feb 10, 2009 7:45 PM
    Edited due to wrong url

  • Rounding Tax amount in row

    Hi Experts,
    One of our customer wants to round the tax amount in each row of marketing documents.
    When searched the help of 'Document Settings:General Tab",  we found a setting field for this called 'Round tax amount in rows'.
    But the same is missing from the Document Settings window, General Tab.
    We are using SAP Business One 2007B, PL13
    Please Help.
    Thanks and Regards
    Ajith G

    Hi Ajith,
    Tax Definition Functions.
    Choose ->> Administration.
    -> Setup.
    -> Financials.
    -> Tax.
    -> Tax engine config.
    Tax Code Determination.
    ->> Tax Formula.
    Select your Formula which you want to ROUND OFF
    then pull down from Operation Round and kip your variable.
    Simple example,
    Service_BaseAmt=Total
    Service_TaxAmt=Round(Service_BaseAmt*Service_Rate,0)
    It will round off 0.5 to 1.0 and less than 0.5 to 0.0.............
    IF you want to Round off final Tax amount(ex. VAT_TaxAmt).
    see the example Tax Creation,
    Service_BaseAmt=Total
    Service_TaxAmt=Service_BaseAmt*Service_Rate
    HigheCess_ST_BaseAmt=Service_TaxAmt
    HigheCess_ST_TaxAmt=HigheCess_ST_BaseAmt*HigheCess_ST_Rate
    VAT_BaseAmt=Total(Total*Service_Rate)((TotalService_Rate))Cess_ST_Rate+((TotalService_Rate)HigheCess_ST_Rate)
    [VAT_TaxAmt= Round(VAT_BaseAmt*VAT_Rate,0)]
    Regards,
    Madhan.

  • Update column with subquery returning more than one row

    Hi Everybody,
    Please let me know how to handle this. I am writing update statement in procedure with subquery and it is returning multiple rows. Please help me, how i can handle this :
    UPDATE TABLEA A
    SET A.ERROR_MESSAGE = (Select B.XERROR_MESSAGE from TABLEB B, TABLEA A WHERE B.id = A.id)
    WHERE A.id = (Select B.id from TABLEB B, TABLEA A WHERE B.id = A.id);
    (Select B.XERROR_MESSAGE from TABLEB B, TABLEA A WHERE B.id = A.id) --- This subquery is returning more than one rows. How i can handle this in Pl/SQL?
    Please let me know. I will be very thankful to you all.
    I will really appreciate your replies and comments.
    Thank you

    Try getting rid of tablea in your subqueries. You already have it in the UPDATE statement.
    UPDATE TABLEA A
    SET    A.ERROR_MESSAGE = (Select B.XERROR_MESSAGE
                              from   TABLEB B
                              WHERE  B.id = A.id
    WHERE  A.id = (Select B.id
                   from   TABLEB B
                   WHERE  B.id = A.id);You can also try a simple MERGE:
    merge into tablea a
    using tableb b
    on    (a.id = b.id)
    when  matched then update
          set a.error_message = b.xerror_message;

  • Need to set the Vissible row count Dynamically

    Hi,
       I have requirement where i am supposed to set the Vissible row count for a table dynmaically, depending upon the number of rows in a table.

    Or use a calculated attribute.
    Create an attribute in the context called calcVisibleRowCount of type integer and make it read only and calculated. Then bind that attribute to the visibleRowCount attribute of your table.
    The method for the attribute looks something like this:
    (this displays 10 rows per page if more than 10 records in the node, otherwise it displays the same number of rows in the table as in the context)
      public int getCalcVisibleRowCount(IPrivateStartsida.ILayoutElement element)
        //@@begin getCalcVisibleRowCount(IPrivateStartsida.ILayoutElement)
              if (wdContext.nodeXXXX().size() > 10) {
                   return 10;
              } else {
                   return wdContext.nodeXXXX().size();
        //@@end
    Note that this attribute is not created in the node that you want to count number of elements in.
    Edited by: Richard Linnander on Apr 1, 2011 3:41 PM

  • Select a set of random rows

    I don't understand how the sample clause works on the select statement. Eg. SELECT * FROM clients SAMPLE(50) should return half of all rows in the table, but it's unstable. Sometimes it returns 4, sometimes 3 and even 2 (SELECT COUNT(*) FROM clients returns 6). Why???
    So, if it's really unstable, how do I select a random number of rows from a query? Is there other way?

    As noted, the number of rows returned by SAMPLE can vary. The approach I use is to set the sample number high enough so that the minimum number of rows it returns is always higher than what you want, and then chop off the excess with a rownum filter:
    sql>select empno, ename, job
      2    from emp sample (50)
      3   where rownum <= 3;
        EMPNO ENAME      JOB
         7499 ALLEN      SALESMAN
         7654 MARTIN     SALESMAN
         7839 KING       PRESIDENT
    3 rows selected.
    sql>/
        EMPNO ENAME      JOB
         7566 JONES      MANAGER
         7698 BLAKE      MANAGER
         7782 CLARK      MANAGER
    3 rows selected.
    sql>/
        EMPNO ENAME      JOB
         7499 ALLEN      SALESMAN
         7566 JONES      MANAGER
         7782 CLARK      MANAGER
    3 rows selected.
    sql>/
        EMPNO ENAME      JOB
         7369 SMITH      CLERK
         7521 WARD       SALESMAN
         7839 KING       PRESIDENT
    3 rows selected.

  • Getting Error - Single-row subquery returns more than 1 row (Help Needed)

    I have the following SQL. It selects several rows of data. This data reflects changed records. I want to update PS_UNI_TEXTBK_SKEW for the values selected. Any ideas. For updating I used:
    update ps_uni_textbk_skew s
    set (s.ssr_txbdtl_title, s.ssr_txbdtl_isbn, s.ubs_skew_num, s.process_date, s.ubs_rec_type) = (
    and then I included theselect listed below. (this selects does work). It always produces an error saying 'singl-row subjquery returns more than 1 row'.
    Any help would be appreciated. I've worked on this for a week now trying many different ways. Thanks, Mary
    SELECT NOW.SSR_TXBDTL_TITLE
    ,NOW.SSR_TXBDTL_ISBN
    ,0
    ,SUBSTR(SYSDATE,1,8)
    ,'C'
    FROM
    SELECT C.SUBJECT||C.CATALOG_NBR||C.CLASS_SECTION||C.STRM||B.SSR_TXBDTL_SEQNO AS TYINGKEEN
    ,C.CRSE_ID
    ,C.CRSE_OFFER_NBR
    ,C.STRM
    ,C.SUBJECT
    ,C.CATALOG_NBR
    ,C.CLASS_SECTION
    ,C.DESCR
    ,B.SSR_TXBDTL_SEQNO
    ,B.SSR_CRSEMAT_TYPE
    ,B.SSR_TXBDTL_STATUS
    ,B.SSR_TXBDTL_TITLE
    ,B.SSR_TXBDTL_ISBN
    ,B.SSR_TXBDTL_AUTHOR
    ,B.SSR_TXBDTL_PUBLISH
    ,B.SSR_TXBDTL_EDITION
    ,B.SSR_TXBDTL_PUBYEAR
    ,B.SSR_TXBDTL_NOTES
    FROM PS_CLASS_TBL C,
    PS_SSR_CLS_TXB_DTL B
    WHERE C.CRSE_ID = B.CRSE_ID
    AND C.CRSE_OFFER_NBR = B.CRSE_OFFER_NBR
    AND C.STRM = B.STRM
    AND C.CLASS_SECTION = B.CLASS_SECTION
    ) NOW,
    SELECT SUBJECT||CATALOG_NBR||CLASS_SECTION||STRM||SSR_TXBDTL_SEQNO AS TYINGKEEL
    ,CRSE_ID
    ,CRSE_OFFER_NBR
    ,STRM
    ,SUBJECT
    ,CATALOG_NBR
    ,CLASS_SECTION
    ,DESCR
    ,SSR_TXBDTL_SEQNO
    ,SSR_CRSEMAT_TYPE
    ,SSR_TXBDTL_STATUS
    ,SSR_TXBDTL_TITLE
    ,SSR_TXBDTL_ISBN
    ,SSR_TXBDTL_AUTHOR
    ,SSR_TXBDTL_PUBLISH
    ,SSR_TXBDTL_EDITION
    ,SSR_TXBDTL_PUBYEAR
    ,SSR_TXBDTL_NOTES
    FROM PS_UNI_TEXTBK_SKEW
    ) LAST
    WHERE NOW.TYINGKEEN = LAST.TYINGKEEL
    AND (NOW.SSR_TXBDTL_TITLE <> LAST.SSR_TXBDTL_TITLE
    OR NOW.SSR_TXBDTL_ISBN <> LAST.SSR_TXBDTL_ISBN
    OR NOW.SSR_TXBDTL_AUTHOR <> LAST.SSR_TXBDTL_AUTHOR
    OR NOW.SSR_TXBDTL_PUBLISH <> LAST.SSR_TXBDTL_PUBLISH
    OR NOW.SSR_TXBDTL_EDITION <> LAST.SSR_TXBDTL_EDITION
    OR NOW.SSR_TXBDTL_PUBYEAR <> LAST.SSR_TXBDTL_PUBYEAR
    OR NOW.SSR_TXBDTL_NOTES <> LAST.SSR_TXBDTL_NOTES
    OR NOW.SSR_TXBDTL_STATUS <> LAST.SSR_TXBDTL_STATUS
    OR NOW.SSR_CRSEMAT_TYPE <> LAST.SSR_CRSEMAT_TYPE
    OR NOW.DESCR <> LAST.DESCR);

    1. Take your subqueries
    2. Run those separately to see if they really can return more than one row. If needed modify the subquery by adding GROUP-BY and HAVING-COUNT>1 clauses to determien that.
    3. If you see more than one row coming up from subqueries then the error message you named will arise.
    This is what i would do.
    But in first look you don't have subqueries, you have "inline-views". so i don't understand how the eroor could occur.
    Edited by: CharlesRoos on 22.10.2010 16:38

  • Single Sub Row Query Returns More Than 1 Row!

    I am trying to update values in a table from another table and getting the error: Single Sub Row Query Returns More Than 1 Row.
    I want table B's PRV_NAME updated into table A's PRV_NAME where A.PRVID = B.PRVID where B.PRV_TYPE = M'
    Both tables have all unique PRVID's, however, table B has PRVID's that have the same name. So table B data can look like this:
    PRVID PRV_NAME
    1234 PHOENIX MED
    1235 SAC MED
    1236 SAC MED
    1237 OVERLAND
    etc..
    So, as you can see the PRVID's are unique, but not the PRV_NAME's. Is this the reason why I get this error?
    I did not build the tables and have no control over what is put in them. If this is the reason for the error, is there any way to resolve this?
    For reference, here is the query. Maybe there is something wrong with this?
    update msb_prv_source ps
    set ps.prv_name =
    (select prv00.prv00_prv_name
    from prv00_prv prv00
    join msb_prv_source ps
    on prv00.prv00_prv_id = ps.prvid
    where prv00.prv00_prv_type = 'M')
    Edited by: user12296489 on Apr 19, 2013 10:46 AM

    Hi,
    user12296489 wrote:
    I am trying to update values in a table from another table and getting the error: Single Sub Row Query Returns More Than 1 Row. Post your code. It's hard to say what you're doing wrong when I don't know what you're doing.
    I want table B's PRV_NAME updated into table A's PRV_NAME where A.PRVID = B.PRVID
    Both tables have all unique PRVID's, however, table B has PRVID's that have the same name. So table B data can look like this:
    PRVIDIf b.prvid is really unique, then
    UPDATE  a
    SET     prv_name = (
                     SELECT  prv_name
                     FROM    b
                     WHERE   a.prvid     = b.prvid
    ;should work, whether the other columns are unique or not.
    (Depending on your data and your requirements, you might want to use MERGE rather than UPDATE).
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}
    Edited by: Frank Kulash on Apr 19, 2013 2:00 PM
    I see you've posted your code now:
    update msb_prv_source ps
    set ps.prv_name =
    (select prv00.prv00_prv_name
    from prv00_prv prv00
    join msb_prv_source ps
    on prv00.prv00_prv_id = ps.prvid
    where prv00.prv00_prv_type = 'M')Even if ps.prvid is unique, the sub-query can return more than 1 row if prv00.prv00_prv_id is not unique. When that that's the case, what do you want to happen? Include examples when you post the sample data and desired results.

  • DataTemplate Not showing data but showing correct amount of rows

    I just started using Datatemplates to convert our Answers Reports over to Publisher. Basicly I am using the direct SQL to BI Server method.
    Copy the SQL from the advanced SQL field in BI Answers.
    Place new SQL in DataTemplate
    Construct DataStructure
    It seems to be getting the proper amount of rows but none of the data is shown. I have checked the data multiple times for spelling errors and other simple items but I can't find it. It seems to be making a connection just fine but it does not show and value in the data elements. It just returns 6 empty rows.
    Example XML Attached:
    <dataTemplate name="FiveDayCo" defaultPackage="" dataSourceRef="OracleRPD">
         <properties>
    <property name="include_parameters" value="true"/>
    <property name="include_null_Element" value="true"/>
    <property name="include_rowsettag" value="false"/>
    <property name="scalable_mode" value="off"/>
    <property name="db_fetch_size" value="300"/>
    </properties>
         <parameters/>
         <lexicals/>
         <dataQuery>
              <sqlStatement name="COOR" ><![CDATA[SELECT "- Correspondence"."% 5 Day Correspondence Response Time" saw_0, '90%' saw_1, "- Correspondence"."% 5 Day Correspondence Response Time"-90 saw_2, "- Correspondence Details"."Correspondence Type" saw_3 FROM Finance WHERE ("- Correspondence Details"."Correspondence Type" IN ('Customer Service', 'Routine', 'Undeliverable', 'Privacy')) AND ("Business Unit"."Business Unit ID" = 6.00) AND ("- Record Details"."Record Type" = 'CORE') AND ("- Correspondence Details"."Correspondence Status" <> 'Closed') AND (("- Primary Expected Completed Date"."Primary Expected Year" = cast (YEAR( date '2010-07-01') as char(4)) ) AND ("- Primary Expected Completed Date"."Primary Expected Calendar Month" = MONTH( date '2010-07-01'))) ORDER BY saw_1, saw_3]]></sqlStatement>
         </dataQuery>
         <dataStructure>
              <group name="Coorespondence" source="COOR" >
                   <element name="FiveDayCoorespondenceTime" source="saw_0" function=""/>
                   <element name="KPIValue" source="saw_1" function=""/>
                   <element name="Variance" source="saw_2" function=""/>
                   <element name="CoorespondenceType" source="saw_3" function=""/>
              </group>
         </dataStructure>
    </dataTemplate>

    A few things to check. Does the sql by itself return data?
    Also, do you need the following: <dataTemplate name="FiveDayCo" defaultPackage="" dataSourceRef="OracleRPD"> ? If a package is not used/necessary, remove the reference.
    The following tag should be enough.
    <dataTemplate name="FiveDayCo">
    Your datastructure code should be: (for element name use value (instead of source = ) and I removed function syntax since you didn't specify any function like sum, average)
    <dataStructure>
    <group name="Coorespondence" source="COOR" >
    <element name="FiveDayCoorespondenceTime" value="saw_0" function=""/>
    <element name="KPIValue" value="saw_1"/>
    <element name="Variance" value="saw_2"/>
    <element name="CoorespondenceType" value="saw_3"/>
    </group>
    </dataStructure>
    For a good data template reference, check out the following: http://blogs.oracle.com/xmlpublisher/2009/06/data_template_progression.html
    Hope that helps!

  • ORA-01427: single-row subquery returns more than one row

    I have a problem something like this:
    table A
    id col1 after_update
    1 ? 11
    2 ? 22
    3 ? 33
    3 ? 44
    3 ? 55
    4 ? 66
    5 ? 88
    5 ? ? /* won't be updated */
    6 ? 99
    7 ? null /* updated to null */
    9 ? 20
    table B
    id col2
    1 11
    2 22
    3 33
    3 44
    3 55
    4 66
    4 77
    5 88
    6 99
    8 10
    9 20
    When I try the query:
    update table A
    set col1 = (select distinct col2 from table B) it gives me the error ORA-01427: single-row subquery returns more than one row
    When I try the query:
    update (select x.col1 x_col1,y.col2 y_col2
    from (select id,col1,row_number() over (partition by id order by null /*col1*/) rn
    from table_a
    ) x,
    (select id,col2,row_number() over (partition by id order by col2) rn
    from table_b
    ) y
    where x.id = y.id
    and x.rn = y.rn
    set x_col1 = y_col2
    it gives me an error saying ora-01779 :cannot modify a column which maps to a non key- preserved table. It shows the same even when I add the key to the tables.
    My Database version is Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
    Kindly help.

    Another way, not waterproof too relay on rowid, but in your case it could work.
    You have to verify it by yourself
    update test_a aa
    set col1 =
    (select b.col1 from
    (select
    id, col1
    ,row_number() over
      (partition by id order by col1) rn
    from table_b) b,
    ( select
      rowid, id, col1
    ,row_number() over (partition by id order by col1) sort_order
    from test_a
    ) a
    where
    a.id=b.id
    and
    sort_order = rn
    and
    aa.rowid=a.rowid
    )Edited by: chris227 on 03.04.2013 06:42
    Table name corrected

  • ORA-01427: single-row subquery returns more than one row HELP

    I need to update baemployee.Stock_nbr field with select substr(C.CHECK_DIGIT, 3, 10)
    from EMP_CHECK_DIG c where C.EMPLOYEE = e.EMPLOYEE
    Please help.
    update baemployee e
    set Stock_nbr = (select substr(C.CHECK_DIGIT, 3, 10)
    from EMP_CHECK_DIG c where C.EMPLOYEE = e.EMPLOYEE)
    where exists
    (select C.CHECK_DIGIT
    from EMP_CHECK_DIG c where C.EMPLOYEE = e.EMPLOYEE)
    and exists (select 1 from EMPLOYEE ee where ee.employee = e.employee and ee.emp_status like 'A%');
    ORA-01427: single-row subquery returns more than one row

    Hi,
    Welcome to the forum!
    Whenever you have a question, please post some sample data, so that people can re-create the problem and test their solutions.
    CREATE TABLE and INSERT statements, like the ones below, are great:
    CREATE TABLE      baemployee
    (     employee     NUMBER (4)
    ,     stock_nbr     VARCHAR2 (10)
    INSERT INTO baemployee (employee, stock_nbr) VALUES (1234, 'FUBAR');
    CREATE TABLE     employee
    (     employee     NUMBER (4)
    ,     emp_status     VARCHAR2 (10)
    INSERT INTO employee (employee, emp_status) VALUES (1234, 'ACTIVE');CREATE TABLE AS is good, too:
    CREATE TABLE     emp_check_dig
    AS          SELECT  1234 AS employee, 'AA1234567890ZZZ' AS check_digit     FROM dual
    UNION ALL     SELECT  1234,            'AA2121212121ZZZ'               FROM dual
    ;Also post the results you want from that data. In this case, the results would be the contents of the baemployee table after you run the UPDATE.
    Would you want:
    employee  stock_nbr
    1234       1234567890or would you want
    employee  stock_nbr
    1234       2121212121If you run the UPDATE statement you posted with the data above, you'll get the "ORA-01427: single-row subquery returns more than one row" error, and you can see what causes it: there is more than one row from emp_check_dig that could be used to UPDATE the same row of baemployee. Say what you want to do in this situation (and why), and someone will help you find a way to do it.

  • ORA-01427: single-row subquery returns more than one row -- no solution

    Hello to all:
    I have to tables:
    Table a anwender (Email,Dept). --> all fields are filled
    Table b dingo (Name,email,dept) --> all fields are filled
    I now want to update the table a with the data from table b:
    update anwender a set a.abteilung = ( select distinct b.abteilung from dingo b where b.email = a.email);
    Then I got the error: ORA-01427: single-row subquery returns more than one row
    Every dept is about 100x in the database, so it is clear that i got more than one row back. But how can I update the table now?

    Okay, I got several duplicates, and I deletet a lot of data in my database.
    Now I want to remove all entries with more than one departments per mail adresses.
    a
    select email,count(abteilung) from dingo group by email having count(abteilung)>1 order by count(abteilung)
    shows me all the fake mailadresses.
    But a
    delete from dingo where email in (select email,count(abteilung) from dingo group by email having count(abteilung)>1 order by count(abteilung) );
    gives me a
    SQL Error: ORA-00907: missing right parenthesis
    I´m very confused now ...
    Oops, now I got the solution:
    delete from dingo where email in (select email from (select email,count(abteilung) from dingo group by email having count(abteilung)>1 )) ;
    Edited by: user8309218 on Dec 18, 2009 6:24 AM

Maybe you are looking for

  • Can I change the pressure amount of a brush line –drawn by mouse pen- after I drew it?

    Hey everybody, I am using illustrator for doing some calligraphy and I am not really experienced with this program. I am using a mouse pen with pressure to draw/write calligraphies. My question is, can I change the pressure amount after I drew lines

  • Views in master data

    Hi, How can I hide/supress/madatory some fileds and tab pages in customer master data and material master data? Pls advise me the t-code or menu path. Regards, Student

  • Moving Files from Movies Folder

    I have a lot of home videos on itunes that I categorize as "tv shows" so it's easier for me to find what I'm looking for. To do that I have to add them to the "movies" category then later change the file info for "tv show". However, when I do that th

  • Question regarding upgrade to InDesign 2.0

    I've been using InDesign 2.0 for years, and want to upgrade to a higher version. Will cs 5.5 be able to open files in the older format? Thanks for any help.

  • SXCE snv_114 SRSS 4.1 multihead maximize across both screens

    I have been running snv_104 for some time and several versions prior with success using SRSS 4.1. This is a home setup (mostly to keep me current on Solaris, which we use at work). Several attempts at upgrading past 104 have caused SRSS to quit worki