Solved

Oracle Update statement based on a condition

Posted on 2014-10-04
5
306 Views
Last Modified: 2014-10-04
I need to conditionally update a table.

Update Table1
SET date_group = 'Group1'  WHERE (Select Table1.days_old from Table1 WHERE Table1.days_old  BETWEEN 1 AND 7 ) ;

Is this syntax correct?

Thanks,
0
Comment
Question by:Dovberman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 37

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 100 total points
ID: 40361181
no, why use table1 twice ?

Update Table1
SET date_group = 'Group1'  
WHERE days_old  BETWEEN 1 AND 7  ;

Open in new window

0
 
LVL 49

Accepted Solution

by:
PortletPaul earned 400 total points
ID: 40361182
No. Try this instead:

UPDATE Table1
SET date_group = 'Group1'
WHERE Table1.days_old BETWEEN 1 AND 7
;

Assuming days_old is an integer field
But I suspect you are performing a calculation; what is that calculation?

Syntax examples:
http://www.techonthenet.com/oracle/update.php

Documentation (10g):
http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_10007.htm
0
 

Author Comment

by:Dovberman
ID: 40361290
Thanks,

Days_Old = To_Days(SysDate-Start_Date)

Table1 was referenced twice by mistake.  I had modified a statement that updated table 1 from rows joined in table 2.
0
 

Author Comment

by:Dovberman
ID: 40361296
I like the comprehensive 10g link.

The final result of this task is to feed an aging report.  There are several age groups which will appear in a cross tab type report.
0
 

Author Closing Comment

by:Dovberman
ID: 40361307
Thank you.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

717 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