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

    /  

     --语句块结束符号

  • 相关阅读:
    转: sublime text常用插件和快捷键
    转: markdown基本语法
    sqlite详细介绍
    webpack配置babel-loader
    vue骨架屏以及seo优化
    路由滚动行为
    anywhere随启随用的静态文件服务器
    node.js http-server 搭建本地服务器
    vuex中mutations数据响应
    vue项目开发优化
  • 原文地址:https://www.cnblogs.com/shihao/p/2704423.html
Copyright © 2011-2022 走看看