• 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 存储过程名字;

  • 相关阅读:
    8. Andrénalin ★ Serial
    1 Acid burn ★ Nag,Name/Serial,Serial
    【CPP】字符串和格式化输入输出
    什么是生成器
    【python密码学编程】8.使用换位加密法加密
    【python密码学编程】6.凯撒加密法
    【CPP】数据和C
    【python密码学编程】7.暴力破解凯撒加密法
    HDOJ 4515 小Q系列故事——世界上最遥远的距离
    POJ1131 Octal Fractions
  • 原文地址:https://www.cnblogs.com/moly/p/9702366.html
Copyright © 2020-2023  润新知