简体   繁体   English

'IN'在db2 sql查询中如何工作?

[英]How does 'IN' works in db2 sql query?

My requirement is to select data from DB2 table where phone number is equal to 16 set of phone numbers.I have tried to run this query given below on my local test data and my program is successfully working! 我的要求是从DB2表中选择电话号码等于16组电话号码的数据。我尝试对本地测试数据运行以下给出的查询,并且程序成功运行! But , when i try to run this same program on real table(backup table) , my RUN jcl is getting failed with S722 abend. 但是,当我尝试在真实表(备份表)上运行相同的程序时,我的RUN jcl因S722异常终止而失败。

i feel it is not space abend because we are using file with attributes of 7 cylinders(1 primary,6 secondary). 我觉得这不是空间上的弯曲,因为我们使用的文件具有7个柱面(1个主要,6个辅助)的属性。 According to my research i found out that sql query with 'IN ,'LIKE' takes too much time to execute so changed Time parameter in Jobcard to NOLIMIT. 根据我的研究,我发现使用'IN','LIKE'进行sql查询需要太多时间来执行,因此将Jobcard中的Time参数更改为NOLIMIT。 But noluck !! 但是,祝你好运!

Can someone help me with any other way of writing this query ? 有人可以通过其他任何方式帮助我编写此查询吗? or help me to rectify this issue.... 或帮助我纠正此问题。

query like this : 查询像这样:

EXEC SQL
DECLARE WS-CURSOR CURSOR WITH HOLD FOR
SELECT CUST_ID,CUST_NAME,SEQ_NUM,PHONE_NUM FROM PHONE_TAB 
  WHERE PHONE_NUM IN ('123456789','789456123','456789123','789456123' etc) AND
        PHONE_TYPE = 'DU' 
END-EXEC.

Thanks in advance !! 提前致谢 !!

The Sx22 family of abends indicate exceeding some system defined parameter. Sx22异常家族表示超出某些系统定义的参数。 A S322 typically indicates you've exceeded the amount of CPU time in the TIME parameter on your job card or job step, for example. 例如,一个S322通常指示您已超过作业卡或作业步骤上TIME参数中的CPU时间。

A S722 abend indicates you have produced more spool output than is allowed by your shop's JES parameters. S722异常结束表示您所产生的线轴输出超出了商店的JES参数所允许的范围。 You need to determine the source of that spool output to resolve the abend. 您需要确定该假脱机输出的源以解决异常终止。

You may have a core dump (CEEDUMP), debugging output you've coded (SYSOUT or SYSPRINT or STDOUT or STDERR), or a runaway report DD you've coded. 您可能具有核心转储(CEEDUMP),已编码的调试输出(SYSOUT或SYSPRINT或STDOUT或STDERR)或已编码的失控报告DD。 The JESMSGLG DD visible in the spool either at the top of your output in SDSF or by selecting your job with a '?' JESMSGLG DD在线轴中可见,或者在SDSF中输出的顶部,或者通过选择带有“?”的作业 may report errors prior to the S722. 可能会在S722 之前报告错误。

Perhaps you are experiencing a S322 which leads to the S722. 也许您正在遇到通向 S722的S322。 This is entirely possible since the problem occurs with a large quantity of data. 这完全有可能,因为问题发生在大量数据上。

Setting the time parameter to NOLIMIT is an expensive debugging technique as most mainframe shops have a chargeback algorithm in place, typically CPU time = money in someone's budget. 将时间参数设置为NOLIMIT是一项昂贵的调试技术,因为大多数大型机商店都采用了退款算法,通常,CPU时间=某人的预算中的钱。 Your shop may have a JES exit in place that substitutes some other value for NOLIMIT specifically to prevent its use. 您的商店可能有一个JES出口,该出口用其他一些值代替NOLIMIT专门用于阻止其使用。

As indicated by user6542823, you could add a JOBPARM LINES=some-large-number to get around the S722, but you'll still have to resolve the underlying problem. 如user6542823所示,您可以添加JOBPARM LINES = some-large-number来绕过S722,但是您仍然必须解决根本的问题。

z/OS tries to give you as much information as possible to debug. z / OS尝试为您提供尽可能多的信息以进行调试。 Make use of what it gives you. 利用它给您带来的好处。

Given... 鉴于...

  • you've said your program executes fine with local test data 您说过您的程序可以使用本地测试数据很好地执行
  • the problem manifests when running against a backup of the production sized data 在对生产大小的数据进行备份时,该问题就会显现出来

...then if ... ... 如果 ...

  • the definition of table PHONE_TAB in your local test data matches that in the backup and the production data 本地测试数据中表PHONE_TAB的定义与备份数据和生产数据中的定义匹配
  • your program binds successfully 您的程序成功绑定
  • you have authorization to read the backup data 您有权读取备份数据

...the problem is likely not with your SQL but rather related to the volume of data. ...问题可能不在于您的SQL,而是与数据量有关。

Look at the EXPLAIN output for your package and you'll likely see you're scanning the entire PHONE_TAB table. 查看软件包的EXPLAIN输出,您可能会看到您正在扫描整个PHONE_TAB表。 Perhaps there is an index in place in production that is absent in the backup you're testing against. 也许生产中存在一个索引,而您要测试的备份中没有该索引。

Here's a inline table join instead of doing a where in clause 这是一个内联表联接,而不是执行where in子句

IRL I would put the values into a temp table and join to the temp table. IRL,我会将这些值放入临时表中并加入到临时表中。 But for example I've done this in-line. 但是例如,我已经完成了此操作。

SELECT CUST_ID,CUST_NAME,SEQ_NUM,PHONE_NUM FROM PHONE_TAB

join (
values('123456789'),('789456123'),('456789123'),('789456123')
) as b (ph) on phone_num = ph

where PHONE_TYPE = DU 

Two table query might be fastest hard to tell but for me it is definitely easier to maintain two tables than a program that creates a SQL statement every time it runs. 两表查询可能很难分辨,但是对我来说,维护两个表绝对比每次运行时创建SQL语句的程序容易。

SELECT CUST_ID,CUST_NAME,SEQ_NUM,PHONE_NUM FROM PHONE_TAB

join look_tab b on phone_num = b.ph

where PHONE_TYPE = DU 

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

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