Uncategorized

SQL History

Posted on:

V$SQL view has the following column and statistics data. select sql_txt from v$sql select s.username, s.sid, s.serial#,t.sql_text “Last SQL”from gv$session s, gv$sqlarea twhere s.sql_address =t.address ands.sql_hash_value =t.hash_value

SQL

Time Dimension – SQL Query

Posted on:

SELECT— DAY LEVELtime_id AS day_id,INITCAP(TO_CHAR(time_id,’fmMonth DD, YYYY’)) AS day_desc,INITCAP(TO_CHAR(time_id, ‘fmDAY’)) AS day_name,TO_NUMBER(TO_CHAR(time_id – 1, ‘D’)) AS day_of_week,TO_NUMBER(TO_CHAR(time_id, ‘DD’)) AS day_of_month,TO_NUMBER(TO_CHAR(time_id, ‘DDD’)) AS day_of_year,1 AS days_in_day, — MONTH LEVELTO_CHAR(time_id, […]

SQL

Exclude Days SQL Function

Posted on:

create or replace FUNCTION EXCLUDE_WEEKEDNDS (p_start_date IN date, p_end_date IN date)RETURN NUMBERISl_count NUMBER;BEGINl_count := 0;SELECT COUNT(1) INTO l_countFROM(WITH DATA AS(SELECT–to_date(trunc(p_start_date), ‘YYYY-MM-DD’) date1,–to_date(trunc(p_end_date), ‘YYYY-MM-DD’) date2p_start_date date1,p_end_date date2FROM dual)SELECT date1+LEVEL-1 […]