Solved

Oracle Update statement based on a condition

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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
File generation using utl_file 4 46
Oracle DATE Column Space 11 65
SQL Retrieve Values 4 57
Get FileTypes from a list of FileNames  in a Table field 18 43
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to recover a database from a user managed backup

863 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

25 Experts available now in Live!

Get 1:1 Help Now