Add the string at the end of the column name

Hi all

I wonder whether it is possible or not. I created a similar table to another table to help-


create table table_name in select * from table_name1;
Now, I want to differentiate the name of the column of the previous table column names. I want to add E at the end of all column names. Is it possible using sql Command in sql or Toad workshop without doing it manually as I have more than 100 columns in this table?



Thanks in advance.



Kind regards



Pascal M

Hello

Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
Connected as hr

SQL> create table test_1(col1 number, col2 varchar2(30));

Table created

SQL> create table test_2 as select * from test_1;

Table created

SQL> desc test_2;
Name Type         Nullable Default Comments
---- ------------ -------- ------- --------
COL1 NUMBER       Y
COL2 VARCHAR2(30) Y                         

SQL>
SQL> DECLARE
  2     v_table_name USER_TAB_COLUMNS.TABLE_NAME%TYPE := 'TEST_2';
  3     c_column_suffix CONSTANT VARCHAR2(1) := 'E';
  4  BEGIN
  5     FOR REG IN (SELECT UTC.COLUMN_NAME
  6                   FROM USER_TAB_COLUMNS UTC
  7                  WHERE utc.TABLE_NAME = v_table_name) LOOP
  8        EXECUTE IMMEDIATE 'ALTER TABLE ' || v_table_name || ' RENAME COLUMN ' ||
  9                          reg.column_name || ' TO ' ||
 10                          substr(reg.column_name,
 11                                 1,
 12                                 29) || c_column_suffix;
 13     END LOOP;
 14  END;
 15  /

PL/SQL procedure successfully completed

SQL> desc test_2;
Name  Type         Nullable Default Comments
----- ------------ -------- ------- --------
COL1E NUMBER       Y
COL2E VARCHAR2(30) Y                         

SQL>

Kind regards

Tags: Database

