Skip to Main Content
  • Questions
  • Toad query using variables returns no data. The same query returns data in Oracle SQL developer

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question.

Asked: May 28, 2024 - 1:51 pm UTC

Last updated: June 10, 2024 - 6:50 am UTC

Version: Toad for Oracle 17.0

Viewed 1000+ times

You Asked

Hi

I have a query that is spooling results to a text file via an automated process Monday to Friday. Below are the variables that are used in the query. The queries returns data in Oracle SQL Developer, but returns only the headers with no data when I use Toad for Oracle 17.0 Patch 1. When I check the variables and they do have the same data in Oracle SQL and Toad. The query is very long as it pulls data from many schema (I inherited this), so I just took 4 schema to show you what the query does. The automated process is using TOAD. Why am I getting no data in Toad ?


DEFINE nextDate = TO_CHAR(sysDate,'yyyymmdd') ;
DEFINE prevDateS = 'TO_CHAR(SYSDATE - ( CASE RTRIM(TO_CHAR(SYSDATE,''day'')) when ''monday'' THEN 3 ELSE 1 END ), ''yyyymmdd'')';

------QUERY BELOW

set verify off
set heading off
set pagesize 0
set linesize 1200
set echo off
set termout off
set trimspool on
set blanklines on
set feedback off
set trimout off
set embedded off
SPOOL C:users/Charges.txt

DEFINE nextDate = TO_CHAR(sysDate,'yyyymmdd') ;
DEFINE prevDateS = 'TO_CHAR(SYSDATE-(CASE RTRIM(TO_CHAR(SYSDATE,''day'')) when ''monday''THEN 3 ELSE 1 END ), ''yyyymmdd'')' ;

PROMPT TRAN_ID,SYSTEM_REF,BEARER,FEE_TYPE,CURRENCY,FEE,TERRITORY

