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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:05:31+00:00 2026-06-08T16:05:31+00:00

I would like to check if there’s no data coming from SQL query then

  • 0

I would like to check if there’s no data coming from SQL query then file should not be created.

Here is my code:

CREATE OR REPLACE PROCEDURE VR_AD_INTEGRATION_EXPORT AS
    l_v_file UTL_FILE.file_type
BEGIN
 l_v_file := UTL_FILE.fopen('integration', 'HRMtoAD1_'||to_char(sysdate,'YYYYMMDD')||'_'||to_char(sysdate,'HH24MISS'), 'w', 32767);
FOR x IN (SELECT * FROM (SELECT 
           decode(pid, NULL, RPAD(' ',7,' '), RPAD(user_id, 7, ' '))|| '' ||
           decode(name_last, NULL, RPAD(' ',50,' '), RPAD(name_last, 50, ' '))
           str FROM vr_ad_integration WHERE integrated = 'N') str WHERE rownum <= 1000 ORDER BY rownum)
LOOP
    BEGIN
        UTL_FILE.put_line(l_v_file, x.str);
    END;
END LOOP;
UTL_FILE.fflush(l_v_file);
UTL_FILE.fclose(l_v_file);
END VR_AD_INTEGRATION_EXPORT;

Now I can create file successfully in a remote location. However, what if there’s no data in select query? no file should be created. If I am correct, I need to include exception code but I have no idea how to do it in this case. Any suggestion?

Cheers! 🙂

  • 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-08T16:05:32+00:00Added an answer on June 8, 2026 at 4:05 pm

    There are several ways to achieve this. One is to adopt a more procedural approach with a explicit cursor and only open the file once a record is fetched. A second is to modify your code to include a count inside the loop and delete the file if the count is zero.

    Here is a third choice, which is a variant on the previous option. It tests the size of the file and if it is zero deleted it using the UTL_FILE.FREMOVE() command. Note the need to store the generated file name in a variable for reference later.

    CREATE OR REPLACE PROCEDURE VR_AD_INTEGRATION_EXPORT AS
         l_v_file UTL_FILE.file_type;
         l_filename varchar2(128);  
         f_exists boolean;
         f_size pls_integer;
         f_blk_size pls_integer;
    BEGIN  
        l_filename := 'HRMtoAD1_'||to_char(sysdate,'YYYYMMDD')||'_'||to_char(sysdate,'HH24MISS');
        l_v_file := UTL_FILE.fopen('integration',  l_filename , 'w', 32767); 
        FOR x IN (SELECT * FROM (SELECT
                 decode(pid, NULL, RPAD(' ',7,' '), RPAD(user_id, 7, ' '))|| '' ||            decode(name_last, NULL, RPAD(' ',50,' '), RPAD(name_last, 50, ' '))
                str 
                     FROM vr_ad_integration 
                     WHERE integrated = 'N') str 
             WHERE rownum <= 1000 ORDER BY rownum) LOOP
         BEGIN
             UTL_FILE.put_line(l_v_file, x.str);
         END; 
        END LOOP; 
        utl_file.fgetattr('integration',  l_filename , f_exists, f_size, f_blk_size);
        if f_size > 0 then
            UTL_FILE.fflush(l_v_file); 
            UTL_FILE.fclose(l_v_file); 
        else
            UTL_FILE.fclose(l_v_file); 
            utl_file.fremove('integration',  l_filename);
        end if;
    END VR_AD_INTEGRATION_EXPORT; 
    

    There is some useful functionality in the UTL_FILE package beyond reading and writing lines. I suggest you read the documentation to find out more.

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

Sidebar

Related Questions

I would like to check how many files are there in the specified directory.
I would like to check to see if there are any keys in $_POST
I would like to compare two dates in Perl to check there difference(days,months and
I would like to check how to print a success message if there is
I would like to check whether a folder exists or not if not create.
I have a COM interop assembly, and I would like to check from a
I have a very specific LINQ query. I would like to check the existence
I would like to hide my submit button if there's not input fields in
I would like to check the first radio button of each group. But there
I would like to check if there are blank embedded forms into my form,

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.