关于 游标 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;
---关于游标 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;
---关于游标 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;
---关于for 循环的例子
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;
---关于 loop循环的例子
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; ---关于游标和loop循环的例子
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;
---关于异常处理的例子
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; ---关于异常处理的例子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;
---关于包的例子 定义包
create or replace package peace_pkg
as
function test1(in1 in varchar2)
return number;
procedure test2 (in2 in varchar2);
end peace_pkg;
---关于包的例子 定义包体
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;

oracle 存储过程和函数例子的更多相关文章

  1. oracle 存储过程和函数例子 --2

    关于 游标 if,for 的例子 create or replace procedure peace_if is cursor var_c is select * from grade; begin ...

  2. oracle 存储过程,函数和包

    创建存储过程: 语法:create [or replace] PROCEDURE 过程名(参数列表)  AS PLSQL子程序体: 调用 存储过程的方式 两种1.execute(exec)     - ...

  3. JAVA调用Oracle存储过程和函数

    连接数据库的工具类: import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; imp ...

  4. oracle 存储过程,存储函数,包,

    http://heisetoufa.iteye.com/blog/366957 认识存储过程和函数 存储过程和函数也是一种PL/SQL块,是存入数据库的PL/SQL块.但存储过程和函数不同于已经介绍过 ...

  5. Oracle存储过程、函数、包加密wrap

    wrap加密可以将PL/SQL的代码实现部分隐藏,提高代码的安全性,如存储过程.函数.包等都隐藏. wrap加密的方法有两种,下面以函数为例分别介绍一下: 方法一: 编写好函数后保存到 d:\test ...

  6. Oracle————存储过程与函数

    存储过程存储过程参数模式包括IN.OUT. IN OUT. IN(默认参数模式):表示当存储过程别调用时,实参值被传递给形参:形参起变量作用,只能读该参数,而不能修改该参数.IN模式参数可以是变量或表 ...

  7. Oracle存储过程及函数的练习题

    --存储过程.函数练习题 --(1)创建一个存储过程,以员工号为参数,输出该员工的工资create or replace procedure p_sxt1(v_empno in emp.empno%t ...

  8. Oracle存储过程及函数

    1.在Oracle中,存储过程包括三部分组成:定义部分.执行部分.和异常处理部分(即例外) eg1:输入员工编号,查询员工的姓名和薪资 create or repalce  procedure myp ...

  9. Oracle存储过程和函数使用方法

    一.存储过程(PROCEDURE) 使用过程, 不仅可以简化客户端应用程序的开发和维护,而且可以提高应用程序的运行性能.  CREATE [OR REPLACE] PROCUDURE procedur ...

随机推荐

  1. WPF 蒙层罩,正在加载

    参考园子里的一篇文章,比较好用.可以直接用,可以自己改. 动画效果: 容器的触发器,旋转容器: 属性配置:使用依赖属性,并且在xaml中写绑定.

  2. IDisplayTransformation

    IDisplayTransformation Bounds Full extent in world coordinates. The Bounds property controls the ful ...

  3. debug 使用lldb

    http://www.zddhub.com/memo/2015/12/20/lldb-golang-debug/ go build -gcflags "-N -l" -o test ...

  4. ipmi使用

    1.安装ipmitool Linux: yum -y install OpenIPMI-tools 备注:Linux机器也可以安装ipmi  yum -y install OpenIPMI OpenI ...

  5. Entity FrameWork初始化数据库的四种策略

    程序猿就是苦逼,每天还得分出一些时间去写博文.天真的很热,今天就随便写一点啦! 1.EF初始化数据库的四中策略 EF可以根据项目中的模型自动创建数据库.下面我们就分类看看Entity Framewor ...

  6. iOS-self.layer.shouldRasterize属性

    当shouldRasterize设成true时,layer被渲染成一个bitmap,并缓存起来,等下次使用时不会再重新去渲染了.实现圆角本身就是在做颜色混合(blending),如果每次页面出来时都b ...

  7. System.Threading.Timer使用心得

    System.Threading.Timer 是一个使用回调方法的计时器,而且由线程池线程服务,简单且对资源要求不高. "只要在使用 Timer,就必须保留对它的引用."对于任何托 ...

  8. Java基础之创建窗口——创建应用程序窗口(TryWindow)

    控制台程序. 准备好应用程序窗口及其包含的组件并显示,这称为实现窗口.调用应用程序窗口对象的setVisible()方法就会实现窗口.实现了应用程序的GUI之后,在主线程中修改或查询GUI可能会导致死 ...

  9. spring纯java注解式开发(一)

    习惯了用XML文件来配置spring,现在开始尝试使用纯java代码来配置spring. 其实,spring的纯java配置,简单来说就是将bean标签的内容通过注解转换成bean对象的过程,没什么神 ...

  10. acm算法模板(4)

    杂乱小模板 状态压缩dp小技巧 x&-x是取x的最后一个1的位置. x-=x&-x是去掉x的最后一个1. 读入外挂 int nxt_int(){// neg or pos    cha ...