如何从同一输出窗口中的两个查询获得结果?

时间:2018-01-02 12:13:07

标签: oracle oracle-sqldeveloper

我需要在一个输出窗口中同时输出以下两个查询。

QUERY 1

SELECT C.SERVICENAME, C.SERVICEID , B.SOAPIN, B.SOAPOUT, A.TIMESTAMP
FROM Schema1.LG_LOGENTRIES A, Schema1.LG_SOAPREQUESTS B, Schema1.CFG_SOAPSERVICES C
WHERE B.SERVICEID =C.SERVICEID AND 
C.SERVICENAME <>'UploadAndPrepareDocumentEx1__sdweb_services_preload' AND
A.ID=B.LOGENTRYID AND B.TIMESTAMP BETWEEN TO_DATE('02/01/2018 11:55:00','dd/mm/yyyy hh24:mi:ss')
AND TO_DATE('02/01/2018 12:03:59','dd/mm/yyyy hh24:mi:ss') AND A.USERID IN (SELECT ID FROM Schema1.CFG_USERS 
WHERE NAME=UPPER(TO_CHAR('CGBXGVSG')));

查询2

SELECT B.JSONIN, B.JSONOUT,  A.TIMESTAMP, B.EVENT_MESSAGE, A.PROCESSID, A.status, A.SERVERNAME
FROM Schema1.LG_LOGENTRIES A, Schema1.LG_EVENT B
WHERE B.EVENT_MESSAGE NOT IN ('getFileImage','submitBase64','loadDocumentToSign','getRefData') AND
A.ID=B.LOG_ENTRYID AND B.TIMESTAMP BETWEEN TO_DATE('31/12/2017 13:43:00','dd/mm/yyyy hh24:mi:ss')
AND TO_DATE('31/12/2017 13:53:59','dd/mm/yyyy hh24:mi:ss') AND A.USERID IN (SELECT ID FROM Schema1.CFG_USERS 
WHERE NAME=UPPER(TO_CHAR('CTHX8Y2G')));

2 个答案:

答案 0 :(得分:1)

使用F5运行 - 您将同时获得两个查询&#39;脚本面板中的输出。

我谈到这有何不同here

script output when running more than 1 statement with F5

答案 1 :(得分:0)

UNION可能是一个选项,但你必须

  • 统一两个列列表(即它们必须返回必须具有相同数据类型的相同数量的列),这意味着您必须向两个查询添加某些NULL列
  • 包含附加标识符,以便您知道哪个SELECT返回了哪些值

如果你想让它们并排,呵呵,那并不容易。大声思考:你必须有一个加入这些价值观的专栏。那些SELECT将是内联视图。您将使用聚合函数(例如MAX)以及DECODE(或CASE)来从两个查询中选择值。不久:太痛苦了。

现在,你为什么要那样做?两个独立的窗户并排放置有什么问题?

[编辑] 显示UNION的外观示例

select c.servicename, c.serviceid, b.soapin, b.soapout, a.timestamp, to_char(null), to_char(null), to_char(null)  , to_number(null), to_char(null), to_char(null)
from ... the rest of your 1st query
union
select null         , null       , null    , null     , a.timestamp, b.jsonin     , b.jsonout    , b.event_message, a.processid    , a.status     , a.servername 
from ... the rest of your 2nd query