I got the following script that does actually the following, it uses an email-address to
- search for that user
- search for messages from that user
- search for Entries of that user
- puts the findings to a file
currently that is working but now I would like to do the following:
Replace the sub select "SELECT ID FROM DBSCHEMA.USERS WHERE EMAIL ='&SEARCH'
" with a kind of variable to not put (and execute) this statement multiple times in the script.
But what ever I tried did not work. (Started using DECLARE block - than the spool was not working, end everything else just broke the script)
I'm using a oracle database - but i would like to stick to generic commands if possible.
DEFINE SEARCH='search@example.org';
spool OUTPUTFILE.out
prompt Start Searching by mail '&SEARCH'
SELECT
'ID;NAME;LAST_LOGIN;EMAIL_ADDRESS;FIRST_NAME;LAST_NAME;BLABLA;LANGUAGE_ID;'
FROM
DUAL;
SELECT
ID||';'||NAME||';'||LAST_LOGIN||';'||EMAIL||';'||FIRST_NAME||';'||LAST_NAME||';'||BLABLA||';'||LANGUAGE_ID||';'
FROM
DBSCHEMA.USERS
WHERE
EMAIL ='&SEARCH';
prompt Feedback messages
prompt ID;SUBJECT;MESSAGE;TIMESTAMP;
SELECT
ID||';'||SUBJECT||';'||MESSAGE||';'||TIMESTAMP||';'
FROM
DBSCHEMA.SITE_FEEDBACK
WHERE
USER_ID = (SELECT ID FROM DBSCHEMA.USERS WHERE EMAIL ='&SEARCH');
prompt Other Entries
prompt ID;TITLE;BLABLA;TIMESTAMP;
SELECT
ID||';'||TITLE||';'||BLABLA||';'||TIMESTAMP||';'
FROM
DBSCHEMA.SITE_ENTRY
WHERE
USER_ID = (SELECT ID FROM DBSCHEMA.USERS WHERE EMAIL ='&SEARCH');
spool off;