Solved

Update, Set, and Select

Posted on 2003-10-24
4
8,366 Views
Last Modified: 2013-12-01
Can anyone tell me why this statement is not working.  I keep getting a

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

error

UPDATE tmp10110191
   SET mnth_sales_amt =
          (SELECT   SUM (dlycsh.sales_amt)
               FROM tmx.dlycsh, chgdata.tmp10110191
              WHERE dlycsh.tran_dt >= TO_DATE ('01/01/03', 'MM/DD/YY')
                AND dlycsh.tran_dt <= TO_DATE ('10/22/03', 'MM/DD/YY')
           GROUP BY dlycsh.site_no)

Thanks,

jms
0
Comment
Question by:jmsloan
4 Comments
 
LVL 22

Expert Comment

by:Helena Marková
ID: 9625117
I think that there are more dlycsh.site_no (GROUP BY dlycsh.site_no) than one there.
0
 
LVL 2

Expert Comment

by:renuraj
ID: 9635131
Could you post us the table tmp10110191 structure!

If tmp10110191 table has site_no column, SQL below will do
UPDATE tmp10110191 t
   SET t.mnth_sales_amt =
          (SELECT   SUM (dlycsh.sales_amt)
               FROM tmx.dlycsh, chgdata.tmp10110191
              WHERE dlycsh.tran_dt >= TO_DATE ('01/01/03', 'MM/DD/YY')
                AND dlycsh.tran_dt <= TO_DATE ('10/22/03', 'MM/DD/YY')
                AND dlycsh.site_no = t.site_no)

Regards,
0
 
LVL 3

Accepted Solution

by:
evedder earned 20 total points
ID: 9654255

Your subquery is returning multiple rows, maybe you should test first the subquery alone and see how many rows it retrieves you, if you receive more than one row you have to use an "any" or "all" clause for comparisons

like

UPDATE tmp10110191
   SET mnth_sales_amt > any
          (SELECT   SUM (dlycsh.sales_amt)
               FROM tmx.dlycsh, chgdata.tmp10110191
              WHERE dlycsh.tran_dt >= TO_DATE ('01/01/03', 'MM/DD/YY')
                AND dlycsh.tran_dt <= TO_DATE ('10/22/03', 'MM/DD/YY')
           GROUP BY dlycsh.site_no)


that is talking about syntax but to make your statement to work properly we need to know the logistic

regards!
0
 

Expert Comment

by:ksrsrao
ID: 10587210
hi
u must use where condition after subqry
ex given  below
update bak_party_fa a set add1=(select substr(add1,1,30) from bak_party
where a.party_code=acct_head) where party_code in
(select b.acct_head from bak_party b)
regards
kalaga
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

-Xmx and -Xms are the two JVM options often used to tune JVM heap size.   Here are some common mistakes made when using them:   Assume BigApp is a java class file for the below examples. 1.         Missing m, M, g or G at the end …
Most of the developers using Tomcat find it easy to configure the datasource in Server.xml and use the JNDI name in the code to get the connection.  So the default connection pool using DBCP (or any other framework) is made available and the life go…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question