請問如何join不同資料庫的兩個表格? |
答題得分者是:Fishman
|
supertony
一般會員 發表:8 回覆:9 積分:3 註冊:2006-07-11 發送簡訊給我 |
各位網友大家好:
我使用的是Delphi7、Oracle資料庫、MS SQL Server資料庫,想要達到的目的是將Oracle db的A表格,join MS SQL SERVER的B表格,將資料顯示在畫面上並產生報表(FastReport)。我目前的做法是建立兩個ADOConnection、分別連接Oracle、SQL Server,再用兩個ADOQuery分別查出所需要的資料。查出後,再用兩個二維的陣列存放抓出的資料,最後,在用迴圈的方式比對兩個陣列中關聯欄位值是否相同,若相同,表示這分屬兩個資料庫表格的資料應該join成一筆,再寫入StringGrid中。挖塞~光是描述就覺得粉繁瑣,想當然爾,效能一定很差。想請教各位網友有沒有遭遇過類似的需求?該怎麼改進能使程式、步驟更簡單、效率更好呢?請各位網友不吝指教,謝謝! ^0^ 舉例:Oracle DB:select 員工編號, 員工姓名 ,部門代碼 from employee; MS SQL Server:select 部門名稱 ,部門代碼 from department; *在畫面上秀出"員工編號"、"員工姓名"、"部門名稱"、"部門代號"等欄位 Data1Array存放Oracle抓出的資料、Data2Array存放SQL Server抓出的資料; if Data1Array[i,2] = Data2Array[j,1] ==> 將兩陣列的資料合併為一筆資料寫入StringGrid中。 (i , j 為兩陣列跑迴圈比對資料時所用之變數) |
Fishman
尊榮會員 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
直接在 Oracle 這一個 ADOQuery 中增加 Lookup Field 即可
http://delphi.ktop.com.tw/board.php?cid=30&fid=66&tid=68157 http://delphi.ktop.com.tw/board.php?cid=30&fid=71&tid=41566 或是 http://delphi.ktop.com.tw/board.php?cid=30&fid=66&tid=74159 Fishman
------
Fishman |
supertony
一般會員 發表:8 回覆:9 積分:3 註冊:2006-07-11 發送簡訊給我 |
^0^ 非常感謝Fishman網友花時間指點,我參照 http://delphi.ktop.com.tw/board.php?cid=30&fid=66&tid=681575 這篇文章內容後,已順利完成join的功能了,真的非常感謝!在此繼續追問下個問題,也請各位網友不吝指教~
以"New Fields"的功能新增欄位[搜索性欄位(fkLookup)],在設定查詢欄位join時,只能指定一個欄位,若我需要以多個欄位做join的條件時,能使用這種方式嗎?或者還有其他可以達成多個欄位做join條件,組合兩個不同資料庫的Table的方式嗎?感謝大家幫忙~ ^0^ |
Fishman
尊榮會員 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
設定該 LookupField 的 KeyFields & LookupKeyFields 為 id1;id2(用";"區分欄位)
Delphi 的原文說明如下: KeyFields To use more than one field, separate each field name with a semicolon. The specified fields must be of the same types as the corresponding fields in LookupKeyFields, or the lookup fails. LookupKeyFields To specify more than one field, separate each field name with a semicolon. The fields specified in LookupKeyFields must be of the same types as the corresponding fields in KeyFields, or the lookup can't work. Fishman
------
Fishman |
supertony
一般會員 發表:8 回覆:9 積分:3 註冊:2006-07-11 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |