如何在Oracle中的触发查询中使用页面项目值?

发布于 2025-02-09 17:05:47 字数 248 浏览 2 评论 0原文

我希望正确运行以下触发器,但会增加一个错误,即:BAD BIND变量“ P23_ID”。 触发查询是:

Create or replace trigger "newTRG"
Before
Insert on "my_table"
For each row
Begin
If :new."ID" is null then
Insert into my_table (ID) values (:P23_ID);
end if;
End;

I want the following trigger to be run correctly but it rise an error which is: bad bind variable 'P23_ID'.
The trigger query is:

Create or replace trigger "newTRG"
Before
Insert on "my_table"
For each row
Begin
If :new."ID" is null then
Insert into my_table (ID) values (:P23_ID);
end if;
End;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

檐上三寸雪 2025-02-16 17:05:47

使用v()语法:

create or replace trigger "newTRG" before
   insert on "my_table"
   for each row
begin
   if :new."ID" is null then
      insert into my_table ( id ) values (v('P23_ID'));

   end if;
end;

在旁注上,如果这是主要键值,则使用身份列(新方法)或序列(旧方法)填充要容易得多您的专栏。从页面项目中执行此操作是错误的。

Use the v() syntax:

create or replace trigger "newTRG" before
   insert on "my_table"
   for each row
begin
   if :new."ID" is null then
      insert into my_table ( id ) values (v('P23_ID'));

   end if;
end;

On a side note, if this is a primary key value it is a lot easier to use identity columns (the new way) or a sequence (the old way) to populate your column. Doing this from a page item is error prone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文