zoukankan      html  css  js  c++  java
  • oracle存储过程学习

    *: 存储过程创建

    1. 输出查询结果(dbms_output.put_line('用户名为:'||u_name);)

    create or replace procedure p002test
    is
    u_name varchar2(100);
    begin
    select user_name into u_name from t_user;
    dbms_output.put_line('用户名为:'||u_name);
    end p002test;

    2. 简单循环(for xx in list loop xxxxx end loop)

    create or replace procedure p002test
    is
    cursor u_cursor is select user_name, user_remark from t_user;
    begin
    for u_record in u_cursor loop
    dbms_output.put_line(u_record.user_name||': '||u_record.user_remark);
    end loop;
    end p002test;

    3. 传递参数,使用简单异常(当需要输出参数的时候,使用out,或者in out,默认为in)

    create or replace procedure p002test(p_user_id in number, p_user_password in varchar2)
    is
    begin
    update t_user set user_password=p_user_password where user_id = p_user_id;
    commit;
    exception
    when others then
    dbms_output.put_line('修改失败,回滚。');
    rollback;
    end p002test;

    4. 异常信息打印(sqlcode: 异常码,sqlerrm:异常详细)

    create or replace procedure p002test(p_user_id in number, p_user_password in varchar2)
    is
    begin
    update t_user set user_password=p_user_password where user_id = p_user_id;
    commit;
    exception
    when others then
    dbms_output.put_line('修改失败,回滚。errorCode:' || sqlcode || ' errorText:' || substr(sqlerrm,1,200));
    rollback;
    end p002test;

    **: 存储过程调用

    1.

    begin
    p002test();
    end;

    2.

    call p002test();
    call p002test(1, '123');

    ***: 存储过程删除

    drop procedure 存储过程名字;

  • 相关阅读:
    mysql
    mysql
    mysql
    mysql
    sed编辑命令
    awk正则应用
    awk运算符
    awk命令细节
    uniq命令
    sort命令
  • 原文地址:https://www.cnblogs.com/moly/p/9702366.html
Copyright © 2011-2022 走看看