Good afternoon!
I need to change a data type of my entire schema, I have varchar2
80, and I would like to change it to 100, but this all at once ... is it possible?
Good afternoon!
I need to change a data type of my entire schema, I have varchar2
80, and I would like to change it to 100, but this all at once ... is it possible?
-
- LIST THESE COLUMNS
SELECT *
FROM USER_TAB_COLUMNS
WHERE DATA_TYPE = 'VARCHAR2'
AND DATA_LENGTH = 80
- MOUNTING A SCRIPT
SELECT 'ALTER TABLE ' || TABLE_NAME || ' MODIFY ' || COLUMN_NAME || ' ' || DATA_TYPE || '(100)'
FROM USER_TAB_COLUMNS
WHERE DATA_TYPE = 'VARCHAR2'
AND DATA_LENGTH = 80
- PERFORMING
BEGIN
FOR R IN (SELECT 'ALTER TABLE ' || TABLE_NAME || ' MODIFY ' || COLUMN_NAME || ' ' || DATA_TYPE || '(100)'
FROM USER_TAB_COLUMNS
WHERE DATA_TYPE = 'VARCHAR2'
AND DATA_LENGTH = 80) LINHA
LOOP
EXECUTE IMMEDIATE (R.LINHA);
END LOOP;
END;
- generalizing
CREATE OR REPLACE PROCEDURE ALTERA_TAMANHO(POWNER IN CHAR,
PTAMDE NUMBER,
PTAMPARA NUMVER) IS
BEGIN
FOR R IN (SELECT 'ALTER TABLE ' OWNER || '.' || TABLE_NAME || ' MODIFY ' || COLUMN_NAME || ' ' || DATA_TYPE || '(' || PTAMPARA || ')'
FROM DBA_TAB_COLUMNS
WHERE DATA_TYPE = 'VARCHAR2'
AND DATA_LENGTH = PTAMDE) LINHA
LOOP
EXECUTE IMMEDIATE (R.LINHA);
END LOOP;
END;
- TYPE OF OPERATION THAT RECOMMENDS A SAVE BEFORE AND IF POSSIBLE EXECUTION BEFORE --THE TEST ENVIRONMENT