Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

ORACLE SQL - Is this script okay?

  • 14-10-2005 10:13AM
    #1
    Registered Users, Registered Users 2, Paid Member Posts: 24,679 ✭✭✭✭


    Hi all, I'm trying to "oracleize" an SQL statement for one of the guys in the office here and I'm wondering if the following is okay in Oracle. I know it works fine in SQL Server.
    update table1
    set table1.period = table2.period
    from table1, table2
    where table1.client = table2.client 
    and table1.trans_no = table2.fatr_trans_nbr
    and table1.status = '5'
    

    client and trans_no would be the primary key on table1 with client and fatr_trans_nbr being the corresponding foreign key in table2.


Comments

  • Closed Accounts Posts: 756 ✭✭✭Zaph0d


    I don't believe you can use a FROM clause in an Oracle UPDATE statement the way you can in SQL Server.
    UPDATE table1 t1
    SET t1.period= 
    (SELECT t2.period from table2 t2 WHERE t2.client=t1.client
    and t1.trans_no = t2.fatr_trans_nbr
    and t1.status = '5')
    


  • Moderators, Politics Moderators, Paid Member Posts: 44,224 Mod ✭✭✭✭Seth Brundle


    try
    update table1, table2
    set table1.period = table2.period
    where table1.client = table2.client 
    and table1.trans_no = table2.fatr_trans_nbr
    and table1.status = '5'
    

    What datatype is table1.status?

    Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/ .



  • Registered Users, Registered Users 2, Paid Member Posts: 24,679 ✭✭✭✭Sleepy


    It's an integer...

    My real problem with this is that I don't have an Oracle DB to test this on.


  • Moderators, Politics Moderators, Paid Member Posts: 44,224 Mod ✭✭✭✭Seth Brundle


    omit the single quotes!

    Like yourself, I haven't access to oracle on this PC.

    Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/ .



  • Moderators, Politics Moderators, Paid Member Posts: 44,224 Mod ✭✭✭✭Seth Brundle


    Managed to test my script - doesn't work :( - I think that may be for MySQL

    Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/ .



  • Advertisement
  • Closed Accounts Posts: 756 ✭✭✭Zaph0d


    kbannon wrote:
    try
    update table1, table2
    set table1.period = table2.period
    where table1.client = table2.client 
    and table1.trans_no = table2.fatr_trans_nbr
    and table1.status = '5'
    
    Oracle doesn't allow two table names between the UPDATE and SET keywords.


  • Closed Accounts Posts: 98 ✭✭Plankmonkey


    This site will show you:

    http://www.techonthenet.com/index.php


Advertisement