儲存過程使用小結

2021-08-31 04:14:47 字數 1649 閱讀 2892

寫道

create or replace procedure maomao_1217

as for_date date;

for_btntid number;

test int;

cursor cur_date is

select distinct t.thedate from domain_score t;

cursor cur_btntid is

select distinct t.btntid from domain_score t;

begin

for for_date in cur_date loop

for for_btntid in cur_btntid loop

insert into domain_score_tmp

(select a.* from (select * from domain_score t where t.btntid=

for_btntid and t.thedate=

for_date order by t.score desc) a

where rownum < 100);

end loop;

---dbms_output.put_line('this number is '||for_btntid);

end loop;

end maomao_1217;

這是我同學寫的乙個儲存過程,她問我為什麼編譯不過去,我開始也覺得奇怪,和網上寫的都差不多,但為什麼編譯不過去後來仔細看了下是標紅的地方有問題,實際上第一是這種利用for in loop 開啟游標的方式是不需要提前定義每項的,第二,也是最重要的是,並不是說for_btntid 就是乙個number型的編號,而for_btntid.btntid才是乙個number型的變數,所以修改就很簡單了

寫道create or replace procedure maomao_1217

as for_date2 date;

for_btntid2 number;

test int;

cursor cur_date is

select distinct t.thedate from domain_score t;

cursor cur_btntid is

select distinct t.btntid from domain_score t;

begin

for for_date in cur_date loop

for for_btntid in cur_btntid loop

insert into domain_score_tmp

(select a.* from (select * from domain_score t where t.btntid=for_btntid.btntid and t.thedate=for_date.thedate order by t.score desc) a

where rownum < 100);

end loop;

---dbms_output.put_line('this number is '||for_btntid.btntid);

end loop;

end maomao_1217;

SQLSERVER 儲存過程 事務 小結

sqlserver 事務 在儲存過程中使用事務的時候也遇到些概念性的錯誤和操作性的錯誤,特記錄下來。提到事務,一般都知道其是乙個單個的工作單元,也就是使用者定義的乙個操作序列,要麼都成功,要麼都失敗。事務有乙個 隱藏的 xact abort 設定開關,一般在啟用事務 transaction 的時候,...

儲存過程使用

謂儲存過程就是transact sql語句的預編譯集合,這些語句在乙個名稱下儲存並作為乙個單元進行處理。由於儲存過程被預先編譯過,所以執行起來要比單行sql語句效率高出很多,在應用程式開發過程中應盡可能的採用儲存過程進行資料的增加 更新 刪除和查詢操作,以提公升應用程式的整體執行效率。執行sql s...

使用儲存過程

使用儲存過程的目的是 1.通過把過程封裝進單個易於使用的單元中,來簡化操作。2.無須反覆建立一系列步驟,可以確保資料的完整性。3.簡化變更管理。4.改進效能 預編譯 缺點 1.比基本的sql語句更複雜,程式設計師哭暈,dba開心。2.安全許可權問題,資料庫管理員一般都限制儲存過程的建立許可權。只允許...