Results 1 to 6 of 6

Thread: SQL Update query

  1. #1
    Join Date
    Sep 2007
    Location
    Malaysia
    Beans
    280
    Distro
    Ubuntu 11.04 Natty Narwhal

    Question SQL Update query

    Hi,


    I have this code in SQL that works fine.

    Code:
    update Electronics_01 set categories = right(categories;len(categories)-2) where left(categories;2)="1,"
    How do I make it so that it works for multiple tables such as

    Code:
    update Electronics_01,Electronics_02 set Electronics_01.categories = right(Electronics_01.categories;len(Electronics_01.categories)-2 where left (Electronics_01.categories;2)="1,"
    Need to make changes to around 9 tables. What is the correct syntax for performing that task for multiple tables?

    Thanks!
    It's called a beta release for a reason. Not for noobs

  2. #2
    Join Date
    May 2008
    Location
    UK
    Beans
    1,451
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: SQL Update query

    I think we need to know more about your tables, and how they connect together.

    Can you describe the structure of your database.

    at first glance - if you have tables called Electronics_01, Electronics_02 etc - you may well have a troublesome data base structure.
    Tony - Happy to try to help.
    Unless otherwise stated - all code posted by me is untested. Remember to Mark the Thread as Solved.
    Ubuntu user number # 24044 Projects : TimeWarp - on the fly Backups

  3. #3
    Join Date
    Sep 2007
    Location
    Malaysia
    Beans
    280
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: SQL Update query

    Quote Originally Posted by Tony Flury View Post
    I think we need to know more about your tables, and how they connect together.

    Can you describe the structure of your database.

    at first glance - if you have tables called Electronics_01, Electronics_02 etc - you may well have a troublesome data base structure.
    The tables represent 7 attributes of products:

    electronics
    media
    home and living
    health and beauty
    toys
    others
    sports

    each with categories which are basically 'child' of the 'mother'
    electronics is huge so its divided into 01-07, the rest are as is.

    I hope this helps.
    It's called a beta release for a reason. Not for noobs

  4. #4
    Join Date
    Jan 2010
    Location
    Sydney, Australia
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: SQL Update query

    You cant update multiple tables with one update statement. What you can do though is command Oracle to write your multiple update statements for you i.e.
    Code:
    select 'update '||table_name||' set categories = right(categories;len(categories)-2) where left(categories;2)=1;'
    from user_tab_columns
    where column_name = 'categories'
    and then paste it into sqlplus or something similar.
    “Progress is made by lazy men looking for easier ways to do things”
    — Robert A. Heinlein

  5. #5
    Join Date
    Sep 2007
    Location
    Malaysia
    Beans
    280
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: SQL Update query

    Quote Originally Posted by codemaniac View Post
    You cant update multiple tables with one update statement. What you can do though is command Oracle to write your multiple update statements for you i.e.
    Code:
    select 'update '||table_name||' set categories = right(categories;len(categories)-2) where left(categories;2)=1;'
    from user_tab_columns
    where column_name = 'categories'
    and then paste it into sqlplus or something similar.
    Hey! Thanks man! I'll give this a try.
    It's called a beta release for a reason. Not for noobs

  6. #6
    Join Date
    May 2008
    Location
    UK
    Beans
    1,451
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: SQL Update query

    Quote Originally Posted by psycho5 View Post
    The tables represent 7 attributes of products:
    each with categories which are basically 'child' of the 'mother'
    electronics is huge so its divided into 01-07, the rest are as is.
    Why divide it ? Too many columns or too many rows ? If you db engine can't handle large numbers of rows in your table - use a different db engine. If you have two many columns - then dividing it might be the right solution - but i would think of a better naming system.
    Last edited by Tony Flury; June 6th, 2012 at 12:55 PM.
    Tony - Happy to try to help.
    Unless otherwise stated - all code posted by me is untested. Remember to Mark the Thread as Solved.
    Ubuntu user number # 24044 Projects : TimeWarp - on the fly Backups

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •