-------------------------------------------------------------------------------
-- Character functions
-- ASCII
select ascii(substr(csurname,7,1)) from cnv.nino where upper(csurname) like 'LAPEN%';
-- CHR
select chr(144) from dual;
-------------------------------------------------------------------------------
-- DATE functions
-- to_date function
to_date('1998-11-21:07:00:00','YYYY-MM-DD:HH24:MI:SS')
select to_date('1998-11-21:07:00:00','YYYY-MM-DD:HH24:MI:SS') from dual;
to_date('1997-01-01','YYYY-MM-DD')
to_date('31-DEC-97','DD-MON-YY')
-- trunc function
trunc(to_date('1935-12-01','YYYY-MM-DD')) returns 1935-01-01
select * from worker_available
where substr(to_char(schedule_date,'HH:MIPM'),1,7) = '01:21PM';
select * from worker_available
where substr(to_char(schedule_date,'YYYY-MM-DD'),1,10) = '1999-03-01';
-- sysdate function
select sysdate from dual;
-- decode
-- user function
select user from dual;
-- userenv function
select osuser, username, sid from v$session where audsid = userenv('sessionid');
-- function to return current os user
CREATE OR REPLACE FUNCTION ADMIN.F_OSUSER RETURN varchar2
IS
name varchar2(15);
BEGIN
select osuser into name from sys.v_$Session where audsid = userenv('sessionid' ) ;
return name;
EXCEPTION
when others then
null;
END;
/
|