zoukankan      html  css  js  c++  java
  • oracle数据库存储过程中的select语句的位置

    导读:在oracle数据库存储过程中如果用了select语句,要么使用"select into 变量"语句要么使用游标,oracle不支持单独的select语句。

    先看下这个存储过程:

    create or replace procedure pro_test 
    is 
    begin 
    select * from t_test; 
    end pro_test;

    这个存储过程正确吗?

    昨天因为这个,耽误了好久(在一个存储过程中用了select语句,但既没有用游标也没有用into).

    在存储过程(oracle数据库)中如果用了select语句,要么使用"select into 变量"语句要么使用游标,oracle不支持单独的select语句(如表述有误请指出).

    select into 比较简单,但是如果返回的是一个结果集就无法满足要求了.

    游标分Cursor型游标和SYS_REFCURSOR型游标两种

    Cursor型游标--不能用于参数传递

    create or replace procedure pro_test() is

    cusor_1 Cursor is select 字段名 from 表名 where 条件;

    (或者

    select class_name into cursor_2 from class where ...;

    cursor的另一种用法,需要写在begin和end之间)

    begin

    select class_name into cursor_2 from class where ...;

    可以使用

    for xxx in cursor

    loop

    ....

    end loop; --对Cursor进行遍历

    end pro_test;

    SYS_REFCURSOR型游标

    create or replace procedure pro_test(rsCursor out SYS_REFCURSOR) is

    cursor SYS_REFCURSOR;

    name varhcar(20);

    begin

    open cursor for

    select name from student where ...; --使用open来打开进行赋值

    --遍历

    loop

    fetch cursor into name --fetch into来打开遍历的每条数据

    exit when cursor%NOTFOUND; --未找到记录信息

    dbms_output.putline(xxxx);

    end loop;

    rsCursor := cursor;

    end pro_test;

  • 相关阅读:
    Kinect学习笔记(六)——深度数据测量技术及应用
    [device]/proc/devices and /dev/
    [Eth]Mac/Phy/mdio/Rgmii
    [uboot]uboot如何引导系统
    [网络]Linux一些网络知识
    [基础]sizeof和strlen
    [基础]关于extern指针和数组的用法
    [ucos]了解ucos
    [Linux]gcc/libc/glibc
    [i.MX6q]i.MX6q处理器,linux操作系统平台搭建 从SD卡启动系统
  • 原文地址:https://www.cnblogs.com/wuxu/p/10208573.html
Copyright © 2011-2022 走看看