DELETE FROM DC2.OR_100 WHERE PV_USER = '815';
commit;
INSERT INTO DC2.OR_100 (PV_KEY,PV_USER,PV1,PV2,PV3,PV4,PV5,PV6,PV7,PV8,PV9,PV10,PV11,PV_L1,PV_L2)
SELECT LPAD(TO_CHAR(ROWNUM),20,0),TABLE_SELECT.* FROM (
SELECT '815'
 ,SUBSTRB(TO_CHAR(T001.DEN_DATE),1,100) AS A001
 ,SUBSTRB(TO_CHAR(T001.DEN_NO),1,100) AS A002
 ,SUBSTRB(TO_CHAR(T001.DEN_GYO_NO),1,100) AS A003
 ,SUBSTRB(T001.DEN_SYO_CD,1,100) AS A004
 ,SUBSTRB(T002.SYO_KANA,1,100) AS A005
 ,SUBSTRB(TO_CHAR(T001.TOTAL_QTY),1,100) AS A006
 ,SUBSTRB(TO_CHAR(T001.URI_TAN),1,100) AS A007
 ,SUBSTRB(TO_CHAR(T001.URI_KIN_ZEINUKI),1,100) AS A008
 ,SUBSTRB(TO_CHAR(T002.SHI_TANKA_YEN* T001.TOTAL_QTY),1,100) AS A009
 ,SUBSTRB(TO_CHAR(T001.URI_KIN_ZEINUKI- T001.TOTAL_QTY* T002.SHI_TANKA_YEN),1,100) AS A010
 ,SUBSTRB(TO_CHAR(DECODE( T001.URI_KIN_ZEINUKI,0,0,( T001.URI_KIN_ZEINUKI- T002.SHI_TANKA_YEN* T001.TOTAL_QTY)/ T001.URI_KIN_ZEINUKI*100)),1,100) AS A011 ,
SUBSTR(T001.DEN_DATE,1,80) AS A991 ,
SUBSTR(LPAD(TO_CHAR(NVL(TO_CHAR(T001.DEN_NO),0)),20,'0'),1,80) AS A992
FROM
 DC2.SAM_DENPYO T001
,DC2.SAM_SYOHIN T002
WHERE
 T001.DEN_KB(+)='2'
 AND T001.DEN_SYO_CD=T002.SYO_CD(+)
 AND T001.DEN_DATE BETWEEN '20100301' AND '20100310'
ORDER BY
  T001.DEN_DATE
 ,T001.DEN_NO
 ,T001.DEN_GYO_NO
) TABLE_SELECT
;
commit;
EXIT;


