Oracle move column to the first position

后端 未结 8 2024
借酒劲吻你
借酒劲吻你 2021-01-17 23:39

Is there any way to move an column in an Oracle table from last to first position? Someone has dropped the ID column, and recreated it. So now it is at the end, which is a p

相关标签:
8条回答
  • 2021-01-18 00:07

    Recreating the table (via rename/temporary table so you don't lose your data) is the only way I know of.

    I don't believe it's possible to simply change the column order.

    0 讨论(0)
  • 2021-01-18 00:13

    I use this all the time:

    ALTER TABLE MOVE COLUMN column_name TO ordinal_position;
    
    0 讨论(0)
  • 2021-01-18 00:15

    In Oracle 12c it is now easier to rearrange columns logically. It can be achived by making column invisible/visible.If you change a invisible column to visible , the column will appear last in the odering.

    Consider Using Invisible Columns

    Create wxyz table:

    CREATE TABLE t ( w INT,
    y VARCHAR2, z VARCHAR2, x VARCHAR2

    );

    rearrange the x column to the middle:

    ALTER TABLE wxyz MODIFY (y INVISIBLE, z INVISIBLE); ALTER TABLE wxyz MODIFY (y VISIBLE, z VISIBLE);

    DESCRIBE wxyz;

    Name

    w

    x

    y

    z

    0 讨论(0)
  • 2021-01-18 00:16

    You might like to access your table via a view, so you can painlessly rearrange the logical order if it's important to the application technology.

    0 讨论(0)
  • 2021-01-18 00:16

    Not possible to move column in oracle. It will be created in the last position. If anyone wanted so either view needs to be created or new table need to be created

    0 讨论(0)
  • 2021-01-18 00:19

    If there isn't a ton of data/columns, you could simply rename the columns in the order you want. Then just delete * from 'your table name here'. This was a good solution for me since I hadn't inserted many records yet.

    0 讨论(0)
提交回复
热议问题