Question

I am using 11g I have table

CREATE TABLE Agency
(
AgencyID          int   not null PRIMARY KEY,
AgencyName        VARCHAR2(30) not null,
AgencyLtrCode     VARCHAR2(10) not null,
IsActive          VARCHAR2(3) DEFAULT 'yes'NOT NULL,
LastListSentData  DATE DEFAULT SYSDATE ,
LetterSendDate    DATE DEFAULT SYSDATE ,
CertificationDate DATE DEFAULT SYSDATE ,
CeresNo       int,
AgencyAreaID      int not null,
CONSTRAINT fk_Agency FOREIGN KEY (AgencyAreaID) REFERENCES AgencyArea(AriaID)
);

I use procedure to insert new records in it

create or replace PROCEDURE insert_AGENCY_Procedure(
       AGENCYID IN AGENCY.AGENCYID%TYPE,
       AGENCYNAME IN AGENCY.AGENCYNAME%TYPE,
       AGENCYLTRCODE IN AGENCY.AGENCYLTRCODE%TYPE,  
       ISACTIVE IN AGENCY.ISACTIVE%TYPE DEFAULT 'yes',
       LASTLISTSENTDATA IN AGENCY.LASTLISTSENTDATA%TYPE DEFAULT SYSDATE,
       LETTERSENDDATE IN AGENCY.LETTERSENDDATE%TYPE DEFAULT SYSDATE,
       CERTIFICATIONDATE IN AGENCY.CERTIFICATIONDATE%TYPE DEFAULT SYSDATE,
       CERESNO IN AGENCY.CERESNO%TYPE,
       AGENCYAREAID IN AGENCY.AGENCYAREAID%TYPE)
IS BEGIN
  INSERT INTO AGENCY("AGENCYID", "AGENCYNAME","AGENCYLTRCODE","ISACTIVE","LASTLISTSENTDATA","LETTERSENDDATE","CERTIFICATIONDATE","CERESNO","AGENCYAREAID") 
  VALUES             (AGENCYID, AGENCYNAME,AGENCYLTRCODE,ISACTIVE,LASTLISTSENTDATA,LETTERSENDDATE,CERTIFICATIONDATE,CERESNO,AGENCYAREAID);
  COMMIT;
END;​​

right now it throw error "Error at line 17: PLS-00103: Encountered the symbol "" " line 17 had only END; on it

when I submit inserting which looks like

BEGIN
insert_AGENCY_Procedure(9003,'Some Other Church', 'SomOTCh','no',10-10-2011,10/10/2011,10/10/2011,17,2   );
END;

it throws error

ORA-06550: line 2, column 4:
PLS-00306: wrong number or types of arguments in call to 'INSERT_AGENCY_PROCEDURE'
ORA-06550: line 2, column 4:
PL/SQL: Statement ignored

or other insert like

BEGIN
insert_AGENCY_Procedure(9003,'Some Other Church',SomOTCh',DEFAULT,DEFAULT,DEFAULT,DEFAULT,17,2   );
END;

it throws error

ORA-06550: line 2, column 64:
PLS-00103: Encountered the symbol "DEFAULT" when expecting one of the following:

   ( - + case mod new not null 

The question is what is wrong with my procedure? I was trying to resolve this problem but stuck :(

Was it helpful?

Solution

First off, the INSERT_AGENCY_PROCEDURE procedure is defined to take 8 parameters but you are trying to pass in 9 parameters. It appears that you are trying to pass in an AgencyLtrCode but the procedure does not take an AgencyLtrCode as a parameter. You would either have to stop trying to pass in the AgencyLtrCode or you would need to modify the procedure to accept that parameter.

Second, you need to pass dates to the procedure given the declaration. Your actual procedure call will error out because what you are passing in for the date parameters are not dates (and cannot be implicitly converted to dates). Assuming that we eliminate the third parameter (which is what appears to be the AgencyLtrCode discussed above), you would want something like

BEGIN
  insert_AGENCY_Procedure(9003,
                          'Some Other Church', 
                          'no', 
                          to_date('10-10-2011', 'DD-MM-YYYY'), 
                          to_date('10/10/2011', 'DD/MM/YYYY'),
                          to_date('10/10/2011','DD/MM/YYYY'),
                          17,
                          2   );
END;

Third, your procedure is incorrect. The parameters LASTLISTSENTDATA, LETTERSENDDATE, and CERTIFICATIONDATE are defined as dates so you should not call to_date on them. If you do, you force Oracle to implicitly convert the date to a string using the session's NLS_DATE_FORMAT, then convert the string back to a date using the explicit format mask. That will fail if the session's NLS_DATE_FORMAT is not what you expect.

Finally, declaring optional parameters in the middle of a procedure declaration is rarely correct. If you want to use positional binding and you want the ability to omit parameters, the optional parameters need to be at the end of the parameter list. You can define optional parameters in the middle of the parameter list and then use named binds (as DazzaL demonstrates) but that is seldom what you want to force future developers to use.

In your updated procedure, the declaration of the AgencyLtrCode parameter appears to be incorrect

AGENCYLTRCODE IN AGENCYLTRCODE%TYPE

needs to be

AGENCYLTRCODE IN AGENCY.AGENCYLTRCODE%TYPE

You are missing the name of the table.

OTHER TIPS

You're passing ninevalues, but the procedure is only expecting eight. From the table definition you seem to be missingAgencyLtrCode in the procedure.

In the first call you're passing dates as 10-10-2011 or 10/10/2011, which will be evaluated as (different) numbers not dates. You need to at least enclose them in single quotes, but really ought to specify the date mask, as to_date('10/10/2011', 'DD/MM/YYYY') rather than relying on implicit conversions.

In general, if you want to use the defaults, just leave those parameters out, do not pass DEFAULT; that isn't valid in that context. But because you have values to pass after the defaults, you need to name the parameters, i.e.

insert_agency_procedure(agency_id=>9003, ...);

there is no DEFAULT keyword, you just omit the defaults.

in your case you have the defaults in the middle of the API though, so you'd have to use NAMED notation:

begin
  insert_agency_procedure(agencyid => 9003,
                          agencyname => 'Some Other Church',
                          isactive => 'SomOTCh',
                          ceresno => 17,
                          agencyareaid => 2 );
end;
/
or mixed:
begin
  insert_agency_procedure(9003, 'Some Other Church',
                          'SomOTCh',
                          ceresno => 17,
                          agencyareaid => 2 );
end;
/

and in the first exmaple you gave:

BEGIN
insert_AGENCY_Procedure(9003,'Some Other Church', 'SomOTCh','no',10-10-2011,10/10/2011,10/10/2011,17,2   );
END;

you cant just type dates like that. Firstly quote them. Secondly always always use a format mask.

BEGIN
insert_AGENCY_Procedure(9003,'Some Other Church', 'SomOTCh','no',
                        to_date('10-10-2011', 'dd-mm-yyyy'),
                        to_date('10-10-2011', 'dd-mm-yyyy'),
                        to_date('10-10-2011', 'dd-mm-yyyy'),17,2   );
END;

I think you need to enclose your date string in single quotes (if you supply a date, considering you have default values for those parameters):

BEGIN
insert_AGENCY_Procedure(9003,'Some Other Church', 'SomOTCh','no','10-10-2011','10/10/2011','10/10/2011',17,2 );
END;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top