Solved

Oracle Update statement based on a condition

Posted on 2014-10-04
5
290 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
  • 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 48

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that useā€¦
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.

815 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now