Oracle APEX 数据库触发器 - 引用数据库列的问题
我有一个以冒号分隔的值列表,存储在 Oracle 数据库的 varchar2
列 ORDER_PARTS_LIST
中。
(我知道将数据存储在这样的列表中可能不是最佳实践,但现在忽略这个事实。)
以下是相关的表列:
ORDER_TABLE(
ORDER_NUMBER number,
ORDER_PARTS_LIST varchar(4000))
PARTS_TABLE(
PART_NUMBER varchar(20),
ASSIGNED_ORDER_NUMBER number)
我有一个条件触发器:
create or replace trigger "ORDER_PARTS_T1"
BEFORE
insert or update or delete on "ORDER_TABLE"
for each row
begin
if :new.ORDER_PARTS_LIST LIKE '%'+PART_NUMBER+'%' then
update PARTS_TABLE set ASSIGNED_ORDER_NUMBER = :ORDER_NUMBER;
end if;
end;
当我运行此触发器时我收到以下错误:
PLS-00201: identifier 'PART_NUMBER' must be declared
应该发生的情况是触发器检查 PARTS_TABLE
中的哪些 PART_NUMBERs
包含在 ORDER_PARTS_LIST
中这ORDER_TABLE
,然后将 ORDER_TABLE
中受影响行的 ORDER_NUMBER
插入到 ASSIGNED_ORDER_NUMBER
列中代码>PARTS_TABLE。
最后,订单中的所有零件都应标有该订单的编号。
这有什么意义吗???
我不确定如何正确定义此触发器中的变量,以便它运行,老实说,我对触发器是否会执行我认为应该执行的操作(即使这些有效)有一些疑问。任何关于获得像我定义的那样的触发功能的建议或帮助都应该很棒。提前致谢。
I have a colon delimited list of values being stored in a varchar2
column, ORDER_PARTS_LIST
, of my Oracle database.
(I understand that storing data in a list like this might not be best practice but for now just ignore that fact.)
Here are the relevant table columns:
ORDER_TABLE(
ORDER_NUMBER number,
ORDER_PARTS_LIST varchar(4000))
PARTS_TABLE(
PART_NUMBER varchar(20),
ASSIGNED_ORDER_NUMBER number)
I have a conditional trigger:
create or replace trigger "ORDER_PARTS_T1"
BEFORE
insert or update or delete on "ORDER_TABLE"
for each row
begin
if :new.ORDER_PARTS_LIST LIKE '%'+PART_NUMBER+'%' then
update PARTS_TABLE set ASSIGNED_ORDER_NUMBER = :ORDER_NUMBER;
end if;
end;
When I run this trigger I get the following error:
PLS-00201: identifier 'PART_NUMBER' must be declared
What is supposed to happen is that the trigger checks which PART_NUMBERs
, in PARTS_TABLE
, are included in the ORDER_PARTS_LIST
, in the ORDER_TABLE
, and then inserts the ORDER_NUMBER
, for the affected row in ORDER_TABLE
, into the ASSIGNED_ORDER_NUMBER
column, of PARTS_TABLE
.
In the end, all the PARTS in an ORDER should be flagged with that ORDER's NUMBER.
Does that make ANY sense???
I am not certain exactly how to properly define the variables in this trigger so that it runs and honestly I have a few doubts as to whether or not the trigger would do what I think it should even if those worked. ANY suggestions or help in getting the trigger functioing like I have defined it should would be great. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以进行字符串匹配来测试每一行:
例如,如果 ORDER_PARTS_LIST 为
'123:456:789'
,则 INSTR 将找到 id 123、456 和 789 的匹配项,但不会找到 124 的匹配项,例如,45 或 8。当从订单中删除零件时,您将需要一个不同的触发器来
PARTS_TABLE
中的相应字段NULL
:You can do string matching to test each row:
So for example, if ORDER_PARTS_LIST is
'123:456:789'
, the INSTR will find matches for the ids 123, 456 and 789, but not 124, 45 or 8, for example.When parts are removed from an order you will need a different trigger to
NULL
the appropriate fields inPARTS_TABLE
:您正在 ORDER_TABLE 上创建触发器。由于 ORDER_TABLE 不包含名为 PART_NUMBER 的列,因此 Oracle 无法找到标识符“PART_NUMBER”,因为它属于 PARTS_TABLE。
您需要在触发器中编写一个单独的查询来访问 PARTS_TABLE 中的 PART_NUMBER。
You are creating a trigger on the ORDER_TABLE. Since the ORDER_TABLE does not contain a column named PART_NUMBER, Oracle is unable to find the identifier 'PART_NUMBER' as it belongs to the PARTS_TABLE.
You will need to write a separate query in your trigger to access the PART_NUMBER in PARTS_TABLE.
不完全确定这一切是如何组合在一起的(似乎这不会解释多个订单的同一部分),但看起来您想要做的是这样的:
Not entirely sure how this all fits together (seems like this won't account for the same part on multiple orders), but it looks like what you're trying to do is something like this: