• 存储过程


    --存储过程
    --pl/sql

    过程参数有IN/OUT/IN OUT三种类型,其中IN类型可以被过程体引用,但不能改写值;OUT类型不可被过程体引用,但可改写值;IN OUT 既可以被过程体引用,又可以改写值.
    在调用in out类型时,调用过程插入参数时,不能直接用常量。必须用变量。这样才能接收out返回来的值。同理:用out的也不能直接用常量。


    create procedure div(a int,b int)
    as
    c float;
    begin
    c:=a*1.0/b;
    dbms_output.put_line(a||'/'||b||'='||c);
    Exception
    when others then dbms_output.put_line('除数为0');
    end;

    begin
    div(10,0);
    end;

    begin
    div(b=>20,a=>10);
    end;

    create procedure pc1
    (a int:=20,
    b int:=30,
    c int:=40,
    d int:=50)
    as
    e int;
    begin
    e:=a+b+c+d;
    dbms_output.put_line(e);
    end;

    begin
    pc1(1,2,3,4);
    end;
    begin
    pc1(b=>1,d=>2,c=>3);
    end;
    begin
    pc1(10,d=>2);
    end;

    create or replace procedure pc2
    (a int,b in out int ,c out int )
    as
    begin
    c:=a+b;
    b:=a*b;
    end;

    declare
    x int:=20;
    y int:=30;
    begin
    pc2(10, x , y );
    dbms_output.put_line(x||','||y);
    end;

    select * from users

    create or replace procedure procAddUser
    (
    name varchar,
    phone varchar,
    mail varchar,
    loginid varchar,
    loginpwd varchar,
    gender int:=1,
    roleid int:=1,
    stateid int:=1,
    address varchar:='未知'
    )
    as
    begin
    insert into users values (
    USERS_ID_ASQ.nextval,name,address,
    phone,mail,stateid,0,loginid,loginpwd,
    roleid,gender);
    end;


    begin
    procadduser('haha','110','aa@aa.com','haha','123');
    end;
    select * from users

    grant execute on div to abc
    grant select on books to abc


    create function fndiv
    (a int,b int)
    return float
    as
    c float;
    begin
    c:=a*1.0/b;
    return c;
    end;

    select fndiv(10,20) from dual
    select id,title,unitprice, fndiv(unitprice,2) 半价
    from books

    declare
    x float;
    begin
    x:=fndiv(10,20);
    dbms_output.put_line(x);
    end;

    create or replace package haha1
    is
    function fndiv(a int,b int) return float;
    procedure add(a int,b int);
    end;

    create or replace package body haha1
    is
    function fndiv(a int,b int) return float
    as
    begin
    return a*1.0/b;
    end;
    procedure add(a int,b int)
    as
    c int;
    begin
    c:=a+b;
    dbms_output.put_line(c);
    end;
    end;

    select haha1.fndiv(10,20) from dual
    begin
    haha1.add(10,haha1.fndiv(10,20));
    end;

  • 相关阅读:
    9. 如何在控制器或模型中获取当前登录的管理员或登录用户信息
    FastAdmin控制管理员只显示自己添加的数据
    div 隐藏
    使用JavaScript实现Input输入数据后自动计算并实时显示
    thinkphp中在页面怎么格式输出小数和时间
    fastadmin表单提交提示红色OK
    在某个域被使用或改变时,它会改变颜色。【用于提示表单已填充】
    Unix命令行学习
    Ubuntu菜鸟入门(十)—— Flash控件安装
    Ubuntu菜鸟入门(九)—— 支付宝支付控件安装
  • 原文地址:https://www.cnblogs.com/tian114527375/p/4914808.html
Copyright © 2020-2023  润新知