--隱式游標 注意變數賦值用(:=) 連線符用(||)而不是加號(+)
declare
v_pk t_plat_keyword.id
%type; --
主鍵 v_amount_message t_plat_keyword_statistic.amount%
type;
v_amount_talk t_plat_keyword_statistic.amount
%type;
cursor cur is
select
distinct b.name,b.type,b.weixin_pk from
t_plat_keyword b;
begin
for my_cur in
cur loop
v_pk:
=seq_plat_keyword_statistic.nextval; --
主鍵賦值
select
count(1) into v_amount_message from t_webcall_talk a where to_char(substr(a.content,0,1000)) like'%
'||my_cur.name||'%
';select
count(1) into v_amount_talk from t_weixin_message t where t.message like'%
'||my_cur.name||'%
';insert
into
t_plat_keyword_statistic (id,name,amount,weixin_pk,type,create_time)
values (v_pk,my_cur.name,(v_amount_message+v_amount_talk),my_cur.weixin_pk ,my_cur.type,to_char(sysdate,'
yyyy-mm-dd hh:mm:ss
'));
endloop;
end;
--delete from t_plat_keyword_statistic
--select to_char(sysdate,'yyyy-mm-dd hh:mm:ss') from dual
--to_char(substr(a.content,0,1000)) 將clob轉換成字串
--create sequence 建立序列
/*create sequence seq_plat_keyword_statistic
minvalue 1
maxvalue 999999999999
start with 11
increment by 1
nocache;
*/--
將游標加入到儲存過程
create
orreplace
procedure plat_keyword_statistic is
v_pk t_plat_keyword.id
%type; --
主鍵 v_amount_message t_plat_keyword_statistic.amount%
type;
v_amount_talk t_plat_keyword_statistic.amount
%type;
cursor cur is
select
distinct b.name, b.type, b.weixin_pk from
t_plat_keyword b;
begin
for my_cur in
cur loop
v_pk :
= seq_plat_keyword_statistic.nextval; --
主鍵賦值
select
count(1
)
into
v_amount_message
from
t_webcall_talk a
where to_char(substr(a.content, 0, 1000)) like'%
'|| my_cur.name ||'%
';select
count(1
)
into
v_amount_talk
from
t_weixin_message t
where t.message like'%
'|| my_cur.name ||'%
';insert
into t_plat_keyword_statistic (id, name, amount, weixin_pk, type, create_time) values (v_pk, my_cur.name, (v_amount_message + v_amount_talk), my_cur.weixin_pk, my_cur.type, to_char(sysdate, '
yyyy-mm-dd hh:mm:ss
'));
endloop;
exception
when too_many_rows then
dbms_output.put_line(
'返回值多於1行');
when others then
dbms_output.put_line(
'關鍵字統計儲存過程出錯!');
endplat_keyword_statistic;
Oracle隱式游標和顯式游標
oracle隱式游標和顯式游標,游標是什麼?就是在記憶體開闢的一塊臨時儲存空間。1.1oracle有常用的哪些隱式游標 1.2 oracle隱式游標演示 隱式游標 使用的表為oracle預設自帶的emp表 sql rowcount 影響記錄條數 sql found 是否有滿足條件的記錄 set se...
oracle儲存過程,游標
oracle儲存過程,游標 2010 07 07 13 01 create or replace procedure p tb task log is 功能 插入任務到任務日誌表 v task start date date v task end date date v sql code numbe...
oracle 儲存過程 游標
create or replace procedure exception3 as 使用者自定義異常 e too high sal exception 宣告自定義異常 v sal employees.salary type begin select salary into v sal from em...