• 万能动态SQL


    CREATE OR REPLACE PROCEDURE p_test_renbing(i_from_table in varchar2,i_to_table in varchar2)
    IS
    V_COUNT NUMBER(10);
    V_RESULT NUMBER(19,2);
    V_COLUMN VARCHAR2(60);
    IS_TABLE NUMBER;
    BEGIN
      SELECT COUNT(*) INTO IS_TABLE FROM(SELECT table_name FROM user_tables t where t.TABLE_NAME=''||i_to_table||'');
      IF IS_TABLE>0 THEN
        EXECUTE IMMEDIATE 'DROP TABLE '||i_to_table||' ';
        EXECUTE IMMEDIATE 'CREATE TABLE '||i_to_table||' (ID NUMBER(19,2) )';
      ELSE
        EXECUTE IMMEDIATE 'CREATE TABLE '||i_to_table||' (ID NUMBER(19,2) )';
      END IF;
      EXECUTE IMMEDIATE 'INSERT INTO '||i_to_table||'(ID) VALUES(1)';  --初始化
      EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM (SELECT ACCOUNTNAME FROM '||i_from_table||' )' INTO V_COUNT;
      FOR COLUMN_ARRAY IN (SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = ''||i_from_table||'' ORDER BY COLUMN_NAME)
      LOOP
        V_COLUMN := COLUMN_ARRAY.COLUMN_NAME;
        EXECUTE IMMEDIATE 'ALTER TABLE '||i_to_table||' ADD('||V_COLUMN||' NUMBER(19,2))';
        --处理逻辑
        
        EXECUTE IMMEDIATE 'SELECT (SELECT COUNT(*) FROM '||i_from_table||' WHERE '||V_COLUMN||' IS NOT NULL)*100/'||V_COUNT||' FROM DUAL'
                          into V_RESULT
                           ;
        EXECUTE IMMEDIATE 'UPDATE '||i_to_table||' SET '||V_COLUMN||'='||V_RESULT||'';
      END LOOP;
      COMMIT;
    END p_test_renbing;
    
  • 相关阅读:
    LinuxDay10——文本处理工具sed
    设计模式原则----开放封闭原则
    模式设计原则----单一职责原则
    策略模式
    建模工具
    vs查看源码行数
    单例模式(Singleton Pattern)
    UML
    简单工厂模式(Simple Factory Pattern)
    winform ProgressBar
  • 原文地址:https://www.cnblogs.com/keyboardone/p/9837935.html
Copyright © 2020-2023  润新知