批量修改数据库字段类型(ORACLE)

DECLARE
  CURSOR TEMP IS SELECT TABLE_NAME,COLUMN_NAME,DATA_LENGTH FROM USER_TAB_COLUMNS WHERE DATA_TYPE = 'VARCHAR2';
  STR  VARCHAR2(100) := '';
BEGIN
    FOR S IN TEMP LOOP
      STR := 'ALTER TABLE '||S.TABLE_NAME||' MODIFY('||S.COLUMN_NAME||' NVARCHAR2('||S.DATA_LENGTH||'))';
      DBMS_OUTPUT.PUT_LINE(STR);
    EXECUTE IMMEDIATE STR ;
    END LOOP;
END;

你可能感兴趣的:(ORACLE)