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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:30:26+00:00 2026-06-14T17:30:26+00:00

I have a function which has three If/Then statements before opening a cursor. The

  • 0

I have a function which has three If/Then statements before opening a cursor. The If/Then statements check validity prior to opening the cursor.

I would like to add one more If/Then validity check, however, it is a bit more complicated than the others. Below is a sample, and I have block commented what I would like to add:

begin
    if not procedure.validation_function (<variable>, <condition>=TRUE) then
        return variable2;
    end if;

   /* if not exists
    (
       SELECT 'x' FROM table1
       WHERE table1_id = variable1_id
       AND trunc(sysdate) < trunc(table1_date + 60)
    ) then
        return variable2;
    end if; */

    open cursor(<argument>);
    fetch cursor into <variable>;
    close cursor;
    return <variable>;


end;

My problem is that I come from a T-SQL world, and I am finding in PL/SQL the if not exists command does not work. Is there a way I can, from within the function, have an If NO_DATA_FOUND statement where I utilize SELECT?

Is there a way to nest another function within that, so I can:

begin
     SELECT ....
     FROM ....
     WHERE ....
        if NO_DATA_FOUND then
           return variable2;
        end if;
end;
  • 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-14T17:30:27+00:00Added an answer on June 14, 2026 at 5:30 pm

    Exists condition can be used only in SQL statement, it cannot be used directly in PL/SQL. There are several options:

    • Using case expression with exists condition inside a select statement:

      SQL> declare
        2    l_exists number(1);
        3  begin
        4    select case
        5             when exists(select 1
        6                           from employees
        7                          where department_id = 1)
        8             then 1
        9             else 0
       10           end into l_exists
       11      from dual;
       12  
       13     if (l_exists = 1)
       14     then
       15       dbms_output.put_line('exists');
       16     else
       17       dbms_output.put_line(q'[doesn't exist]');
       18     end if;
       19  end;
       20  /
      
       doesn't exist
      
       PL/SQL procedure successfully completed
      
    • Or (rownum is needed to guarantee that the only one record will be returned if there are several records meet matching condition):

      SQL> declare
        2    l_exists number;
        3  begin
        4  
        5    select 1
        6      into l_exists
        7      from employees
        8     where department_id = 100
        9       and rownum = 1;
       10  
       11     dbms_output.put_line('exists');
       12  
       13  exception
       14    when no_data_found
       15    then dbms_output.put_line(q'[doesn't exist]');
       16  end;
       17  /
      
       exists
      
       PL/SQL procedure successfully completed
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a js function which has, until now, always been the callback for
I have a function written in C# which has one parameter type as Dictionary<string
I have a parent component, say P, which has function, say Pfunc. I also
I have a javascript file which has a function calling a server (url) to
I have a class which has a function to retrieve children elements from a
I have a C program which has a function call that is defined in
I have a Login Class which has a function: isCorrect() that takes username and
I have a image which has an mouseover jquery function: $(document).ready(function ()) { mouseenter:
I have progress.js file which has the following code $('#text_area_input').keyup(function() { var text_area_box =$(this).val();//Get
I have a native/unmanaged DLL and it has a CreateObject function which returns a

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.