I'm new to Oracle and SQL Plus etc. having migrated from Datacom/DB, so I'm basically teaching myself.
I wrote a query and debugged it in SQL Plus to assist our Help Desk determine what terminal a user is logged on at. The result was put into a read-only APEX (application express) app by our database guys for security reasons and it turned out pretty nice (snippet link attached).
Our DB guys are way too busy to bug with my learning questions, so here's the controlling info and my question with the existing query...
Info
When a user is not logged on, the date and time (VARCHAR2 columns - 12 and 9 respectively) both contain zeros. If their session was terminated without signing off, or they otherwise became disconnected, we could see both terminal and date info even though they are not actually logged on; therefore, date and time are the controlling factor for the condition test.
How can I...
When a user is logged on, display the date and time they logged on; otherwise, display "Logged Off" instead, so it's obvious to Help Desk staff that the user is not logged on. I've tried a few different things, but keep getting various, mabiguous, syntactical errors.
Original query...
prompt
accept user_id
prompt 'Enter user ID - e.g., zzabc1: '
prompt
SELECT
a.EMPLOYEE_TS_ID AS UserID,
TRIM(a.NAME_LAST)||', '||TRIM(a.NAME_FIRST)||' '||SUBSTR(a.NAME_MIDDLE,1,1) AS User_Name,
b.TERM_ID_SIGN_ON AS Term_ID,
b.DATE_SIGN_ON_MO||'/'||b.DATE_SIGN_ON_DY||'/'||b.DATE_SIGN_ON_CN||b.DATE_SIGN_ON_YR||'-'||b.TIME_SIGN_ON_HR||':'||TIME_SIGN_ON_MN AS Signed_On
FROM PCJIS.EMPLOYEE_S_LV a, PCJIS.EMPLOYEE_USER_S_LV b
WHERE a.EMPLOYEE_TS_ID like upper ('%&user_id%') AND b.SSN = a.SSN
ORDER BY Signed_On DESC, UserID ASC, Terminal_ID ASC ;
Date/Time descending is the primary sort here because so logged on users appear at the top of the list.
Any suggestions would be greatly appreciated. There also has to be a better way of formatting the entire date and time columns DATE_SIGN_ON and TIME_SIGN_ON) than what I did above.
Thanks in advance
I wrote a query and debugged it in SQL Plus to assist our Help Desk determine what terminal a user is logged on at. The result was put into a read-only APEX (application express) app by our database guys for security reasons and it turned out pretty nice (snippet link attached).
Our DB guys are way too busy to bug with my learning questions, so here's the controlling info and my question with the existing query...
Info
When a user is not logged on, the date and time (VARCHAR2 columns - 12 and 9 respectively) both contain zeros. If their session was terminated without signing off, or they otherwise became disconnected, we could see both terminal and date info even though they are not actually logged on; therefore, date and time are the controlling factor for the condition test.
How can I...
When a user is logged on, display the date and time they logged on; otherwise, display "Logged Off" instead, so it's obvious to Help Desk staff that the user is not logged on. I've tried a few different things, but keep getting various, mabiguous, syntactical errors.
Original query...
prompt
accept user_id
prompt 'Enter user ID - e.g., zzabc1: '
prompt
SELECT
a.EMPLOYEE_TS_ID AS UserID,
TRIM(a.NAME_LAST)||', '||TRIM(a.NAME_FIRST)||' '||SUBSTR(a.NAME_MIDDLE,1,1) AS User_Name,
b.TERM_ID_SIGN_ON AS Term_ID,
b.DATE_SIGN_ON_MO||'/'||b.DATE_SIGN_ON_DY||'/'||b.DATE_SIGN_ON_CN||b.DATE_SIGN_ON_YR||'-'||b.TIME_SIGN_ON_HR||':'||TIME_SIGN_ON_MN AS Signed_On
FROM PCJIS.EMPLOYEE_S_LV a, PCJIS.EMPLOYEE_USER_S_LV b
WHERE a.EMPLOYEE_TS_ID like upper ('%&user_id%') AND b.SSN = a.SSN
ORDER BY Signed_On DESC, UserID ASC, Terminal_ID ASC ;
Date/Time descending is the primary sort here because so logged on users appear at the top of the list.
Any suggestions would be greatly appreciated. There also has to be a better way of formatting the entire date and time columns DATE_SIGN_ON and TIME_SIGN_ON) than what I did above.
Thanks in advance