通过在SQLPLUS中执行存储过程将数据插入到Global临时表中

时间:2014-09-04 06:55:23

标签: plsql oracle-sqldeveloper sqlplus

我创建了一个存储过程。并且里面有一个全局临时表。 现在我通过将光标加密到局部变量来将数据插入到此表中。

create or replace PROCEDURE  "DEMO"  
(
PARM_YEAR IN NUMBER,    
PARM_PERIOD IN NUMBER, 
PARM_PERIOD_TYPE IN CHAR,
PARM_PERIOD_ROLL IN CHAR, 
PARM_TYPE IN VARCHAR2,
P_CURSOR IN OUT types.cursorType
)

IS

LOC_EXISTS NUMBER;

LOC_TYPE_PERIOD CHAR(2);
LOC_CURSOR_YEAR INTEGER;
LOC_CURSOR_PERIOD INTEGER;
LOC_CURSOR_TYPE_PERIOD CHAR(2 BYTE);
LOC_CURSOR_DEV_COPCL NUMBER(10,1); 
LOC_CURSOR_DIST_GRP  NUMBER(3,0);

CURSOR DIST_CHART IS


SELECT  X.YEAR , X.PERIOD, X.TYPE_PERIOD, X.COST AS DEV_COPCL

FROM
SMY_PRVDR_TYPE_PRVDR X;

BEGIN

/* Set Period type */

IF (PARM_PERIOD_TYPE = 'Q' AND PARM_PERIOD_ROLL = 'A') THEN
    LOC_TYPE_PERIOD := 'Q';
ELSE IF (PARM_PERIOD_TYPE = 'Q' AND PARM_PERIOD_ROLL = 'R') THEN
    LOC_TYPE_PERIOD := 'RQ';
ELSE IF (PARM_PERIOD_TYPE = 'M' AND PARM_PERIOD_ROLL = 'A') THEN
    LOC_TYPE_PERIOD := 'M';
ELSE
    LOC_TYPE_PERIOD := 'RM';


END IF;
END IF;
END IF;


 LOC_EXISTS := 0;
   SELECT 1 INTO LOC_EXISTS
     FROM ALL_TABLES
    WHERE TABLE_NAME LIKE '%DEMO1%';

   IF LOC_EXISTS = 1 THEN
    EXECUTE IMMEDIATE 'TRUNCATE TABLE DEMO1';
END IF; 


OPEN DIST_CHART;

LOOP 

  FETCH DIST_CHART INTO LOC_CURSOR_YEAR, LOC_CURSOR_PERIOD, LOC_CURSOR_TYPE_PERIOD, 
   LOC_CURSOR_DEV_COPCL;

EXIT WHEN DIST_CHART%NOTFOUND;

SELECT DIST_GRP(LOC_CURSOR_DEV_COPCL) INTO LOC_CURSOR_DIST_GRP FROM DUAL;


EXECUTE IMMEDIATE 'INSERT INTO DEMO1 VALUES  ('|| LOC_CURSOR_YEAR ||', '''|| 
LOC_CURSOR_PERIOD || ''', '''|| LOC_CURSOR_TYPE_PERIOD ||''', '|| LOC_CURSOR_DEV_COPCL 
||', '|| LOC_CURSOR_DIST_GRP || ')';

END LOOP;

CLOSE DIST_CHART;


 EXCEPTION
 WHEN NO_DATA_FOUND THEN
 LOC_EXISTS:=0;

  END;

问题是......     当我执行此存储过程到sql开发人员时,数据会成功插入到全局临时表中。

但是

当我在SQLPLUS中运行相同的执行命令时,过程成功运行,但数据未插入到全局临时表中。

GTT代码

CREATE GLOBAL TEMPORARY TABLE "ICUSER"."DEMO1" 
 (  "YEAR" NUMBER(4,0), 
    "PERIOD" NUMBER(2,0), 
    "TYPE_PERIOD" CHAR(2 BYTE), 
    "DEV_COPCL" NUMBER(*,1), 
    "DIST_GRP" NUMBER(3,0)
  ) ON COMMIT PRESERVE ROWS ;

0 个答案:

没有答案