zoukankan      html  css  js  c++  java
  • oracle pl/sql中record和%rowtype整理

    1. 创建stu表,如下:

      create table stu(s1 number, s2 number);

    2. 定义多维数组, 能用来接受多条返回数据

      方式一:   type type_name is table of stu%rowtype;           # 基于表中行类型的多维数组

          custom_type type_name;                                    # 定义该多维数组变量

          execute immediate 'select * from stu where s1>:1' bulk collect into custom_type using in 5;

      方式二:   type list_name is record(x number, y number);   # 先定义record, record即一维数组, 

          type type_name is table of list_name;                  # 使用定义的一维数组定义多维数组

          custom_type type_name;               # 定义该多维数组变量

          execute immediate 'select * from stu where s1>:1' bulk collect into custom_type using in 5;

    3. 定义一维数组, 用来接受一条返回数据

      方式一:   type list_name is record(x number, y number);    # 先定义record, record即一维数组.

          custom_type list_name                  #定义该一维数组变量.

          execute immediate 'select * from stu where s1=:xx' into custom_type using in 1;

      方式二:   custom_type stu%rowtype;                           # 使用表的行类型定义一维数组变量

          execute immediate 'select * from stu where s1=:xx' into custom_type using in 1;

    4. 以上是演示多行多列和单行多列的返回值接受, 单列多行和单列单行的返回值接受和上面类似, 定义时

        使用table.column%type 或 record(x number)定义行一维的单元素数组后, 再使用同上的定义多维度的

        办法, 即可用来接受单列多维数据或单列单维数据.

  • 相关阅读:
    开更
    PKUSC2016
    Educational Codeforces Round 12 E Beautiful Subarrays
    省选过了,又开始更新了。。。
    我来试试视频功能
    [BZOJ4407]于神之怒加强版
    bzoj3998: [TJOI2015]弦论
    bzoj4569: [Scoi2016]萌萌哒
    2016-5-30模拟测试
    2016-5-26模拟测试
  • 原文地址:https://www.cnblogs.com/quzq/p/12068327.html
Copyright © 2011-2022 走看看