管理层已决定从 db2 Luw v9 迁移。到 Oracle 11g。
这是我创建的 DB2 查询,用于将一堆数据(在 bash 脚本中)转储到一个分隔文件。
EXPORT TO /tmp/dod.v3.del OF DEL MODIFIED BY NOCHARDEL COLDEL| DATESISO MESSAGES /tmp/dod.v3.msg SELECT DISTINCT A.CAMID, A.POSTTIME, A.MODDATE,A.RID,A.SOFTWAREVERSION,B.IPINFO,B.NUMBE ROFRESETSSINCELASTSWDL,C.TOTALNUMOFCOMPLETEDDLS,C. TOTALNUMBEROFDOWNLOADSSTARTED,C.DAILYDOWNLOADSIZE, C.DAILYDOWNLOADTIME,CONCAT(A.MODELNUMBER,(CONCAT('-',A.MANUFACTURERID))) FROM DMS.STBHEADER A JOIN DMS.STBSTATUS B ON A.DMS_ID=B.DMS_ID AND A.MODDATE = CURRENT_DATE - 1 DAY AND A.CAMID NOT IN (-11,125,117) LEFT JOIN DMS.BBVODSTATS C ON A.DMS_ID=C.DMS_ID FOR FETCH ONLY WITH UR;
数据输出看起来像这样漂亮整洁
2925917748|2003-12-05-17.26.58.000000|2013-11-03|36816426252|740||0|||||H25-500
3030176931|2004-11-07-11.48.52.000000|2013-11-03|25167455119|797||15|0|4|0|0|HR44-700
3026464853|2004-11-07-12.40.54.000000|2013-11-03|25166398575|797||17|0|3|0|0|HR44-500
这是我创建的用于执行相同操作的 ORACLE 查询(在 bash 脚本中)
SET ARRAYSIZE 5000 FEEDBACK OFF ECHO OFF HEADING OFF LIN 999 MAXD 999 NEWP NONE;
SET RECSEP OFF TERM OFF TRIM ON TRIMSPOOL ON TRUNCATE OFF UND OFF VER OFF WRA OFF;
SET COLSEP |;
COLUMN CAMID FORMAT 9999999999999;
COLUMN RID FORMAT 9999999999999;
spool /tmp/dod.v3.del.ora;
SELECT DISTINCT
A.CAMID,
LTRIM(RTRIM(TO_CHAR(A.POSTTIME,'YYYY-MM-DD-HH24.MI.SS.FF6'),' ') ,' '),
LTRIM(RTRIM(TO_CHAR(A.MODDATE,'YYYY-MM-DD') , ' ') ,' '),
LTRIM(RTRIM(TO_CHAR(A.RID), ' ') ,' '),
LTRIM(RTRIM(TO_CHAR(A.SOFTWAREVERSION), ' ') ,' '),
LTRIM(RTRIM(TO_CHAR(B.IPINFO), ' ') ,' '),
LTRIM(RTRIM(TO_CHAR(B.NUMBEROFRESETSSINCELASTSWDL) , ' ') ,' '),
LTRIM(RTRIM(TO_CHAR(C.TOTALNUMOFCOMPLETEDDLS) , ' ') ,' '),
LTRIM(RTRIM(TO_CHAR(C.TOTALNUMBEROFDOWNLOADSSTARTE D) , ' ') ,' '),
LTRIM(RTRIM(TO_CHAR(C.DAILYDOWNLOADSIZE) , ' ') ,' '),
LTRIM(RTRIM(TO_CHAR(C.DAILYDOWNLOADTIME) , ' ') ,' '),
LTRIM(RTRIM(TO_CHAR(CONCAT(A.MODELNUMBER,(CONCAT('-',A.MANUFACTURERID))) ), ' ') ,' ')
FROM
DMS.STBHEADER A
JOIN
DMS.STBSTATUS B
ON A.DMS_ID=B.DMS_ID
AND
A.CAMID NOT IN (-11,125,117)
LEFT JOIN
DMS.BBVODSTATS C
ON A.DMS_ID=C.DMS_ID;
数据输出是乱七八糟的前导/尾随空格(添加的 R/LTRIMS 无效):
1814861090|2013-08-27-08.05.17.000000 |2013-08-30|28883762982 |736 |null |0 |4 |4 |0 |0 |HR21-700
2072851526|2013-08-27-08.05.29.000000 |2013-08-30|33064562144 |736 |null |1 |42 |42 |0 |0 |HR24-500
这是 DB2 表的 DDL
Data type Column
Column name schema Data type name Length Scale Nulls
------------------------------- --------- ------------------- ---------- ----- ------
CAMID SYSIBM BIGINT 8 0 No
RID SYSIBM BIGINT 8 0 No
SOFTWAREVERSION SYSIBM VARCHAR 25 0 Yes
MODELNUMBER SYSIBM VARCHAR 25 0 Yes
MANUFACTURERID SYSIBM VARCHAR 25 0 Yes
POSTTIME SYSIBM TIMESTAMP 10 6 Yes
MODDATE SYSIBM DATE 4 0 No
NUMBEROFRESETSSINCELASTSWDL SYSIBM INTEGER 4 0 Yes
IPINFO SYSIBM VARCHAR 100 0 Yes
TOTALNUMOFCOMPLETEDDLS SYSIBM BIGINT 8 0 Yes
TOTALNUMBEROFDOWNLOADSSTARTED SYSIBM BIGINT 8 0 Yes
DAILYDOWNLOADSIZE SYSIBM BIGINT 8 0 Yes
DAILYDOWNLOADTIME SYSIBM BIGINT 8 0 Yes
这是 Oracle 表的 DDL
Name Null? Type
----------------------------------------- -------- ----------------------------
CAMID NOT NULL NUMBER
RID NOT NULL NUMBER
SOFTWAREVERSION VARCHAR2(25)
MODELNUMBER VARCHAR2(25)
MANUFACTURERID VARCHAR2(25)
POSTTIME TIMESTAMP(6)
MODDATE NOT NULL TIMESTAMP(0)
NUMBEROFRESETSSINCELASTSWDL NUMBER
IPINFO VARCHAR2(100)
TOTALNUMOFCOMPLETEDDLS NUMBER
TOTALNUMBEROFDOWNLOADSSTARTED NUMBER
DAILYDOWNLOADSIZE NUMBER
DAILYDOWNLOADTIME NUMBER
我在这里想念什么?如何修复我在 Oracle 中的查询?