1. 데이터를 옮길 대상 테이블을 생성한다. : "TEMP_20130607" 라하자.;

 

CREATE TABLE TEMP_20130607
(
  TXDATE               VARCHAR2(8 BYTE)         NOT NULL,
  WRAP_ACCOUNT_NO      VARCHAR2(20 BYTE)        NOT NULL,
  WRAP_ACCOUNT_AMOUNT  VARCHAR2(4000 BYTE)
)
TABLESPACE APLUS_DATA_TS
PCTUSED    0
PCTFREE    10
INITRANS   1
MAXTRANS   255
STORAGE    (
            INITIAL          64K
            MINEXTENTS       1
            MAXEXTENTS       UNLIMITED
            PCTINCREASE      0
            BUFFER_POOL      DEFAULT
           )
LOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING;

 

2. FUNCTION 생성

 

CREATE OR REPLACE FUNCTION APLUSORA.FNC_LONG2CHAR (  
    ori_rowid        ROWID,  
    ori_column       VARCHAR2,
    ori_table        VARCHAR2  
)  
    RETURN VARCHAR
AS  
    longCont   VARCHAR2 (32767);  
    sqlQuery   VARCHAR2 (2000);
BEGIN  
    sqlQuery :=         'select ' || ori_column || ' from '|| ori_table ||         ' where rowid = '|| CHR (39)|| ori_rowid|| CHR (39);    EXECUTE IMMEDIATE sqlQuery                INTO longCont;        longCont := SUBSTR (longCont, 1, 4000);   RETURN longCont;END;
/

 

3. 실제 사용 쿼리

INSERT INTO TEMP_20130607
(TXDATE,WRAP_ACCOUNT_NO,WRAP_ACCOUNT_AMOUNT)
(SELECT TXDATE,WRAP_ACCOUNT_NO,FNC_LONG2CHAR(ROWID,'WRAP_ACCOUNT_AMOUNT','IFK_CUSTOMER') FROM IFK_CUSTOMER
WHERE  TXDATE = (SELECT MAX(TXDATE) DT FROM IFK_CUSTOMER)
AND     ACCOUNT_STATUS_DESC = '활동')