Solved

Oracle Update statement based on a condition

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
oracle 10G 5 48
Cannot open form error 6 47
T-SQL Convert to PL/SQL 23 61
SQL Retrieve Values 4 41
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
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…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

708 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