欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

oracle 存儲過程和函數(shù)例子

 更新時間:2009年08月05日 22:58:48   作者:  
本文沒有對PL/SQL中的東西有什么說明,只是簡單的舉了幾個例子,希望對大家有用!
作者:peace.zhao
關(guān)于 游標(biāo) if,for 的例子
create or replace procedure peace_if
is
cursor var_c is select * from grade;
begin
for temp in var_c loop
if temp.course_name = 'OS' then
dbms_output.put_line('Stu_name = '||temp.stu_name);
elsif temp.course_name = 'DB' then
dbms_output.put_line('DB');
else
dbms_output.put_line('feng la feng la ');
end if;
end loop;
end;
---關(guān)于游標(biāo) for,case 的例子1
create or replace procedure peace_case1
is
cursor var_c is select * from test_case;
begin
for temp in var_c loop
case temp.vol
when 1 then
dbms_output.put_line('haha1');
when 2 then
dbms_output.put_line('haha2');
when 3 then
dbms_output.put_line('haha3');
when 4 then
dbms_output.put_line('haha4');
else
dbms_output.put_line('qita');
end case ;
end loop;
end;
---關(guān)于游標(biāo) for,case 的例子2
create or replace procedure peace_case2
is
cursor var_c is select * from test_case;
begin
for temp in var_c loop
case
when temp.vol=1 then
dbms_output.put_line('haha1');
when temp.vol=2 then
dbms_output.put_line('haha2');
when temp.vol=3 then
dbms_output.put_line('haha3');
when temp.vol=4 then
dbms_output.put_line('haha4');
else
dbms_output.put_line('qita');
end case ;
end loop;
end;
---關(guān)于for 循環(huán)的例子
create or replace procedure peace_for
is
sum1 number :=0;
temp varchar2(500);
begin
for i in 1..9 loop
temp := '';
for j in 1 .. i
loop
sum1 := i * j;
temp := temp||to_char(i) || ' * ' ||to_char(j) ||' = ' ||to_char(sum1) ||' ';
end loop;
dbms_output.put_line(temp );
end loop;
end;
---關(guān)于 loop循環(huán)的例子
create or replace procedure peace_loop
is
sum1 number := 0;
temp number :=0 ;
begin
loop
exit when temp >= 10 ;
sum1 := sum1+temp;
temp := temp +1;
end loop;
dbms_output.put_line(sum1 );
end;

---關(guān)于游標(biāo)和loop循環(huán)的例子
create or replace procedure loop_cur
is
stu_name varchar2(100);
course_name varchar2(100);
cursor var_cur is select * from grade ;
begin
open var_cur;
loop
fetch var_cur into stu_name,course_name;
exit when var_cur%notfound;
dbms_output.put_line(stu_name|| course_name);
end loop;
close var_cur;
end;
---關(guān)于異常處理的例子
create or replace procedure peace_exp(in1 in varchar2)
is
c_n varchar2(100);
begin
select course_name into c_n from grade where stu_name = in1;
dbms_output.put_line(c_n);
exception
when no_data_found
then
dbms_output.put_line('try');
when TOO_MANY_ROWS
then
dbms_output.put_line('more');
end;

---關(guān)于異常處理的例子2
create or replace procedure peace_insert ( c_n in varchar2)
is
error EXCEPTION;
begin
if c_n = 'OK'
then
insert into course (course_name) values (c_n);
elsif c_n = 'NG' then
insert into course (course_name) values (c_n);
raise error;
else
Dbms_Output.put_line('c_n' || c_n);
end if;
commit;
exception
when error then
rollback;
Dbms_Output.put_line('ERRO');
end;
---關(guān)于包的例子 定義包
create or replace package peace_pkg
as
function test1(in1 in varchar2)
return number;
procedure test2 (in2 in varchar2);
end peace_pkg;
---關(guān)于包的例子 定義包體
create or replace package body peace_pkg
as
function test1(in1 in varchar2)
return number
as
temp number;
begin
temp := 0;
return temp;
end;
procedure test2 (in2 in varchar2)
is
begin
dbms_output.put_line(in2);
end;
end peace_pkg;

相關(guān)文章

  • Oracle查鎖表的實現(xiàn)(史上最全)

    Oracle查鎖表的實現(xiàn)(史上最全)

    Oracle提供幾種不同的方式來查看鎖表,本文主要介紹了Oracle查鎖表的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-12-12
  • Hibernate Oracle sequence的使用技巧

    Hibernate Oracle sequence的使用技巧

    本文介紹了關(guān)于Hibernate中如何使用Oracle sequence的問題以及應(yīng)注意的事項。
    2009-06-06
  • oracle清空所有表數(shù)據(jù)

    oracle清空所有表數(shù)據(jù)

    這篇文章主要介紹了oracle清空所有表數(shù)據(jù),需要的朋友可以參考下
    2014-07-07
  • oracle如何合并多個sys_refcursor詳解

    oracle如何合并多個sys_refcursor詳解

    這篇文章主要給大家介紹了關(guān)于oracle如何合并多個sys_refcursor的相關(guān)資料,以及在文末跟大家分享了sys_refcursor 和 cursor 優(yōu)缺點的比較,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-05-05
  • Oracle 死鎖的檢測查詢及處理

    Oracle 死鎖的檢測查詢及處理

    這篇文章主要介紹了Oracle 死鎖的檢測查詢及處理,文章又描述關(guān)于數(shù)據(jù)庫死鎖的檢查方法的一些相關(guān)資料,需要的朋友可以參考下面文章的具體內(nèi)容
    2021-09-09
  • Oracle分頁查詢性能優(yōu)化代碼詳解

    Oracle分頁查詢性能優(yōu)化代碼詳解

    這篇文章主要介紹了Oracle分頁查詢性能優(yōu)化代碼詳解,簡述了進(jìn)行分頁查詢性能優(yōu)化的原因,具有一定參考價值,需要的朋友可以了解下。
    2017-09-09
  • SQL Server、Oracle和MySQL判斷NULL的方法

    SQL Server、Oracle和MySQL判斷NULL的方法

    本文講述SQL Server、Oracle、MySQL查出值為NULL的替換,在SQL Server Oracle MySQL當(dāng)數(shù)據(jù)庫中查出某值為NULL怎么辦
    2012-11-11
  • Oracle數(shù)據(jù)庫中ORDER BY排序和查詢按IN條件的順序輸出

    Oracle數(shù)據(jù)庫中ORDER BY排序和查詢按IN條件的順序輸出

    這篇文章主要介紹了Oracle數(shù)據(jù)庫中ORDER BY排序和查詢按IN條件的順序輸出的方法,其中ORDER BY的排序結(jié)果需要注意其是否穩(wěn)定,需要的朋友可以參考下
    2015-11-11
  • oracle中去掉回車換行空格的方法詳解

    oracle中去掉回車換行空格的方法詳解

    本篇文章是對oracle中去掉回車換行空格的解決方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • Oracle 數(shù)據(jù)表分區(qū)的策略

    Oracle 數(shù)據(jù)表分區(qū)的策略

    Oracle 數(shù)據(jù)表分區(qū)的策略...
    2007-03-03

最新評論