Unix Technical Forum

MS SQL Server syntax to Oracle

This is a discussion on MS SQL Server syntax to Oracle within the Oracle Miscellaneous forums, part of the Oracle Database category; --> Hi all I have this update statement written for MS SQL Server and need the same statement for Oracle ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 12:36 PM
fgsdfgsdf
 
Posts: n/a
Default MS SQL Server syntax to Oracle

Hi all

I have this update statement written for MS SQL Server and need the same
statement for Oracle (version 9).
I can not find a way to do joins in an update statement in Oracle - is it
possible?

update Ver
set Ver.ObjectCreatedBy = c.CreatedBy,
Ver.ObjectCreated = c.Created
from Ver
join (
select Object, CreatedBy, Created
from Ver
join (
select Object Obj, min(created) Cre
from Ver
group by Object
) b on Ver.Object = b.Obj and Ver.Created = b.Cre
) c on Ver.Object = c.Object

Thanks for your help
Stefan Olofsson


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 12:37 PM
DA Morgan
 
Posts: n/a
Default Re: MS SQL Server syntax to Oracle

fgsdfgsdf wrote:
> Hi all
>
> I have this update statement written for MS SQL Server and need the same
> statement for Oracle (version 9).
> I can not find a way to do joins in an update statement in Oracle - is it
> possible?
>
> update Ver
> set Ver.ObjectCreatedBy = c.CreatedBy,
> Ver.ObjectCreated = c.Created
> from Ver
> join (
> select Object, CreatedBy, Created
> from Ver
> join (
> select Object Obj, min(created) Cre
> from Ver
> group by Object
> ) b on Ver.Object = b.Obj and Ver.Created = b.Cre
> ) c on Ver.Object = c.Object
>
> Thanks for your help
> Stefan Olofsson


www.psoug.org
Click on Morgan's Library
Click on Update

There are examples there that show how to do it.
--
Daniel A. Morgan
University of Washington
damorgan@x.washington.edu
(replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 12:37 PM
fgsdfgsdf
 
Posts: n/a
Default Re: MS SQL Server syntax to Oracle

Thanks!

/Stefan

"DA Morgan" <damorgan@psoug.org> skrev i meddelandet
news:1176824299.52428@bubbleator.drizzle.com...
> fgsdfgsdf wrote:
>> Hi all
>>
>> I have this update statement written for MS SQL Server and need the same
>> statement for Oracle (version 9).
>> I can not find a way to do joins in an update statement in Oracle - is it
>> possible?
>>
>> update Ver
>> set Ver.ObjectCreatedBy = c.CreatedBy,
>> Ver.ObjectCreated = c.Created
>> from Ver
>> join (
>> select Object, CreatedBy, Created
>> from Ver
>> join (
>> select Object Obj, min(created) Cre
>> from Ver
>> group by Object
>> ) b on Ver.Object = b.Obj and Ver.Created = b.Cre
>> ) c on Ver.Object = c.Object
>>
>> Thanks for your help
>> Stefan Olofsson

>
> www.psoug.org
> Click on Morgan's Library
> Click on Update
>
> There are examples there that show how to do it.
> --
> Daniel A. Morgan
> University of Washington
> damorgan@x.washington.edu
> (replace x with u to respond)
> Puget Sound Oracle Users Group
> www.psoug.org



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-08-2008, 12:37 PM
pankaj_wolfhunter@yahoo.co.in
 
Posts: n/a
Default Re: MS SQL Server syntax to Oracle

On Apr 17, 9:36 pm, "fgsdfgsdf" <sdfg...@nospam.se> wrote:
> Thanks!
>
> /Stefan
>
> "DA Morgan" <damor...@psoug.org> skrev i meddelandetnews:1176824299.52428@bubbleator.drizzl e.com...
>
>
>
> > fgsdfgsdf wrote:
> >> Hi all

>
> >> I have this update statement written for MS SQL Server and need the same
> >> statement for Oracle (version 9).
> >> I can not find a way to do joins in an update statement in Oracle - is it
> >> possible?

>
> >> update Ver
> >> set Ver.ObjectCreatedBy = c.CreatedBy,
> >> Ver.ObjectCreated = c.Created
> >> from Ver
> >> join (
> >> select Object, CreatedBy, Created
> >> from Ver
> >> join (
> >> select Object Obj, min(created) Cre
> >> from Ver
> >> group by Object
> >> ) b on Ver.Object = b.Obj and Ver.Created = b.Cre
> >> ) c on Ver.Object = c.Object

>
> >> Thanks for your help
> >> Stefan Olofsson

>
> >www.psoug.org
> > Click on Morgan's Library
> > Click on Update

>
> > There are examples there that show how to do it.
> > --
> > Daniel A. Morgan
> > University of Washington
> > damor...@x.washington.edu
> > (replace x with u to respond)
> > Puget Sound Oracle Users Group
> >www.psoug.org- Hide quoted text -

>
> - Show quoted text -


You can also look into MERGE statement. In your case something like
this

-- Untested

MERGE VER
USING (Ver
join (
select Object, CreatedBy, Created
from Ver
join (
select Object Obj, min(created) Cre
from Ver
group by Object
) b on Ver.Object = b.Obj and Ver.Created =
b.Cre
) Ver.Object = c.Object
) src
on (Ver.Object = src.Object )
WHEN MATCHED THEN
UPDATE SET Ver.ObjectCreatedBy = src.CreatedBy,
Ver.ObjectCreated = src.Created;

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:01 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com