I do something similar, but using rownum so I don't have to use the analytic functions.
SELECT CASE
WHEN ROWNUM > 1
THEN
'Union all' || CHR(10)
END
|| 'Select database, node "Server", mkid "Master Key ID" from whoami@'
|| HOST
|| ',vw_x$kcbtek@'
|| HOST
|| ',v$encryption_wallet@'
|| HOST
|| CHR(10)
|| ' where ts# = 0 and wrl_type = ''HSM'' and status = ''OPEN'''
|| CHR(10)
FROM user_db_links;
On Thu, Dec 22, 2016 at 10:57 AM, davidm_1335 bounce-davidm_1335@toadworld.com wrote:
RE: Dynamic SQL Results to Export Dataset
Reply by davidm_1335
My usual trick for this type of query to create SQL is to use the ROW_NUMBER analytic in a CASE statement to prevent the extra trailing(or leading) text;
SELECT 'Select database, node "Server", mkid "Master Key ID" from whoami@'
|| HOST
|| ',vw_x$kcbtek@'
|| HOST
|| ',v$encryption_wallet@'
|| HOST
|| CHR (10)
|| ' where ts# = 0 and wrl_type = ''HSM'' and status = ''OPEN'''
|| CHR (10)
|| CASE
WHEN row_number() OVER (ORDER BY db_link DESC) != 1 THEN 'UNION ALL'
END
FROM user_db_links
ORDER BY db_link;
To reply, please reply-all to this email.
Stop receiving emails on this subject.
Or Unsubscribe from Toad for Oracle Forum notifications altogether.
Toad for Oracle - Discussion Forum
Flag this post as spam/abuse.
--
Phyllis Helton
Data Magician
Security Gestapo
Digital Products & Strategies, Cru | Data Sciences & Analytics
Office 407-515-4452
phyllis.helton@cru.org