5 then     dbms_ou" /> 5 then     dbms_ou" />
iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >存储过程和函数 oracle
  • 531
分享到

存储过程和函数 oracle

存储过程和函数oracle 2021-01-19 08:01:58 531人浏览 无得
摘要

declare begin   dbms_output.put_line("Hello World"); end; declare   i number := 10; begin   if i > 5 then     dbms_ou

存储过程和函数 oracle


declare
begin
  dbms_output.put_line("Hello World");

end;

declare
  i number := 10;
begin
  if i > 5 then
    dbms_output.put_line("OK");
  end if;

end;

--loop循环

declare
  i number := 1;
begin
  loop
    dbms_output.put_line("OK");
  
    exit when i=10;
      i:=i+1;
  end loop;

end;


--while 循环
declare 
   i number :=1;
begin
   while i<10 loop
     dbms_output.put_line("我说了算");
     i:=i+1;
     end loop;
end;

-- 1-100之间所有的偶数

declare
  i number := 1;
begin
  while i <= 100 loop
    if mod(i, 2) = 0 then
      dbms_output.put_line(i);
    end if;
    i := i + 1;
  end loop;
end;


--智能循环 for循环 

declare
begin
  for i in 1 .. 10 loop
    dbms_output.put_line(i);
  end loop;

end;

declare
   x number:=1;
  y number:=1;
  begin
    while x<=10 loop
      dbms_output.put_line("----->"||x);
      y:=1;
      while y<=5 loop
        if x=7 and y=3 then
          exit;
          end if;
        dbms_output.put_line(y);
        y:=y+1;
        end loop;
        x :=x+1; 
      end loop;
end;

--存储过程定义的

create procedure getMax(x number,y number)
is

  begin
   if x>y then
     dbms_output.put_line("X:"||x);
     else
          dbms_output.put_line("Y:"||y); 
          end if;
end;

--调用存储过程
在PL/sql中的SQL window中可以执行的
call getMax(2,5);
begin
  getMax(7,3);
end;
在PL/SQL中的SQL window中不可以执行的
execute getMax(4,7)
exec getMax(8,5);


create or replace procedure getMax(x number :=1,y number:=2)
is

  begin
   if x>y then
     dbms_output.put_line("X:"||x);
     else
          dbms_output.put_line("Y:"||y); 
          end if;
end;

call getMax();

--存储过程的参数

--编写一个存储过程,比较第一个参数和第二个参数,将最大的值存储在第三个参数中


create or replace procedure getMax(x number,y number,z out number)
is

  begin
   if x>y then
    z:=x;
     else
      z:=y;
          end if;
end;

declare 
          da number;
begin
  getMax(110,3,da);
       dbms_output.put_line(da);
end;


--存储过程类似java中的方法,但不是,因为没有返回值,
--函数就是java中的方法,具有返回值的。 两者的区别就是有无返回值


create or replace function getCountMax(x in out,y in out number) return number
is
begin 
  if x>y then
    dbms_output.put_line(x);
    y:=x+y;
    return x;
  else
    dbms_output.put_line(y);
    y:=x+y;
    return y-x;
    end if;
end;

select getCountMax(5,7) from dual;


 

您可能感兴趣的文档:

--结束END--

本文标题: 存储过程和函数 oracle

本文链接: https://www.lsjlt.com/news/5110.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • oracle怎么显示表的字段
    如何显示 oracle 表的字段 在 Oracle 数据库中,可以使用 DESC 命令显示表的字段。 语法: DESC table_name 参数: table_name:要显示字段的表...
    99+
    2024-05-14
    oracle
  • oracle怎么看所有的表
    在 oracle 数据库中查看所有表的步骤:连接到数据库运行查询:select table_name from user_tables; 如何使用 Oracle 查看所有表 ...
    99+
    2024-05-14
    oracle
  • oracle怎么显示行数
    如何使用 oracle 显示行数 在 Oracle 数据库中,有两种主要方法可以显示行数: 1. 使用 COUNT 函数 SELECT COUNT(*) FROM table_n...
    99+
    2024-05-14
    oracle
  • oracle怎么显示百分比
    oracle中显示百分比的方法有:使用百分号“%”;使用to_char()函数;使用format()函数(oracle 18c及更高版本);创建自定义函数。 Oracle 显...
    99+
    2024-05-14
    oracle
  • oracle怎么删除列
    oracle 中删除列的方法有两种:1)使用 alter table table_name drop column column_name 语句;2)使用 drop colum...
    99+
    2024-05-14
    oracle
  • sql怎么查看表的索引
    通过查询系统表,可以获取表的索引信息,包括索引名称、是否唯一、索引类型、索引列和行数。常用系统表有:mysql 的 information_schema.statistics、postg...
    99+
    2024-05-14
    mysql oracle
  • sql怎么查看索引
    您可以使用 sql 通过以下方法查看索引:show indexes 语句:显示表中定义的索引列表及其信息。explain 语句:显示查询计划,其中包含用于执行查询的索引。informat...
    99+
    2024-05-14
  • sql怎么查看存储过程
    如何查看 sql 存储过程的源代码:使用 show create procedure 语句直接获取创建脚本。查询 information_schema.routines 表的 routi...
    99+
    2024-05-14
  • sql怎么查看视图表
    要查看视图表,可以使用以下步骤:使用 select 语句获取视图中的数据。使用 desc 语句查看视图的架构。使用 explain 语句分析视图的执行计划。使用 dbms 提供...
    99+
    2024-05-14
    oracle python
  • sql怎么查看创建的视图
    可以通过sql查询查看已创建的视图,具体步骤包括:连接到数据库并执行查询select * from information_schema.views;查询结果将显示视图的名称、...
    99+
    2024-05-14
    mysql
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作