Oracle從表的中文註釋建立中文視圖

CREATE OR REPLACE PROCEDURE CN_COMMENT_TO_CHINESE_VIEW(TABLENAME IN VARCHAR2)
  AUTHID CURRENT_USER IS--解決建立視圖權限不足的問題
  CURSOR TABLE_COMMENT IS
    SELECT * FROM USER_COL_COMMENTS WHERE TABLE_NAME = TABLENAME;
  RECORD_TABLE_COMMENT TABLE_COMMENT%ROWTYPE;
  CREATE_VIEW_SQL VARCHAR2(1000);
BEGIN
  CREATE_VIEW_SQL := 'create view ' || TABLENAME || '_CN as select ';
  FOR RECORD_TABLE_COMMENT IN TABLE_COMMENT LOOP
  
    CREATE_VIEW_SQL := CREATE_VIEW_SQL || RECORD_TABLE_COMMENT.COLUMN_NAME ||
                       ' as ' || RECORD_TABLE_COMMENT.COMMENTS || ' ,';
  
  END LOOP;
  CREATE_VIEW_SQL := RTRIM(CREATE_VIEW_SQL, ' ,');
  CREATE_VIEW_SQL := CREATE_VIEW_SQL || ' from ' || TABLENAME;
  DBMS_OUTPUT.PUT_LINE(CREATE_VIEW_SQL);
  EXECUTE IMMEDIATE CREATE_VIEW_SQL;
END;
相關文章
相關標籤/搜索