Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Why doesn't this compile?!

Re: Why doesn't this compile?!

From: Tim X <timx_at_spamto.devnul.com>
Date: 10 Jan 2003 22:49:39 +1100
Message-ID: <87r8bl9qcs.fsf@tiger.rapttech.com.au>


"Jorge Carvalho" <rdc02271_at_yahoo.com> writes:

> Hello!
> I'm a newbie and I'm trying to create a package, but i always get a
> compilation error.
> Here is the code (i don't see where is the problem! I create the interface
> without problems, but i try to create the function createDataType2 i get a
> compilation error; apparently there is something worng with the select
> inside this function...)
> Thanks for your help and attention.
> Best Regards,
> Jorge Carvalho
> rdc02271_at_yahoo.com
>
> create or replace package body pf_pack_managementGeneral as
> function createDataType(ls_name varchar2,ln_size number,ln_decimals number)
> return varchar2 is
> ls_dataType varchar2(30);
> begin
> --use this to create a real data type
> --ls_name:=UPPER(ls_name); --doesn't upper exist?!
> ls_dataType:=
> CASE ls_name
> WHEN 'VARCHAR2' then 'varchar2(' || to_char(ln_size) ||')'
> WHEN 'NUMBER' then 'number(' || to_char(ln_size) || ',' ||
> to_char(ln_decimals) || ')'
> end;
> return ls_dataType;
> end createDataType;
>
> function createDataType2(ln_id number) return varchar2 is
> --ls_name varchar2(50);
> --ln_size number(4);
> --ln_decimals number(2);
> ls_name DATATYPES.RealDataTypeName%TYPE;
> ln_size PROPERTIES.Size_%TYPE;
> ln_decimals PROPERTIES.Decimals%TYPE;
>
> begin
> --use this to create a real data type
> --select * from datatypes into lr_datatype where id=:new.iddatatype;
> SELECT datatypes.RealDataTypeName,properties.Size_,properties.Decimals
> from properties,datatypes into ls_name,ln_size,ln_decimals WHERE
> properties.iddatatype=datatypes.id AND properties.id=ln_id;
> return createDataType(ls_name,ln_size,ln_decimals);
> end createDataType2;
> end pf_pack_managementGeneral;
>
> create or replace package pf_pack_managementGeneral as --package
> specification
> function createDataType(ls_name varchar2,ln_size number,ln_decimals number)
> return varchar2;
> function createDataType2(ln_id number) return varchar2;
> end pf_pack_managementGeneral;
>
>

Just at a glance I can see one error, you have forgotten to specify wether your parameters to your functions are IN, OUT or both. e.g. function name(param1 IN varchar2, -- input value, cannot be modified

                   param2 OUT varchar2, -- to be modified and pass back
                   param3 IN OUT varchar2) -- input + may be modified

It is possibly better to first define each function as a stand alone function, get it compiled and debugged and then put it into a package. This will eliminate package creation errors at first and allow you to concentrate on getting the functions right. You can then put them inside the package and worry about any specific package type errors. Also, breaking it into individual functions will allow you to debug with smaller units, which will probably be a lot more effective and less time consuming.

Start with small steps and then build up as you gain understanding and confidence - walk now, run later.

HTH Tim

-- 
Tim Cross
The e-mail address on this message is FALSE (obviously!). My real e-mail is
to a company in Australia called rapttech and my login is tcross - if you 
really need to send mail, you should be able to work it out!
Received on Fri Jan 10 2003 - 05:49:39 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US