The below query works fine in SQL*Plus, but if I place it in a procedure, it refuses to compile. I have tried a few other ways to rewrite the query, but this is the most efficient. Any help would be greatly appreciated.

1 create or replace procedure xx as
2 cursor gethisthdr is
3 select *
4 from schema.table H
5 where H.STATUS <> 'CANCELLED'
6 and TRUNC(H.THEDATE) > to_date(NVL((select TRUNC(S.THEDATE)
7 from schema1.table1 S
8 where H.CODE = S.CODE
9 and H.ORG||' 1 1' = S.ORG
10 and H.ID = S.ID), '01-JAN-0001'), 'DD-MON-YYYY');
11 begin
12 null;
13* end;
SQL> /

Warning: Procedure created with compilation errors.

SQL> show errors
Errors for PROCEDURE XX:

LINE/COL ERROR
-------- -----------------------------------------------------------------
6/49 PLS-00103: Encountered the symbol "SELECT" when expecting one of
the following:
( - + mod not null others
avg
count current exists max min prior sql stddev sum variance
execute forall time timestamp interval date



10/87 PLS-00103: Encountered the symbol "," when expecting one of the
following:
. ( * % & - + ; / at for mod rem and or
group having intersect minus order start union where connect
||

14/0 PLS-00103: Encountered the symbol "end-of-file" when expecting
one of the following:
begin function package pragma procedure form

SQL>