PL/SQL - generate the error statement if the text file is not generated

I have the following code as follows:
SET SERVEROUTPUT ON SIZE 1000000;
SET TIMING ON;
--SPOOL draft.log
DECLARE
CURSOR C1 
IS 
SELECT * FROM Transaction;

I_record_gen  INTEGER:=0;
l_file                    utl_file.file_type;
C_date                    CONSTANT VARCHAR2(8) := TO_CHAR(SYSDATE,'YYYYMMDD');

BEGIN
l_file := utl_file.fopen('Transaction_DIR','Transaction_'||C_date||'.txt', 'w' );
   FOR q IN C1 LOOP
   Utl_File.Put_Line(l_File,q.trans_id || '|' ||q.seq_no|| '|' ||q.count);
   I_record_gen:= 1;
   END LOOP;
 Utl_File.Fclose(l_File);
    EXCEPTION
    
   WHEN I_record_gen = 0 THEN
dbms_output.put_line('Batch job runs successfully with no customer list extracted ');
    WHEN others THEN
           dbms_output.put_line('SQLERRCODE='||SQLCODE||'|'||SQLERRM);

WHEN 

END;
/
Based on the code, I want to generate a declaration in the error log if my variable I_record_gen has the value 0 when it has not entered my loop to generate the content of the file is generate.

My code is correct? If not, how am I suppose to do?

It looks like you want a custom exception. You can do the following:

SET SERVEROUTPUT ON SIZE 1000000;
SET TIMING ON;
--SPOOL draft.log
DECLARE
CURSOR C1
IS
SELECT * FROM Transaction;

I_record_gen  INTEGER:=0;
l_file                    utl_file.file_type;
C_date                    CONSTANT VARCHAR2(8) := TO_CHAR(SYSDATE,'YYYYMMDD');
recordGenExc     EXCEPTION;

BEGIN
l_file := utl_file.fopen('Transaction_DIR','Transaction_'||C_date||'.txt', 'w' );
   FOR q IN C1 LOOP
   Utl_File.Put_Line(l_File,q.trans_id || '|' ||q.seq_no|| '|' ||q.count);
   I_record_gen:= 1;
   END LOOP;
 Utl_File.Fclose(l_File);

 IF I_record_gen = 0 THEN
      RAISE recordGenExc;
 END IF;

    EXCEPTION

   WHEN recordGenExc THEN
     dbms_output.put_line('Batch job runs successfully with no customer list extracted ');
    WHEN others THEN
           dbms_output.put_line('SQLERRCODE='||SQLCODE||'|'||SQLERRM);

END;
/ 

I added the following:

-Adding a statement to an exception in the section DECLARE to your code.
-Added a conditional to check the I_record_gen = 0 and then raised the exception if it was 0

Tags: Database

