2015年6月22日 星期一

[SSIS][PostgreSQL]Error code:0x80040E21 Description: Multiple-step OLE DB operation generated errors.

        在SSIS Project裡,我打算從PostgreSQL匯入資料到SQL Server上,然後執行時出現如下錯誤,從錯誤訊息裡得知好像是欄位型態轉換的問題

[OLE DB Destination [29]] Error: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80040E21.
An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 11.0"  Hresult: 0x80040E21
Description: "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.".

[OLE DB Destination [29]] Error: An error occurred while setting up a binding for the "name" column. The binding status was "DT_NTEXT".
The data flow column type is "DBBINDSTATUS_UNSUPPORTEDCONVERSION".
The conversion from the OLE DB type of "DBTYPE_IUNKNOWN" to the destination column type of "DBTYPE_WVARCHAR" might not be supported by this provider.

        PostgreSQL該欄位上是TEXT,而SQL端對應欄位是NVARCHAR,我中間沒有加入資料轉換元件,對於異質資料轉換,我習慣在來源端就先轉掉好了,比較不容易出問題,所以直接在PostgreSQL來源端用cast轉換就好,例子如下
select id,cast(name as varchar(32)) as name from accounts
         這樣就沒再出錯囉

2015年6月17日 星期三

[SSIS]如何連到PostgreSQL

        首先去下載psqlodbc,因Server是64 bit的,用Visual Studio開發SSIS Project得用32 bit,而我開發佈署都在同一台Server上,所以兩種Driver都得裝喔

        安裝完Driver後,設定ODBC Data Source Administrator,也是32 bit與64 bit都要設,記得名稱要設一樣的,下面會講一下設定


2015年6月6日 星期六

[SQL Server]Linked Server到Oracle時,出現'To_Date' is not a recognized built-in function name的解法

       用連結伺服器連到Oracle要取資料,因為有日期時間的過濾條件,在Oracle需要用To_Date函數,但此函數無法通過SQL Server語法剖析的檢查,會出如下的錯誤
Select * From LK_ORA..HR.EMPLOYEES Where  Login_Date >= To_Date('2015-05-01 00:00:00','yyyy-mm-dd hh24:mi:ss') And Login_Date < TO_DATE('2015-05-02 00:00:00','yyyy-mm-dd hh24:mi:ss');


       解法一:在Oracle建View,在SQL端直接讀View,但多了道建View的手續

       解法二:在SQL端改用Exec,比較簡單,範例如下
EXEC ('Select * From HR.EMPLOYEES Where  Login_Date >= To_Date(''2015-05-01 00:00:00'',''yyyy-mm-dd hh24:mi:ss'') And Login_Date < TO_DATE(''2015-05-02 00:00:00'',''yyyy-mm-dd hh24:mi:ss'')') at LK_ORA;


2015年5月28日 星期四

[SSMS][SSIS]Connecting to the Integration Services service on the computer "localhost" failed with the following error: "Access is denied."

        環境是Win 2012 R2與SQL 2014,以管理者身分登入Local端後,用SSMS連SSIS時發生如下錯誤

        Grant Permissions to Integration Services Servic這篇沒用,因為已經是管理者了
     
        結果又是用右鍵Run as administrator執行SSMS就可以解了,UAC好麻煩

2015年5月15日 星期五

[SSAS]不錯用的MDX Designer工具

        Open Source的,有商用版本,測試的用開源的就夠了,載點在MDX Parser,Builder,DOM and OLAP visual controls with Writeback for Silverlight,下載Ranet.UILibrary.Olap-3.5.927.0.msi喔

        怎麼安裝使用?可參考下面的簡單說明,雖然產生的MDX也是不乾淨,但可以讓你用UI拉ROWS與COLUMNS,幫你快速產生MDX範例來改,對我們這種MDX沒有很熟悉的DBA來說,就很夠用了

2015年5月10日 星期日

[Oracle]分批刪除資料

        一次取得所有待刪除資料的ROWID,然後分批小量刪除資料

Set Serveroutput On;
DECLARE
  V_DATE DATE;
  Type V_Rowid Is Table Of Varchar2(100) Index By Binary_Integer;
  Var_Rowid V_Rowid;        
  Cursor V_Cur Is Select /*+parallel(a,2)*/Rowid From Hr.Employee Where LoginDate <= V_Date;

Begin
  V_Date := To_Date(To_Char(Trunc(Sysdate-60),'YYYY-MM-DD HH24:MI:SS'),'YYYY-MM-DD HH24:MI:SS');

  Open V_Cur ;

  Loop
  Fetch V_Cur Bulk Collect
          Into Var_Rowid Limit 10000;
  Forall I In 1 .. Var_Rowid.Count
  Delete From Hr.Employee  Where  Rowid =Var_Rowid(I);
  Commit;
Exit When V_Cur%Notfound Or V_Cur%Notfound Is Null;
End Loop;

Close V_Cur;

End;

2015年4月17日 星期五

[Oracle]如何在SQLPlus格式化輸出成CSV

        SQLPlus預設環境下有很多System Variable,如果沒特別去設定,用SPOOL輸出到文字檔時,可能會看到一些不乾淨資料,像是表頭、回傳筆數及統計時間等等的

        如下圖,配合一些System Variable設定就可以不顯示了