Similar Questions

  • Can I add the column to the playlist to my music list in itunes?

    I consult my entire list of music, and I'd like to know what category of playlist I created that the song is in. Can I add the column to the playlist to my music list?

    I use an older iTunes. You cannot create a column for playlists, but you can right click on individual tracks and is one of the elements to display the items in the lists of reading in which it is contained.

  • Display the name of the tag as the column name and the value in the tag as a row of data from the input string.

    Hi Forum members,

    I am looking for a query display the name of the tag as the column name and the value in the tag as a row of data.

    I have to print the values within the tag to a file by choosing the value of the flags. the sequence of the tags will vary each time, as the tag name will change dynamically.

    So here is the example of input data and the expected output. The string in the text column must be separated as the column names and values.

    Input data
    Select 1 as seqno,' < > 0210A 50 4f < / 4f > < 5f20 > TEST CARD 16 < / 5f20 > < 5f2a > < / 5f2a > < 82 > 1 c 00 < / 82 > ' double text


    Output:

    Seqno 4f 5f20 5f2a 82
    0210A 50 16 1 00 TEST CARD 1

    Please help me by providing your entries on this.

    We use the version of Oracle 11.2.

    Note: This is not the XML string

    Thank you

    Shree

    with

    data in the form of

    (select 1 as seqno,'<4f>0210 A 50<5f20>TEST CARD 16<5F2a><82>00 1' text of all the double union)

    Select 2 as seqno,'XYZ<4F>0210 A 50<5f20>TEST CARD 16<5f2a><82>00 1' text of all the double union

    Select 3 as seqno,'<4f>0210 A 50<5f20>TEST CARD 16<5F2A><82>1 00XYZ ' text of all the double union

    Select option 4 as seqno,'<4F>0210 A 50<5F20>TEST CARD 16<5f2A><82>1 00XYZ' double text

    )

    Select d.seqno, x.*

    d the data,

    XMLTable ('/ root')

    by the way xmltransform (xmltype ('': replace (replace (text,'<><>'),)))

    XmlType (q'~http://www.w3.org/1999/XSL/Transform "version ="1.0"> ")

                                                     

                                                       

                                                         

                                                       

                                                     

                                                     

                                                       

                                                         

                                                       

                                                     

    ~'

    )

    )

    path of columns '4f' varchar2 (10) "tag4f."

    path of "5f20' varchar2 (30)"tag5f20. "

    path of '5f2a' varchar2 (10) "tag5f2a."

    path of varchar2 (10) "82" "tag82.

    ) x


    SEQNO 4f 5f20 5f2a 82
    1 0210A 50 16 TEST CARD - 1 00
    2 0210A 50 16 TEST CARD - 1 00
    3 0210A 50 16 TEST CARD - 1 00
    4 0210A 50 16 TEST CARD - 1 00

    with

    data in the form of

    (select 1 as seqno,'<4f>0210 A 50<5f20>TEST CARD 16<5F2a><82>00 1' text of all the double union)

    Select 2 as seqno,'XYZ<4F>0210 A 50<5f20>TEST CARD 16<5f2a><82>00 1' text of all the double union

    Select 3 as seqno,'<4f>0210 A 50<5f20>TEST CARD 16<5F2A><82>1 00XYZ ' text of all the double union

    Select option 4 as seqno,'<4F>0210 A 50<5F20>TEST CARD 16<5f2A><82>1 00XYZ' double text

    ),

    Chopper (seqno, Key, value, String) as

    (select seqno,

    regexp_substr (text,'<(.+?)>', 1, 1, null, 1),

    regexp_substr (Text,'>(.*?))

    regexp_substr (text,'<.+?>. *? ) (.*) $', 1, 1, null, 1). » <>'

    from the data

    Union of all the

    Select seqno,

    regexp_substr (String,'<(.+?)>', 1, 1, null, 1),

    regexp_substr (String,'>(.*?))

    regexp_substr (String,'<.+?>. *? ) (.*) $', 1, 1, null, 1)

    Chopper

    where regexp_substr (string,'<(.*?)>', 1, 1, null, 1) is not null

    )

    Select '4f', seqno, '5f2a', '82', '5f20.

    of (seqno, lower (key) select key, value)

    Chopper

    )

    Pivot (max (value) for key in ('4f' as '4f', '5f20' as '5f20', '5f2a' as '5f2a', "82" as "82"))

    Concerning

    Etbin

  • How to add the chapter name and page not for reference

    Hello

    How to add the chapter name and page not for reference in indesign CS6.

    Thank you

    Please try variable notion of text

  • Add the short name field for specifications in the XSL file

    Hello

    I'm looking for help to see if it is possible to add the short name for the inputs and spare field in a specification of Formulation in the XSL file. If it is possible, how can I do this?

    Thanks in advance.

    Well, CSS is much more locked, by design. So it's a little (or maybe a lot) more complicated.

    Also remember that if you change the CSS schema, and you use the web service contract that we provide for the CSS message, then the approach will probably be different. This means that the web service contract would not support additional XML nodes, unless he expects them.

    If you do not use our web service contract, then you could make changes in the XML in a different way. Can you elaborate on how you receive the message in CSS?

    Basically, if you use the web service method, then you will probably need to use the ExportExtensions method, which is documented in the CSS guide. ExportExtensions allows you to include xml code in a node specific extensibility through managers, which are classes that you configure in the config\extensions\exportExtensions.xml configuration file. It is currently the custom how sections are included in syndication. So you can add your own XML nodes and call you a custom class to provide additional data that you need.

  • How to add the column to Adobe flex mxml or actionsctpt mx:DataGrid?

    I have the simple mxml code

    <mx:DataGrid id="DGG"
                
    editable="true">
       
    <mx:dataProvider>
           
    <mx:Object scheduledDate="4/1/2006"/>
       
    </mx:dataProvider>
    </mx:DataGrid>
    <mx:Button id="SetBut"
              
    label="Set Array as Data Provider"
              
    click="SetDP(); AddBut.visible = true;"
              
    x="100.5"
              
    y="164"
              
    width="211"/>
    <mx:Button id="AddBut"
              
    label="Add a column!"
              
    click="AddCol();"
              
    x="100.5"
              
    y="194"
              
    width="211"
              
    visible="false"/>
    <mx:Script>
        <![CDATA[
            import mx.controls.dataGridClasses.DataGridColumn;
            import mx.collections.ArrayCollection;

            [Bindable]
            public var MyAC:ArrayCollection=new ArrayCollection([{scheduledDate: "4/1/2006", homeTeam: "Chester Bucks"}]);

            public function SetDP():void
            {
                DGG.dataProvider=MyAC
            }

            public function AddCol():void
            {
                MyAC.addItem({scheduledDate: "4/5/2007", homeTeam: "Long Valley Hitters", Umpire: "Amanda Hugenkis"});
                DGG.columns.push(new DataGridColumn("Umpire"));
            }
        ]]>
    </mx:Script>

    I want to add lines to my datagrid table how do such thing?

    How to add the column to Adobe flex mxml or actionsctpt mx:DataGrid?

    (You can place this code in a Flash or AIR application - it compiles without error, but will not add any columns =)

    Change this:

    public void SetDP (): void
    {
    DGG.dataProvider = MyAC
    MyAC.addItem ({scheduledDate: "05/04/2007", homeTeam: "long hitters Valley", umpire: "Amanda Hugenkis"});
    }
               
    public void AddCol (): void
    {
    var dgc:DataGridColumn = new DataGridColumn ("Umpire");
    var ca:Array = DGG.columns;
    CA.push (DGC);
    DGG.columns = ca;
    }

    Dany

  • Display the column name of the column more recently updated

    I wonder if it is possible to display the name of the column in the column most recently updated in a table.

    Example:

    Emp table

    Name

    Height

    Weight

    Age

    Update_Date

    Update_Column

    Original record (03/20/14)

    Name size weight Age Update_date Update_Column

    John                                                 03/20/14          Name

    Then someone comes and update the height on 22/03/14:

    Name size weight Age Update_date Update_Column

    John 5'9 03/22/14 height

    And the Update_date and the Update_column would change again if someone came and put a value for the age. And so on.

    Is this possible?

    Also, if the above is possible, would it be possible to display the name of extreme right column if a user updated several columns at the same time?

    Example:

    User updates the sub-folder:

    Name size weight Age Update_date Update_Column

    John 5'9 03/22/14 height

    And adds weight and age at the same time on 24-03-14:

    Name size weight Age Update_date Update_Column

    John 5'9 150 31 03/24 / 14

    The Update_Column would display age because it is the furthest to the right. (Think by reading from left to right, the column that has been updated if the extreme right)

    So to sum things, I need to be able to display Updated_date (which will be the date of the day when the record is the last updated) and Updated_Col (which is the column name of the column was last updated, and if multiple columns are updated then display that value has been updated last in)

    I hope that the examples help to clarify things.

    Thank you

    Steven

    I think I found a solution.

    delimiter //
    create table a (
      id int (10) unsigned auto_increment,
      a int(10),
      b int(10),
      update_date datetime NULL,
      update_column varchar(16) NULL,
      primary key (id)
    )//

    create trigger bu_a before update on a for each row begin
      set NEW.update_date = NOW();
      set NEW.update_column = NULL;
      -- you need to start with the rightmost column if you want
      -- that matched with the highest priority
      if OLD.b != NEW.b then
       set NEW.update_column = "b";
      elseif OLD.a != NEW.a then
       set NEW.update_column = "a";
      end if;
    end //

    TEST

    insert into a (id,a,b) values (1,1,1), (2,1,1), (3,1,1), (4,1,1)[
    update a set b = 2 where id = 2;
    update a set a = 2 where id = 3;
    update a set a = 2 where id = 4;
    update a set b = 2 where id = 4;
    select * from a;

    DISPLAY

    ID  A   B   UPDATE_DATE                    UPDATE_COLUMN
    1   1   1   (null)                          (null)
    2   1   2   March, 24 2014 23:22:33+0000      b
    3   2   1   March, 24 2014 23:22:33+0000      a
    4   2   2   March, 24 2014 23:22:33+0000      b

  • Necessary emergency with a request: fill date of prior art on the column name

    Hello

    Can you please help me with the query. I would be grateful for your time and your help.

    I have the query and the following output. Basically, the query selects a date, a table and counties received documents based on the current date, day-1, - 2 days-, 3 days-4 days-5 days and especially 5 days. It's the query I wrote. Now the requirement has slightly changed and described below.

    Current query:

    SELECT SUM (CASE WHEN TRUNC (SYSDATE) TRUNC ( )File_Date() = 0 PUIS 1 AUTRE 0 FIN) Zéro ,

    SUM (CASE WHEN TRUNC (SYSDATE) TRUNC ( )File_Date() = 1 PUIS 1 AUTRE 0 FIN)   One ,

    SUM (CASE WHEN TRUNC (SYSDATE) TRUNC ( )File_Date() = 2 PUIS 1 AUTRE 0 FIN) Two ,

    SUM (CASE WHEN TRUNC (SYSDATE) TRUNC ( )File_Date() = 3 ALORS 1 SINON 0 FIN) Trois ,

    SUM (CASE WHEN TRUNC (SYSDATE) TRUNC ( )File_Date() = 4 PUIS 1 AUTRE 0 FIN) Quatre ,

    SUM (BOX WHEN TRUNC (SYSDATE) TRUNC (File_Date) = 5 THEN 1 ELSE 0 END) Five ,

    SUM (CASE WHEN TRUNC (SYSDATE) TRUNC ( )File_Date() > 5 PUIS 1 AUTRE 0 FIN) OverFive ,

    COUNTY (*) Total

    DE DOCUMENT_TABLE

    OUTPUT:

    Zero

    One

    Two

    Three

    Four

    Five

    More than five

    Total

    3

    6

    3

    6

    10

    50

    100

    178

    Now the desired output:

    The column name must be the date, for example the column name, we're Sysdate, two column name is Sysdate-1 day and the result would look like:

    OUTPUT:

    17/12/2014

    16/12/2014

    15/12/2014

    14/12/2014

    13/12/2014

    12/12/2014

    More than five

    Total

    3

    6

    3

    6

    10

    50

    100

    178

    Hi, just try below as you say it's urgent

    Select sysdate, sysdate-1, sysdate-2, sysdate-3,-4, etc of daul sysdate

    Union

    your query

    (you must ensure for the same type of data)

    are you using oracle report or just in the sql query. If the reports, then you can manage very easily with the introduction of a formula column.

  • Select the column name when the value = something

    Is there a way to select the column name when there is a specific value in it?

    As follows:

    create table (abc123)

    COLUMN1 VARCHAR2 (50).

    COLUMN2 VARCHAR2 (50).

    Column3 varchar2 (50)

    );

    insert into abc123 values ('yes', 'Yes', 'No');

    insert into abc123 values ('no', 'Yes', 'No');

    INSERT INTO ABC123 VALUES ('no ',' no', 'No');

    insert into abc123 values ('yes', 'Yes', 'Yes');

    SELECT CASE WHEN COLUMN1 = 'Yes' THEN - the name of the column would be here somehow?

    WHEN COLUMN2 = 'Yes' THEN - the name of the column would be here somehow?

    WHERE Column3 = 'Yes' THEN - the name of the column would be here somehow?

    Another null

    finish as abc123 columnname

    final results for the just Column1 would be:

    COLUMN1

    NULL VALUE

    NULL VALUE

    COLUMN1

    I'm not sure what I use to get the name of column in there

    Thank you.

    Hello

    708631 wrote:

    Is there a way to select the column name when there is a specific value in it?

    As follows:

    create table (abc123)

    COLUMN1 VARCHAR2 (50).

    COLUMN2 VARCHAR2 (50).

    Column3 varchar2 (50)

    );

    insert into abc123 values ('yes', 'Yes', 'No');

    insert into abc123 values ('no', 'Yes', 'No');

    INSERT INTO ABC123 VALUES ('no ',' no', 'No');

    insert into abc123 values ('yes', 'Yes', 'Yes');

    SELECT CASE WHEN COLUMN1 = 'Yes' THEN - the name of the column would be here somehow?

    WHEN COLUMN2 = 'Yes' THEN - the name of the column would be here somehow?

    WHERE Column3 = 'Yes' THEN - the name of the column would be here somehow?

    Another null

    finish as abc123 columnname

    final results for the just Column1 would be:

    COLUMN1

    NULL VALUE

    NULL VALUE

    COLUMN1

    I'm not sure what I use to get the name of column in there

    Thank you.

    Thanks for posting the CREATE TABLE and INSERT for the sample data.

    Don't forget to post the exact results you want from these sample data.  If the results depend on the parameters you want to pass a run time, then give a few different examples, with the the desired results of each.

    You can hardcode the values you want, such as the column names in a query.  For example:

    SELECT CASE WHEN column1 = 'Yes' THEN 'Column1' END like y1

    CASE WHEN column2 = 'Yes' THEN 'Column2' END like y2

    CASE WHEN Column3 = 'Yes' THEN 'Column2' END like y3

    , a. *-If wanted

    Of abc123 one

    ;

  • Can I use * and the list of the column names in a select query

    PLSQL again.  Can I use * and the list of the column names in a select query, i.e. Select *, col1, col2 from Mytable.  When I do that my questions tend to the bomb.  Can do in other databases.

    Thank you

    Mike

    Hi, Mike,.

    If there is something else in the more SELECT clause *, then * must be qualified with a table name or alias.

    For example:

    SELECT Mytable. *, col1, col2

    FROM MyTable;

  • How to move the column label to the right of the column name in the project Panel

    How does a gesture the column label in the project panel to the left of the name to the right of the column name column... machines windows can do this while the macbook pro (3 of 3) this is impossible...

    I still want the opportunity to bring him here where he was.

  • How to export data to excel that has 2 tables with the same number of columns and the column names?

    Hi everyone, yet once landed upward with a problem.

    After trying many things to myself, finally decided to post here...

    I created a form in form builder 6i in which clicking on a button, the data gets exported to the excel sheet.

    It works very well with a single table. The problem now is that I cannot do the same with 2 tables.

    Because the tables have the same number of columns and the columns names.

    Here are the 2 tables with column names:

    Table-1 (MONTHLY_PART_1) Table-2 (MONTHLY_PART_2)
    SL_NOSL_NO
    MODELMODEL
    END_DATEEND_DATE
    U-1U-1
    U-2U-2
    U-4U-4
    ..................
    ..................
    U-20U-20
    U-25U-25

    Given that the tables have the same column names, I get the following error :

    402 error at line 103, column 4

    required aliases in the SELECT list of the slider to avoid duplicate column names.

    So how to export data to excel that has 2 tables with the same number of columns and the column names?

    Should I paste the code? Should I publish this query in 'SQL and PL/SQL ' Forum?

    Help me with this please.

    Thank you.

    Wait a second... is this a kind of House of partitioning? Shouldn't it is a union of two tables instead a join?

    see you soon

  • Rename the column name of the view

    Suppose I have an employee of the table with the column name. Now, I want to make a view of the employee to the table with the name of the First_name and Last_name column. Is this possible?

    You can also use aliases in the view definition:

    CREATE VIEW employee_view (
      first_name,
      last_name
    ) AS
      SELECT first,
             last
      FROM   employee;
    

    However, you can rename a column in a view. You would have to DROP and CREATE or to CREATE or REPLACE.

    Concerning
    Peter

  • use a (selection list) element as the column name in the select?

    I have a popup LOV key based on a select (dynamic list of values)
    I want to display and return - select columns in the select statement to be determined by another list.

    I tried:

    Select distinct: P133_COLUMN d: P133_COLUMN r
    FROM MyTable

    but then I don't you the value of: P133_COLUMN... so if: P133_COLUMN is 'EMPNO' LOV popup displays the text "EMPNO" and referred the text 'EMPNO', not the empno column values...

    If I change

    Select distinct P133_COLUMN d & P133_COLUMN r
    FROM MyTable

    I get the standard
    "LOV query is not valid, a display and a return value is needed, the column names must be different. If your query contains a query online, the first CLAUSE in the SQL statement must not belong to the query online. »

    Anyone?

    Also, I was wondering if it is possible to set the textfield object in the item popup LOV to accept the input text directly as well as the selected value, but the first part of the question is the important part.

    Concerning

    Andreas

    Hello Andy,

    Change your LOV to something like this:
    'select' return. : P133_COLUMN |' d, ' | : P133_COLUMN | "as r from myTable";

    Greetings,
    Roel

    http://roelhartman.blogspot.com/

  • Anyway, to remove the column names in the result of the query of SQLPLUS

    Hello

    I am using sqlplus to run a script that returns results with the column names.

    Anyway is to omit the names of columns in the result of the sqlplus query?

    I would like to have only results with their column names in the output.

    Thanks in advance!

    Hello

    Maybe your LINES (IZE) is not defined?

    SCOTT>set lines 130
    SCOTT>select status, machine, module
      2    from v$session
      3   where upper(username) = 'SCOTT';
    
    STATUS   MACHINE                                                          MODULE
    -------- ---------------------------------------------------------------- ------------------------------------------------
    INACTIVE PFAE3\VPC4894-03                                                 TOAD 9.7.2.5
    ACTIVE   PFAE3\VPC4894-03                                                 SQL*Plus
    
    2 rows selected.
    
    SCOTT>
    

    As an alternative to the linesize parameter, you can format the columns:

    SCOTT>set lines 80
    SCOTT>col status for a8
    SCOTT>col machine for a30
    SCOTT>col module for a30
    SCOTT>select status, machine, module
      2    from v$session
      3   where upper(username) = 'SCOTT';
    
    STATUS   MACHINE                        MODULE
    -------- ------------------------------ ------------------------------
    INACTIVE PFAE3\VPC4894-03               TOAD 9.7.2.5
    ACTIVE   PFAE3\VPC4894-03               SQL*Plus
    
    2 rows selected.
    
    SCOTT>
    

    Concerning
    Peter

