将新列添加到表中时,需要更改所有相关对象(短时间内)

时间:2019-05-19 19:04:03

标签: plsqldeveloper

我在表中有一个数据模型更改:添加一个新列。 但是存在4-5 procedure/pkg/views个表的所有列。 我们必须将该新列添加为proc/pkg/view中的新行。 我们如何实现这一目标?

应该是这样,我将输入作为新列提供,并且新列应像在所有proc/pkg/view中一样被添加到任何地方。

我尝试从Dba_source表中获取行号,并对pkg DBMS_METADATA.GET_DDL()进行了操作。但是格式不正确。使用了循环,在过程结束时也不需要添加新行。

代码:到目前为止已开发:


DECLARE
   PROC_v       VARCHAR2 (4000);
   l_sql        VARCHAR2 (9000 CHAR);
   V_NEW_COL    VARCHAR2 (10) := 'INST_NAME';
   v_byte       NUMBER (5);
   v_byte_st    NUMBER (5) := 1;
   v_blnk_cnt   NUMBER;
   v_line_ed    NUMBER (5);
   v_line_st    NUMBER (5);

   TYPE src_line IS TABLE OF NUMBER (5);

   l_src_line   src_line;
BEGIN
   SELECT line
     BULK COLLECT INTO l_src_line
     FROM DBA_SOURCE
    WHERE     OWNER = 'TEST'
          AND TYPE = 'PROCEDURE'
          AND NAME = 'PROCESS_EMP'
          AND (TEXT LIKE '%CURRENCY%' OR TEXT = 'END;'); --Currency is last column in the table

   v_line_st := 1;

   FOR j IN l_src_line.FIRST .. l_src_line.LAST
   LOOP
      DBMS_OUTPUT.put_line ('Line start' || v_line_st);
      v_line_ed := l_src_line (j);
      DBMS_OUTPUT.put_line ('Line End' || v_line_ed);

      SELECT COUNT (1)
        INTO v_blnk_cnt
        FROM DBA_SOURCE
       WHERE     OWNER = 'TEST'
             AND TYPE = 'PROCEDURE'
             AND NAME = 'PROCESS_EMP'
             AND text = CHR (10)
             AND LINE BETWEEN v_line_st AND v_line_ed;

      SELECT SUM (LENGTH (TEXT)) + v_blnk_cnt * 10
        INTO v_byte
        FROM DBA_SOURCE
       WHERE     OWNER = 'TEST'
             AND TYPE = 'PROCEDURE'
             AND NAME = 'PROCESS_EMP'
             AND LINE BETWEEN v_line_st AND v_line_ed;

      v_line_st := l_src_line (j) + 1;
      --dbms_output.put_line(v_line_st);
      DBMS_OUTPUT.put_line (v_byte);
      DBMS_OUTPUT.put_line (v_byte_st);

      PROC_v: =
         DBMS_LOB.SUBSTR (
            (DBMS_METADATA.get_ddl ('PROCEDURE', 'PROCESS_EMP')),
            v_byte,
            v_byte_st); -- to extract Source code and convert HUGECLOB into VARCHAR
      PROC_v := PROC_v || '                           ' || V_NEW_COL;
      /*CASE WHEN l_src_line.LAST THEN
      PROC_v:= PROC_v || CHR(10) ||'/';
      ELSE
      PROC_v:= PROC_v||'                           '|| V_NEW_COL;
      END CASE;*/ -- This part did not work
      DBMS_OUTPUT.put_line (PROC_v);

      v_byte_st := v_byte + v_byte_st;
   --execute immediate l_sql;
   END LOOP;
END;
/

我将输入作为新列,新列应添加到所有地方,例如在所有proc / pkg / view中。我需要稍后概括该解决方案

0 个答案:

没有答案