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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:23:58+00:00 2026-05-27T04:23:58+00:00

In a procedure if my first query returns null value or returns no records

  • 0

In a procedure if my first query returns null value or returns no records then my second query has to run even the second query returns null value or returns no records then a default value has to return. how to make this procedure? should i use if else statement or exception handler?

  • 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-27T04:23:58+00:00Added an answer on May 27, 2026 at 4:23 am

    One way of doing this would be to nest IF statements, something like this:

    create or replace function get_queue_id 
        (p_product_code in mo_product_master.product_code%type
         , p_intermediary_code in intrfc_intermediary_mstr_view.intermediary_code%type)
        return mo_product_master.queue_id%type
    as
        return_value number;
    begin
        -- preferred_choice 
        begin
            select pm.queue_id 
            into return_value
            from mo_product_master pm 
            where pm.product_code=p_product_code
        exception
            when no_data_found then
                null;
        end;
    
        if return_value is null then
            -- second_choice 
            begin
                select qim.queue_id 
                into return_value
                from mo_queue_inter_map_master qim
                    , intrfc_intermediary_mstr_view imv 
                where qim.category_code =imv.category_code 
                and imv.intermediary_code=p_intermediary_code;
            exception
                when no_data_found then
                    null;
            end;
    
            if return_value is null then
                -- default_value 
                select id 
                into return_value
                from mo_queue_master 
                where queue_name='others' 
                and status='Active';
            end if;
        end if;
        return return_value;
    end;
    /
    

    It is a bit clunky but it does the job.

    Suppressing the NO_DATA_FOUND exception is not usually recommended practice but I think it fits this scenario: not finding the first QUEUE_ID is part of the regular business logic rather than an exception which needs to be handled. I don’t think nesting the subsequent selects in the exception handler is nearly as expressive of the business rules.

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

Sidebar

Related Questions

I have a stored procedure that returns two int Values. The first can not
I have a stored procedure that returns a dynamic query, e,g if i pass
Say I have a stored procedure that returns data from a SELECT query. I
I have a dynamic query that returns around 590,000 records. It runs successfully the
The scenario is first run an expensive sorted query and save the first 100,000
When I execute a stored procedure first time, it (for example) takes 3 minutes
Which command will executed first,If a stored procedure have individual multiple select commands;
I'm after a simple stored procedure to drop tables. Here's my first attempt: CREATE
procedure MyProc(Eval: Boolean); begin if not Eval then Exit; /* do stuff */ /*
ALTER PROCEDURE [dbo].[GetDocumentsAdvancedSearch] @SDI CHAR(10) = NULL ,@Client CHAR(4) = NULL ,@AccountNumber VARCHAR(20) =

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.