DELETE FROM DC2.OR_100 WHERE PV_USER = '348';
commit;
INSERT INTO DC2.OR_100 (PV_KEY,PV_USER,PV1,PV2,PV3,PV4,PV5,PV6,PV7,PV8,PV9,PV10,PV_L1,PV_L2)
SELECT LPAD(TO_CHAR(ROWNUM),20,0),TABLE_SELECT.* FROM (
SELECT '348'
 ,SUBSTRB(CASE WHEN T007.NENGETSU=' ' OR T007.NENGETSU IS NULL THEN ' ' ELSE SUBSTR(T007.NENGETSU,1,4) || '/' || SUBSTR(T007.NENGETSU,5,2) END,1,100) AS A001
 ,SUBSTRB(CASE WHEN T001.DEN_DATE=' ' OR T001.DEN_DATE IS NULL THEN ' ' ELSE SUBSTR(T001.DEN_DATE,1,4) || '/' || SUBSTR(T001.DEN_DATE,5,2) || '/' || SUBSTR(T001.DEN_DATE,7,2) END,1,100) AS A002
 ,SUBSTRB(TO_CHAR(T001.DEN_NO,'FM00000000'),1,100) AS A003
 ,SUBSTRB(TO_CHAR(T001.DEN_GYO_NO,'FM999999999999990'),1,100) AS A004
 ,SUBSTRB(RTRIM(TO_CHAR(T001.DEN_SYO_CD)),1,100) AS A005
 ,SUBSTRB(RTRIM(TO_CHAR(T002.SYO_KANA)),1,100) AS A006
 ,SUBSTRB(TO_CHAR(T001.TOTAL_QTY,'FM999999999999990.0'),1,100) AS A007
 ,SUBSTRB(TO_CHAR(T001.URI_TAN,'FM999999999999990'),1,100) AS A008
 ,SUBSTRB(TO_CHAR(T001.URI_KIN_ZEINUKI,'FM999999999999990'),1,100) AS A009
 ,SUBSTRB(TO_CHAR(decode( T001.CASE_QTY,0,0,mod( T001.BARA_QTY, T001.CASE_QTY)),'FM999999999999990'),1,100) AS A010 ,
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_DEMO.SAM_DENPYO T001
LEFT OUTER JOIN DC2_DEMO.SAM_DAY T007 ON
 T001.DEN_DATE=T007.HIDUKE
LEFT OUTER JOIN DC2_DEMO.SAM_SYOHIN T002 ON
 T001.DEN_SYO_CD=T002.SYO_CD
WHERE
 T001.DEN_KB='2'
 AND T001.DEN_DATE BETWEEN '20100101' AND '20100110'
ORDER BY
  T001.DEN_DATE
 ,T001.DEN_NO
 ,T001.DEN_GYO_NO
) TABLE_SELECT
;
commit;
EXIT;


