如何構建銀行資料倉儲

2021-04-14 11:41:09 字數 2639 閱讀 4544

/*--ntext搜尋

按 tb 表中的 keyword 在 ta 中查詢 content

列出每個 keyword 在 content 中的具體位置

--鄒建 2004.07(引用請保留此資訊)--*/

--測試資料

create table ta(id int identity(1,1),content ntext)

insert ta select '我是中國人我是中國人'

union all select '中國人民愛中國 中國人民愛中國 中國人民愛中國 中國人民愛中國'

create table tb(keyword nvarchar(100))

insert tb select '中'

union all select '中國'

go/****************==處理********************====*/

if exists (select * from dbo.sysobjects where id = object_id(n'[序數表]') and objectproperty(id, n'isusertable') = 1)

drop table [序數表]

go--為了效率,所以要乙個輔助表配合

select top 4000 id=identity(int,1,1) into 序數表

from syscolumns a,syscolumns b

alter table 序數表 add constraint pk_id_序數表 primary key(id)

go--建立處理的儲存過程

create proc p_search

ascreate table #t(id int,keyword nvarchar(100),position int)

declare @s nvarchar(4000),@keyword nvarchar(100)

declare @id int,@i int,@ilen int

declare tb cursor local for

select a.id,b.keyword,position=charindex(b.keyword,a.content)-1,ilen=4000-len(b.keyword)

from ta a,tb b

where charindex(b.keyword,a.content)>0

open tb

fetch tb into @id,@keyword,@i,@ilen

while @@fetch_status=0

begin

select @s=substring(content,@i+1,4000)

from ta where id=@id

while @s<>''

begin

insert #t(id,keyword,position)

select @id,@keyword,id+@i

from 序數表

where charindex(@keyword,@s,id)=id

select @i=@i+@ilen,@s=substring(content,@i+1,4000)

from ta where id=@id

endfetch tb into @id,@keyword,@i,@ilen

endclose tb

deallocate tb

select * from #t

go--呼叫示例

exec p_search

go--刪除測試

drop table 序數表,ta,tb

drop proc p_search

/*--測試結果

id          keyword   position 

----------- --------- ----------

1           中        3

1           中        8

1           中國      3

1           中國      8

2           中        1

2           中        6

2           中        9

2           中        14

2           中        17

2           中        22

2           中        25

2           中        30

2           中國      1

2           中國      6

2           中國      9

2           中國      14

2           中國      17

2           中國      22

2           中國      25

2           中國      30

(所影響的行數為 20 行)

資料倉儲構建步驟

構建企業級資料倉儲五步法 一 確定主題 即確定資料分析或前端展現的主題 例 某年某月某地區的啤酒銷售情況 主題要體現出某一方面的各分析角度 維度 和統計數值型資料 量度 之間的關係,確定主題時要綜合考慮.二 確定量度kpi 確定主題後,需要考慮分析的技術指標 例 年銷售額等等 它們一般為資料值型資料...

銀行資料倉儲體系實踐(8) 主資料模型設計

主資料區域中保留了資料倉儲的所有基礎資料及歷史資料,是資料倉儲中最重要的資料區域之一,那主資料區域中主要分為近源模型區和整合 主題 模型區。上一節講到了模型的設計流程如下圖所示。那近源模型層的設計在第2.3和3這兩個步驟中相對簡化,模型表設計的結構同源系統的表結構,欄位也一一對映即可。那下面以整合 ...

基於 Hive 構建資料倉儲

設想有一批各種型別的離線 或實時 資料 文字 csv excel 等 我們如何挖掘這些資料背後的價值,分析這些資料之間的關聯?很容易想到的就是,寫程式把每種資料按照某種規則抽取出來放到關係型資料庫中進行分析。這樣做可能存在什麼樣的問題?按照某種規則進行抽取,是否會導致原始資料資訊的丟失?因為前期設計...