0% found this document useful (0 votes)
5 views4 pages

usp_citizen_audit_trail_count;;

The document defines a PL/SQL procedure named 'usp_citizen_audit_trail_count' that retrieves citizen login details and counts based on specified parameters. It accepts flags for either 'CITIZEN' or 'LOGIN' to determine the type of data to return, and it includes error handling and logging mechanisms. The procedure outputs a count of logins and a cursor with detailed login activity information, or returns 'No Data' if the conditions are not met.

Uploaded by

Debasis Bhuyan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

usp_citizen_audit_trail_count;;

The document defines a PL/SQL procedure named 'usp_citizen_audit_trail_count' that retrieves citizen login details and counts based on specified parameters. It accepts flags for either 'CITIZEN' or 'LOGIN' to determine the type of data to return, and it includes error handling and logging mechanisms. The procedure outputs a count of logins and a cursor with detailed login activity information, or returns 'No Data' if the conditions are not met.

Uploaded by

Debasis Bhuyan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

create or replace PROCEDURE usp_citizen_audit_trail_count (

p_flag VARCHAR2,
p_aadhaar_no NUMBER,
p_from_date DATE,
p_to_date DATE,
p_out OUT NUMBER,
p_result OUT SYS_REFCURSOR
) AS

l_err_code VARCHAR2(200);
l_err_msg VARCHAR2(200);
l_from_date VARCHAR2(100);
l_to_date VARCHAR2(100);
l_trackstrattime TIMESTAMP(6) := systimestamp;
l_procedurename VARCHAR2(55) := $$plsql_unit;
l_date_check NUMBER;
BEGIN
/* ===============================================
Author : Debasis Bhuyan
Created/Optimized: 10-07-2024 15:00:33
Purpose : citizen login details with count
================================================
*/
l_from_date := to_char(trunc(p_from_date), 'DD-MON-YY');
l_to_date := to_char(trunc(p_to_date), 'DD-MON-YY');
IF
l_from_date IS NOT NULL
AND l_to_date IS NOT NULL
THEN
l_date_check := 1;
ELSE
l_date_check := 0;
END IF;

IF upper(p_flag) = 'CITIZEN' THEN


SELECT /*+ PARALLEL(8) */
COUNT(DISTINCT aadhaar_no) total_login
INTO p_out
FROM
tbl_citizen_audit_trail a
WHERE
( ( l_date_check = 1
AND trunc(a.created_on) BETWEEN l_from_date AND l_to_date )
OR ( l_date_check = 0
AND 1 = 1 ) );

OPEN p_result FOR SELECT /*+ PARALLEL(8) */


aadhaar_no,
spdp_id,
to_char(create_date, 'DD-MM-YYYY') create_date,
activity_name,
total_count
FROM
(
SELECT
aadhaar_no,
spdp_id,
trunc(create_date) create_date,
activity_name,
total_count
--rnk
FROM
(
SELECT
a.aadhaar_no
aadhaar_no,
lpad(substr(a.spdp_id, - 4),
length(a.spdp_id), 'X') spdp_id,
a.activity_name
activity_name,
COUNT(a.aadhaar_no)
total_count,
MAX(trunc(a.created_on))
create_date
--RANK() OVER(PARTITION BY
a.aadhaar_no ORDER BY trunc(a.created_on) DESC) rnk
FROM
tbl_citizen_audit_trail a
WHERE
( ( l_date_check = 1
AND trunc(a.created_on) BETWEEN
l_from_date AND l_to_date )
OR ( l_date_check = 0
AND 1 = 1 ) )
AND a.spdp_id IS NOT NULL
GROUP BY
a.aadhaar_no,
a.spdp_id,
-- trunc(a.created_on),
a.activity_name
)
ORDER BY
3 DESC
)
;

ELSIF upper(p_flag) = 'LOGIN' THEN


SELECT /*+ PARALLEL(8) */
COUNT(aadhaar_no) total_login
INTO p_out
FROM
tbl_citizen_audit_trail a
WHERE
a.aadhaar_no = nvl(p_aadhaar_no, a.aadhaar_no)
AND ( ( l_date_check = 1
AND trunc(a.created_on) BETWEEN l_from_date AND l_to_date )
OR ( l_date_check = 0
AND 1 = 1 ) );

OPEN p_result FOR SELECT /*+ PARALLEL(8) */


aadhaar_no,
spdp_id,
to_char(create_date, 'DD-MM-YYYY') create_date,
log_in_time,
log_out_time,
SUBSTR(to_timestamp(logout_time, 'DD-MM-RR
HH:MI:SS.FF9 AM') - to_timestamp(login_time, 'DD-MM-RR HH:MI:SS.FF9 AM'),11,9)
-- to_timestamp(log_out_time, 'HH:MI:SS PM') -
to_timestamp(log_in_time, 'HH:MI:SS PM')
duration,
activity_name,
url,
ip_address,
executor
FROM
(
SELECT
a.aadhaar_no
aadhaar_no,
lpad(substr(a.spdp_id, - 4),
length(a.spdp_id), 'X') spdp_id,
trunc(a.created_on)
create_date,
a.log_in_time
login_time,
a.log_out_time
logout_time,
to_char(a.log_in_time, 'hh12:mi:ss PM')
log_in_time,
to_char(a.log_out_time, 'hh12:mi:ss PM')
log_out_time,
a.activity_name
activity_name,
a.url
url,
a.ip_address
ip_address,
a.executor
executor
FROM
tbl_citizen_audit_trail a
WHERE
a.aadhaar_no = nvl(p_aadhaar_no,
a.aadhaar_no)
AND ( ( l_date_check = 1
AND trunc(a.created_on) BETWEEN
l_from_date AND l_to_date )
OR ( l_date_check = 0
AND 1 = 1 ) )
AND a.spdp_id IS NOT NULL
)
ORDER BY
3 DESC;

ELSE
OPEN p_result FOR SELECT
'No Data'
FROM
dual;

p_out := 0;
END IF;

dbms_output.put_line('deb#3333333333');
EXCEPTION
WHEN OTHERS THEN
l_err_code := sqlcode;
l_err_msg := substr(sqlerrm, 1, 200);
proc_error_log(l_err_code, l_err_msg, l_procedurename, '');
END usp_citizen_audit_trail_count;

You might also like