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

  • 相关阅读:
    Python如何爬取淘宝MM呢?教你一招
    Python爬虫实战之如何爬取百度贴吧帖子?案例详解
    SpringBoot定时任务如何正确运用?案例详解
    JS数组之重排序方法
    JS数组之栈和队列
    JS数组之转换方法
    计算机相关推荐教程
    多维数组
    重新认识变量和数组
    数组
  • 原文地址:https://www.cnblogs.com/moly/p/9702366.html
Copyright © 2011-2022 走看看