Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

ORACLE SQL - Is this script okay?

Options
  • 14-10-2005 10:13am
    #1
    Registered Users Posts: 24,172 ✭✭✭✭


    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 Posts: 39,098 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?


  • Registered Users Posts: 24,172 ✭✭✭✭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 Posts: 39,098 Mod ✭✭✭✭Seth Brundle


    omit the single quotes!

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


  • Moderators, Politics Moderators Posts: 39,098 Mod ✭✭✭✭Seth Brundle


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


  • 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