【问题标题】:DB2 select query in NWDS 7.0 not returning any resultNWDS 7.0 中的 DB2 选择查询不返回任何结果
【发布时间】:2012-06-21 07:17:12
【问题描述】:

这次我遇到了另一个问题,它是关于 DB2 查询的,在 NWDS 中运行。我使用的数据库规范是:

Database:-     EP1,
Schema:-       W2HCMSC,
Tablespace:-   W2HCMTS,
Table:-        TESTEMPLOYEE,
Cloumns:-      ZONE, Workshop, Year, Employee Name, Designation, DOB.

带有值的数据库快照是我要运行的选择语句,它是带有 where 子句的选择查询,但它不返回任何行。 这些是详细信息:

select * from w2hcmsc.testemployee

(返回 4 行)

select * from w2hcmsc.testemployee where 'w2hcmsc.Zone' = '1'

(0 行返回)

select * from w2hcmsc.testemployee where 'Zone' = 1

(SQL0420N 在 函数“DECFLOAT”。 SQLSTATE=22018)

select * from w2hcmsc.testemployee where zone = 1

SQL0206N “ZONE”在使用它的上下文中无效。 SQLSTATE=42703

select * from w2hcmsc.testemployee where Zone = 1

SQL0206N “ZONE”在使用它的上下文中无效。 SQLSTATE=42703

select * from w2hcmsc.testemployee where 'Zone' = '1'

(已选择 0 条记录)。

请告诉我为什么带有 where 子句的选择查询不起作用。我必须以任何不同的方式编写它吗?

【问题讨论】:

    标签: sql db2


    【解决方案1】:

    尝试使用列的完全限定名称:

    select * from w2hcmsc.testemployee where w2hcmsc.testemployee.ZONE = 1
    

    或为表创建一个别名并使用它:

    select * from w2hcmsc.testemployee AS t1 where t1.ZONE = 1
    

    【讨论】:

    • 如果给定 t1.Zone 和 t1.ZONE 那么我得到 sql 错误 -206。如果使用 't1.Zone',则会出现 sql 错误 -420
    • 我已经解决了至少我认为的问题。问题在于,在 DB2 中,列名并非全部大写,但在解释列名时,会从小写转换为大写,这就是列不匹配的原因。感谢所有帮助:)
    【解决方案2】:

    您的列名似乎是大小写混合的。避免在列名中使用混合大小写通常是一个好主意——虽然 DB2 支持这一点,但它会产生诸如此类的令人头疼的问题。

    解决方案是使用双引号(而不是单引号)引用您的列名:

    select * from w2hcmsc.testemployee where "Zone" = 1
    

    或者,使用表相关名称:

    select * from w2hcmsc.testemployee as t1 where t1."Zone" = 1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多