I need some assistance with the following PL/SQL code which displays the time difference in minutes between two date values. The first part before the IF-Statement returns the needed information, but the challenge comes in when i'm trying to write an IF-Statement to display the time difference for only those jobs that have exceeded 15 Minutes then send Email notification through Exchange Server.
Your assistance is appreciated in advance.
Declare
l_found boolean :=false;
Cursor C5
is
(SELECT CASE LENGTH(JCSBMTIME)
WHEN 0 THEN
round(((sysdate - to_date
(TO_DATE(TO_CHAR(to_number(JCSBMDATE)+1900000),'YYYYDDD') || ' ' ||
to_char(to_date(CONCAT('000000',JCSBMTIME),'HH24:MI:SS'),'HH24:MI:SS')
,'DD-MON-YY HH24:MI:SS')) * 1440),2)
WHEN 1 THEN
round(((sysdate - to_date
(TO_DATE(TO_CHAR(to_number(JCSBMDATE)+1900000),'YYYYDDD') || ' ' ||
to_char(to_date(CONCAT('00000',JCSBMTIME),'HH24:MI:SS'),'HH24:MI:SS')
,'DD-MON-YY HH24:MI:SS')) * 1440),2)
WHEN 2 THEN
round(((sysdate - to_date
(TO_DATE(TO_CHAR(to_number(JCSBMDATE)+1900000),'YYYYDDD') || ' ' ||
to_char(to_date(CONCAT('0000',JCSBMTIME),'HH24:MI:SS'),'HH24:MI:SS') ,'DD-
MON-YY HH24:MI:SS')) * 1440),2)
WHEN 3 THEN
round(((sysdate - to_date
(TO_DATE(TO_CHAR(to_number(JCSBMDATE)+1900000),'YYYYDDD') || ' ' ||
to_char(to_date(CONCAT('000',JCSBMTIME),'HH24:MI:SS'),'HH24:MI:SS') ,'DD-
MON-YY HH24:MI:SS')) * 1440),2)
WHEN 4 THEN
round(((sysdate - to_date
(TO_DATE(TO_CHAR(to_number(JCSBMDATE)+1900000),'YYYYDDD') || ' ' ||
to_char(to_date(CONCAT('00',JCSBMTIME),'HH24:MI:SS'),'HH24:MI:SS') ,'DD-
MON-YY HH24:MI:SS')) * 1440),2)
WHEN 5 THEN
round(((sysdate - to_date
(TO_DATE(TO_CHAR(to_number(JCSBMDATE)+1900000),'YYYYDDD') || ' ' ||
to_char(to_date(CONCAT('0',JCSBMTIME),'HH24:MI:SS'),'HH24:MI:SS') ,'DD-
MON-YY HH24:MI:SS')) * 1440),2)
ELSE
round(((sysdate - to_date
(TO_DATE(TO_CHAR(to_number(JCSBMDATE)+1900000),'YYYYDDD') || ' ' ||
to_char(to_date(CONCAT('',JCSBMTIME),'HH24:MI:SS'),'HH24:MI:SS') ,'DD-MON-
YY HH24:MI:SS')) * 1440 ),2)
END AS "DATETIME_DIFF",
JCUSER, JCJOBNBR, JCSBMTIME FROM SVM900E1.F986110
WHERE JCSBMDATE = (TO_CHAR(sysdate,'YYYYDDD')-1900000)
AND JCJOBSTS in ('P','S','W'));
Begin
For Y in C5
Loop
l_found := true;
dbms_output.put_line(Y.DATETIME_DIFF||' '||Y.JCUSER||' ' ||Y.JCJOBNBR||'
'||Y.JCSBMTIME);
End loop;
if not l_found
Then
dbms_output.put_line('No records found');
End if;
Case Y.DATETIME_DIFF when > 15
Then
dbms_output.put_line(Y.JCUSER||' ' ||Y.JCJOBNBR||' '||Y.JCSBMTIME);
Else 'No records';
End case;
End;
Pay attention to your Y iterator scope. You are trying to use it out of loop statement.
You code should be like this. I omit part of cursor declaration
--at first init to false
l_found := false;
for Y in your_cursor loop
-- if we are in loop , we are found a record , change value to true
l_found := true;
check conditions, do output etc...
end loop;
-- if cursor have no result
if not l_found then
dbms_output.put_line('No records found');
end if;
Related
I am getting
ORA-06502: PL/SQL: numeric or value error in below code:
record_state := record_state || 'Inserting record Entry for student: ' ||
roll_no || ' for date: ' || To_Char(admission_date,'yyyymmdd') ||
' # ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') || CHR(10);
Below are the datatypes:
roll_no - NUMBER(10,0)
admission_date - TIMESTAMP(6)
record_state - CLOB
You need to use to_clob to convert string to clob and then you can concat two clobs as following:
record_state := record_state ||
to_clob(
'Inserting record Entry for student: ' || roll_no || ' for date: ' || To_Char(admission_date,'yyyymmdd') || ' # ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') || CHR(10)
);
Cheers!!
if you have lob objects, i would suggest to use a DBMS_LOB library.
DECLARE
record_state CLOB;
BEGIN
DBMS_LOB.CREATETEMPORARY(record_state);
-- here you should make sure that the string is not too long (max 32K), otherwise the concatenation with pipes will not work. There will be an exception.
DBMS_LOB.append (record_state , 'Inserting record Entry for student: ' || roll_no || ' for date: ' || To_Char(admission_date,'yyyymmdd') || ' # ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') || CHR(10));
-- do more operations
dbms_lob.freetemporary(record_state);
END ;
/
my procedure is like below;
CREATE OR REPLACE PROCEDURE updateWEEK_SALES_REPORTS
( p_start IN WEEK_SALES_REPORT.StartDate%TYPE,
p_end IN weekly_sales_report.EndDate%TYPE)
IS
BEGIN
UPDATE WEEK_SALES_REPORT SET ComAmount = SaleAmount*ComRate WHERE (StartDate-EndDate) = (p_start-p_end);
SELECT concat('The commission amount for report ',ReportID,' has been updated to ',ComAmount,' dollars,
which is',ComRate,'% of the total sale amount of ',SaleAmount,' dollars.')
COMMIT;
END;
/
but show errors is
7/3 PL/SQL: SQL Statement ignored
7/10 PL/SQL: ORA-00909: invalid number of arguments
I'm pretty sure you're trying to print your message to the console. For that, you want dbms_output.
CREATE OR REPLACE PROCEDURE updateWEEK_SALES_REPORTS
( p_start IN date,
p_end IN date)
IS
BEGIN
UPDATE WEEK_SALES_REPORT SET ComAmount = SaleAmount*ComRate WHERE (StartDate-EndDate) = (p_start-p_end);
dbms_output.put_line('The commission amount for report ' || ReportID || ' has been updated to ' || ComAmount || ' dollars,
which is' || ComRate || '% of the total sale amount of ' || SaleAmount || ' dollars.');
COMMIT;
END;
Yes, #Jacob H is right, CONCAT takes only 2 parameters. Use || instead, much uglier than your version, though:
SELECT 'The commission amount for report ' || ReportID ||
' has been updated to ' || ComAmount || ' dollars, which is' ||
ComRate || '% of the total sale amount of ' || SaleAmount ||
' dollars.' ...
Furthermore, you need to SELECT it INTO some variable like, f.i.
SELECT ... INTO myvar FROM DUAL;
I am having trouble to pass the right date format to my procedure. I did search on the forum but did not find a solution. When I extract the value in my string I get the following result
select *
from (select a.col1,
a.col2,
a.col3,
dense_rank() over(order by a.col2) as TheRank,
round((count(*) over(order by a.col2)), 1) as UniqueRank
from abt_t a
where a.col4 >= to_date(05 - JAN - 98, 'YYYY-MM-DD')
and a.col4 <= 05 - JAN - 98
and (a.col2 <= '15:59' and a.col2 >= '09:30')
order by 1 asc, 2)
where TheRank = 390
and UniqueRank = 05 - JAN - 98
the value 05 - JAN - 98 is pretty different then the one I have initiated p_start_dt date:= to_date('1998-01-05', 'YYYY-MM-DD');
I have tried
Here is my procedure :
create or replace procedure GET_VOL_OPTION_test is
BEGIN
DECLARE
-- Local variables here
w_sqlcode number := 0;
w_sqlerrm char(500) := '';
query_str VARCHAR2(2000);
TYPE cur_typ IS ref CURSOR;
V_TABLE varchar2(200) :=NULL;
c cur_typ;
inv_num NUMBER;
exp_dt date;
Curr_dt date;
inv_amt varchar2(5);
p_start_dt date:= to_date('1998-01-05', 'YYYY-MM-DD');
CURSOR CUR_OVRDDEF_PARAM_EN IS
select tname from OPT_TBL_NM_2015_T order by tname;
BEGIN
FOR XX IN CUR_OVRDDEF_PARAM_EN LOOP
BEGIN
----
query_str := 'select * from (select a.col1, a.col2, a.col3,' ||
'dense_rank() over (order by a.col2) as TheRank,' ||
'round((count(*) over (order by a.col2)),1) as UniqueRank ' ||
/*'from '|| p_stock || ' a' ||*/
'from abc_t a' ||
' where a.col4 >= to_date(' || to_char(p_start_dt) || ', ''YYYY-MM-DD'')' || ' and ' || 'a.col4 <= ' || p_start_dt ||
' and (a.col2 <= ''15:59'' and a.col2 >= ''09:30'')' ||
'order by 1 asc,2)' ||
'where TheRank = 390 and UniqueRank = ' || p_start_dt;
OPEN c FOR query_str ;
LOOP
FETCH c INTO inv_num, exp_dt, curr_dt, inv_amt;
EXIT WHEN c%NOTFOUND;
-- process row here
END LOOP;
/* EXCEPTION
WHEN OTHERS THEN NULL;
END;*/
EXCEPTION
WHEN OTHERS THEN
w_sqlcode := SQLCODE;
w_sqlerrm := SQLERRM;
END;
END LOOP;
COMMIT;
END;
END;
I am using oracle 12. If you need more information, please don't hesitate.
Regards,
Christian
The problem is that you are calling to_char(p_start_dt) without a format mask (or, later, using string concatenation on the dates) and Oracle will convert the date to a string using the NLS_DATE_FORMAT session parameter. As you have found, this is probably set to DD-MON-YY and is causing you issues. If you are going to convert dates to strings and embed it into the dynamic SQL then you need to specify the format mask for the conversion (i.e. TO_CHAR( p_start_date, 'YYYY-MM-DD' )); however, a better solution would be to:
Use bind variables in your dynamic SQL and then just pass the date in when you open the cursor:
DECLARE
-- Local variables here
w_sqlcode number := 0;
w_sqlerrm char(500) := '';
query_str VARCHAR2(2000)
:= 'select * from (select a.col1, a.col2, a.col3,' ||
'dense_rank() over (order by a.col2) as TheRank,' ||
'count(*) over (order by a.col2) as UniqueRank' ||
' from abc_t a' ||
' where a.col4 BETWEEN :start_dt AND :start_dt' ||
' and (a.col2 <= ''15:59'' and a.col2 >= ''09:30'')' ||
'order by 1 asc,2)' ||
'where TheRank = 390 and UniqueRank = :start_dt';
c SYS_REFCURSOR;
inv_num NUMBER;
exp_dt DATE;
Curr_dt DATE;
inv_amt VARCHAR2(5);
p_start_dt DATE := DATE '1998-01-05';
CURSOR CUR_OVRDDEF_PARAM_EN IS
select tname from OPT_TBL_NM_2015_T order by tname;
BEGIN
FOR XX IN CUR_OVRDDEF_PARAM_EN LOOP
BEGIN
OPEN c FOR query_str USING p_start_dt;
LOOP
FETCH c INTO inv_num, exp_dt, curr_dt, inv_amt;
EXIT WHEN c%NOTFOUND;
-- process row here
END LOOP;
EXCEPTION
WHEN OTHERS THEN
w_sqlcode := SQLCODE;
w_sqlerrm := SQLERRM;
END;
END LOOP;
COMMIT;
END;
/
Also, why are you comparing UniqueRank to a date value?
This is the line where you create the date comparision:
' where a.col4 >= to_date(' || to_char(p_start_dt) || ', ''YYYY-MM-DD'')' || ' and ' || 'a.col4 <= ' || p_start_dt ||
and you get
where a.col4 >= to_date(05 - JAN - 98, 'YYYY-MM-DD') and a.col4 <= 05 - JAN - 98
So obviously your standard date format is 'DD - MON - RR'. Why do you even rely on a setting? You should specify the format in to_char, such as:
to_char(p_start_dt, 'YYYY-MM-DD')
rather than using to_char(p_start_dt) or p_start_dt (which is both the same; a date converted to string using the default setting).
You are also missing quotes. The correct syntax would have been:
' where a.col4 >= to_date(''' || to_char(p_start_dt, 'YYYY-MM-DD') || ''', ''YYYY-MM-DD'') and ' ||
'a.col4 <= to_date(''' || to_char(p_start_dt, 'YYYY-MM-DD') || ''', ''YYYY-MM-DD'')' ||
or simpler with ISO date literals:
' where a.col4 >= date ''' || to_char(p_start_dt, 'YYYY-MM-DD') || ''' and ' ||
'a.col4 <= date ''' || to_char(p_start_dt, 'YYYY-MM-DD') || '''' ||
which is of course the same as
' where a.col4 = date ''' || to_char(p_start_dt, 'YYYY-MM-DD') || '''' ||
Hi i'm a begginer in pl/sql under oracle. i'tried to write this pl/SQL programm but i had this error:
Encountered the symbol "WHILE" when expecting one of the following: . ( * # % & - + / at loop mod remainder rem ..'
SET SERVEROUTPUT ON
DECLARE
CURSOR EMP_CURSOR IS SELECT EMPLOYEE_NAME, SALARY, DATE_HIRE FROM EMPLOYEES WHERE DEPARTMENT_ID=1;
BEGIN
FOR EMP_REC IN EMP_CURSOR
WHILE EMP_REC%FOUND
LOOP
IF EMP_REC.SALARY > 10000 AND EMP_REC.DATE_HIRE< DATE '2000-01-01'
THEN
DBMS_OUTPUT.PUT_LINE (EMP_REC.EMPLOYEE_NAME || ' earns ' || EMP_REC.SALARY || 'and joined the organization on ' || EMP_REC.DATE_HIRE);
END IF;
END LOOP;
END LOOP;
END;
/
SET SERVEROUTPUT OFF
Try this:
DECLARE
CURSOR EMP_CURSOR IS SELECT EMPLOYEE_NAME, SALARY, DATE_HIRE FROM EMPLOYEES WHERE DEPARTMENT_ID=1;
BEGIN
FOR EMP_REC IN EMP_CURSOR
LOOP
IF EMP_REC.SALARY > 10000 AND EMP_REC.DATE_HIRE< DATE '2000-01-01'
THEN
DBMS_OUTPUT.PUT_LINE (EMP_REC.EMPLOYEE_NAME || ' earns ' || EMP_REC.SALARY || 'and joined the organization on ' || EMP_REC.DATE_HIRE);
END IF;
END LOOP;
END;
I'm having problems retrieving the time from a date field in a SP. If I run the query:
select TO_CHAR(HOR_HST_ATN,'YYYY/MM/DD HH24:MI:SS') AS HOR_HST_ATN FROM AAM0_DT_RSTCN ;
It returns the date and time ok.
But in the SP, the code:
SELECT FEC_DSD_ATN, FEC_HST_ATN, NOM_SEM_DSD_ATN, NOM_SEM_HST_ATN,
TO_DATE(HOR_DSD_ATN ,'DD/MM/YYYY HH24:MI:SS') as HOR_DSD_ATN,
TO_DATE(HOR_HST_ATN,'DD/MM/YYYY HH24:MI:SS') as HOR_HST_ATN
returns just the date ok but the time is 00:00
If I try the select in the SP with TO_CHAR as in:
SELECT FEC_DSD_ATN, FEC_HST_ATN, NOM_SEM_DSD_ATN, NOM_SEM_HST_ATN,
TO_CHAR(HOR_DSD_ATN ,'YYYY/MM/DD HH24:MI:SS') as HOR_DSD_ATN,
TO_CHAR(HOR_HST_ATN,'YYYY/MM/DD HH24:MI:SS') as HOR_HST_ATN
I get the error: SQLCODE: -6502 SQLERRM: ORA-06502: PL/SQL: error ...
Any clues ? BTW I must use a SP to retrieve this value.
Update: the column is type date. Here's the full SP:
FUNCTION FN_AAM_EV_RSTCN (
I_NUM_CONTRATO IN AAM0_DT_RSTCN.NUM_CONTRATO%TYPE,
I_COD_PFL IN AAM0_DT_RSTCN.COD_PFL%TYPE,
I_COD_APL_PFM IN AAM0_DT_RSTCN.COD_APL_PFM%TYPE,
I_COD_PTO IN AAM0_DT_RSTCN.COD_PTO%TYPE,
I_COD_FNC IN AAM0_DT_RSTCN.COD_FNC%TYPE
) RETURN BOOLEAN
AS
T_FEC_DSD_ATN AAM0_DT_RSTCN.FEC_DSD_ATN%TYPE;
T_HOR_DSD_ATN AAM0_DT_RSTCN.HOR_DSD_ATN%TYPE;
T_FEC_HST_ATN AAM0_DT_RSTCN.FEC_HST_ATN%TYPE;
T_HOR_HST_ATN AAM0_DT_RSTCN.HOR_HST_ATN%TYPE;
T_NOM_SEM_DSD_ATN AAM0_DT_RSTCN.NOM_SEM_DSD_ATN%TYPE;
T_NOM_SEM_HST_ATN AAM0_DT_RSTCN.NOM_SEM_HST_ATN%TYPE;
O_RESULTSET2 REST_REFCUR;
BEGIN
OPEN O_RESULTSET2 FOR
SELECT FEC_DSD_ATN, FEC_HST_ATN, NOM_SEM_DSD_ATN, NOM_SEM_HST_ATN,
TO_CHAR(HOR_DSD_ATN ,'DD/MM/YYYY HH24:MI:SS') as HOR_DSD_ATN,
TO_CHAR(HOR_HST_ATN,'DD/MM/YYYY HH24:MI:SS') as HOR_HST_ATN
FROM AAM0_DT_RSTCN
WHERE ROWNUM <=1
AND NUM_CONTRATO = NVL ( I_NUM_CONTRATO, NUM_CONTRATO )
AND COD_PFL = NVL ( I_COD_PFL, COD_PFL )
AND COD_APL_PFM = NVL ( I_COD_APL_PFM, COD_APL_PFM )
AND COD_PTO = NVL ( I_COD_PTO, COD_PTO )
AND COD_FNC = NVL ( I_COD_FNC, COD_FNC )
AND FLG_RCS = 'D'
AND COD_TPO_CDC = 'PC'
;
FETCH O_RESULTSET2 INTO T_FEC_DSD_ATN, T_FEC_HST_ATN, T_NOM_SEM_DSD_ATN, T_NOM_SEM_HST_ATN, T_HOR_DSD_ATN, T_HOR_HST_ATN ;
IF (O_RESULTSET2%NOTFOUND) THEN
RETURN TRUE;
ELSE
dbms_output.put_line('EVALUO RESTRICCIONES: T_FEC_DSD_ATN ' || T_FEC_DSD_ATN || ' T_FEC_HST_ATN : ' || T_FEC_HST_ATN || ' T_NOM_SEM_DSD_ATN: ' ||
T_NOM_SEM_DSD_ATN || ' T_NOM_SEM_HST_ATN: ' || T_NOM_SEM_HST_ATN || ' T_HOR_DSD_ATN: ' || TO_CHAR(T_HOR_DSD_ATN ,'DD/MM/YYYY HH24:MI:SS') ||
' T_HOR_HST_ATN: ' || TO_CHAR(T_HOR_HST_ATN ,'DD/MM/YYYY HH24:MI:SS') );
IF (NOT((T_FEC_DSD_ATN IS NULL) and (T_FEC_HST_ATN IS NULL)) ) THEN
IF ( NOT ((T_FEC_DSD_ATN <= SYSDATE) AND (T_FEC_HST_ATN >= SYSDATE ))) THEN
RETURN FALSE;
END IF ;
END IF ;
RETURN TRUE;
END IF ;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN TRUE;
WHEN OTHERS THEN
IF O_RESULTSET2%ISOPEN THEN
CLOSE O_RESULTSET2;
END IF;
DBMS_OUTPUT.PUT_LINE('ERROR en FN_AAM_EV_RSTCN : ');
DBMS_OUTPUT.PUT_LINE(' SQLCODE: ' || SQLCODE );
DBMS_OUTPUT.PUT_LINE(' SQLERRM: ' || SQLERRM );
ROLLBACK;
END FN_AAM_EV_RSTCN;
Your problem lies with the following code:
...
T_HOR_DSD_ATN AAM0_DT_RSTCN.HOR_DSD_ATN%TYPE;
T_HOR_HST_ATN AAM0_DT_RSTCN.HOR_HST_ATN%TYPE;
...
SELECT FEC_DSD_ATN, FEC_HST_ATN, NOM_SEM_DSD_ATN, NOM_SEM_HST_ATN,
TO_CHAR(HOR_DSD_ATN ,'DD/MM/YYYY HH24:MI:SS') as HOR_DSD_ATN,
TO_CHAR(HOR_HST_ATN,'DD/MM/YYYY HH24:MI:SS') as HOR_HST_ATN
FROM AAM0_DT_RSTCN
...
FETCH O_RESULTSET2 INTO T_FEC_DSD_ATN, T_FEC_HST_ATN, T_NOM_SEM_DSD_ATN,
T_NOM_SEM_HST_ATN, T_HOR_DSD_ATN, T_HOR_HST_ATN ;
Since the HOR_DSD_ATN and HOR_HST_ATN columns have the DATE data type, your local variables (T_HOR_DSD_ATN and T_HOR_HST_ATN) are also DATEs. However, in your SELECT you are converting these dates to strings with the TO_CHAR function. Therefore, your fetch is effectively doing this (I've made up some dates here):
T_HOR_DSD_ATN := '03/02/2010 09:33:30';
T_HOR_HST_ATN := '01/01/2010 12:30:00';
Since you are assigning a string to a date variable, Oracle must do an implicit TO_DATE - therefore it is using the session's NLS_DATE_FORMAT to convert them, which probably just gets the date portion (e.g. DD/MM/YYYY) and loses the time values.
To fix it, just remove the TO_CHAR()s from your SELECT statement - that way you will get dates + time values unmodified into your local variables.
Since the TO_DATE function takes a VARCHAR as argument, you wouldn't use this function on a DATE field. If you want to retrieve both the date and the time from a DATE field you would just SELECT the fields without functions:
SELECT FEC_DSD_ATN, FEC_HST_ATN, NOM_SEM_DSD_ATN, NOM_SEM_HST_ATN,
HOR_DSD_ATN, HOR_HST_ATN
...
update
The problem is that you are fetching TO_CHAR(HOR_DSD_ATN, 'DD/MM/YYYY HH24:MI:SS') into a DATE field. There is an implicit conversion that truncates your date. Use to_char on a DATE variable and use to_date on a CHAR variable.
My suggestion:
FUNCTION FN_AAM_EV_RSTCN(I_NUM_CONTRATO IN AAM0_DT_RSTCN.NUM_CONTRATO%TYPE,
I_COD_PFL IN AAM0_DT_RSTCN.COD_PFL%TYPE,
I_COD_APL_PFM IN AAM0_DT_RSTCN.COD_APL_PFM%TYPE,
I_COD_PTO IN AAM0_DT_RSTCN.COD_PTO%TYPE,
I_COD_FNC IN AAM0_DT_RSTCN.COD_FNC%TYPE)
RETURN BOOLEAN AS
BEGIN
FOR cc IN (SELECT FEC_DSD_ATN, FEC_HST_ATN, NOM_SEM_DSD_ATN,
NOM_SEM_HST_ATN, HOR_DSD_ATN, HOR_HST_ATN
FROM AAM0_DT_RSTCN
WHERE ROWNUM <= 1
AND NUM_CONTRATO = NVL(I_NUM_CONTRATO, NUM_CONTRATO)
AND COD_PFL = NVL(I_COD_PFL, COD_PFL)
AND COD_APL_PFM = NVL(I_COD_APL_PFM, COD_APL_PFM)
AND COD_PTO = NVL(I_COD_PTO, COD_PTO)
AND COD_FNC = NVL(I_COD_FNC, COD_FNC)
AND FLG_RCS = 'D'
AND COD_TPO_CDC = 'PC') LOOP
dbms_output.put_line(' T_HOR_DSD_ATN: ' ||
TO_CHAR(cc.HOR_DSD_ATN, 'DD/MM/YYYY HH24:MI:SS') ||
' T_HOR_HST_ATN: ' ||
TO_CHAR(cc.HOR_HST_ATN, 'DD/MM/YYYY HH24:MI:SS'));
-- your logic with return boolean
END LOOP;
-- no rows found
RETURN TRUE;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('ERROR en FN_AAM_EV_RSTCN : ');
DBMS_OUTPUT.PUT_LINE(' SQLCODE: ' || SQLCODE);
DBMS_OUTPUT.PUT_LINE(' SQLERRM: ' || SQLERRM);
RAISE;
END FN_AAM_EV_RSTCN;
If HOR_HST_ATN is a date column then TO_DATE(HOR_HST_ATN,'DD/MM/YYYY HH24:MI:SS') must be a typo. You probably mean TO_CHAR().
If the columns were populated by dates without a time element Oracle defaults the time to midnight...
SQL> create table t23 (d date)
2 /
Table created.
SQL> insert into t23 values (sysdate)
2 /
1 row created.
SQL> insert into t23 values (to_date('03-FEB-2010', 'DD-MON-YYYY'))
2 /
1 row created.
SQL> select to_char(d, 'DD/MM/YYYY HH24:MI:SS') as datetime from t23
2 /
DATETIME
-------------------
02/02/2010 17:59:51
03/02/2010 00:00:00
SQL>