0

Can you tell me how to update multiple rows in oracle as when I fired the update statement it gave me the following error

UPDATE  BI_BSELATEST_LATESTPRICESTEST
SET PREVIOUS_DAY_CLOSE =
    (SELECT  DISTINCT aa.DLYPRICE_CLOSE 
     FROM  DATAFEED_EQTY.FEED_DLYPRICE aa  ,
           (
           SELECT  a.sc_code ,  MAX(a.DLYPRICE_DATE) as max_date
           from    DATAFEED_EQTY.FEED_DLYPRICE a,BI_BSELATEST_LATESTPRICES b
           where   a.SC_CODE = b.SC_CODE
           and    a.ST_EXCHNG = 'BSE'
           and    a.DLYPRICE_DATE <   b.upd_time 
           group by a.sc_code
         ) bb
    WHERE  aa.SC_CODE =  bb.sc_code
    and    aa.DLYPRICE_DATE = max_date)

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

Thanks in advance

2
  • 2
    None of the answers you've gotten on any questions before are good enough to accept (you accept answers by clicking the checkmark to the left)? Commented Jun 17, 2010 at 7:29
  • Thanks for posting some code. You can also format the code properly by indenting each line with 4 spaces (or highlight and click the "code" button on the toolbar) Commented Jun 17, 2010 at 7:30

2 Answers 2

2

A subquery in your statement is wrong. You left off either a WHERE or FIRST clause, and now it's returning multiple values when it shouldn't.

You're basically trying to say PREVIOUS_DAY_CLOSE should be multiple values at the same time. I'm guessing you left off a WHERE clause on your subselect, which would link the results of that subquery to the particular row you're trying to update. Something like (note the bolded line):

UPDATE  BI_BSELATEST_LATESTPRICESTEST
SET PREVIOUS_DAY_CLOSE =
    (SELECT  DISTINCT aa.DLYPRICE_CLOSE 
     FROM  DATAFEED_EQTY.FEED_DLYPRICE aa  ,
           (
           SELECT  a.sc_code ,  MAX(a.DLYPRICE_DATE) as max_date
           from    DATAFEED_EQTY.FEED_DLYPRICE a,BI_BSELATEST_LATESTPRICES b
           where   a.SC_CODE = b.SC_CODE
           and    a.ST_EXCHNG = 'BSE'
           and    a.DLYPRICE_DATE <   b.upd_time 
           group by a.sc_code
         ) bb
    WHERE  aa.SC_CODE =  bb.sc_code
    and    aa.DLYPRICE_DATE = max_date

   AND bb.sc_code = BI_BSELATEST_LATESTPRICESTEST.sc_code

    )

Although, I'll be honest, I'm not exactly sure what you're trying to do with this query.

Sign up to request clarification or add additional context in comments.

10 Comments

m i want to update records in PREVIOUS_DAY_CLOSE field in BI_BSELATEST_LATESTPRICESTEST table with the values i get in select statement hope this info helps you..
@devang - Right, so for a certain given row of BI_BSELATEST_LATESTPRICESTEST, which value that you get from the select statement do you want. One column from one row can only have one value at any given time, right?
yes correct i get only when value for one column..but still it gives me the same error ORA-01427: single-row subquery returns more than one row.
@devang - I don't think you're quite understanding. Take your subselect out and try running it by itself and see what results you get, because you'll surely get more than one row.
@lc- i tried running the select and sub select query it gives me some 1000 rows now can u tell me how to update these rows in the PREVIOUS_DAY_CLOSE column in BI_BSELATEST_LATESTPRICESTEST table.
|
0

I think what you want is this:

UPDATE  BI_BSELATEST_LATESTPRICESTEST b
SET PREVIOUS_DAY_CLOSE =
    (SELECT  DISTINCT aa.DLYPRICE_CLOSE 
     FROM  DATAFEED_EQTY.FEED_DLYPRICE aa  ,
           (
           SELECT  a.sc_code ,  MAX(a.DLYPRICE_DATE) as max_date
           from    DATAFEED_EQTY.FEED_DLYPRICE a
           where   a.SC_CODE = b.SC_CODE
           and    a.ST_EXCHNG = 'BSE'
           and    a.DLYPRICE_DATE <   b.upd_time 
           group by a.sc_code
         ) bb
    WHERE  aa.SC_CODE =  bb.sc_code
    and    aa.DLYPRICE_DATE = max_date)

This removes BI_BSELATEST_LATESTPRICESTEST from the sub-query and instead tells the database to use the columns from the table that it is updating to filter the sub-query. As you had written it, the database had no way of knowing how to correlate the columns from the sub-query to the table being updated.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.