zoukankan      html  css  js  c++  java
  • oracle 存储过程 stored procedure 查询一条记录或多条记录

    创建基本表

    -- Create table

    create table USER_INFORMATION

    (

    P_ID            NUMBER,

    USER_LOGIN_NAME NVARCHAR2(30)

    )

    创建包:

    create or replace package pack_test is  

           type cur_test is ref cursor;  

    end pack_test; 

    /  

    --这个不能少呀,加上这个就可以在sql/plus中运行了,这个是结束符号

    创建存储过程

    create or replace procedure proc_cur(p_id in number,p_cur out pack_test.cur_test)   

    is   

           v_sql varchar2(400);

    begin  

           if p_id = 0 then   

              open p_cur for select * from user_information;   

           else   

              v_sql := 'select * from user_information where id =: p_id';   

              open p_cur for v_sql using p_id;   

           end if;   

    end proc_cur;

    测试存储过程

    -- Test statements here  

    set serveroutput on

    declare   

     v_id number := 0;  

     v_row USER_INFORMATION%rowtype;   --注意这里是表名

     p_cur pack_test.cur_test;

    begin   

     proc_cur(v_id, p_cur);  

     loop  

        fetch p_cur into v_row;  

        exit when p_cur%notfound;  

        DBMS_OUTPUT.PUT_LINE(v_row.USER_LOGIN_NAME||'='||v_row.P_ID);  

     end loop;  

     close p_cur;  

    end

    /  

     --语句块结束符号

  • 相关阅读:
    没有生产管理,只会生产的企业即将被淘汰
    实施一套MES系统需要多少钱?
    MES助力日立电梯提升精细化管理水平
    数据定义
    (CVE-2017-16995)Ubuntu内核提权
    (CVE-2017-7494)Linux Samba远程代码执行
    (CVE-2019-13272)Linux本地提权
    vulnhub 之 dc6
    vulnhub 之 dc 5
    vulnhub 之 dc4
  • 原文地址:https://www.cnblogs.com/shihao/p/2704423.html
Copyright © 2011-2022 走看看