简体   繁体   English

DB2 sql查询运行

[英]DB2 sql query run

Trying to run some query for DB2, but get no results. 试图为DB2运行一些查询,但没有结果。

SELECT APPLICATION_ID, 
       CLIENT_WRKSTNNAME 
  FROM TABLE(MON_GET_CONNECTION(cast(NULL as bigint), -2)) AS t 
 WHERE APPLICATION_ID IN (SELECT ''''||APPLICATION_ID||'''' 
                            FROM SYSIBM.SYSDUMMY1)

The problem is in subquery in WHERE clause. 问题出在WHERE子句中的子查询中。 If I'll run only the 如果我只运行

SELECT ''''||APPLICATION_ID||'''' 
  FROM SYSIBM.SYSDUMMY1 

part and copy/paste the result into the big query - I would get needed result. 部分并将结果复制/粘贴到大查询中-我将获得所需的结果。 Result of sub-query looks like this: '92.81.111.13.51632.13022516453' , it must be String/varchar. 子查询的结果如下所示: '92.81.111.13.51632.13022516453' ,它必须是String / varchar。

What am I doing wrong? 我究竟做错了什么?

Your query does not make sense. 您的查询没有意义。 Here is the version with table aliases: 这是带有表别名的版本:

SELECT t.APPLICATION_ID, t.CLIENT_WRKSTNNAME 
  FROM TABLE(MON_GET_CONNECTION(cast(NULL as bigint), -2)) AS t 
 WHERE t.APPLICATION_ID IN (SELECT ''''||t.APPLICATION_ID||'''' FROM SYSIBM.SYSDUMMY1);

One possibility is that the field APPLICATION_ID is being compared to itself, with quotes. 一种可能性是正在将字段APPLICATION_ID与自身进行比较,并带有引号。 SYSIBM.SYSDUMMY1 does not have a column called APPLICATION_ID . SYSIBM.SYSDUMMY1没有名为APPLICATION_ID的列。 So, this query is equivalent to: 因此,此查询等效于:

SELECT t.APPLICATION_ID, t.CLIENT_WRKSTNNAME 
  FROM TABLE(MON_GET_CONNECTION(cast(NULL as bigint), -2)) AS t 
 WHERE t.APPLICATION_ID = ''''||t.APPLICATION_ID||'''' ;

Another possibility is that APPLICATION_ID is a variable. 另一种可能性是APPLICATION_ID是变量。 In that case, you should name the variable something like v_APPLICATION_ID so it is not confused with the column name. 在这种情况下,应将变量命名为v_APPLICATION_ID之类的名称,以免将其与列名混淆。

It looks like you want something like: 您似乎想要以下内容:

 WHERE '.'||t.APPLICATION_ID||'.' like '%.'||v_APPLICATION_IDS||'.%' ;

This is assuming the list in v_APPLICATION_IDS is separated by periods. 假设v_APPLICATION_IDS的列表由句点分隔。 Usually, it would be separated by commas and you would use ',' instead of '.' 通常,它将用逗号分隔,并且您将使用','而不是'.' .

WITH s AS (SELECT APPLICATION_ID AS application_id FROM SYSIBM.SYSDUMMY1)
SELECT CLIENT_WRKSTNNAME
FROM TABLE(MON_GET_CONNECTION(cast(NULL as bigint), -2)) AS t
INNER join s as s on s.application_id=t.APPLICATION_ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM