Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6098749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:11:37+00:00 2026-05-23T13:11:37+00:00

I have written this function in SQL and I can’t figure out why but

  • 0

I have written this function in SQL and I can’t figure out why but it keeps on returning an error in the exception section. I’ve checked the syntax, got documented but I had no luck, will anyone please help?


Error returned:

Error on line 83: PLS-00103: Found symbol "EXCEPTION" instead one of the following:
    begin case declare end exit for goto if loop mod null pragma raise return select update while with
    <<
    close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe

create or replace function InsertPeriodoEvento
    (NomePeriodo in varchar,
    aInizio in integer,
    aFine in integer,
    NomeEvento1 in varchar,
    g1 in integer,
    m1 in integer,
    a1 in integer,
    NomeEvento2 in varchar,
    g2 in integer,
    m2 in integer,
    a2 in integer)
return integer is

id_Periodo number;

begin
savepoint prima_di_tutto;

insert into Periodo (Nome) values (NomePeriodo);

select Id into id_Periodo from Periodo where Nome=NomePeriodo;


if NomeEvento2 is null then
    begin
        insert into Evento (Nome, Giorno, Mese, Anno, IdPeriodo)
            values (NomeEvento1, g1, m2, a2, IdPeriodo);

        update Periodo set
            AnnoFine = aFine,
            IdEventoInizio = (select Id from Evento where Nome = NomeEvento1)
            where Periodo.Id = id_Periodo;
    end;
else
    if NomeEvento1 is null then
    begin

        insert into Evento (Nome, Giorno, Mese, Anno, IdPeriodo)
            values (NomeEvento2, g2, m2, a2, IdPeriodo);

        update Periodo set
            AnnoInizio = aInizio,
            IdEventoFine = (select Id from Evento where Nome = NomeEvento2)
            where Periodo.Id = id_Periodo;
    end;
else
    begin
        insert into Evento (Nome, Giorno, Mese, Anno, IdPeriodo)
            values (NomeEvento1, g1, m2, a2, IdPeriodo);


        insert into Evento (Nome, Giorno, Mese, Anno, IdPeriodo)
            values (NomeEvento2, g2, m2, a2, IdPeriodo);


        update Periodo set
            IdEventoInizio = (select Id from Evento where Nome = NomeEvento1),
            IdEventoFine = (select Id from Evento where Nome = NomeEvento2)
            where Periodo.Id = id_Periodo;
    end;
end if;

commit;


return 1;


EXCEPTION
when OTHERS then
    rollback to prima_di_tutto;
    return 0;

 end InsertPeriodoEvento;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:11:38+00:00Added an answer on May 23, 2026 at 1:11 pm

    Your second problem, after adding the END IF as described by @schurik, is that you have mixed up a column name with a variable name in your inserts:

        insert into Evento (Nome, Giorno, Mese, Anno, IdPeriodo)
            values (NomeEvento2, g2, m2, a2, IdPeriodo);
    

    should be

        insert into Evento (Nome, Giorno, Mese, Anno, IdPeriodo)
            values (NomeEvento2, g2, m2, a2, id_Periodo);
    

    IdPeriodo is a column in the table. id_Periodo is the variable that holds its value. This needs to be fixed in all four inserts into Evento.

    On an unrelated note, you can consolidate these two lines:

    insert into Periodo (Nome) values (NomePeriodo);
    
    select Id into id_Periodo from Periodo where Nome=NomePeriodo;
    

    into:

    insert into Periodo (Nome) values (NomePeriodo) returning Id into id_Periodo;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a function to print database table to an array like this
I have written my own function, which in C would be declared like this,
I have written this code to join ArrayList elements: Can it be optimized more?
I have written the following function in Java. This function returns current timestamp by
I am working with PL/SQL (Oracle). I have written queries before, but I'm not
I have written this short function to protect against my_sql injection, because of its
I have written this clone method for when the parent of the Employee class
I have written this program, which sorts some ints using a functor: #include<iostream> #include<list>
I have written this code to convert string in such format 0(532) 222 22
I have written this query for retrieving data from mysql as below select FeedbackCode,EMailID,FeedbackDetail,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.