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 problem because some of our PHP Scripts are using the first column as an identifier (one Abstract Model with more than 100 other Models using this base object...)
See also:
For certain tables, you can change the order in which columns are displayed by clicking and dragging a column heading to a new position. In other tables, you can use the Reorder Columns dialog to change the position of the columns.
[FIRST | AFTER col_name]: FIRST or AFTER can be used to change a column's order. FIRST is used if we want to make our column the first column of a table, AFTER keyword is used if we're going to place our column after a specific column (col_name).
Instead, just right-click on the column headers, select 'Columns', and reorder as desired. Then move up the columns you want to see first… Put them in the order you want – it won't affect the database.
The position of the column cannot be specifically given. If you need a column list in a certain order, then use a view. SELECT * FROM table_x ; new_col will appear last.
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;
w
x
y
z
the simplest way to modify the logical order of the columns of a table is to rename your table and create a view with the "right" column positions:
ALTER TABLE your_table RENAME TO your_table_t;
CREATE VIEW your_table AS SELECT <columns in the right order> FROM your_table_t;
-- grants on the view (the same as the table)
GRANT ** TO ** ON your_table;
Your application will behave as if the columns were in the "right" position. You don't have to touch at the physical structure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With