DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: remove first 3 characters from table name

  1. #1
    Join Date
    Dec 2002
    Posts
    28

    remove first 3 characters from table name

    I run a similar command on many tables where the table name differs but the structure is the same i.e U##table name = table name minus the first 3 characters U##. Is there a simpler way to extract all tables owned by user a where the table name is like U## and the upper table value is the U## table table minus the first 3 characters.

    UPDATE cars
    SET U##model_no = UPPER(model_no);


    UPDATE trucks
    SET U##license_no = UPPER(license_no);

  2. #2
    Join Date
    Mar 2001
    Location
    Reading, U.K
    Posts
    598
    Do you need to extract the first three characters...
    from U##USER
    to USER

    Use SUBSTR('U##USER', 1, 3)

    or

    SELECT table_name FROM ALL_TABLES WHERE owner LIKE 'U##%';
    Cheers!
    OraKid.

  3. #3
    Join Date
    Dec 2001
    Location
    UK
    Posts
    1,684
    Hi.

    In your question you are talking about manipulating table_names, but in your examples you seem to be manipulating column names. The following code will perform the actions shown in your examples:


    BEGIN
    FOR c IN (SELECT table_name, column_name
    FROM user_tab_columns
    WHERE column_name like 'U##%')
    LOOP
    EXECUTE IMMEDIATE 'UPDATE ' || c.table_name ||
    ' SET ' || c.column_name || ' = UPPER(' || SUBSTR(c.column_name, 4) || ')';
    END LOOP;
    END;
    /


    If I've missed the point please clarify the question and I'll have another go

    Cheers
    Last edited by TimHall; 09-12-2003 at 04:31 AM.
    Tim...
    OCP DBA 7.3, 8, 8i, 9i, 10g, 11g
    OCA PL/SQL Developer
    Oracle ACE Director
    My website: oracle-base.com
    My blog: oracle-base.com/blog

Posting Permissions

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


Click Here to Expand Forum to Full Width