• 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)定义行一维的单元素数组后, 再使用同上的定义多维度的

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

  • 相关阅读:
    Ado.Net基础拾遗一:读取数据
    Linq 简明教程
    ASP.NET MVC DropdownList的使用
    inner join, left join ,right join 结果
    C#基础之 派生类
    SQL Server 笔试题总结
    SQL Server 基础 之 CASE 子句
    昨晚京东校招笔试,没考一道.net,全考java了
    利用scrapy和MongoDB来开发一个爬虫
    linux 获取网卡的IP地址
  • 原文地址:https://www.cnblogs.com/quzq/p/12068327.html
Copyright © 2020-2023  润新知