SQL DELETE A COLUMN ORACLE code example

Example 1: delete column from table oracle PL SQL

ALTER TABLE table_name DROP COLUMN column_name;

Example 2: oracle drop column

ALTER TABLE my_table DROP COLUMN my_col;
-- To check if column exists before renaming it:
DECLARE
    l_cnt INTEGER;
BEGIN
    SELECT count(*) INTO l_cnt
    FROM dba_tab_columns		-- or all_tab_columns (depending on grants)
    WHERE owner = 'my_schema' AND table_name = 'my_table' 
    	AND column_name = 'my_col';
    IF (l_cnt = 1) THEN
        EXECUTE IMMEDIATE 'ALTER TABLE my_schema.my_table DROP COLUMN my_col';
    END IF;
END;

Example 3: oracle alter table delete column

alter table table_name drop column column_name;
alter table table_name drop (column_name1, column_name2);

Tags:

Sql Example