oracle儲存過程之切割字串 二

2021-09-01 13:13:21 字數 4234 閱讀 3873

呼叫及乙個普通的查詢過程

呼叫**(乙個function):

--通過分割,把乙個字串的值獲取到最後乙個

function getlastvaluebyseperator(p_str in varchar2,

p_delimiter in varchar2) return varchar2 as

cursor c is

select t.* from table(common_tool.fn_split(p_str, p_delimiter)) t;

r c%rowtype;

resultval varchar(100);

begin

open c;

loop

fetch c

into r;

exit when c%notfound;

-- dbms_output.put_line(r.column_value);

resultval := r.column_value;

end loop;

return resultval;

end;包頭:

create or replace package wcity2_statistic is

-- author : administrator

-- created : 2012/10/24 9:48:34

-- purpose :

--定義乙個游標型別

type ref_cursor is ref cursor;

--通過分割,把乙個字串的值獲取到最後乙個

function getlastvaluebyseperator(p_str in varchar2,

p_delimiter in varchar2) return varchar2;

--page統計分析子系統呼叫該介面檢視頁面資訊,

--頁面資訊包括頁面編碼、頁面名稱、頁面歸屬地等,

--其中頁面編碼字段要求唯一且不能為空。

procedure sp_pager_stats;

--訪問資訊

procedure sp_uservisit_stat(c_uservisit out ref_cursor);

procedure sp_download_stat(c_download out ref_cursor);

--資源資訊

procedure sp_resource_stat(c_resource out ref_cursor);

--查詢訂購資訊

procedure sp_order_stat(c_order out ref_cursor);

--查詢應用資訊

--查詢:服務訂閱資訊

procedure sp_bind_stat(c_bind out ref_cursor);

--查詢產品資訊

procedure sp_product_stat(c_product out ref_cursor);

end wcity2_statistic;

包體:
create or replace package body wcity2_statistic is

--通過分割,把乙個字串的值獲取到最後乙個

function getlastvaluebyseperator(p_str in varchar2,

p_delimiter in varchar2) return varchar2 as

cursor c is

select t.* from table(common_tool.fn_split(p_str, p_delimiter)) t;

r c%rowtype;

resultval varchar(100);

begin

open c;

loop

fetch c

into r;

exit when c%notfound;

-- dbms_output.put_line(r.column_value);

resultval := r.column_value;

end loop;

return resultval;

end;

--頁面資訊

procedure sp_pager_stats is

begin

-- cur_page as select * from oms_wireless. template_file_working;

null;

end sp_pager_stats;

--訪問資訊

procedure sp_uservisit_stat(c_uservisit out ref_cursor) as

--定義游標

/*cursor c_uservisit is

select t.city,t.username,t.username as telphone,'' as ip

from inte***ce_wireless.user_login_log t ;*/

begin

open c_uservisit for

select t.city, t.username, t.username as telphone, '' as ip

from inte***ce_wireless.user_login_log t;

end;

procedure sp_download_stat(c_download out ref_cursor) as

begin

open c_download for

select *

from inte***ce_wireless.log_statistics t

where t.uri like '%download%';

end;

--資源資訊

procedure sp_resource_stat(c_resource out ref_cursor) as

--v_resource oms_wireless.resource_info%rowtype;

v_id oms_wireless.resource_info.id%type;

v_type oms_wireless.resource_info.name%type;

v_name oms_wireless.resource_info.name%type;

begin

open c_resource for

select t.id as id,

getlastvaluebyseperator(t.name, '.') as type,

t.name

from oms_wireless.resource_info t;

/*while (c_resource%found) loop

fetch c_resource

into v_id, v_type, v_name;

v_type := 'test';

dbms_output.put_line('aa:' + v_type);

end loop;*/

end;

--查詢訂購資訊

procedure sp_order_stat(c_order out ref_cursor) as

begin

open c_order for

select pd.order_id, pd.pay_account, pd.pay_account

from inte***ce_wireless.pay_record pd;

end;

--查詢應用資訊

begin

end;

--查詢:服務訂閱資訊

procedure sp_bind_stat(c_bind out ref_cursor) as

begin

open c_bind for

from inte***ce_wireless.menu_info menu

end;

--產品資訊

procedure sp_product_stat(c_product out ref_cursor) as

begin

null;

end;

end wcity2_statistic;

Oracle內建儲存過程之DBMS OUTPUT

1.dbms output 1.1 作用 除錯pl sql程式 命令作用 備註enable 在serveroutput on的情況下,用來使dbms output生效 預設即開啟 啟用serveroutput set serveroutput on 關閉serveroutput set server...

Oracle的PL SQL程式設計之儲存過程 1

pl sql 優點 1.提高應用程式的執行效能 2.模組化的設計思想 分頁儲存過程,訂單,轉賬.3.減少網路傳輸量 開發工具 1.sqlplus開發工具 2.pl sql developer開發工具 4.提高安全性 缺點 1.移植性不好 建立儲存過程 sql create or replace pr...

oracle 儲存過程之游標(loop)使用

declare 宣告兩個變數 v id varchar2 50 v int number cursor yb is select a.id from t d5 punishment a where a.removed 0 begin v int 1 變數賦值 open yb 開啟游標 loop 開始...