zoukankan      html  css  js  c++  java
  • oracle基础代码使用

    create or replace procedure pr_test1 is
    
    v_case number(3) := 100;--定义变量
    
    
    begin
    --  /*判断语句
    if 2>1 then
      dbms_output.put_line('条件成立');
     else
       dbms_output.put_line('条件不成立');
       end if;
        
    if 2<1 then
      dbms_output.put_line('条件成立');
    
    elsif 4>3 then
       dbms_output.put_line('条件不成立1');
       end if;
       
       elsif 4 > 2 then
       dbms_output.put_line('条件不成立2');
      
     elsif 7>3 then
       dbms_output.put_line('条件不成立3');
       
       end if;
    --  */ 
    
       case v_case   --定义v_case
         
       when 1 then   --当v_case为1时
         dbms_output.put_line('条件成立12');--输出
    
     when 100 then
    dbms_output.put_line('条件成立112');
    
    else--其他匹配都不成立时
    dbms_output.put_line('条件不成立,条件不匹配!');
    end case;
    
    case 
      when 8>7 then 
        dbms_output.put_line('8>7成立');
        when 9>8 then
          dbms_output.put_line('9>8成立');
          else
            dbms_output.put_line('都不成立');
    end case;
    
    <<loop1>>--标签,只是为了标注退出的是循环loop1
    loop
      v_case := v_case - 1;
      dbms_output.put_line('v_case的值 = '||v_case);
    --if(v_case = 90) then
    --dbms_output.put_line('退出循环');
    exit loop1 when v_case = 90;
    
    --end if;  
    
      end loop;
      
    while v_case >80
      loop
        v_case :=v_case - 1;
        dbms_output.put_line('v_case的值 = '||v_case);
        end loop;
    
    
    
    for inx in 1..20 loop--定义一个变量从1开始一直到20
      v_case := v_case + inx;
      dbms_output.put_line('v_case的值 = '||v_case);
      end loop;
    
    for inx in reverse 1..20 loop--从大到小开始,从20开始一直到1
    v_case := v_case + inx;
      dbms_output.put_line('v_case的值 = '||v_case);
    end loop;
    
    
    
    end pr_test1;
    if判断语句 case语句 循环语句使用方式
    create or replace procedure pr_test5 is
    begin
      update t_hq_ryxx set bumbm = '103' where bumbm is null;--where 是判断条件
    
    if sql%rowcount > 0 then
      dbms_output.put_line('更新了  '||sql%rowcount||'  条记录');
    else
      dbms_output.put_line('更新了 0 条记录');
    end if;
    commit;--提交语句
    end pr_test5;
    数据的更新操作
    --通过输入编号进行相关内容的匹配,匹配成功后输出相关内容
    create or replace procedure pr_test3(v_bh in varchar2,v_xx in out varchar2) is
    begin
      --定义输入输出xingm变量为v_xm 并将bianh为变量v_bh ,输入的是编号,与bumbm匹配才可以输出配上的姓名
     select xingm into v_xx from t_hq_ryxx where bianh = v_bh and bumbm = v_xx;
     if sql%found then
       dbms_output.put_line('查找到le数据!');
     else
       dbms_output.put_line('未查找到数据');
       end if;
     exception
       when no_data_found then
         
       dbms_output.put_line('未查找到数据');
       
       dbms_output.put_line('sqlcode:'||sqlcode);--错误代码
       dbms_output.put_line('sqlerrm:'||sqlerrm);--错误信息
       
       when others then
         
       dbms_output.put_line('查找出错');
     
       dbms_output.put_line('sqlcode:'||sqlcode);--错误代码
       dbms_output.put_line('sqlerrm:'||sqlerrm);--错误信息
    end pr_test3;
    
    
    create or replace procedure pr_test4(v_bh in varchar2) is
    v_xm t_hq_ryxx.xingm%type;
    begin
       v_xm :='102';
      pr_test3(v_bh,v_xm);
      dbms_output.put_line(''||v_xm);
    end pr_test4;
    oracle子程序数据关联及异常处理
  • 相关阅读:
    Python的运算符
    RabbitMQ 的配置文件
    安装新版本的rabbitmq
    Ubuntu 16.04 安装rabbitmq
    Python Web 版本tailf, grep
    解决pycharm问题:module 'pip' has no attribute 'main'
    Python argparse
    Ansible 并行和异步
    cef相关
    浏览器透明设置例子,qt5.6才支持
  • 原文地址:https://www.cnblogs.com/name-hanlin/p/4928854.html
Copyright © 2011-2022 走看看