473,804 Members | 2,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help on Oracle Update statement

Don
Hi,

I am moving from Sybase to Oracle and I used to be able to do update
statement like this in Sybase:

UPDATE TABLE1
SET T1.field1 = T2.field2
FROM TABLE1 T1, TABLE2 T2
WHERE T1.field2 = T2.field2
AND ....

but in Oracle it is not valid. Does anyone know how to convert it to
Oracle?

Thanks in advance..

Jul 19 '05 #1
4 57666
Don,

Try something like this:

UPDATE TABLE1
SET FIELD1 =
(SELECT FIELD2 FROM TABLE2
WHERE TABLE2.FIELD2 = TABLE2.FIELD1)
....
--
Cheers,
Chris

_______________ _______________ _____

Chris Leonard, The Database Guy
http://www.databaseguy.com

Brainbench MVP for Oracle Admin
http://www.brainbench.com

MCSE, MCDBA, OCP, CIW
_______________ _______________ _____

"Don" <do************ ***@telus.net> wrote in message
news:q0******** *************** *********@4ax.c om...
Hi,

I am moving from Sybase to Oracle and I used to be able to do update
statement like this in Sybase:

UPDATE TABLE1
SET T1.field1 = T2.field2
FROM TABLE1 T1, TABLE2 T2
WHERE T1.field2 = T2.field2
AND ....

but in Oracle it is not valid. Does anyone know how to convert it to
Oracle?

Thanks in advance..

Jul 19 '05 #2
Don <do************ ***@telus.net> wrote in message news:<q0******* *************** **********@4ax. com>...
Hi,

I am moving from Sybase to Oracle and I used to be able to do update
statement like this in Sybase:

UPDATE TABLE1
SET T1.field1 = T2.field2
FROM TABLE1 T1, TABLE2 T2
WHERE T1.field2 = T2.field2
AND ....

but in Oracle it is not valid. Does anyone know how to convert it to
Oracle?

Thanks in advance..


One form is:
update table1 t1
set t1.field1 = ( select t2.field2
from table2 t2
where t2.field2 = t1.field1 ...
)
where exists ( select 'X' from table2 t3
where t3.field2 = t1.field1 ...other cond ...
);

The first subquery gets the value from the other table where the
values match while the where clause on the update prevent updating the
column to null for non-matching rows.

HTH -- Mark D Powell --
Jul 19 '05 #3
Don

And yes, using alias/and subquery is working .. thanks for all who
response quickly..

Now my next question is : would the alias works in multiple nest
level? For example :

