0

我有 2 个查询,它们动态获取数据。

  1. Select cid from table1 where cNumber={{custNbr}}

这里 {{custNbr}} 来自一个 .txt 文件。

  1. update table2 set status='A' where customer_id=NVL({{cid}},0000)

这里 {{customer_id}} 来自步骤 1 的输出。

问题:当第 1 步返回 NULL 时,它实际上返回一个空字符串''。因此,第 2 步转化为 -

update table2 set status='A' where customer_id=NVL(,0000)

这会引发错误 java.sql.SQLSyntaxErrorException: ORA-00936: missing expression

如何重写查询以使其工作。

4

1 回答 1

0

在您的情况下,为第一个查询的结果提供后备可能就足够了:

Select nvl(cid, -1) as cid
  from table1 
  where cNumber={{custNbr}}

这假定 -1 没有作为客户 ID 出现在 table2 中。因此,UPDATE将在语法上有效,但它将更新零行。

警告

但是,我强烈怀疑无法将NULL值作为数据库查询输入的工具。您可能希望就此联系开发测试支持。

于 2017-05-17T09:25:13.893 回答