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 632153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:02:43+00:00 2026-05-13T20:02:43+00:00

I’ve been somewhat haphazardly grouping subsections of code in BEGIN…END blocks when it seems

  • 0

I’ve been somewhat haphazardly grouping subsections of code in BEGIN…END blocks when it seems right. Mostly when I’m working on a longer stored procedure and there’s a need for a temporary variable in one spot I’ll declare it just for that portion of the code. I also do this when I want to identify and handle exceptions thrown for a specific piece of code.

Any other reasons why one should nest blocks within a procedure, function or another larger block of PL/SQL?

  • 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-13T20:02:43+00:00Added an answer on May 13, 2026 at 8:02 pm

    When you want to handle exceptions locally like this:

    begin
       for emp_rec in (select * from emp) loop
          begin
             my_proc (emp_rec);
          exception
             when some_exception then
                log_error('Failed to process employee '||emp_rec.empno);
          end;
       end loop;
    end;
    

    In this example, the exception is handled and then we carry on and process the next employee.

    Another use is to declare local variables that have limited scope like this:

    declare
        l_var1 integer;
        -- lots of variables
    begin
       -- lots of lines of code
       ...
       for emp_rec in (select * from emp) loop
          declare
             l_localvar integer := 0;
          begin
             -- Use l_localvar
             ...
          end
       end loop;
    
    end;
    

    Mind you, wanting to do this is often a sign that your program is too big and should be broken up:

    declare
       l_var1 integer;
       -- lots of variables
       ...
       procedure local_proc (emp_rec emp%rowtype):
          l_localvar integer := 0;
       begin
          -- Use l_localvar
          ...
       end
    begin
       -- lots of lines of code
       ...
       for emp_rec in (select * from emp) loop
          local_proc (emp_rec);
       end loop;
    
    end; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.