Oracle Apex 验证 - 有效产品名称

发布于 2025-01-09 07:03:28 字数 766 浏览 1 评论 0原文

我在这里有一个验证初学者的问题:

我有一个选择列表项,选项: 产品 SKU

如果用户选择 SKU 选项,则会显示一个新的文本字段项目,供客户记下 SKU 编号。 然后,我的验证会尝试阻止插入无效的 SKU。 这就是我到目前为止所得到的:

declare 

  v_rows_approved_min number;
  v_rows_approved_max number;
  err varchar2(300);

begin

if :P8_PRODUCT_OR_SKU = 'SKU' -- THIS IS MY SELECT LIST ITEM
then

  err := 'Not a valid SKU';

  v_rows_approved_min := 1;
  select count(*) into v_rows_approved_max from SKU_TABLE;

  for cur_a in (select SKU from SKU_TABLE) 
  loop
    exit when v_rows_approved_min > v_rows_approved_max;
    if :P8_SKU = cur_a.SKU
    then return err;
    else null;
    end if;
    v_rows_approved_min := v_rows_approved_min + 1;

  end loop;

 else null;

 end if;

 end;

不确定这里发生了什么,有人可以帮忙吗?

谢谢!

I have a Validation beginner's question here:

I have a select list item, options:
Product
SKU

If the user selects the SKU option a new textfield Item is shown for the customer to write down the SKU number.
My validation then tries to prevent an invalid SKU to be inserted.
This is what I have so far:

declare 

  v_rows_approved_min number;
  v_rows_approved_max number;
  err varchar2(300);

begin

if :P8_PRODUCT_OR_SKU = 'SKU' -- THIS IS MY SELECT LIST ITEM
then

  err := 'Not a valid SKU';

  v_rows_approved_min := 1;
  select count(*) into v_rows_approved_max from SKU_TABLE;

  for cur_a in (select SKU from SKU_TABLE) 
  loop
    exit when v_rows_approved_min > v_rows_approved_max;
    if :P8_SKU = cur_a.SKU
    then return err;
    else null;
    end if;
    v_rows_approved_min := v_rows_approved_min + 1;

  end loop;

 else null;

 end if;

 end;

Not sure what's going on here, can anyone help please?

Thanks!

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

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

发布评论

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

评论(1

花期渐远 2025-01-16 07:03:28

这段代码过于复杂。它检查表中是否存在页面项值,如果找到匹配则返回错误。这是通过一个带有一些附加逻辑的循环来完成的,当迭代次数达到选择计数时退出循环。最后一个逻辑是不需要的。如果表包含 5 行,则循环将进行 5 次迭代。无需从表 (v_rows_approved_max) 中执行 SELECT 计数,然后检查每次迭代是否尚未达到该数字...

此外,没有 RETURN 语句如果找不到匹配项,则将其添加到末尾。

这是重写的尝试:

DECLARE
---- not needed
--  v_rows_approved_min NUMBER;
--  v_rows_approved_max NUMBER;
  err VARCHAR2(300) := 'Not a valid SKU';
BEGIN
  IF :P8_PRODUCT_OR_SKU = 'SKU' -- THIS IS MY SELECT LIST ITEM
  THEN
    ---- err can be defaulted in declaration
    --err := 'Not a valid SKU';
    
    --v_rows_approved_min := 1;
    
    ---- not needed see  below
    --SELECT COUNT(*) INTO v_rows_approved_max FROM sku_table;

    FOR cur_a IN ( SELECT sku FROM sku_table ) LOOP
      ---- not needed. You're looping through the table, v_rows_approved_min will be > than v_rows_approved_max    
      --EXIT WHEN v_rows_approved_min > v_rows_approved_max;
      IF :P8_SKU = cur_a.sku THEN
        RETURN err;
---- not needed
--      ELSE
--        NULL;
      END IF;
---- not needed      
--      v_rows_approved_min := v_rows_approved_min + 1;
    END LOOP;

---- not needed
--  ELSE
--    NULL;
  END IF;
  -- you need to return something whenever the function ends...
  RETURN NULL;
END;
/

但是......
这可以大大简化。

创建“返回的行”类型的验证

来源:

SELECT
  1
  FROM
  sku_table WHERE sku = :P8_SKU

错误消息:不是有效的 SKU

服务器端条件(类型项目 = 值):项目:P8_PRODUCT_OR_SKU;值:SKU

这执行完全相同的操作。

This code is overly complex. It checks if a page item value exists in a table and returns an error if a match is found. This is done with a loop with some additional logic to exit the loop with the number of iterations reaches the select count. That last logic is not needed. If a table contains 5 rows, then the loop will have 5 iterations. No need to do a SELECT count from the table (v_rows_approved_max) and then check every iteration if that number has not been reached yet...

Also, there is no RETURN statement if not match is found, so that is added at the end.

Here is an attempt at a rewrite:

DECLARE
---- not needed
--  v_rows_approved_min NUMBER;
--  v_rows_approved_max NUMBER;
  err VARCHAR2(300) := 'Not a valid SKU';
BEGIN
  IF :P8_PRODUCT_OR_SKU = 'SKU' -- THIS IS MY SELECT LIST ITEM
  THEN
    ---- err can be defaulted in declaration
    --err := 'Not a valid SKU';
    
    --v_rows_approved_min := 1;
    
    ---- not needed see  below
    --SELECT COUNT(*) INTO v_rows_approved_max FROM sku_table;

    FOR cur_a IN ( SELECT sku FROM sku_table ) LOOP
      ---- not needed. You're looping through the table, v_rows_approved_min will be > than v_rows_approved_max    
      --EXIT WHEN v_rows_approved_min > v_rows_approved_max;
      IF :P8_SKU = cur_a.sku THEN
        RETURN err;
---- not needed
--      ELSE
--        NULL;
      END IF;
---- not needed      
--      v_rows_approved_min := v_rows_approved_min + 1;
    END LOOP;

---- not needed
--  ELSE
--    NULL;
  END IF;
  -- you need to return something whenever the function ends...
  RETURN NULL;
END;
/

however...
This can be greatly simplified.

Create a validation of type "Rows returned"

Source:

SELECT
  1
  FROM
  sku_table WHERE sku = :P8_SKU

Error Message: Not a valid SKU

Server Side condition (Type Item = Value): Item: P8_PRODUCT_OR_SKU; Value: SKU

This does exactly the same thing.

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