Skip to main content
Adicionada a palavra reservada IMMEDIATE.
Fonte Link

Se você estiver utilizando PL-SQL no seu script, pode resolver desta maneira:

DECLARE
  CURSOR C_CONSTRAINT IS
    SELECT CONSTRAINT_NAME 
      FROM user_cons_columns 
     WHERE COLUMN_NAME = 'CANCELAMENTO' 
       AND table_name = 'NAVIO';       
  V_CONSTRAINT C_CONSTRAINT%ROWTYPE;       
BEGIN    
    OPEN C_CONSTRAINT;
    LOOP
      FETCH C_CONSTRAINT INTO V_CONSTRAINT;
      EXIT WHEN C_CONSTRAINT%NOTFOUND;
      EXECUTE IMMEDIATE 'ALTER TABLE NAVIO DROP CONSTRAINT'CONSTRAINT ' || V_CONSTRAINT.CONSTRAINT_NAME;
    END LOOP;
END;

Se você estiver utilizando PL-SQL no seu script, pode resolver desta maneira:

DECLARE
  CURSOR C_CONSTRAINT IS
    SELECT CONSTRAINT_NAME 
      FROM user_cons_columns 
     WHERE COLUMN_NAME = 'CANCELAMENTO' 
       AND table_name = 'NAVIO';       
  V_CONSTRAINT C_CONSTRAINT%ROWTYPE;       
BEGIN    
    OPEN C_CONSTRAINT;
    LOOP
      FETCH C_CONSTRAINT INTO V_CONSTRAINT;
      EXIT WHEN C_CONSTRAINT%NOTFOUND;
      EXECUTE 'ALTER TABLE NAVIO DROP CONSTRAINT' || V_CONSTRAINT.CONSTRAINT_NAME;
    END LOOP;
END;

Se você estiver utilizando PL-SQL no seu script, pode resolver desta maneira:

DECLARE
  CURSOR C_CONSTRAINT IS
    SELECT CONSTRAINT_NAME 
      FROM user_cons_columns 
     WHERE COLUMN_NAME = 'CANCELAMENTO' 
       AND table_name = 'NAVIO';       
  V_CONSTRAINT C_CONSTRAINT%ROWTYPE;       
BEGIN    
    OPEN C_CONSTRAINT;
    LOOP
      FETCH C_CONSTRAINT INTO V_CONSTRAINT;
      EXIT WHEN C_CONSTRAINT%NOTFOUND;
      EXECUTE IMMEDIATE 'ALTER TABLE NAVIO DROP CONSTRAINT ' || V_CONSTRAINT.CONSTRAINT_NAME;
    END LOOP;
END;
Fonte Link

Se você estiver utilizando PL-SQL no seu script, pode resolver desta maneira:

DECLARE
  CURSOR C_CONSTRAINT IS
    SELECT CONSTRAINT_NAME 
      FROM user_cons_columns 
     WHERE COLUMN_NAME = 'CANCELAMENTO' 
       AND table_name = 'NAVIO';       
  V_CONSTRAINT C_CONSTRAINT%ROWTYPE;       
BEGIN    
    OPEN C_CONSTRAINT;
    LOOP
      FETCH C_CONSTRAINT INTO V_CONSTRAINT;
      EXIT WHEN C_CONSTRAINT%NOTFOUND;
      EXECUTE 'ALTER TABLE NAVIO DROP CONSTRAINT' || V_CONSTRAINT.CONSTRAINT_NAME;
    END LOOP;
END;