如何在 PL/SQL 中以行类型文字作为参数调用过程? [英] How to call a procedure with a rowtype literal as parameter in PL/SQL?

查看:54
本文介绍了如何在 PL/SQL 中以行类型文字作为参数调用过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个表和一个接受表行类型的一个参数的过程:

CREATE TABLE t (a NUMBER, b NUMBER);创建过程 p (x t%ROWTYPE) 是开始空值;结尾;

我可以使用 rowtype 文字调用该过程,即不显式创建 rowtype 变量(或至少不显式列出和分配它的每个字段)?以下两种方法都会产生以下错误:

p(1, 2);

p((1, 2));

<块引用>

PLS-00306:调用P"时的参数数量或类型错误

解决方案

您也可以从游标循环构造记录:

for r in (从双选 1, 2)环形p(r);结束循环;

不幸的是,PL/SQL 记录只是简单的结构,不像对象类型那样带有构造函数.(我希望他们这样做.)

Lets say I have a table and a procedure that accepts one argument of the tables rowtype:

CREATE TABLE t (a NUMBER, b NUMBER);

CREATE PROCEDURE p (x t%ROWTYPE) IS
BEGIN
  NULL;
END;

Can I call that procedure using a rowtype literal, that is without explicitly creating a rowtype variable (or at least not explicitly listing and assigning every field of it)? The two following approaches both generate the below error:

p(1, 2);

p((1, 2));

PLS-00306: wrong number or types of arguments in call to 'P'

解决方案

You could also construct the record from a cursor loop:

for r in (
    select 1, 2 from dual
)
loop
    p(r);
end loop;

Unfortunately PL/SQL records are just simple structures and don't come with constructors as object types do. (I wish they did.)

这篇关于如何在 PL/SQL 中以行类型文字作为参数调用过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