Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Query Alias For The Purpose Of An Update Statement

Ray WinkelmanJul 25 2016 — edited Jul 26 2016

Hey All,

So this a pretty specific SQL question. SQL server allows a from clause in update statements. I'm trying to mimic this behaviour in an Oracle stored procedure, while circumventing the need for a complex routine, ex: selecting the values I need for the comparisons in the where clause into variables.

Ideally I would like to use the WITH keyword, but I haven't got this to compile. It may be possible, however.

Help meh! 

Here's my code: (This doesn't compile and is intended to give you guys an idea of what I'm attempting to do)

with dups

     as (select ticketid,

                assetid,

                Max(ticketassetid) as TicketAssetId

         from   ticketasset

         where  isactive = 1

         group  by ticketid,

                   assetid

         having Count(ticketassetid) > 1)

update dbo$ticketasset

set    isactive = 0

where  ticketasset.ticketassetid < dups.ticketassetid

   and ticketasset.ticketid = dups.ticketid

   and ticketasset.assetid = dups.assetid

   and ticketasset.isactive = 1;

This post has been answered by Solomon Yakobson on Jul 25 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 23 2016
Added on Jul 25 2016
14 comments
3,012 views