CREATE OR REPLACE PACKAGE KMP_ALGOR_PKG
創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括英吉沙網(wǎng)站建設(shè)、英吉沙網(wǎng)站制作、英吉沙網(wǎng)頁制作以及英吉沙網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,英吉沙網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到英吉沙省份的部分城市,未來相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
AS
TYPE next_arr_tt IS TABLE OF INT INDEX BY PLS_INTEGER;
PROCEDURE match_str(org_str VARCHAR2, pat_str VARCHAR2);
FUNCTION get_pre_arr(pat_st VARCHAR2) RETURN next_arr_tt;
END kmp_algor_pkg;
CREATE OR REPLACE PACKAGE BODY KMP_ALGOR_PKG
AS
PROCEDURE match_str(org_str VARCHAR2, pat_str VARCHAR2)
AS
pat_next_arr next_arr_tt := get_pre_arr(pat_st => pat_str);
k INT := 0;
seq_cnt INT := 0;
BEGIN
FOR i IN 1..length(org_str) LOOP
WHILE(k > 0 AND substr(org_str, i, 1) <> substr(pat_str, k + 1, 1)) LOOP
k := pat_next_arr(k-1);
END LOOP;
IF(substr(pat_str, k + 1, 1) = substr(org_str, i, 1)) THEN
k := k + 1;
END IF;
IF(k = length(pat_str)) THEN
seq_cnt := seq_cnt + 1;
dbms_output.put_line('the '||pat_str||' '||seq_cnt||'th match found in '||org_str||' at index '||(i - k + 1));
k := pat_next_arr(k - 1);
END IF;
END LOOP;
IF(seq_cnt = 0) THEN
dbms_output.put_line('no match found');
END IF;
END match_str;
FUNCTION get_pre_arr(pat_st VARCHAR2) RETURN next_arr_tt
AS
ret_next_arr next_arr_tt;
k INT := 0;
BEGIN
ret_next_arr(0) := 0;
FOR umark IN 1..length(pat_st) - 1 LOOP
WHILE(k > 0 AND substr(pat_st, umark + 1 , 1) <> substr(pat_st, k + 1, 1)) LOOP
k := ret_next_arr(k - 1);
END LOOP;
IF(substr(pat_st, k + 1, 1) = substr(pat_st, umark + 1, 1)) THEN
k := k + 1;
END IF;
ret_next_arr(umark) := k;
END LOOP;
RETURN ret_next_arr;
END get_pre_arr;
END kmp_algor_pkg;