举个例子对照下 declare type r is record( i number, w number); r1 r; begin select 1 a, 2 b into r1 from dual; dbms_output.put_line(r1.i||r1.w); end;如果需要存储多条记录(表结构): type t is table of r index by pls_integer;
举个例子对照下 declare type r is record( i number, w number); r1 r; begin select 1 a, 2 b into r1 from dual; dbms_output.put_line(r1.i||r1.w); end;如果需要存储多条记录(表结构): type t is table of r index by pls_integer;存储过程里每次这样执行时都创建TYPE?
举个例子对照下 declare type r is record( i number, w number); r1 r; begin select 1 a, 2 b into r1 from dual; dbms_output.put_line(r1.i||r1.w); end;如果需要存储多条记录(表结构): type t is table of r index by pls_integer;存储过程里每次这样执行时都创建TYPE?这里只是一个临时的type,并不是一个像TABLE 一样的对象永久存在数据库中,就好比一个变量的作用
举个例子对照下
declare
type r is record(
i number,
w number);
r1 r;
begin
select 1 a, 2 b into r1 from dual;
dbms_output.put_line(r1.i||r1.w);
end;如果需要存储多条记录(表结构):
type t is table of r index by pls_integer;
一是在PLSQL中需要动态创建,拼字符串总是麻烦,易出错,易出问题
二是如提前创建,往往需求是随着代码展开而发生变化的,提前预知所有的内容和结构是不可能的
【如果你后续都是很多子查询,为什么不能预订下来。不过有改动,你后续代码都要改,莫不如就定死临时表的结构】
三是如动态创建,最大麻烦是DDL并发问题,一个在create,一个在drop肯定有问题
【如果多用户都要有这类需求,那就不是建临时表了,而是实体表或物化视图了】
三是如动态创建,对于on commit preserve rows的临时表想drop掉还得加奇淫技巧trunacate
【若单用户truncate也无所谓】整个不太明白。
目前看大致应该如此:
单用户:可以使用临时表,但此时db的优势已不多,其实一般都是用应用实现。
多用户:建立统一体系。
如:一个过程定期在扫,然后所有应用使用其结果表。当然不限如此
type到底怎么用?
举个例子对照下
declare
type r is record(
i number,
w number);
r1 r;
begin
select 1 a, 2 b into r1 from dual;
dbms_output.put_line(r1.i||r1.w);
end;如果需要存储多条记录(表结构):
type t is table of r index by pls_integer;存储过程里每次这样执行时都创建TYPE?
举个例子对照下
declare
type r is record(
i number,
w number);
r1 r;
begin
select 1 a, 2 b into r1 from dual;
dbms_output.put_line(r1.i||r1.w);
end;如果需要存储多条记录(表结构):
type t is table of r index by pls_integer;存储过程里每次这样执行时都创建TYPE?这里只是一个临时的type,并不是一个像TABLE 一样的对象永久存在数据库中,就好比一个变量的作用