Maybe you are looking for

  • How to copy the address bar

    Once upon a time in a browser, there was an EDICT to copy the link into the address bar. I would like to have this feature because it is difficult to highlight the address so it can be copied to the generic copy. I searched mozilla for this function

  • RAM compatibility?

    Hi there everyone in that I currently have 8 GB (2 x 4) Ram my iMac late 2014 5 k and I want to upgrade. I read on the forums that if I buy 2x8gb ram, I'll be able to add them to my current 8 GB giving me a total of 24 GB of RAM. Is this correct? Sho

  • HP photosmart 8250 test page has color photos and cyan lines

    I have a HP photosmart 8250 which had a paper jam, and then I got an error message that says the print carriage was stuck and deserved to be deleted. I set myself with the help of HP printed tips on this Web site. But now, with a test print, it shows

  • Can I use the old sndrec32.exe (comes with XP) in Windows 7 and Vista?

    SNDREC32.exe was demand for Sound Recorder in XP and it changed to SoundRecorder.exe in Vistra and Windows 7. The new version will allow to record more than one minute of audio, but (as with most things in life when something is given something is re

  • Failure of keyboard of blackBerry Smartphones

    My BlackBerry Bold 9780 malfunction keyboard, when I try to type a letter at random times, he will give me two to four letters. Not random letters, but the letter I type, for example "aaaa". Sometimes the keyboard stops working for at least one or tw