Read last line of a log of the file using UTL_FILE

Hi all

My environment is--> Oracle 11 g Database Release 1 on Windows 2003 Server SP2.
Requirement is-> reading last line of a log file with UTL_FILE.

I am reading the last line of a log file that is generated by our own application. I am able to get the last row using the script but the problem below is in the log file, has some blank lines at the end so I get the output as white.

Script
Declare
DIRECTORY VARCHAR2 (300): = 'BACKUP ';
name VARCHAR2 (300): = 'Client_Log_02-05 - 2011.log';
l_file UTL_FILE.file_type;
l_text VARCHAR2 (32767).
BEGIN

l_file: = UTL_FILE.fopen (DIRECTORY, filename, 'r', 32767);
UTL_FILE.get_line (l_file, l_text, 32767);
-DBMS_OUTPUT.put_line (' Frontline: |' | l_text |) '|');
BEGIN
LOOP
UTL_FILE.get_line (l_file, l_text, 32767);
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
END;
Dbms_output.put_line (' last line: |' | l_text |) '|');
UTL_FILE.fclose (l_file);
END;

Please advice me how to skip/ignore empty lines... If you have web links or scripts please share.

Thank you for your help

Shan

I think that there are many ways... we have to save the last string that is not empty like this:

DECLARE
    directory   VARCHAR2 (300) := 'BACKUP';
    filename    VARCHAR2 (300) := 'Client_Log_02-05-2011.log';
    l_file      UTL_FILE.file_type;
    l_text      VARCHAR2 (32767);
    l_text_not_null      VARCHAR2 (32767);
BEGIN
    l_file :=
        UTL_FILE.fopen (directory,
                        filename,
                        'r',
                        32767);
    UTL_FILE.get_line (l_file, l_text, 32767);

    BEGIN
        LOOP
            UTL_FILE.get_line (l_file, l_text, 32767);
            IF REPLACE (REPLACE (TRIM (l_text), CHR (10)), CHR (13)) IS NOT NULL THEN
               l_text_not_null := l_text;
            END IF;
        END LOOP;
    EXCEPTION
        WHEN NO_DATA_FOUND
        THEN
            NULL;
    END;
    DBMS_OUTPUT.put_line ('Last Line : |' || NVL(l_text_not_null, l_text) || '|');
    UTL_FILE.fclose (l_file);
END;

Tags: Database

