Oracle 10G表格。检查数据库中是否存在值

发布于 2025-02-12 15:54:50 字数 1015 浏览 1 评论 0原文

问题1:

在插入如何检查您在该文本框中输入的值是否确实与数据库中的值相匹配。 我的榜样和方法不起作用。显示的错误是:

表,视图在此上下文中不允许。

按下按钮[添加按钮]

//blockname            compare     //database table DRINK, column drink_id
IF (:RESERVATION_BLOCK.DRINK_ID<>DRINK.DRINK_ID) THEN
MESSAGE('IF PART');
ELSE
MESSAGE('ELSE PART'); 
END IF;
    

问题2:

使用if语句添加数据库 显示的不工作错误是按按钮按下扳机升高时

未经处理的异常ORA-00001。

我的示例不起作用:按下按钮时[保存按钮]无需if语句即可完美地工作,但这不是一个好练习

IF (:RESERVATION_BLOCK.DRINK_ID is null) THEN
 MESSAGE('No Drink Ordered');
ELSIF (:RESERVATION_MENU_DRINK_BLOCK.DRINK_ID is not null) THEN
  INSERT INTO RESERVATION_DRINK
  VALUES(
  :RESERVATION_BLOCK.RESERVATION_ID, //comes from previous tab pane block
  :RESERVATION_MENU_DRINK_BLOCK.DRINK_ID,
  :RESERVATION_MENU_DRINK_BLOCK.QUANTITY);
  COMMIT;
  MESSAGE('DRINK ORDER SAVED SUCCESSFULLY!');
END IF;                     

Question 1 :

while inserting how will you check whether the value you entered in that textbox does matched with that in the database.
My example and approach not working. error displayed is:

table, view does not allow in this context.

when button pressed[Add button]

//blockname            compare     //database table DRINK, column drink_id
IF (:RESERVATION_BLOCK.DRINK_ID<>DRINK.DRINK_ID) THEN
MESSAGE('IF PART');
ELSE
MESSAGE('ELSE PART'); 
END IF;
    

QUESTION 2:

Using if statement to add in database
not working error displayed is when button pressed trigger raised

unhandled exception ORA-00001.

My example not working: when button pressed [SAVE button] code works perfectly without if statement but that's not a good practice when having null

IF (:RESERVATION_BLOCK.DRINK_ID is null) THEN
 MESSAGE('No Drink Ordered');
ELSIF (:RESERVATION_MENU_DRINK_BLOCK.DRINK_ID is not null) THEN
  INSERT INTO RESERVATION_DRINK
  VALUES(
  :RESERVATION_BLOCK.RESERVATION_ID, //comes from previous tab pane block
  :RESERVATION_MENU_DRINK_BLOCK.DRINK_ID,
  :RESERVATION_MENU_DRINK_BLOCK.QUANTITY);
  COMMIT;
  MESSAGE('DRINK ORDER SAVED SUCCESSFULLY!');
END IF;                     

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

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

发布评论

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

评论(1

花期渐远 2025-02-19 15:54:50

问题的第一部分:您不能在中引用中的

DECLARE
   l_cnt  NUMBER;
BEGIN
   SELECT COUNT (*)
     INTO l_cnt
     FROM drink d
    WHERE d.drink_id = :reservation_block.drink_id;

   IF l_cnt > 0
   THEN
      MESSAGE ('That ID exists');
   ELSE
      MESSAGE ('That ID does not exist');
   END IF;
END;

表>表示您尝试插入重复值,该值受唯一索引限制(可能是主要或唯一的密钥约束)。

该怎么办?

  • 修复ID值;我没有如何将其填充到块中,但是您做到了错误。考虑使用序列,以确保值始终是唯一
  • 修改约束的唯一的;也许它必须是复合(有两个或多个列,而不仅仅是id
  • 可能是最愚蠢的解决方案,但是 - 是一个解决方案,毕竟:删除独特的约束

The first part of the question: you can't reference table in IF, do it before it:

DECLARE
   l_cnt  NUMBER;
BEGIN
   SELECT COUNT (*)
     INTO l_cnt
     FROM drink d
    WHERE d.drink_id = :reservation_block.drink_id;

   IF l_cnt > 0
   THEN
      MESSAGE ('That ID exists');
   ELSE
      MESSAGE ('That ID does not exist');
   END IF;
END;

As of your second question: ORA-00001 means that you tried to insert a duplicate value which is restricted by unique index (might be a primary or unique key constraint).

What to do?

  • fix the ID value; I don't have how you populated it into the block, but you did it wrong. Consider using a sequence so that Oracle would make sure that values are always unique
  • modify the constraint; maybe it has to be composite (having two or more columns, not just the ID)
  • probably the most stupid solution, but - it is a solution, after all: drop the unique constraint
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文