SELECT TRAN_ID||';'||SYSTEM_REF||';'||BEARER||';'||FEE_TYPE||';'||CURRENCY||';'||FEE||';'||TERRITORY
FROM
(
(
SELECT ----------1------History-----
T.GPTRANID as TRAN_ID, R.REFERENCETEXT as SYSTEM_REF, C.BEARER,
C.PROMPT AS FEE_TYPE, C.CURRENCY, SUM(to_char(C.AMOUNT/100, 999999999999999.99)) as FEE,
'FCIBBBBB' as TERRITORY
FROM FCIBBBBB_HIST.GPTRAN T, FCIBBBBB_HIST.GPTRAN_CHARGE C, FCIBBBBB_HIST.GPTRAN_REFERENCE R, FCIBBBBB_HIST.GPTRAN_AMOUNT A, FCIBBBBB_HIST.gptran_parsedmessage pmsg
WHERE T.GPTRANID = C.GPTRANID AND T.GPTRANID = R.GPTRANID AND T.GPTRANID = A.GPTRANID AND T.gptranid = pmsg.gptranid
AND T.status IN ('Completed','Canceled')
AND R.referenceTag = 'SYSREF'
AND T.messageType in ('103','202' )
and A.Linkelmtags like '%TRANAMT%'
and pmsg.creater is null
and pmsg.tag = 'HISTMOVEDATE'
and pmsg.tagValue >= &prevDateS
GROUP BY T.GPTRANID, R.REFERENCETEXT, C.BEARER, C.PROMPT, C.CURRENCY
)
UNION ALL
(
SELECT -------1---------SendTo Swift-----
T.GPTRANID as TRAN_ID, R.REFERENCETEXT as SYSTEM_REF, C.BEARER,
C.PROMPT AS FEE_TYPE, C.CURRENCY, SUM(to_char(C.AMOUNT/100, 999999999999999.99)) as FEE,
'FCIBBBBB' as TERRITORY
FROM FCIBBBBB.GPTRAN T, FCIBBBBB.GPTRAN_CHARGE C, FCIBBBBB.GPTRAN_REFERENCE R, FCIBBBBB.GPTRAN_AMOUNT A
WHERE T.GPTRANID = C.GPTRANID AND T.GPTRANID = R.GPTRANID AND T.GPTRANID = A.GPTRANID
AND T.status IN ('SentTo SWIFT')
AND A.amountid = (select am.amountid from FCIBBBBB.gptran_amount am, FCIBBBBB.gptran_parsedmessage pmsg , FCIBBBBB.gptran g
where g.gptranid = pmsg.gptranid and pmsg.tag ='TRANAMT' and am.amountid = pmsg.amountid
and g.gptranid = T.gptranid
and pmsg.creater is null
)
AND R.referenceTag = 'SYSREF'
AND T.messageType in ('103','202' )
AND A.valueDate >= &prevDateS
AND A.valueDate < &nextDate
GROUP BY T.GPTRANID, R.REFERENCETEXT, C.BEARER, C.PROMPT, C.CURRENCY
)
UNION ALL
(
SELECT ----------2------History-----
T.GPTRANID as TRAN_ID, R.REFERENCETEXT as SYSTEM_REF, C.BEARER,
C.PROMPT AS FEE_TYPE, C.CURRENCY, SUM(to_char(C.AMOUNT/100, 999999999999999.99)) as FEE,
'FCIBJMKN' as TERRITORY
FROM FCIBJMKN_HIST.GPTRAN T, FCIBJMKN_HIST.GPTRAN_CHARGE C, FCIBJMKN_HIST.GPTRAN_REFERENCE R, FCIBJMKN_HIST.GPTRAN_AMOUNT A, FCIBJMKN_HIST.gptran_parsedmessage pmsg
WHERE T.GPTRANID = C.GPTRANID AND T.GPTRANID = R.GPTRANID AND T.GPTRANID = A.GPTRANID AND T.gptranid = pmsg.gptranid
AND T.status IN ('Completed','Canceled')
AND R.referenceTag = 'SYSREF'
AND T.messageType in ('103','202' )
and A.Linkelmtags like '%TRANAMT%'
and pmsg.creater is null
and pmsg.tag = 'HISTMOVEDATE'
and pmsg.tagValue >= &prevDateS
GROUP BY T.GPTRANID, R.REFERENCETEXT, C.BEARER, C.PROMPT, C.CURRENCY
)
UNION ALL
(
SELECT ----------2------SendTo Swift-----
T.GPTRANID as TRAN_ID, R.REFERENCETEXT as SYSTEM_REF, C.BEARER,
C.PROMPT AS FEE_TYPE, C.CURRENCY, SUM(to_char(C.AMOUNT/100, 999999999999999.99)) as FEE,
'FCIBJMKN' as TERRITORY
FROM FCIBJMKN.GPTRAN T, FCIBJMKN.GPTRAN_CHARGE C, FCIBJMKN.GPTRAN_REFERENCE R, FCIBJMKN.GPTRAN_AMOUNT A
WHERE T.GPTRANID = C.GPTRANID AND T.GPTRANID = R.GPTRANID AND T.GPTRANID = A.GPTRANID
AND T.status IN ('SentTo SWIFT')
AND A.amountid = (select am.amountid from FCIBJMKN.gptran_amount am, FCIBJMKN.gptran_parsedmessage pmsg , FCIBJMKN.gptran g
where g.gptranid = pmsg.gptranid and pmsg.tag ='TRANAMT' and am.amountid = pmsg.amountid
and g.gptranid = T.gptranid
and pmsg.creater is null
)
AND R.referenceTag = 'SYSREF'
AND T.messageType in ('103','202' )
AND A.valueDate >= &prevDateS
AND A.valueDate < &nextDate
GROUP BY T.GPTRANID, R.REFERENCETEXT, C.BEARER, C.PROMPT, C.CURRENCY
)
);
/
SPOOL OFF;

and Connor said...

Sorry, but if it works in SQL Plus or SQL Developer, then we can't really help you, because TOAD isn't our product - you need to speak to Quest.

At a guess - perhaps an inconsistency in the Oracle client version each tool is picking up.

But it sounds to me like you're paying a nice hefty license fee for something that doesn't work. SQL Dev is free, as is SQLcl

Rating

  (2 ratings)

Comments

A reader, May 30, 2024 - 1:57 pm UTC

Connor

When I run it in SQL Plus I get the error ORA-00922 missing or invalid option
Connor McDonald
June 05, 2024 - 2:36 pm UTC

Where? We can't see your output, how you ran it, etc etc.... We need to see details.

Chuck Jolley, June 05, 2024 - 7:04 pm UTC

Hard to tell, but try changing the ampersands to colons.
Ampersand is text substitution in TOAD when you probably want binds which are designated by colons.

PS Why not use sqlplus for running what looks like a script?
Connor McDonald
June 10, 2024 - 6:50 am UTC

Agreed.