Solved

Oracle Update statement based on a condition

Posted on 2014-10-04
5
303 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Retreiving column names in Windows but not in Unix 11 93
Oracle collections 15 53
Oracle Distributed Transaction Lock Error ORA-01591 8 88
pl/sql parameter is null sometimes 2 38
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
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…
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.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

737 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