管理層決定從db2 Luw v9遷移。到Oracle 11g。Db2/Oracle-無法刪除空格
這是我創建的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
這是我創建做同樣的(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;
數據輸出是在Oracle查詢亂七八糟的領先/尾隨空間(添加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
這是DDL的DB2表
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
這是的DDL Oracle表
缺少什麼我在這裏?我怎樣才能解決我的查詢在Oracle?
亞歷克斯,你「釘牢它」。刪除TRIM()和大多數SET命令後,我得到的輸出匹配。但是,我的代碼中沒有SET NULL,但這是一個簡單的修復方法。謝謝。接受並投票決定。 – Chris