Similar Questions

  • CANNOT ACCESS THE FILE USING UTL_FILE

    I created using mon_repertoire
    create or replace directory mon_repertoire as 'd:\try ';

    then I did
    GRANT read, write on DIRECTORY mon_repertoire TO scott;

    then I create a following procedure d...


    Create or replace procedure UTLTEST as
    utl_file.file_type F1.
    Start
    -Open a file in write mode
    F1: is utl_file.fopen('MY_DIR','newfile.txt','W');.
    -Write a line to a file
    UTL_FILE.put_line (f1, 1.) "This is a test of package UTL_FILE);
    UTL_FILE.put_line (f1 2), Oracle has added a new procedure in the package ');
    UTL_FILE.put_line (f1 3), Let's see together the procedure one ');
    -Closes a file
    UTL_FILE.fclose (F1);
    end;

    I got the following errors:


    ERROR on line 1:
    ORA-29283: invalid file operation
    ORA-06512: at "SYS." UTL_FILE", line 475
    ORA-29283: invalid file operation
    ORA-06512: at "SCOTT. UTLTEST', line 5
    ORA-06512: at line 1


    How can I do this task?

    Hello

    Create an inventory of items that points to a physical directory on the server.

    If the path to the physical directory in the db server is D:\applications

    Then,
    Simply create the directory as object

    CREATE or replace directory mon_repertoire is "D:\applications";

    Then try your coding plsql.

  • I'm seeing a class at the University on the program line in my iPad. The file says: index.htm, I went to University and they said that Adobe didn't create the form of FRO us to see this kind of presentations on the iPad or the iPhone. The presentation I h

    I'm seeing a class at the University on the program line in my iPad. The file says: index.htm, I went to University and they said that Adobe didn't create the plug in for us to see this kind of presentations on the iPad or the iPhone. The presentation is in PowerPoint.

    is it possible...

    I am a student of the line and we assume that we could use our currencies everywhere.

    can you give me an and

    Thank you

    Carola

    PowerPoint is a microsoft program and ms and adobe are not the same companies and do not have the same products.

    That said, your class probably uses an adobe product and probably displays a swf file.  the reason why you cannot view SWFs on ios devices is a matter of apple.  Apple won't allow flash on their devices player.

    use a computer with a web browser or a mobile android.  or look over the shoulder of someone who has one of these.

  • Get the following error when trying to install adobe reader in Windows 10... "the file 'C:\ProgramData\Adobe\Setup\{AC76BA86-7AD7-1033-7B44-AC0F074E4100}\AcroRead.msi' is not a valid package for the Adobe Reader XI product... How can I fix it

    Get the following error when trying to install adobe reader in Windows 10... "the file 'C:\ProgramData\Adobe\Setup\{AC76BA86-7AD7-1033-7B44-AC0F074E4100}\AcroRead.msi' is not a valid package for the Adobe Reader XI product... How can I solve this problem? Thank you.

    Hi JFO58,

    I recommend you to run on your system cleaning tool:Download Adobe Reader and Acrobat tool - Adobe Labs

    Later, try to install reader again by using the following link: Adobe Acrobat Reader DC install for all versions

    Kind regards
    Rahul

  • BLOB data in the directory using UTL_FILE

    Hi all

    "I wrote a procedure to store BLOB data in the directory using * UTL_FILE.



    Using the package UTL_FILE, I created procedure below. Procedure runs successfully without any error, but the file is not written to the directory. Pls find my procedure below.
    * CREATE OR REPLACE PROCEDURE Write_BLOB_To_File
    AS
    v_lob_loc BLOB;
    v_buffer RAW (32767).
    v_buffer_size directory.
    v_amount directory.
    v_offset Number (38): = 1;
    v_chunksize INTEGER.
    v_out_file UTL_FILE. TYPE_DE_FICHIER;
    BEGIN
    -- | SELECT THE LOB LOCATOR
    SELECT an attachment
    IN v_lob_loc
    ATTACHMENT
    WHERE attachment_id = 720;
    -- | DISCOVER THE CHUNKSIZE FOR THAT LOB COLUMN
    v_chunksize: = DBMS_LOB. GETCHUNKSIZE (v_lob_loc);
    IF (v_chunksize < 32767) CAN
    v_buffer_size: = v_chunksize;
    ON THE OTHER
    v_buffer_size: = 32767;
    END IF;
    v_amount: = v_buffer_size;
    -- | OPENING A LOB IS OPTIONAL
    DBMS_LOB. OPEN (v_lob_loc, DBMS_LOB. LOB_READONLY);
    -- | WRITE THE CONTENT OF A LOB IN A FILE
    v_out_file: = UTL_FILE. FOPEN)
    location = > "EXAMPLE_LOB_DIR"
    filename = > "Test.doc."
    OPEN_MODE = > 'w ',.
    max_linesize = > 32767);
    While v_amount > = v_buffer_size
    LOOP
    DBMS_LOB. READ)
    lob_loc = > v_lob_loc,
    amount = > v_amount,
    offset = > v_offset,
    buffer = > v_buffer);
    v_offset: = v_offset + v_amount;
    UTL_FILE. () PUT_RAW
    file = > v_out_file,
    buffer = > v_buffer,
    AutoFlush = > true);
    UTL_FILE. FFLUSH (file = > v_out_file);
    -UTL_FILE. NEW_LINE (file = > v_out_file);
    END LOOP;
    UTL_FILE. FFLUSH (file = > v_out_file);
    UTL_FILE. FCLOSE (v_out_file);
    -- | THE LOB OF CLOSING IS REQUIRED IF YOU OPENED IT
    DBMS_LOB. Close (v_lob_loc);
    END; *


    I have provided the necessary privileges for the schema and directory. But the file is not written to the directory. can you please advise me

    OPEN_MODE-online 'w' change to open_mode-online "wb."

  • How to add programs to the start of the file using Vista

    How to add programs to the start of the file using Vista

    Hi Harry,.

    Oddly enough, you can actually do it in msconfig except if it is already there and simply not checked as opposed to not being do not at all (although you would think that they would understand this option).

    The easiest way is to add the program (or a shortcut to the program) in the folder all Menu Programs Startup.   Here is the procedure: http://www.ehow.com/how_5098465_add-startup-programs.html.  Remember, to do this, you must either a shortcut existing (perhaps on the desktop or elsewhere in the menu all programs) or you need to find the source file (probably somewhere in C:\Program Files depending on what you want to add) and either copy it and add it to the startup folder or right-click on it and create a shortcut to copy into the startup folder.  Once you reboot, this program starts during the initial commissioning process and you will now be able to control using msconfig.exe, if you wish.

    Another option is to do this by using the registry editor.  If you decide to try this, first create a restore AND system restoration point backup of the registry before you begin.  Here is the procedure: http://www.ehow.com/how_7304438_add-program-msconfig-regedit.html.  I recommend to use this ONLY if the previous procedure does not work for some reason any as long as that the procedure is simpler and safer.

    If you want a simpler way to manage and control startup programs, you can try it free WinPatrol http://www.winpatrol.com/download.html that change monitors for startup programs if you set it to run in real-time so that you know when to try new programs are added to your Start menu and, for the purposes of this question includes an Add button which opens a link to a window of Windows Explorer where you can browse the program you want to add, click open to select and then add it directly to the commissioning.  If you prefer it does not work all the time, you can simply uncheck the box which includes this program and it will work only when you choose to run (but at the start, will work as an indication otherwise or configured).  It will appear not in the start menu in all programs (Finally, WinPatrol is, but not programs, it adds to the start), but it will appear in WinPatrol (which also lets you manage what you want or not start with checkboxes as in msconfig) and sure in msconfig - but only after a reboot is complete the process of adding.

    I hope this helps.  Personally, I use WinPatrol myself and let it run in real time.  Since I do a lot of installations, it helped me often prevent the addition of a startup item I haven't really need and reduces how many times I actually need to check what is happening out there.

    If this answers your question without the need to repost in another forum, please mark it as an answer.  If this isn't the case, then of course you must republish as suggested above.

    Good luck!

  • How can I select the files in a folder with the help of a list with the files you want and after that rename only the files using another list with desired new names?

    How can I select the files in a folder with the help of a list with the files you want and after that rename only the files using another list with desired new names?

    I have only:
    D: / images (where are necessary + not need files)
    -a list with only the necessary files
    -a list with new names for the files needed
    Thank you.

    Hi Pustiu,

    Thanks for posting in the Microsoft Community.

    You want to know how to select the files in a folder using a list with the files you want and after that rename only the files using another list with desired new names.

    I would have you post your query in the TechNet forums because it caters to an audience of it professionals.

    Your query will be better addressed there.

    Check out the link-

    http://social.technet.Microsoft.com/forums/en-us/w7itprogeneral/threads

    We know if you need help. We will be happy to help you. We, at tender Microsoft to excellence.

    Thank you.

  • How to get a list of paths for all the files used in a project

    I have a CC Pro first project that has a large number of bins.  A sequence in one of these bins uses files of the other tanks.  I'll try to find the locations of all of the files used in the project.

    (1) obviously I can select each item in the timeline and display in the finder, but there are a lot of clips

    (2) the use of the video associated with each file in the project would help.  However

    1. I have not found a way to display only the clips that have the use of the video if all locations have not been developed.

    2. use video shows its use for all sequences, so it should be manually checked traction towards the bottom for each file see if it is used in the sequence in question.

    (3) I tried to export the project to the final cut pro xml.  The url path gives me the information I need.  For some reason, however, when I do the single export item information are here, not the information for all the other elements of the project.

    (4) I got tired of export for speedgrade, and all file names are there.  However, the railways are not.

    Basically, I want to find all the files in the project and transfer them to a specific folder for this project.  There must be a way to do this, but I'm not...

    You can import the sequence in a new project and then use the project manager to make them all together.

  • Writing a file on the network using UTL_FILE

    Hi all

    Can we write a file on a path to the network using UTL_FILE. I have full access on the network folder, which I use as directory object.

    Details of the environment:
    Oracle Database 10g XE
    WIN XP


    Concerning
    SIS

    SMON wrote:
    but I remember not so utl_file works with UNC paths or not, just try it & see!

    To do this, if the account that runs the writing has permissions to the destination. We use UNC paths in some of our environments.

  • create the file using flex

    Hello

    I work in flex.

    I want to create the file using flex 4.

    I use this code

    private var file:File;

    private function addfolder (): void

    {

    file = new File ("file:///C:/MyNewFolder");

    file.createDirectory ();

    }

    the error is

    Type was not found or was not a compilation constant: file.

    anyone helpme

    concerning

    Athi

    Hello

    With flex, you need to display the filereference function record. Because of the security sandbox you cannot programmatically save files or create folders, you need to open a box to browse to windows files, so the user can create a folder or save a file.

    private void testme (): void

    {

    var fi: FileReference = new FileReference();

    fi. Save ('Hello');<=== this="" would="" open="" a="" system="" file="" save="">

    }

    David.
  • Can I add date to name the file using burst

    Hi all

    I know that we can add the date to the file using %y and %m %d for

    E-mail
    AT·
    WEBDAV

    But is it possible to add the date to the file name if I'm bursting my file to a shared location.

    I tried this %y and %m %d but it does not work for explosion.

    Please answer

    Thank you
    Ronny

    Raise an SR to support this for the file option
    and
    To work around this problem, change your query bursting enrollment, to_char (sysdate, 'DDMMYYY') for the day, month and year, inorder to add to the file name component.

  • Last line of text missing in the popup when it is generated

    Hi all

    We are experiencing a strange problem where the last line of text in any subject that appears in a pop-up window to another topic is missing (not shown). However, if you view the topic in a normal browser window, the last line of the text is present. It happened not in earlier versions of RoboHelp; only 8 HR. If someone has encountered this problem, and if so, could you address them and how?

    In all of our subjects, the last line of the text is a footer with a Disclaimer Privacy and "and the" current date. I noticed that in any topic that was connected via popup with another topic, RoboHelp adds a strange between the closing tag < /p > script of this line and the closing < / body > and < / html > tags. This script could be causing the problem? An example script is pasted at the bottom of this message.

    I appreciate any assistance! My system information is listed below. Let me know if you need further information.

    Many thanks in advance,

    Lisa

    RoboHelp HTML version 8.0.2.208

    Output type: WebHelp

    Source control: Microsoft Visual SourceSafe 8.0.50727.42

    <? HR-script_start? > < script type = "text/javascript" language = "JavaScript1.2" > / / <! [CDATA]
    If (typeof (TextPopupInit)! = 'function') TextPopupInit = new Function();
    If (typeof (FilePopupInit)! = 'function') FilePopupInit = new Function();
    TextPopupInit ('a9', 'POPUP379827639');
    FilePopupInit ('a5');
    FilePopupInit ('a6');
    TextPopupInit ('a3', 'POPUP382536905');
    TextPopupInit ('a8', 'POPUP389987027');
    FilePopupInit ('a1');
    FilePopupInit ('a14');
    TextPopupInit ('a15', 'POPUP387795029');
    TextPopupInit ('a4', 'POPUP386495466');
    TextPopupInit ('a11', 'POPUP388870525');
    TextPopupInit ('a13', 'POPUP387792022');
    FilePopupInit ('a12');
    TextPopupInit ('a2', 'POPUP410568235');
    FilePopupInit ('a16');
    TextPopupInit ('a10', 'POPUP386843632');
    TextPopupInit ('a7', 'POPUP388085251');
    []] > < / script > <? HR-script_end? >

    See section 20.

    http://www.Grainge.org/pages/authoring/RH8/using_rh8.htm

    See www.grainge.org for creating tips and RoboHelp

    @petergrainge

  • How to read the content .vmtx of the file using PowerCLI

    Hi all

    I have a virtual computer model in one of the NFS attached to my ESX host data stores.
    I need to get the display name and some other details of the vmtx this model file.
    Any method to get values from vmtx file using PowerCLI... ?

    Thank you in advace for all help.

    Hello, MattGeorgey-

    One way you could do this would be to use the Copy-DatastoreItem cmdlet to retrieve the .vmtx file, and then you can read it, Get-Content on it, etc., as you please.  Something like:

    ## copy the VMTX file from the datastore to a local spotCopy-DatastoreItem vmstore:\MyDatacenterName\my_datastore_name\myTemplate\myTemplate.vmtx C:\temp\.
    
    ## get the contents of the VMTX file$colVMTXContents = gc C:\Temp\myTemplate.vmtx## get the line that contains the "displayName" value$colVMTXContents | Select-String displayName
    

    And, you can access some of the elements that are specified in the file .vmtx using the property Config.ExtraConfig of the display of the model as object:

    ## get the template object$tmplMyTemplate = Get-Template myTemplate## get a particular value for an ExtraConfig item$tmplMyTemplate.ExtensionData.Config.ExtraConfig | ?{$_.Key -eq "nvram"}
    

    How do I?

  • The list of permissions of the files using the command line

    Hi all

    My windows operating system is windows Server 2003 R2.

    Now, I'm trying to find a solution that can display all the permissions of the file of each folder and its subdirectory by using the command line syntax.
    I tried to use ICACLS to solve this problem, but its result contains the permissions of all files/folders. I just want to have the permission of files, not the permissions of each individual files.

    Is it possible to just show the permissions of folders with ICACLS? If it is possible, what sentence from command line?

    However, I also looked at Systinterals AccessChk and AccessEnum without finding a solution.

    If you have no good solution, please share with me.

    Advanced thanks.

    Hi Leo,

    The question you have posted is related to file permissions in Server 2003 and it would be better suited to the TechNet community.

    Please visit the link below to find a community that will provide the support you want.

    http://social.technet.Microsoft.com/forums/en-us/winserversecurity/threads

    Hope it will be useful.

  • Read the files using BlackBerry device Simulator...

    In the device Simulator if you take a photo using the camera option it shows that it is saved as a .jpg file.

    I can read such a file using the FileConnection method? This file is real?

    Or should I use a real BlackBerry device to simulate it?

    Because what I'm looking for is to read the image stored in the device and attach it to an email and send it.

    But it seems as if this file is not accessible, even if I give the path of it.

    For example:

    FileConnection fconn = (FileConnection)Connector.open("file:///SDCard/BlackBerry/picture/IMG00017.jpg");

    Can anyone give a solution for this?

    Third-party applications are not able to read the example of media (pictures, sounds, etc.) which is preinstalled on a BlackBerry handheld.  You should be able to read files created by the user or other applications.

Maybe you are looking for