Useful shortcuts for vi editor

Tuesday 21 March 2017

How to manage logon mechanism with trigger ?

CREATE OR REPLACE TRIGGER SYS.DENY_LOGIN
   AFTER LOGON
   ON DATABASE
BEGIN
   IF     TO_CHAR (SYSDATE, 'hh24') BETWEEN 08 AND 22
      AND SYS_CONTEXT ('USERENV', 'SESSION_USER') = 'HR'
   THEN
      raise_application_error (
         -20001,
         'You cannot login between 08 AM and 06 PM. Please contact with Alper!');
   END IF;
END deny_login;
/

Error message:
ORA-00604: error occurred at recursive SQL level 1
ORA-20001: You cannot login between 08 AM and 06 PM. Please contact with Alper!
ORA-06512: at line 5

LISTAGG examples

SQL>
select LISTAGG (last_name, ', ')  WITHIN GROUP (order by last_name)
from employees

SQL>
select LISTAGG (first_name || ' ' || last_name, ', ') WITHIN GROUP (order by first_name)
from employees

SQL>
select LISTAGG (first_name || ' ' || salary, ', ') WITHIN GROUP (order by salary desc)
from employees

SQL>
select LISTAGG (first_name || ' ' || salary || ' ' || NVL2(commission_pct, commission_pct, '0'), ', ') WITHIN GROUP (order by salary desc)
from employees

Thursday 9 March 2017

How to define "idle_time" ?

Check parameter of resource_limit
SQL> show parameter resource;

If it is 'False'

SQL> alter system set resource_limit = true;

Add it into init.ora file permanently

*.resource_limit=true;

Modify default profile

SQL> alter profile default limit idle_time 1440;
-- 1440 -> 24 hour

Check default profile setting

SQL> select profile, resource_name, limit from dba_profiles 
where lower(profile) = 'default' and resource_name = 'IDLE_TIME';

Monitor idle sessions
SQL> select * from v$session where status = 'SNIPED' order by logon_time desc;

How to kill tty/pts terminal?

Check first your connection to prevent killing yourself
$ tty

Kill other connection
$ skill -9 pts/1
or
# skill -KILL pts/1

Info
Teletypewriter - TTY
pseudo terminal slave - PTS