儲存過程中的一些片斷

2021-08-25 07:00:10 字數 1280 閱讀 5138

create or replace procedure 儲存過程名

astype ref_cursor is ref cursor;--定義游標

mycursor ref_cursor;

--定義需要的變數

變數1 number;

begin

變數ny:=to_char(sysdate,'yyyymm');

strsql:='select 欄位1, 欄位2, 欄位3,

decode(f.欄位,'||''''||變數||''''||','||''''||變數||''''||','||''''||變數||''''||') 字段

from 表1 a

join 表2 b on a.欄位=b.欄位

join b'||變數ny||'c c on a.欄位= c.欄位

join 表3 d on a.欄位= d.欄位

left 表4 e on substr(d.欄位,'||''''||變數||''''||','||''''||變數||''''||')=e.欄位

left join 表5 f on e.欄位=f.欄位 and f.欄位='||''''||變數||''''||'

left join 表6 g on e.欄位=g.欄位

where a.欄位='||''''||變數||'''' || 'or a.欄位='||''''||變數||'''';

open mycursor for strsql; --開啟游標

if mycursor%isopen then --判斷開啟成功

loop --迴圈獲取記錄集

fetch mycursor into 變數,變數,變數,變數; --獲取游標中的記錄

if mycursor%found then --游標的found屬性判斷是否有記錄

if 變數 is not null then

select count(*) into 變數 from 表 where 字段 = 變數;

if 變數 = 0 then

insert into 表(字段, 字段, 字段, 字段)

values(變數, 變數, 變數, 變數);

else

update 表 set 字段=表, 字段=表 where 字段 = 變數;

end if;

commit;

end if;

else

exit;

end if;

end loop;

end if;

close mycursor;

end;

Sybase IQ 的儲存過程中的一些問題

1.在建立儲存過程時,必須要有比較好的編輯工具,否則iq會幫你把儲存過程優化得面目全非 比如連續的賦值語句 select a1 a1 select a2 a2 select a3 a1 a2 想想結果是 a1a2 但是它會幫你優化為select a1 a1 a2 a2 a3 a1 a2 根據從右到左...

大雨中的一些片斷

片斷1 01年7月,和同事離開屁坑大學,是乙個夏天。當時拿了很多行李 電腦 書籍等在rs樓下準備打車,突然下了大雨,眼看趕火車要誤點了。s師兄二話不說,打著傘去東門,給我們叫了乙個計程車,他雖然坐在計程車回來,但是渾身淋得像落湯雞一樣。而我們幾人著急搬東西上計程車,急忙忙的趕火車,似乎也沒怎麼道謝就...

Linux移植過程中的一些錯誤

問題點 1 yaffs2根檔案系統無法掛載 failed to execute linuxrc.attempting defaults.kernel panic not syncing no init found.try passing init option to kernel.原因 mkyaff...