Ignored in stored procedure with clause

oracleoracle-11gplsql

Hi i'm currently working with oracle that will give me my requered output.
I able to make the query but when i'm putting it in stored procedure it gives me error of Error(11,1): PL/SQL: SQL Statement ignored and Error(15,20): PL/SQL: ORA-00936: missing expression

here's my query not in procedure:

with 
t1  as (
select * from vw_break_time_doublebreak 
/* where clause that satisfies your query */
where date_time >= date '2020-01-01' and date_time < date '2020-02-01'
)
,t2 as (
select shift, trunc(min(min(date_time)) over (), 'mm') mn, last_day(max(max(date_time)) over ()) mx 
from t1
group by shift
)
,t3 as (
select shift, mn + level - 1 dateshift from t2
connect by mn + level - 1  <= mx
and prior shift = shift
and prior sys_guid() is not null
)
SELECT t3.shift, t3.dateshift AS date_time, count (CNT) AS COUNT
    FROM t3 
    left join 
    vw_break_time_doublebreak db
    on (t3.shift = db.shift and t3.dateshift = TRUNC (db.date_time))
GROUP BY t3.shift, dateshift
ORDER BY t3.shift, dateshift;

but when i put it on store procedure it has error:

create or replace PROCEDURE           sp_bt_getcountDblBreakbyshift (
   in_date      IN       VARCHAR2,
   in_date_end  IN       VARCHAR2,
   in_pagenum   IN       INT,
   p_rec        OUT      sys_refcursor
)
AS
BEGIN
   OPEN p_rec FOR

with   <-------Error here
t1  as (
select * from vw_break_time_doublebreak 
/* where clause that satisfies your query */
where date_time >= date in_date and date_time < date in_date_end <------ error here
)
,t2 as (
select shift, trunc(min(min(date_time)) over (), 'mm') mn, last_day(max(max(date_time)) over ()) mx 
from t1
group by shift
)
,t3 as (
select shift, mn + level - 1 dateshift from t2
connect by mn + level - 1  <= mx
and prior shift = shift
and prior sys_guid() is not null
)
SELECT t3.shift, t3.dateshift AS date_time, count (CNT) AS COUNT
    FROM t3 
    left join 
    vw_break_time_doublebreak db
    on (t3.shift = db.shift and t3.dateshift = TRUNC (db.date_time))
GROUP BY t3.shift, dateshift
ORDER BY t3.shift, dateshift;
END;

sorry i'm just kinda new in oracle and don't know what i'm doing wrong.
hope someone help me out with this.

Best Answer

date in_date, date in_date_end: that is incorrect syntax. Use TO_DATE with the appropriate format string, example: to_date(in_date_end, 'YYYY-MM-DD').

But date values should be passed with DATE type, not VARCHAR2 and all the above becomes unnecessary.