473,836 Members | 1,907 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 57672
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
40293
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
10240
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
3277
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
12729
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
3022
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
14257
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
1193
by: aakcse | last post by:
Help needed in understanding the below update statement update results_key set result = temp.tally from(
0
9810
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
9656
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10567
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,...
0
10237
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6972
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
5641
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
5811
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4437
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4000
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.