UPDATE TABLE1 T1
set T1.field1 = ( select T2.field1 from TABLE2 T2 where T2.field2 = (
select T3.field3 from TABLE3 T3 where T3.field1 = T1.field1 )

Thanks again ...
Ma*********@eds .com (Mark D Powell) wrote:
Don <do************ ***@telus.net> wrote in message news:<q0******* *************** **********@4ax. com>...
Hi,

I am moving from Sybase to Oracle and I used to be able to do update
statement like this in Sybase:

UPDATE TABLE1
SET T1.field1 = T2.field2
FROM TABLE1 T1, TABLE2 T2
WHERE T1.field2 = T2.field2
AND ....

but in Oracle it is not valid. Does anyone know how to convert it to
Oracle?

Thanks in advance..


One form is:
update table1 t1
set t1.field1 = ( select t2.field2
from table2 t2
where t2.field2 = t1.field1 ...
)
where exists ( select 'X' from table2 t3
where t3.field2 = t1.field1 ...other cond ...
);

The first subquery gets the value from the other table where the
values match while the where clause on the update prevent updating the
column to null for non-matching rows.

HTH -- Mark D Powell --


Jul 19 '05 #4
Don <do************ ***@telus.net> wrote in message news:<db******* *************** **********@4ax. com>...
And yes, using alias/and subquery is working .. thanks for all who
response quickly..

Now my next question is : would the alias works in multiple nest
level? For example :

UPDATE TABLE1 T1
set T1.field1 = ( select T2.field1 from TABLE2 T2 where T2.field2 = (
select T3.field3 from TABLE3 T3 where T3.field1 = T1.field1 )

Thanks again ...
Ma*********@eds .com (Mark D Powell) wrote:
Don <do************ ***@telus.net> wrote in message news:<q0******* *************** **********@4ax. com>...
Hi,

I am moving from Sybase to Oracle and I used to be able to do update
statement like this in Sybase:

UPDATE TABLE1
SET T1.field1 = T2.field2
FROM TABLE1 T1, TABLE2 T2
WHERE T1.field2 = T2.field2
AND ....

but in Oracle it is not valid. Does anyone know how to convert it to
Oracle?

Thanks in advance..


One form is:
update table1 t1
set t1.field1 = ( select t2.field2
from table2 t2
where t2.field2 = t1.field1 ...
)
where exists ( select 'X' from table2 t3
where t3.field2 = t1.field1 ...other cond ...
);

The first subquery gets the value from the other table where the
values match while the where clause on the update prevent updating the
column to null for non-matching rows.

HTH -- Mark D Powell --


Yes, you can nest subqueries including coordinated sub-queries though
in my experience the second subquery would be coordinated to the first
subquery which in turn is coordinated to the driving query. In your
example you would probably be better off to combine the two subqueries
into a join.

HTH -- Mark D Powell --
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6027
by: cricketunes | last post by:
Hi everyone :) I have made a form to get values and insert them to a database. I have 1) A file conn.php that does the initial connections 2) The form file form.php 3) Action file action.php which gets values from form.php to do insert/delete/update.
4
40285
by: francis70 | last post by:
Hi, I have these 2 problem? Is there a way in Oracle to read UNCOMMITED data. i.e. in Oracle the normal behaviour is that a user's updates to a table are visible to other users ONLY when the user commits. But in Informix there is this thing called ISOLATION LEVELS. For example by setting the ISOLATION LEVEL to DIRTY READ, a user will read dirty data, i.e. the last uncommited updated value of a field by some other user. Is
4
10239
by: Surendra | last post by:
I have this query that I need to use in an Update statement to populate a field in the table by the value of Sq ---------------------------------------------------------------------------- Inline View Query: Select Sq from ( Select substr(to_date(End_Date,"DD-MON-YYYY"),4), End_Date, Rank() Over (Partition by substr(to_date(End_Date,"DD-MON-YYYY"),4) Order by End_Date) As Sq
8
3276
by: Cherrish Vaidiyan | last post by:
hello googles, I have a small sqlplus problem. i have created a table with date field along with other varchar2,number etc. But unfortunately i made a mistake in entering the date. for some date records i made an error in month... say for 20 record.Now i need to correct the month.HOW???? i have tried with 'update' statement using like,=,... etc.All resulted in failure.i thought of converting date datatype to character and then use the...
11
12723
by: Markus Breuer | last post by:
I have a question about oracle commit and transactions. Following scenario: Process A performs a single sql-INSERT into a table and commits the transaction. Then he informs process B (ipc) to read the new date. So process B starts "select ..." but does not get the previously inserted row. The timespan between commit and select is very short. (NOTE: two different sessions are used) Questions: 1.) Does commit when returning from call...
0
3019
by: gshawn3 | last post by:
Hi, I am having a hard time creating a Trigger to update an Oracle database. I am using a SQL Server 2005 Express database on a Win XP Pro SP2 desktop, linked to an Oracle 10g database on a remote Windows 2003 server. Both machines are on the same domain and very close physically (<1ms ping). I have set up the Oracle linked server in SQLEXPRESS, added the login/pw information, and I can execute select and update queries
2
14254
by: Vinod Sadanandan | last post by:
All, Below listed are the new features in Oracle 11g ,please join me in this discussion to generate a testcase and analyze each of the listed features . Precompilers: Additional Array INSERT and SELECT Syntax Support by Pro*C/C++ and Pro*COBOL Precompilers: Dynamic SQL Statement Caching in Pro*C/C++ and Pro*COBOL Precompilers: Fix Execution Plan in Pro*C/C++ and Pro*COBOL Precompilers: Flexible B Area Length...
4
239
by: Don | last post by:
Hi, I am moving from Sybase to Oracle and I used to be able to do update statement like this in Sybase: UPDATE TABLE1 SET T1.field1 = T2.field2 FROM TABLE1 T1, TABLE2 T2 WHERE T1.field2 = T2.field2 AND ....
1
1192
by: aakcse | last post by:
Help needed in understanding the below update statement update results_key set result = temp.tally from(
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10562
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10319
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10303
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5508
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.