Oracle存储过程问题

时间:2014-09-02 20:47:24

标签: sql oracle stored-procedures

我之前从未创建过存储过程。我看了很多,看到的任何模板都不适合我。

我需要一个存储过程。这将会一个接一个地运行一系列脚本(总共27个)。

下面是需要运行的字符串片段,但我不知道如何通过程序执行此操作,除非有替代方法。

    DELETE
  FROM EXTRACT_WORK_000;
-----------------------------------------------------------------step00a1b ITEMMASTER
DELETE
  FROM SITES_TO_BE_PROCESSED;
-----------------------------------------------------------------STEP00a1b_DAYCOUNT_APPEND_TO_EXTRACT_WORK_000
INSERT INTO EXTRACT_WORK_000 (LOC_ID, 
                              FSCL_YR_NUM, 
                              FSCL_WK_IN_YR_NUM, 
                              MAXOFACTIVITYDAYS) 
SELECT LOC_ID, 
       FSCL_YR_NUM, 
       FSCL_WK_IN_YR_NUM, 
       MAX(ACTIVITYDAYS) AS MAXOFACTIVITYDAYS 
  FROM EXTRACT_ORDER_DETAIL 
 GROUP BY LOC_ID, FSCL_YR_NUM, FSCL_WK_IN_YR_NUM;
-----------------------------------------------------------------step00a1c
INSERT INTO SITES_TO_BE_PROCESSED (LOC_ID, 
                                   FSCL_YR_NUM, 
                                   FSCL_WK_IN_YR_NUM) 
SELECT LOC_ID, 
       FSCL_YR_NUM, 
       FSCL_WK_IN_YR_NUM 
  FROM EXTRACT_ORDER_DETAIL 
 GROUP BY LOC_ID, FSCL_YR_NUM, FSCL_WK_IN_YR_NUM;
-----------------------------------------------------------------step00a2_APPEND_TO_PERIOD
INSERT INTO PERIOD_XREF (FSCL_WK_IN_YR_NUM, 
                         CALDR_YR_NUM, 
                         FSCL_PD_NUM) 
SELECT PERIOD_XTND.FSCL_WK_IN_YR_NUM, 
       PERIOD_XTND.CALDR_YR_NUM, 
       PERIOD_XTND.FSCL_PD_NUM 
  FROM PERIOD_XTND, 
       PERIOD_XREF 
 WHERE PERIOD_XTND.FSCL_PD_NUM = PERIOD_XREF.FSCL_PD_NUM (+) 
   AND PERIOD_XTND.CALDR_YR_NUM = PERIOD_XREF.CALDR_YR_NUM (+) 
   AND PERIOD_XTND.FSCL_WK_IN_YR_NUM = PERIOD_XREF.FSCL_WK_IN_YR_NUM (+) 
   AND (PERIOD_XREF.FSCL_WK_IN_YR_NUM IS NULL 
         OR PERIOD_XREF.CALDR_YR_NUM IS NULL 
         OR PERIOD_XREF.FSCL_PD_NUM IS NULL) 
 GROUP BY PERIOD_XTND.FSCL_WK_IN_YR_NUM, PERIOD_XTND.CALDR_YR_NUM, PERIOD_XTND.FSCL_PD_NUM;
-----------------------------------------------------------------step00a2a_periods_to_process
DELETE
  FROM PERIOD_TO_PROCESS;
-----------------------------------------------------------------step00a2bperiods_to_process
INSERT INTO PERIOD_TO_PROCESS (FSCL_YR_NUM, 
                               FSCL_WK_IN_YR_NUM) 
SELECT EXTRACT_ORDER_DETAIL.FSCL_YR_NUM, 
       EXTRACT_ORDER_DETAIL.FSCL_WK_IN_YR_NUM 
  FROM EXTRACT_ORDER_DETAIL 
 GROUP BY EXTRACT_ORDER_DETAIL.FSCL_YR_NUM, EXTRACT_ORDER_DETAIL.FSCL_WK_IN_YR_NUM;
-----------------------------------------------------------------STEP00a3_CASEFLOW_PARM
INSERT INTO CONTROL_RECORDS (LOC_ID, 
                             CASEFLOW_USPD_MAX) 
SELECT /*+ FULL(CONTROL_RECORDS) */ LOCATION.LOC_ID, 
       5 AS Expr1 
  FROM LOCATION, 
       CONTROL_RECORDS 
 WHERE LOCATION.LOC_ID = CONTROL_RECORDS.LOC_ID (+) 
   AND CONTROL_RECORDS.LOC_ID IS NULL 
 GROUP BY LOCATION.LOC_ID, 5;

1 个答案:

答案 0 :(得分:2)

Hii

这是一个创建存储过程的简单示例

CREATE OR REPLACE PROCEDURE PROC(
    P_LOC_ID            IN NUMBER,
    P_FSCL_YR_NUM       IN NUMBER,
    P_FSCL_WK_IN_YR_NUM IN NUMBER,
    P_MAXOFACTIVITYDAYS IN NUMBER )
AS
BEGIN
  -------------------------------STEP00a1b_DAYCOUNT_APPEND_TO_EXTRACT_WORK_000
  INSERT
  INTO EXTRACT_WORK_000 VALUES
    (
      P_LOC_ID,
      P_FSCL_YR_NUM,
      P_FSCL_WK_IN_YR_NUM,
      P_MAXOFACTIVITYDAYS
    ) ;
END PROC;

你可以用你的所有陈述来做这件事

我希望我能帮助你

度过愉快的一天