oracle 如何检查查询中的两个条件并获得结果

pinkon5k  于 2023-06-22  发布在  Oracle
关注(0)|答案(2)|浏览(188)

我有一个查询,我试图添加功能来检查以下参数:

'CRYPTO_CHECKSUM_TYPES_SERVER=(SHA256)','CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA512)','CRYPTO_CHECKSUM_TYPES_SERVER=(SHA512)','CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA256)'

我有数据,其中我得到参数名称(从上面)和count_found(如果找到,则为1,如果未找到,则为0
这里我需要检查CRYPTO_CHECKSUM_TYPES_SERVER是否设置了SHA256SHA512。如果两者都没有设置,则查询需要报告。CRYPTO_CHECKSUM_TYPES_CLIENT也一样。
如果我运行当前查询,我会得到这样的结果:

HOST_NAME COUNT_FOUND   PARAMETER                                   FILE_CHECKED
host123    0           CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA256)    /local/dbms/oracle/product/11.2.0.4/db_1/network/admin/sqlnet.ora
host123    0           CRYPTO_CHECKSUM_TYPES_SERVER=(SHA512)    /local/dbms/oracle/product/11.2.0.4/db_1/network/admin/sqlnet.ora
host123    1           CRYPTO_CHECKSUM_TYPES_SERVER=(SHA256)    /local/dbms/oracle/product/11.2.0.4/db_1/network/admin/sqlnet.ora
host123    0           CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA512)    /local/dbms/oracle/product/11.2.0.4/db_1/network/admin/sqlnet.ora

我现在尝试用current condition添加检查:

where (PARAMETER in ('CRYPTO_CHECKSUM_TYPES_SERVER=(SHA256)','CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA512)','CRYPTO_CHECKSUM_TYPES_SERVER=(SHA512)','CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA256)'))

新条件:

where (PARAMETER in ('CRYPTO_CHECKSUM_TYPES_SERVER=(SHA256)','CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA512)','CRYPTO_CHECKSUM_TYPES_SERVER=(SHA512)','CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA256)'))
and ((PARAMETER='CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA256)' and count_found=0) and (PARAMETER='CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA512)' and count_found=0))

但是在添加新条件之后,查询不会返回任何内容。
这里的问题是什么?
我试图添加条件,但查询没有返回任何行。我如何检查2个参数,这是在2个不同的行。

tzdcorbm

tzdcorbm1#

您编写的查询不返回任何内容,因为没有行满足条件。
你的意思是这样的吗?
样本数据:

SQL> WITH
  2     test (count_found, parameter)
  3     AS
  4        (SELECT 0, 'CRYPTO_CHECKSUM_TYPES_SERVER=(SHA256)' FROM DUAL
  5         UNION ALL
  6         SELECT 0, 'CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA256)' FROM DUAL
  7         UNION ALL
  8         SELECT 0, 'CRYPTO_CHECKSUM_TYPES_SERVER=(SHA512)' FROM DUAL
  9         UNION ALL
 10         SELECT 0, 'CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA512)' FROM DUAL)

查询:

11  SELECT *
 12    FROM test
 13   WHERE (parameter, count_found) IN (('CRYPTO_CHECKSUM_TYPES_SERVER=(SHA256)', 0),
 14                                      ('CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA512)', 0),
 15                                      ('CRYPTO_CHECKSUM_TYPES_SERVER=(SHA512)', 0),
 16                                      ('CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA256)', 0));

COUNT_FOUND PARAMETER
----------- -------------------------------------
          0 CRYPTO_CHECKSUM_TYPES_SERVER=(SHA256)
          0 CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA256)
          0 CRYPTO_CHECKSUM_TYPES_SERVER=(SHA512)
          0 CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA512)

SQL>
clj7thdc

clj7thdc2#

您试图找到一行,其中PARAMETER同时是'CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA256)''CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA512)'。这是永远不会发生的,因为一行只能包含一个值。
相反,您希望检查行何时是一个值OR另一个值,并使用OR而不是AND

where PARAMETER in (
        'CRYPTO_CHECKSUM_TYPES_SERVER=(SHA256)',
        'CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA512)',
        'CRYPTO_CHECKSUM_TYPES_SERVER=(SHA512)',
        'CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA256)'
      )
and   (  (   PARAMETER = 'CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA256)'
         and count_found=0 )
      OR 
         (   PARAMETER = 'CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA512)'
         and count_found=0 )
      )

可以简化为:

where PARAMETER in (
        'CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA512)',
        'CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA256)'
      )
and   count_found=0

如果您还需要服务器值,则:

where PARAMETER in (
        'CRYPTO_CHECKSUM_TYPES_SERVER=(SHA256)',
        'CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA512)',
        'CRYPTO_CHECKSUM_TYPES_SERVER=(SHA512)',
        'CRYPTO_CHECKSUM_TYPES_CLIENT=(SHA256)'
      )
and   count_found=0

相关问题