初始化 pl/sql 记录类型
在 PL/SQL 中,varray
可以在创建时初始化为:
TYPE colour_tab IS VARRAY(3) OF VARCHAR2(20);
french_colours colour_tab := colour_tab('RED','WHITE','BLUE');
是否有 PL/SQL 记录类型的等效初始化方法?
type location_record_type is record (
street_address varchar2(40),
postal_code varchar2(12),
city varchar2(30),
state_province varchar2(25),
country_id char(2) not null := 'US'
);
In PL/SQL, a varray
can be initialised at creation time as:
TYPE colour_tab IS VARRAY(3) OF VARCHAR2(20);
french_colours colour_tab := colour_tab('RED','WHITE','BLUE');
Is there an equivalent method of initialisation for PL/SQL record types?
type location_record_type is record (
street_address varchar2(40),
postal_code varchar2(12),
city varchar2(30),
state_province varchar2(25),
country_id char(2) not null := 'US'
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
使用函数充当一种“构造函数”(查看函数 f()):
Use a function to act as a kind of "constructor" function (look at function f()):
Oracle 18c 允许使用 限定表达式:
上面的输出是...
您可以此处在 Oracle Live SQL 中运行上述示例代码。 (不幸的是,该网站需要登录。)
Oracle 18c allows record initialization with qualified expressions:
Output of the above is ...
You can run the above sample code in Oracle Live SQL here. (Unfortunately that site requires a logon.)
不,没有。您必须显式分配每个值。 此处参考文档。
No, there is not. You have to assign each value explicitly. Documentation reference here.
记录类型实际上是为保存 SELECT 语句中的行而设计的。
显然,对于查询不是 SELECT * FROM 单个表的情况(因为在这种情况下,我们可以使用
%ROWTYPE
代替)。Record types are really designed for holding rows from SELECT statements.
Obviously for cases where the query isn't a SELECT * FROM a single table (because in that scenario we can use
%ROWTYPE
instead.记录初始化在其声明中执行
并通过从 DUAL 中选择来记录分配:
Record initialization is performed in its declaration
and record assignment by selecting into from DUAL:
您可以创建一个返回该记录类型的函数。
请参阅下面的示例代码:
You can create a function that return that record type.
See below sample code: