Oracle Portal - Error WWV-17050 - Failed to parse..

First let me say that I am not very experienced with PL-SQL and that is probably where my error is.  I am getting this error inside of Oracle portal.  I do have a schema called famis7i.world where I have successfully established a database link.  With other simples SQL statements I am able to run reports and get the data I want.  In this particular PL-SQL code I don’t know where the problem is.  The portlet I wan to add is a “report from SQL”  The code for the report is as fallowed:  PS: Please refer to the rest of my posting after the SQL code!

select 'Q'||(to_char(add_months(sysdate,6),'Q') - 1) "QUATER",
bsc_training_hours(decode( (to_char(add_months(sysdate,6),'Q') - 1), '1','07/01/'||to_char(sysdate,'RR'), '2','10/01/'||to_char(sysdate,'RR'),'3','01/01/'||(to_char(sysdate,'RR')+1),'4','04/01/'||(to_char(sysdate,'RR')+1)),
decode( (to_char(add_months(sysdate,6),'Q') - 1), '1','10/01/'||to_char(sysdate,'RR'), '2','01/01/'||to_char(sysdate,'RR'),'3','04/01/'||(to_char(sysdate,'RR')+1),'4','07/01/'||(to_char(sysdate,'RR')+1))) "TRAINING_HOURS_FOR_QUARTER",
        bsc_training_hours_year(decode( (to_char(add_months(sysdate,6),'Q') - 1), '1','07/01/'||to_char(sysdate,'RR'), '2','10/01/'||to_char(sysdate,'RR'),'3','01/01/'||(to_char(sysdate,'RR')+1),'4','04/01/'||(to_char(sysdate,'RR')+1)),
decode( (to_char(add_months(sysdate,6),'Q') - 1), '1','10/01/'||to_char(sysdate,'RR'), '2','01/01/'||to_char(sysdate,'RR'),'3','04/01/'||(to_char(sysdate,'RR')+1),'4','07/01/'||(to_char(sysdate,'RR')+1))) "TRAINING_HOURS_PER_YEAR",
        fm_emps('1') "FM_EMPS",
        round((bsc_training_hours_year(decode( (to_char(add_months(sysdate,6),'Q') - 1), '1','07/01/'||to_char(sysdate,'RR'), '2','10/01/'||to_char(sysdate,'RR'),'3','01/01/'||(to_char(sysdate,'RR')+1),'4','04/01/'||(to_char(sysdate,'RR')+1)),
decode( (to_char(add_months(sysdate,6),'Q') - 1), '1','10/01/'||to_char(sysdate,'RR'), '2','01/01/'||to_char(sysdate,'RR'),'3','04/01/'||(to_char(sysdate,'RR')+1),'4','07/01/'||(to_char(sysdate,'RR')+1))) / fm_emps('1')),2) "AVG_PER_EMP"
from dual
     

I can tell this is calling:  (bsc_training_hours_year) and (bsc_training_hours) which are functions inside of a system schema.  So, I know this function must exist.  When I try to create (BSC_TRAINING_HOURS_YEAR) I get the fallowing error.  I am posting the code first then the error!

(p_start IN VARCHAR2, p_end IN VARCHAR2) RETURN NUMBER IS

begin
  declare
  vtrain number;
begin

  select  sum(hours)
    into vtrain
  from famis_labor@famis7i.world
  where wo_number = 'SWO001252'
  and trunc(work_date) >= to_date(p_end, 'MM/DD/RR') -365
  and trunc(work_date) <= to_date(p_end, 'MM/DD/RR')
    and employee in (select employee from famis_emp@famis7i.world where crew in ('ENGR','ENERGY','REFR','PAINT','CARP','LOCK','PLUM','SIGNAGE','AUTO','ELEC','METAL','GDSFM','GDSPARK','GDSHSE','EQUIP OPER','IRR SPEC','LEAD GRDS','RECYCLE','MOVE', 'CUST')
                   )
  order by 1;
return vtrain;
exception when others then
 vtrain := '0';
 return vtrain;
end;



end;

ERROR:

Line No. 3 : PLS-00103: Encountered the symbol "(" when expecting one of the following:

. @ % ; is authid as cluster order using external character
deterministic parallel_enable pipelined aggregate
(WWV-17050)
Line No. 5 : PLS-00103: Encountered the symbol "BEGIN" when expecting one of the following:

language
(WWV-17050)
Line No. 27 : PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:

begin function package pragma procedure form
(WWV-17050)
ORA-24344: success with compilation error (WWV-11230)
Failed to parse as PORTAL - create or replace Function SYSTEM.BSC_TRAINING_HOURS_YEAR
return VARCHAR2
(p_start IN VARCHAR2, p_end IN VARCHAR2) RETURN NUMBER IS

begin
declare
vtrain number;
begin

select sum(hours)
into vtrain
from famis_labor@famis7i.world
where wo_number = 'SWO001252'
and trunc(work_date) >= to_date(p_end, 'MM/DD/RR') -365
and trunc(work_date) <= to_date(p_end, 'MM/DD/RR')
and employee in (select employee from famis_emp@famis7i.world where crew in ('ENGR','ENERGY','REFR','PAINT','CARP','LOCK','PLUM','SIGNAGE','AUTO','ELEC','METAL','GDSFM','GDSPARK','GDSHSE','EQUIP OPER','IRR SPEC','LEAD GRDS','RECYCLE','MOVE', 'CUST')
)
order by 1;
return vtrain;
exception when others then
vtrain := '0';
return vtrain;
end;



end; (WWV-08300)


Please help!!!

Thank you.
tadeu_lbcAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bochgochCommented:
Your syntax is wrong>>

begin
declare
vtrain number;
begin

You have a declare within the first begin that is not valid, the sequence is...

declare
begin
end;

One other thing that spring to mind is your database link - has that been created within the PORTAL schema?

bg
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bochgochCommented:
...Check those couple of things and I'm sure we'll get further errors to look at...
0
tadeu_lbcAuthor Commented:
Thank you.

I tried but still same erros!  Here is the code again!  And yes I do a database link under the rigth schema!

(p_start IN VARCHAR2, p_end IN VARCHAR2) RETURN NUMBER IS

begin
  declare
  vtrain number;
begin

  select  sum(hours)
    into vtrain
  from famis_labor@famis7i.world
  where wo_number = 'SWO001252'
  and trunc(work_date) >= to_date(p_end, 'MM/DD/RR') -365
  and trunc(work_date) <= to_date(p_end, 'MM/DD/RR')
    and employee in (select employee from famis_emp@famis7i.world where crew in ('ENGR','ENERGY','REFR','PAINT','CARP','LOCK','PLUM','SIGNAGE','AUTO','ELEC','METAL','GDSFM','GDSPARK','GDSHSE','EQUIP OPER','IRR SPEC','LEAD GRDS','RECYCLE','MOVE', 'CUST')
                   )
  order by 1;
return vtrain;
exception when others then
 vtrain := '0';
 return vtrain;
end;



end;
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java App Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.