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

  • SEARCH
  • Home
  • 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 7812327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:28:05+00:00 2026-06-02T04:28:05+00:00

My stored procedure looks like follows: sqlQuery := ‘DROP INDEX idArchivoIndex’; EXECUTE IMMEDIATE sqlQuery;

  • 0

My stored procedure looks like follows:

  sqlQuery := 'DROP INDEX idArchivoIndex';
  EXECUTE IMMEDIATE sqlQuery;

  EXCEPTION --En caso de que no exista el índice capturamos la excepcion
    WHEN index_not_exists THEN NULL; --y la ignoramos

  sqlQuery := 'CREATE INDEX idArchivoIndex'||
              ' ON '||qusuario||' (id_archivo)';
  EXECUTE IMMEDIATE sqlQuery;

  doresetvalidacion(qusuario, idarchivo);

  IF (tipoDependencia = 'PEC') THEN
    dovalidapec(qusuario,qaniofiscal,idarchivo,imprimirMensajes);
    COMMIT;
  ELSIF (tipoDependencia = 'SAGARPA') THEN
    dovalidacionpec(qusuario,qaniofiscal,idarchivo,imprimirMensajes);
    COMMIT;
  END IF;

If the exception is not raised the procedure just drops the index but no index is recreated ! I thought that this part of the code

EXCEPTION
    WHEN index_not_exists THEN NULL;

Handled the error and then continue with the code below it. Now that I see the results what’s after the EXCEPTION is executed if and only if the exception was raised.

What I want is to simplify my code, I don’t want to copy-paste the same block of code before the EXCEPTION clause just to make it work as I expect. Is there a way to achieve it? Maybe with a nested BEGIN ... END block? Or will I have to make a separate procedure to reuse code?

Cheers.

UPDATE

create or replace
PROCEDURE DOVALIDAINFORMACION 
(
  QARCHIVO IN VARCHAR2
, QUSUARIO IN VARCHAR2
, QANIOFISCAL IN VARCHAR2
) AS
  imprimirMensajes CHAR;
  tipoDependencia VARCHAR2(25);
  idArchivo NUMBER;
  sqlQuery VARCHAR2(100);
  index_not_exists EXCEPTION;
  PRAGMA EXCEPTION_INIT(index_not_exists, -1418);
BEGIN

  sqlQuery := 'DROP INDEX idArchivoIndex';
  EXECUTE IMMEDIATE sqlQuery;
  ----------------------
  EXCEPTION --En caso de que no exista el índice capturamos la excepcion
    WHEN index_not_exists THEN --y la ignoramos
      NULL;
  END;
  ----------------------
  sqlQuery := 'CREATE INDEX idArchivoIndex'||
              ' ON '||qusuario||' (id_archivo)';
  EXECUTE IMMEDIATE sqlQuery;

  doresetvalidacion(qusuario, idarchivo);

  IF (tipoDependencia = 'PEC') THEN
    dovalidapec(qusuario,qaniofiscal,idarchivo,imprimirMensajes);
    COMMIT;
  ELSIF (tipoDependencia = 'SAGARPA') THEN
    dovalidacionpec(qusuario,qaniofiscal,idarchivo,imprimirMensajes);
    COMMIT;
  END IF;

END DOVALIDAINFORMACION;

But can’t compile the procedure.

Error(32,3): PLS-00103: Se ha encontrado el símbolo "SQLQUERY"
Error(33,48): PLS-00103: Se ha encontrado el símbolo ";" cuando se esperaba uno de los siguientes:     ) , * & = - + < / > at in is mod remainder not rem    <an exponent (**)> <> or != or ~= >= <= <> and or like LIKE2_    LIKE4_ LIKEC_ between || member SUBMULTISET_ 
  • 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-06-02T04:28:07+00:00Added an answer on June 2, 2026 at 4:28 am

    I suspect that are just missing an extra BEGIN in your updated code. An EXCEPTION clause always matches to a BEGIN and an END. In the code that you posted, the EXCEPTION matches the procedure’s BEGIN. You need it to match the BEGIN of the nested PL/SQL block.

    create or replace
    PROCEDURE DOVALIDAINFORMACION 
    (
      QARCHIVO IN VARCHAR2
    , QUSUARIO IN VARCHAR2
    , QANIOFISCAL IN VARCHAR2
    ) AS
      imprimirMensajes CHAR;
      tipoDependencia VARCHAR2(25);
      idArchivo NUMBER;
      sqlQuery VARCHAR2(100);
      index_not_exists EXCEPTION;
      PRAGMA EXCEPTION_INIT(index_not_exists, -1418);
    BEGIN
      BEGIN
        sqlQuery := 'DROP INDEX idArchivoIndex';
        EXECUTE IMMEDIATE sqlQuery;
      EXCEPTION --En caso de que no exista el índice capturamos la excepcion
        WHEN index_not_exists THEN --y la ignoramos
          NULL;
      END;
    
      sqlQuery := 'CREATE INDEX idArchivoIndex'||
                  ' ON '||qusuario||' (id_archivo)';
      EXECUTE IMMEDIATE sqlQuery;
    
      doresetvalidacion(qusuario, idarchivo);
    
      IF (tipoDependencia = 'PEC') THEN
        dovalidapec(qusuario,qaniofiscal,idarchivo,imprimirMensajes);
        COMMIT;
      ELSIF (tipoDependencia = 'SAGARPA') THEN
        dovalidacionpec(qusuario,qaniofiscal,idarchivo,imprimirMensajes);
        COMMIT;
      END IF;
    END DOVALIDAINFORMACION;
    

    As an aside, it seems odd to drop and then immediately re-create an index in a PL/SQL block. If this is somehow related to your question about recreating an index after a load, I’m afraid that you may have misunderstood my answer. In my earlier answer, I was pointing out that it may be more efficient to drop the index, load your 10 million rows of data, and then re-create the index. Assuming that the loads are happening in the stored procedure calls you are making in this code, you would want the index to be re-created after the loads are complete.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a line in my SQL Stored Procedure that looks like this (works
I have a stored procedure with an IN OUT parameter declared like follows: create
I have a really simple stored procedure that looks like this: CREATE PROCEDURE _Visitor_GetVisitorIDByVisitorGUID
I have a SQL Server Stored Procedure that looks like this: CREATE PROCEDURE [dbo].[my_stored_procedure]
I have created a Stored Procedure, that looks like this: DELIMITER €€ CREATE PROCEDURE
I'm getting a uniqueidentifier into a Stored Procedure that looks like this 00000000-0000-0000-0000-000000000000 .
I have a stored procedure called usp_getTotalOrder which looks like Select * from Order
I have inherited code that looks like this: Stored Procedure UpdateSomeStuff Update Table1 Set
My stored procedure looks like: WITH MYCTE(....) AS ( ... ) UPDATE ... (using
I've got a mySql stored procedure that looks like this-- delimiter | create procedure

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.