Similar Questions

  • Not able to reverse the text file in ODI

    Hi guru,.

    I tried to load the data from Oracle database to text file. But I am facing problem during file reverse text.

    The columns in the text file are not reversed in the ODI data store. I get no error.

    Are there specific measures that I'm missing here? Any ideas / docs / links would be appreciated.


    As a solution, I added column manully right now and I can go futher. But I would be happy if reverse ODI will do it for me.

    Kind regards

    Manmohan Sharma

    Hi Matt,

    A thought,

    Make sure your data store is NOT LOCKED (UNLOCK) in reverse.

    Thank you
    Guru

  • I get this error: the specified file is not a commercial product

    I bought for scrapbooking, files from the internet and try to use it with my software of CM.  Once downloaded, I can't import the info to my Creative memories because I get the error message that the specified file is not a commercial product.

    Communicate with the scrapbooking software company or the company that provided the files Add on for the help on this product.

    writing in the new message: * e-mail address is removed from the privacy... *

    I bought for scrapbooking, files from the internet and try to use it with my software of CM. Once downloaded, I can't import the info to my Creative memories because I get the error message that the specified file is not a commercial product.

  • Cannot delete the file and the error is "the specified file is not valid or too long." Specify a different file name.

    Hello

    I have filenames with weird values inside (created by Application software).
    Here is an example:
    GIBtmpphoto0_11:27:16.145.png

    When I try to delete it, I have the following error:
    The specified file is not valid or too long. Specify a different file name.

    And it takes a lot of space in my hard drive.

    How is it possible to remove it?

    Thank you.
    Best regards
    Marc

    Original title: delete files with weird names

    Hello

    My corrupt files are found on a disk of material on my computer.
    I have re-formatted the full disk to remove these files.

    Best regards
    Marc

  • RAW of Nikon D7000 import fail - error: the following files were not imported because they could not be read.

    I'm on a Mac under OS X 10.11.

    I connect the camera via USB, open Adobe Photoshop Lightroom CC (2015 2.1 - Camera Raw 9.2), click on the button import and display all the. NEF files on the camera.  I check 'in the subfolder"and it by default selects 'by date' with 'Format for a Date' 2015/10 which I accept.  I then select the collection that I want to add to, define rule change in file name and click on the import button blue with all the selected photos.

    Import does not work and I get the error: the following files were not imported because they could not be read.

    I read in the forums and many people claim that this is due to a problem with file permissions.  The is not the case here.  I am logged in as myself, running Lightroom like myself (the process of Lightroom is held by me) and my entire repertoire belongs to me, including the "2015/10" record he would write in.  In addition, I can manually enter this directory and manually create and delete files and folders with no problems.

    So the foregoing proves no problem licensing insofar as the operating system and the file system is concerned, and also proves that this is a specific problem with Lightroom.  Why is it not work?  I pay several hundred dollars a year for a subscription of CC; I need this job.

    The error was due to permissions of file after all.  When you import media, must be very carefully considered defects of menu import gear - if you "subfolder" selected, look at the setting for "Destination Folder" - in my case, it was set to ""/ "."  This is the root directory, so it's obvious standard user level permissions won't allow files to be written here, or I wanted to have whatever it is put into memory.  It was particularly easy to miss because it's only a simple slash.  Once I set the destination folder to a location in my directory, import worked well.

  • Trying to fix a CID parent access to a file descriptor of delta but VM still does not start. Other error "cannot open the disk...". The specified file is not a virtual disk.

    Starting the virtual machine has been tried several times earlier when I received the error message to tell the parent disk had been changed since the child was created. I looked at the resolution and had a go at fixing.

    I downloaded the vmdk files to find the problematic descriptor file it corrected and then download the a back fixed to the data store. I then removed the VM of the inventory and then re he added before attempting to start it. He says now the specified file is not a virtual disk. Unfortunately, I didn't know that he was still working on a snapshot file and had been for some time. It was a former VM test that I had played a little bit with all learning on VMware, but unfortunately he had a few files on it which is no longer, I have backup ups for and I could really do with recovery of them! The base file and delta file are always on display in the data store and I can re - use the base file in a new virtual machine but I need the data from the snapshot if possible file. Not sure if it can be manually engaged at the base (I have a copy of). I'm new to this depth of troubleshooting and according to research I realize it is a great chance, the data is not recoverable. Having said that if there is no hope at all then I would try or at least have someone who knows what they're doing a go help before you tell me everything is lost! I'm not really bothered to get the virtual machine running again, but must be able to copy some files in the C drive.

    Any help much appreciated.

    Thank you

    Craig

    I can't tell you if the data in the virtual drive itself can be retrieved by the attached hard file. However, it seems that you have used an editor who added a BOM (Byte-Order-Mark) at the beginning of the file, which made her an invalid for ESXi.

    André

  • I can download more pictures from a SD card to Lightroom is.  I can download pictures or Aperture but Lightroom CC gives me the error "the following files were not imported because they could be readable." and then it lists all the files on the disc. I sh

    I can download more pictures from a SD card to Lightroom is.  I can download pictures or Aperture but Lightroom CC gives me the error "the following files were not imported because they could be readable." and then it lists all the files on the disc. I shoot in Raw.  I know it's a problem because I see the number of entries when I have the problem of google.  What I don't see is Adobe recognizing the problem OR suggest a solution.  It is a big problem since I have to find ways to get photos in Lightroom.  Can you please tell me what I should do to get my pictures downloaded.  I had no problem before subscribing to Adobe CC when I used 5 Lightroom.

    A changes to privileges stick? Check the folder again. Should look like this - see image. Also check similar to the folder that you copy photos to.

  • When I tried to power on VM ends up in the right error: the specified file is not a virtual disk. Cannot open disk ' / vmfs/volumes/4d48ad95-ad5e027a-67f4-e41f1360cc9e/Iso/ser01/ser01.vmdk' or one of the snapshot disks it depends on.

    I stop a virtual machine after a certain time, I tried to power. Its has ended up in the following error message

    Reason: The specified file is not a virtual disk. Cannot open disk ' / vmfs/volumes/4d48ad95-ad5e027a-67f4-e41f1360cc9e/Iso/ser01/ser01.vmdk' or one of the snapshot disks it depends on.

    The machine was working fine before the closure.

    In the data store, the file type of the virtual machine is 'file' instead of 'virtual drive '.

    Help, please

    You are missing the file descriptor hard. The xxxx - flat hard is the file that contains the data effectively. But the xxxx.vmdk is missing, which is a text file that connects to the flat file.

    AWo

  • Why I get this error message when I try to import? 'The following files were not imported because they could not be read. (645)"I can see them :(

    Why I get this error message when I try to import? 'The following files were not imported because they could not be read. (645)"I can see them

    Is working this morning!

    Depends on your operating system

    Go to google, try typing in

    Change the Windows permissions

    or

    Change the permissions of Mac

  • ORA-07391: sftopn: fopen error, cannot open the text file.

    Hello

    The last 3 days, we get the error in the alert below log.

    [ORA-00600: internal error code, arguments: [kmgs_parameter_update_timeout_1], [27091] [] [] [], [], []]
    ORA-27091: unable to queue I/O
    ORA-27072: IO file error

    I check as the same partners to it in metalink I found permission to check the directory solution. (DOC ID367619.1)
    I got permission from ORACLE_HOME\dbs $ to 777, but still m making the same mistake.

    also I try to recreate spfile so that I try to create pfile first

    create pfile from spfile

    I get the error below.

    ORA-07391: sftopn: fopen error, cannot open the text file.

    ls - lrt sp * in the below output shows $ORACLE_HOME

    -rwxrwxrwx 1 ora10g 3584 20 September dba10 05:42 < SID > spfile .ora

    Help, please.

    Thanks in advance

    user8757749 wrote:
    The output of ls - lrt is in the path $ORACLE_HOME\dbs only

    We also have the database version 10.2.0.4 that the spfile even uses everyday cold backup of the database.

    also, I put the 777 permission to the file.

    OK, I guess there will be corruption of the SPFILE as if edited manually or in any other cases too.

    You have a backup of SPFILE? backup of the file PFILE or?

    then starting using this SPFILE, if any backup then start with PFILE and then create SPFILE from PFILE.

    Otherwise, you can copy the contnets of the parameters of the alert log file initialization and paste in the editor and the instance of starutp.

    These are the options.

  • Error when you try to add a song to Windows Movie Maker: the selected file is not valid or is corrupted.

    Sometimes, when I add a song to Windows Movie Maker it does not work.

    When I try to add one of my songs, it is said: C:\Documents and Settings\Utilisateur\Mes documents\Ma Musique\iTunes\iTunes Media\Music\Craig Smart\I Miss You - Craig Smart.mp3 could not be imported. The selected file is not valid or is corrupted.

    Help, please

    When I try to add one of my songs, it is said: C:\Documents and Settings\Utilisateur\Mes documents\Ma Musique\iTunes\iTunes Media\Music\Craig Smart\I Miss You - Craig Smart.mp3 could not be imported. The selected file is not valid or is corrupted.

    Help, please

    2 responses on itunes and Windows Media Player (WMP) are:

    1.

    RE: iTunes and WMP - MusicBridge

    Found this on the web. I can't vouch for it. Use it at your own risk.

    Excerpt:
    iTunes is not compatible with Windows Media Player. iTunes is - like Apple-very protective of any product and does not like to share. So, you have to force off iTunes and WMP.

    To do this, you can use this sloppy program: MusicBridge.
    The description of its creator:
    MusicBridge allows people who use both iTunes and WMP on the same machine to keep their libraries in sync. MusicBridge offers a variety of synchronization options so that you can manage your collection of music in the media player, or both. MusicBridge duplicates of meta-data between Windows Media Player and iTunes, it does not copy the physical files between applications.

    Version 2.0.1 is a bug fixing release.

    Best thing: it's free.
    http://download.CNET.com/MusicBridge/3000-2141_4-10530687.HTML?tag=mncol;psum

    2.

    courtesy of musiclover101:
    convert the songs in your iTunes library to a format that Windows Media Player can understand

    You can convert the songs in your iTunes library to a format of Windows Media Player can understand - (I tend to use mp3). This can be done inside of iTunes itself. If the songs in your iTunes library were purchased in the iStore and were purchased in the plus version (indicated by a small sign above the price of a song +), then they are DRM free, so they can be converted easily. However, if the songs were not purchased in the format more, you can convert them for 30 cents each. I highly recommend that you do as the plus version of songs are premium quality - and since they are DRM free, you can use them in almost all applications and you can burn them to CD and play almost anywhere. All the songs on the iTunes store are now version more, so you don't have to worry about searching for them in the future.
    To convert songs to Windows Media Player can understand, open iTunes, and then do the following:
    1. click Edit, preferences, and go to the general tab
    2. click on the button "import settings".
    3. change the "import using" at "MP3 encoder".
    4. click OK and go back to your music library
    5. choose the list view and select the first piece of your library
    6. scroll all the way to the last song in your library
    7. press the button SHIFT key, then click the last song to select all the songs in your library
    8. click on "Advanced" and then "Create MP3 Version."
    9. your songs should start to convert and according to how many songs do you have in your library, this could take some time
    10. open Windows Media Player and press F3 or click file, add it to the library

    11. click on OK - Windows Media Player should start to search for songs on your computer and after that he finished the search, you should find the songs in your library in your Windows Media Player to iTunes library.

    NOTE: This method will not work unless you have purchased iTunes songs or if you have converted the songs iTunes more for each 30 c

    For the benefits of others looking for answers, please mark as answer suggestion if it solves your problem.

  • Error: the specified file is not a virtual disk

    After working flawlessly for months, something went haywire today and my next attempt to access my VM Fusion has been met with "the specified file is not a virtual disk.  I followed a number of proposed solutions here and on the support without result page.

    A question I have is it makes sense that my hard file is 1 KB in size and the text in TextEdit is gibberish (compared to, say, my .vmx file denominated in English for the most part)?  The last update for my performed hard at 12:33 today, where many of the other files (including files hard # s 21) have been updated at 14:52.  Is it possible that my hard file is corrupted?  If so, can it be rebuilt if I don't have a backup?

    If you don't have a good copy of the file to replace the one damaged with "Windows XP Pro.vmdk" then use attached which was created from information in the vmware.log file provided in the .tgz support group.

    The attached file "Windows_XP_Pro.vmdk.zip" contains a "Windows XP Pro.vmdk" file to replace the one damaged.

  • Skip (project) to check, because the apk file has not changed.

    Hello all, I get the message 'Skip (project) to check, because the apk file has not been modified' in the error log when I'm checking an Android APK. Since I donot have required a device or a simulator (lack of processor), I'm not able to test the signed .bar file generated by ignoring the message above.

    Please can anyone suggest a solution for the question do face. Thanks in advance.

    Hey there,

    I see something like:

    "Skip ProjetTest to check, because the apk file has not changed."

    in my Console, but not in the error log.

    If it is in the console, it's just a normal journal letting you know that the tools didn't need to check again because the project, including the manifesto, has not changed quite significantly between runs you need to double check.

    Justin

  • "The specified file is not a virtual disk" Please someone help, very URGENT

    Dear members,

    Yesterday the electricity of night exploded, so my PC crashed. Today when I tried to open my virtual computer (Workstation 8), it says error: "the specified file is not a virtual disk.

    Tried to do a lot a lot of things that I found online. Nothing has worked yet. My head is about to explode, because I had the very important company data on this machine.

    If someone could provide a working solution, I could pay.

    Please help me!

    Thank you very much, I'm so desperate.

    Attached is some useful info, such as my iii and vmdk, etc files. PNG for the image of the full file in the directory of the virtual machine list.

    On the screen, it seems that you have lost SERVER - s014.vmdk (zero bytes). You can try to replace this file with a hard clean/empty file (for example a copy of the SERVER - s010.vmdk) to see if this allows the access card to the virtual disk again. However, first save all files of the virtual machine to ensure you can return to the current state. At least create a snapshot after you replaced the hard file.

    According to the blocks of data previously stored in this file, you may have lost up to 2 GB of data.

    André

  • Need help: UTL_FILE read and write in the text file

    Hello, I'm on version 11 GR 2 by using the UTL_FILE function to read a text file and then write the lines where it starts with the word "foo" and put an end to my writing in the text file where the line with the word "ZEN". Now I have several lines that begin with 'foo' and 'ZEN' allow a paragraph, and in this paragraph, there is a line that begins with "DE4.2". Therefore,.
    I need to write all of the paragraphs that include the "DE4.2" line in their beginning and end of lines 'foo' and 'ZEN '.

    FOR EXAMPLE:

    FOO/234E53LLID
    IT'S MY SECOND LINE
    IT'S MY THIRD LINE
    DE4.2 IT OF MY FOURTH LINE
    IT'S MY FIFTH LINE
    ZEN/DING3434343

    FOO/234E53LLID
    IT'S MY SECOND LINE
    IT'S MY THIRD LINE
    IT'S MY FIFTH LINE
    ZEN/DING3434343

    I'm only interested in writing the first paragraph tha includes line DE4.2 in one of the paragraph of lines not the second ther that does not include the "DE4.2".

    Here is my code so far:

    CREATE OR REPLACE PROCEDURE my_app2 IS
    Utl_file.file_type INFILE;
    outfile utl_file.file_type;
    buffer VARCHAR2 (30000);
    b_paragraph_started BOOLEAN: = FALSE; -flag to indicate which required paragraph is started

    BEGIN
    -Open a file to read
    INFILE: = utl_file.fopen ('TEST_DIR', 'mytst.txt', 'r');
    -Opens a file for writing
    outfile: = utl_file.fopen ('TEST_DIR', "Out.txt", "w");

    -Check the file is open
    IF utl_file.is_open (infile)
    THEN
    -lines in the file in loop
    LOOP
    BEGIN
    UTL_FILE.get_line (infile, buffer);
    APPLICATION STARTING POINT-
    Buffer IF LIKE 'foo %' THEN
    b_paragraph_started: = TRUE;
    END IF;
    -SEARCH FOR GRADS APPS
    IF b_paragraph_started AND buffering LIKE '% 4% ' THEN
    UTL_FILE.put_line (outfile, buffer, FALSE);
    END IF;
    -REQUEST FOR ENDPOINT
    Buffer IF LIKE '% ZEN' THEN
    b_paragraph_started: = FALSE;
    END IF;
    UTL_FILE.fflush (outfile);

    EXCEPTION
    WHEN no_data_found THEN
    EXIT;
    END;
    END LOOP;
    END IF;
    UTL_FILE.fclose (INFILE);
    UTL_FILE.fclose (outfile);
    EXCEPTION
    WHILE OTHERS THEN
    raise_application_error ("-20099, ' UTL_FILE unknown error");
    END my_app2;
    /

    When I run this code I get only one line: DE4.2 it ME LACK THE WHOLE PARAGRAPH

    PLEASE ADVISE...

    I agree with reservations of Justin on the length of a "paragraph" and the number of users that are running at the same time, so here is a version without the collections.

    CREATE or replace PROCEDURE my_app2 IS
       infile utl_file.file_type;
       outfile utl_file.file_type;
       buffer VARCHAR2(30000);
       b_paragraph_started BOOLEAN := FALSE; -- flag to indicate that required paragraph is started
       b_toprint BOOLEAN := FALSE;
       l_para_start pls_integer;  -- start of "paragraph"
    BEGIN
       infile := utl_file.fopen('TEST_DIR', 'mytst.txt', 'r');
       outfile := utl_file.fopen('TEST_DIR', 'out.txt', 'w');
       LOOP
          BEGIN
             utl_file.get_line(infile, buffer);
             IF buffer LIKE 'FOO%' THEN
                b_paragraph_started := TRUE;
                l_para_start := UTL_FILE.FGETPOS(infile) - (length(buffer) + 1);
             END IF;
             IF b_paragraph_started and buffer like '%DE4%' THEN
                b_toprint := TRUE;
             END IF;
             If buffer like 'ZEN%' THEN
                IF b_toprint THEN
                   UTL_FILE.FSEEK(infile, l_para_start);
                   utl_file.get_line(infile, buffer);
                   while buffer not like 'ZEN%' loop
                      utl_file.put_line(outfile,buffer, FALSE);
                      utl_file.get_line(infile, buffer);
                   end loop;
                   utl_file.put_line(outfile,buffer, FALSE);
                end if;
                b_paragraph_started := FALSE;
                b_toprint := false;
                utl_file.fflush(outfile);
             end if;
          EXCEPTION
             WHEN no_data_found THEN
                EXIT;
             END;
       END LOOP;
       utl_file.fclose(infile);
       utl_file.fclose(outfile);
    END my_app2;
    

    Test:

    SQL> !cat mytst.txt
    FOO/234E53LLID
    THIS IS MY SECOND LINE
    THIS IS MY THIRD LINE
    DE4.2 THIS IS MY FOURTH LINE
    THIS IS MY FIFTH LINE
    ZEN/DING3434343
    
    FOO/234E53LLID
    THIS IS MY SECOND LINE
    THIS IS MY THIRD LINE
    THIS IS MY FIFTH LINE
    ZEN/DING3434343
    
    FOO/234E53LLID again
    THIS IS MY second SECOND LINE
    THIS IS MY second THIRD LINE
    DE4.2 THIS IS MY second FOURTH LINE
    THIS IS MY second FIFTH LINE
    ZEN/DING3434343 again
    
    SQL> exec my_app2;
    
    PL/SQL procedure successfully completed.
    
    SQL> !cat out.txt
    FOO/234E53LLID
    THIS IS MY SECOND LINE
    THIS IS MY THIRD LINE
    DE4.2 THIS IS MY FOURTH LINE
    THIS IS MY FIFTH LINE
    ZEN/DING3434343
    FOO/234E53LLID again
    THIS IS MY second SECOND LINE
    THIS IS MY second THIRD LINE
    DE4.2 THIS IS MY second FOURTH LINE
    THIS IS MY second FIFTH LINE
    ZEN/DING3434343 again
    

    You may need to change the length (buffer) + 1 depending on your platform and if you want a blank line s NLE out paragraphs, add another call to put_line after that outside of the loop in the fi l_toprint block.

    John

Maybe you are looking for

  • anchor named links do not work in iframes

    In developing my site web I came across the problem that Firefox does not scroll to the targets of links of anchor named in a page, when the page is in an iframe. In seeking solutions, I read a lot of dated 2010-2011, it is one thing to security... a

  • Disable the activity of background App on Wifi?

    I'm still new to Android and I'm very stingy on battery usage, and I want to know is possible to disable the background monitoring, querying, data or business applications when I'm on wifi? I did some research and it seems that there is only one opti

  • Multiply Defined error installation update

    Hello I have a .cod of an application I submitted to the world app in June. I'm currently testing the update of the application to a new version with new data, I have now. I installed the original .cod (same as on app world) through javaloader. Then

  • BlackBerry smartphones only 1 E-mail accounts emails, instead of 2

    Configuration of curve of my father, I put in place since two e-mail accounts after you have created a user name for the account of his BlackBerry. I didn't enter the login / pw for both accounts (1 work, 1 Gmail) and they both came back successfully

  • RELEASE DATE "BOLD" of ATT blackBerry Smartphones?

    What is the latest?