UTL package

hey is there any way to check the filename from OS in pl/sql block. if we have a oracle directory named ABC reside physically on c:\backup. backup folder contain 4 different name file like PKMX1, PKMX2.dmp is there any UTL package which enable us to check if filename already there then remove old one create new. i have found UTL package which delete file from directory but how can i check either filename already there or not. plz check this
UTL_FILE package
FUNCTION FOPEN (location IN VARCHAR2,
filename IN VARCHAR2,
open_mode IN VARCHAR2)
RETURN UTL_FILE.FILE_TYPE;

You should use FGETATTR procedure and it's exist parameter to know whether the file exists or not
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_file.htm
FGETATTR Procedure
This procedure reads and returns the attributes of a disk file.
Syntax
UTL_FILE.FGETATTR(
   location    IN VARCHAR2,
   filename    IN VARCHAR2,
   exists      OUT BOOLEAN,
   file_length OUT NUMBER,
   blocksize   OUT NUMBER);- - - - - - - - - - - - - - - - - - - - -
Kamran Agayev A. (10g OCP)
http://kamranagayev.wordpress.com

Similar Messages

  • Installing utl packages

    how i can install utl packages in oracle 8i.
    eg. i want to use utl.smtp package for sending mails from my forms, but it gives me an error saying that dentifier 'UTL_SMTP.CONNECTION' must be declared
    can u please help me.
    uday

    Hi,
    You have to compile the package ORACLE_HOME/rdbms/utlsmtp.sql as sys.
    Here is an example on how call/use package utl_smtp:
    DECLARE
         smtp_out utl_smtp.connection ;
         PROCEDURE send_header(name IN VARCHAR2, header IN VARCHAR2) AS
         BEGIN
              utl_smtp.write_data(smtp_out, name || ': ' || header || utl_tcp.CRLF);
         END ;
         BEGIN
              smtp_out := utl_smtp.open_connection('smtp.swipnet.se');
              utl_smtp.helo(smtp_out, 'sune.se');
              utl_smtp.mail(smtp_out, '[email protected]');
              utl_smtp.rcpt(smtp_out, '[email protected]');
              utl_smtp.open_data(smtp_out);
              send_header('From', '"Sender" <[email protected]>');
              send_header('To', '"Recipient" <[email protected]>');
              send_header('Subject', 'Test');
              utl_smtp.write_data(smtp_out, utl_tcp.CRLF || 'Hello world!');
              utl_smtp.close_data(smtp_out);
              utl_smtp.quit(smtp_out);
         EXCEPTION
              WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
                   utl_smtp.quit(smtp_out);
              WHEN others THEN
                   RAISE_APPLICATION_ERROR(-20100, 'Fail! Cannot send e-mail: ' || sqlerrm) ;
    END ;
    Regards - Tommy

  • Website for UTL packages

    Please let me know the website where i can get the list of UTL packages and its uses.

    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96612/toc.htm
    Cheers
    Sarma.

  • EFT Payment Program. Writing to a flat file using UTL Package

    Hi guys
    I wonder if someone can help me. I'm battling with something in pl/sql. I have a procedure that writes to a flat file. Each procedure I call writes a single section of the file, e.g "create_hdr_rec_line_fn" writes the header on top of the file and "create_std_trx_rec_line_fn" writes the body below the header. Then lastly the procedure that writes the trailer at the bottom of the file.
    My problem comes here: I have a proc that calculates the hash total.
    This is done by " utl_file.put_line(g_file_id, g_seed_number)". I want to write the hash total next to the trailer section of the file and not below it. How can I do this? Here's the example of the flat file produced. The very last line is the hash total, but I my hash total to be on the same line as the (Trailer). I want it to be just next to the trailer. I hope my question is clear. Please see my procedure below the flat file.
    Thanking you in advance....
    My flat file
    FHSSVSDIM15000932008102810483220081028T (header)
    SD0009300100001D19874200019873402211ACSA JOHANNESBURG INTERNATIONA (Line1-Detail)SC00093001D14540500014540057261IS H/O MAIN ACCOUNT 0000000124959315207 (Line-Transaction)
    ST00093000000700000000070000000000020000001806378410000000000000000000001806378 (Trailer)
    58298239848772973764654319387982 (hash total)
    My procedure
    PROCEDURE eft(errbuf OUT NOCOPY VARCHAR2,
    retcode OUT NOCOPY NUMBER,
    p_payment_batch IN VARCHAR2) IS
    v_eft_date VARCHAR2(100);     
    BEGIN
    v_eft_date := TO_CHAR(SYSDATE, 'DD-MON-RRRR_HH24_MI_SS');
    g_payment_batch := p_payment_batch;
    g_file_name := 'EFT'||v_eft_date||'.txt';
    g_file_id := utl_file.fopen(g_dir_name,
    g_file_name,
    'W');
    utl_file.put_line(g_file_id,
    create_hdr_rec_line_fn);
    create_std_trx_rec_line_fn(g_file_id);
    create_std_contra_rec_line_fn(g_file_id);
    create_std_trailer_fn(g_file_id);
    utl_file.put_line(g_file_id,
    g_seed_number);
    utl_file.fclose_all;
    IF (update_tables != TRUE) THEN
    Fnd_File.put_line(Fnd_File.LOG, 'Failed to update payment batch tables. Cancel the batch');
    END IF;
    EXCEPTION
    WHEN OTHERS THEN
    Fnd_File.put_line(Fnd_File.LOG, 'Print Error - eft' || SUBSTR(SQLERRM, 1, 250));
    END eft;

    user643734 wrote:
    Hi cdkumar
    I'm not quite sure if I understand what you mean. Are you saying that I should use the "PUT" to write 'create_std_trailer_fn' and and then use the "PUT_LINE" to write 'g_seed_number'? Could you please show me what you mean by changing the proc I posted on my question with your suggestions.How about, rather than use code it for you, you try changing the code and giving it a go yourself.
    Essentially PUT_LINE will write out the data and put a "new line" character on the end so the next output will appear on the following line; PUT will just output the data without terminating the line, so any subsequent output will just append to the end.
    It's very simple. Give it a go.

  • UTL File output shows junk characters

    Hi,
    I have a interface where i'am displaying the details in a text file using the UTL package.
    The output is showing correctly but there are few junk characters at the end of the string like small boxes.
    Can anybody advice as why this is happening and how to fix it.
    Thanks in advance,

    Hi,
    I would appreciate if any one has any suggestion on this issue.
    Thank You,
    Mohammed

  • Upload and Copy files using PLSQL.

    Hi All,
    Can UTL package can be used to upload any local data file to server?
    Or is there any in-built package which can be used to upload files to servers and copy files to another directory?
    Thanks in advance.

    Avishek wrote:
    Thanks.
    But i've a requirement to upload and copy files from one directory to another.
    How can i approach?Realize we only know what you post & so far you have posted NOTHING useful.
    How exactly does end user interact with the DB?
    3-tier application?
    EndUser<=>browser<=>WebServer<=>ApplicationServer<=>DatabaseServer
    What OS name & version for client system?
    Handle:      Avishek
    Email:      [email protected]
    Status Level:      Newbie (5)
    Registered:      Jun 3, 2008
    Total Posts:      68
    Total Questions:      27 (16 unresolved)

  • 11g Upgrade - Network ACL

    I want to upgrade my oracle 10g database to 11g. the utlui112.sql script shows following -
    WARNING: --> Database contains schemas with objects dependent on network packages.
    .... Refer to the Upgrade Guide for instructions to configure Network ACLs.
    .... USER MDMSYS has dependent objects.
    According to documentation , it is not clear whether I need to install XML DB before upgrade or after upgrade to 11g.
    I run the following query and result is as follows -
    SQL >SELECT * FROM DBA_DEPENDENCIES WHERE referenced_name IN ('UTL_TCP','UTL_SMTP','UTL_MAIL','UTL_HTTP','UTL_INADDR')
    AND owner NOT IN ('SYS','PUBLIC','ORDPLUGINS');
    OWNER NAME TYPE REFERENCED_OWNER REFERENCED_NAME REFERENCED_TYPE
    REFERENCED_LINK_NAME DEPE
    MDMSYS MDM_JOB PACKAGE BODY PUBLIC UTL_TCP SYNONYM
    HARD
    MDMSYS MDM_JOB PACKAGE BODY MDMSYS UTL_TCP NON-EXISTENT
    Can someone plaease help on how I can configure the network ACLs?

    Hi ,
    You can grant to a network and not necessary to grant each machines IP details.
    Also this has to be granted to users or the principal is the schema who will be executing this utl_smtp.
    If there are multiple users, then you need to grant access to each user.
    You need to configure below steps to grant access to the user for utl operations.
    This is a new security feature to 11g.
    Please review below document :
    Oracle® Database Security Guide
    11g Release 1 (11.1)
    Part Number B28531-06
    4 Configuring Privilege and Role Authorization
    Managing Fine-Grained Access to External Network Services
    URL : http://download.oracle.com/docs/cd/B28359_01/network.111/b28531/authorization.htm#CIHDAJDJ
    A example of the setting:
    =================
    If you are creating the ACL for the first time, you can directly go to step (d).
    Please replace the values in < > with your environment values.
    a. Drop the user privilege:(please run the below for all the users who are granted connect privilege).
    BEGIN
    DBMS_NETWORK_ACL_ADMIN.delete_privilege (
    acl => '<mailserver_acl.xml>',
    principal => '<MYUSER>',
    is_grant => FALSE,
    privilege => 'connect');
    COMMIT;
    END;
    b. Unassign the network details from ACL (The ip address are only example, please replace with the
    values you have specified)
    BEGIN
    DBMS_NETWORK_ACL_ADMIN.unassign_acl (
    acl => '<mailserver_acl.xml>',
    host => '<192.168.2.3>',
    lower_port => <25>,
    upper_port => <25>);
    COMMIT;
    END;
    c. Drop the ACL
    BEGIN
    DBMS_NETWORK_ACL_ADMIN.drop_acl (
    acl => '<mailserver_acl.xml>');
    COMMIT;
    END;
    d. Create the acl again fresh:
    BEGIN
    DBMS_NETWORK_ACL_ADMIN.create_acl (
    acl => 'mailserver_acl.xml',
    description => 'Mailserver ACL',
    principal => '<MYUSER>',
    is_grant => TRUE,
    privilege => 'connect',
    start_date => SYSTIMESTAMP,
    end_date => NULL);
    COMMIT;
    END;
    e. Assign the acl to the network:(please have the ip address modified to correct IP of the machine where this utl package is targetted run.)
    for example IP/hostname of mail server should be there for UTL_SMTP to execute.
    BEGIN
    DBMS_NETWORK_ACL_ADMIN.assign_acl (
    acl => 'mailserver_acl.xml',
    host => '<192.168.2.3>',
    lower_port => <25>,
    upper_port => <25>);
    COMMIT;
    END;
    f.Test the package.
    Thanks,
    Sathya

  • Making data in tables online and offline - Backup and Recovery

    Hi All,
    I'm working on a project where the functionality is similar to 'Backup and Recovery' for database tables.
    Lets say we have a set of 6 tables T1, T2.... T6. They do have relationship between them. The tables in questions are simple standard tables, which are not table partitioned.
    - I want remove the records from live tables based on user entered date ranges and store it in some offline medium.
    - I might want make the data online again from the offline medium; Application should be able use that data without any modifications.
    - Different offline mediums can be
    a) Flat file
    b) Different table space
    c) Any other secondary medium (like XML, tape..Etc,)
    The total number of records will run in millions.
    The proposed solution should consider,
    1. Performance - Java solutions not feasible. Anything in SQL, PL/SQL or runs in DB itself(tools) are OK.
    2. Reliability - Should be highly reliable, Data corruption simply unacceptable.
    3. Security - Users should not be able to make out of the file.
    Few options include:
    1. Use partition
    2. Use SQL*Loader
    3. Export and import of tables.
    My main targets:
    1. Reduce space.
    2. Increase performance for queries.
    Please pass on your suggestions, any help is highly appreciated!
    Thanks In Advance!

    Few points to note:
    1. I agree partition would be right solution, but as I mentioned in my earlier statement, 'The tables in questions are simple standard tables, which are not table partitioned.'. The tables right now are not partitioned and I believe we cannot add/modify partitions, if the table were not created with the partition option. One work around is to build a partitioned table and copying all the properties(indexes,rows,constraints) from the existing non-partitioned table. But I suspect this is highly riskier and we can't afford to it.
    2. I need to support Oracle database versions starting from 8.0.6.
    3. Flat file is mandatory, others are optional. I can restrict our discussion just for a file.
    4. Considering the above points, the only option I could think of is I can move the records from the table to flat file and remove from tables. When required rollback the file data to the table and application would be able to use it. For export/import few options are: SQL*loader, exp/imp utilities, PL/SQL file UTL packages
    Thanks In Advance

  • Webutil and DB transfer

    Is there any chance that DB transfer feature will also be available for previous database server versions, like 8i ?
    Or they are missing some functionality required for that ?
    As far as I know 8i supports BLOBs and loading files into them...

    OK, i did some research on my own and here are my findings (correct me if I'm wrong somewhere):
    The only missing UTL package is UTL_ENCODE wchich is used for BASE64 encoding/decoding needed for communication with JavaBeans or something like that.
    I have found on Metalink forums thread about missing this functionality in oracle 8.1.7, and someone there provided link to free package which implements it.
    Assuming it does it's job right, if I replace in WEBUTIL_DB package calls to UTL_ENCODE with the new one, is it all that needs to get it working ?
    Of course I know that by using 3rd-party software code this solution may not be supported by Oracle, but it's better than nothing. Oh, I forgot that webutil is not supported anyway right now :)
    BTW, I don't understand why Oracle doesn't want to provide this package for earlier releases, it is simple one and not dependant on new features (I think). Instead when people are asking about this functionality the answer is: "Migrating to 9i is the best and only option"...

  • Help needed to write in excel sheet

    Hi,
    I currently need to read a table and write it in a file.
    iam able to do it by using UTL package.The utl file also writes in xls format.but if a record has two column.
    both the columns are written in a single column in excel
    sheet.Kindly suggest me how to solve this problem
    Thanks in advance.

    1. spool a file with 'csv' extension using Sql*Plus.
    2. Use a delimiter for columns.
    For example,
    select '"'||column1||'","'||column2||'"'
    from mytable

  • APEX component is invalid

    Hi,
    I create a new database a few weeks back (11.1.0.7 on AIX 6.1). Now i planned to upgrade it to 11.2.0.1 but it is showing me that APEX component is invalid. Can anyone guide me how to make it valid again?
    Comp ID Component                          Status    Version
    APEX    Oracle Application Express         INVALID   3.0.1.00.12
    CATALOG Oracle Database Catalog Views      VALID     11.1.0.7.0
    CATJAVA Oracle Database Java Packages      VALID     11.1.0.7.0
    CATPROC Oracle Database Packages and Types VALID     11.1.0.7.0
    EXF     Oracle Expression Filter           VALID     11.1.0.7.0
    JAVAVM  JServer JAVA Virtual Machine       VALID     11.1.0.7.0
    ORDIM   Oracle Multimedia                  VALID     11.1.0.7.0
    OWM     Oracle Workspace Manager           VALID     11.1.0.7.0
    RUL     Oracle Rules Manager               VALID     11.1.0.7.0
    XDB     Oracle XML Database                VALID     11.1.0.7.0
    XML     Oracle XDK                         VALID     11.1.0.7.0

    Hi ,
    I also faced the same issue.I tried by giving execute priviliges on utl packages to apex_*** schema which did not help me
    execute privs on utl packages was granted using ACL in 11GR2.
    I am plannin to uninstall this component and reinstall.
    If other has any solution ,Please share !!!
    Thanks,
    AM

  • XML to CLOB & UTF-8 Queries

    I need to create xml files from the available data in the DB tables. I am planning to use SQL/XML functions(xmlroot,xmlelement etc) to construct a well-formed
    xml and stored in CLOB data objects. I will use SPOOL command to get the clob (OUT parameter) in my client server (UNIX).
    Does any temporary CLOB objects will be created and not cleared by Oracle engine in the table space? If yes,how can i use dbms_lob.freetemporary(clobvar);
    to clear the CLOB object after the successful creation and spooling of the xml is done.
    I need to have utf-8 character set and achieve url escaped chracters as well, please let me know if these can be done without using UTL_HTTP or any other UTL packages.

    DDL & DML
    CREATE TABLE EMP_DETAILS (ENAME VARCHAR2(50),ID NUMBER(20),HIREDATE DATE);
    INSERT INTO EMP_DETAILS (ENAME,ID,HIREDATE) VALUES ('SCOTT',1,SYSDATE-1);
    INSERT INTO EMP_DETAILS (ENAME,ID,HIREDATE) VALUES ('SAM',2,SYSDATE-2);
    INSERT INTO EMP_DETAILS (ENAME,ID,HIREDATE) VALUES ('JIM',3,SYSDATE-3);
    PL/SQL
    create or replace
    PACKAGE body test_pack
    IS
    PROCEDURE test_proc (vxml OUT CLOB)
    IS
      xml   CLOB;
      vQuery  VARCHAR2(1000);
    BEGIN
      select
          XMLROOT(
            xmlelement("root",
             xmlagg(
               xmlelement("emp",
                 xmlelement("name", ename)
               , xmlelement("hiredate", hiredate)
           ),version '1.0" encoding="UTF-8').getClobVal()
           into xml
        from EMP_DETAILS;
       vxml := xml;
      END test_proc;
    END;Does this pl/sql code block create any temp CLOB's (or) do i need clear/free xml CLOB variable used here after completion or in case of exception?

  • Uploading a flat file into Oracle

    Hello guys
    Can somebody please help me. I've got a flat file that i want to read into oracle via UTL Package. I can read the file successfully if I manually replace the dots with underscores. But when I receive the file, before I upload it into Oracle, it comes in with dots on the file name. eg. The file looks like this: 'IS.DIM16.EFTS.GG24.INTAUD.TEST_20090219105728' then I have to manually replace the dots with underscores to make the file look like this: 'IS_DIM16_EFTS_GG24_INTAUD.TEST_20090219105728'.
    I don't want to change it manually. Is there a way to replace the dots with underscores before I read the file? Or is the a way to make Oracle read the dots? I've tried uploading the file with the dots but it gives me this error:
    ORA-29283: invalid file operation.
    Your help would be greatly appreciated.
    Thanks

    When i try this, i don't get any error. Can you be more specific ? Code , Expample , OS, version ....
    DECLARE
    v_handle utl_file.file_type;
    BEGIN
    v_handle:= utl_file.fopen ('/enspac03/output/ao/in','IS.DIM16.EFTS.GG24.INTAUD.TEST_20090219105728','r');
    dbms_output.put_line ('Open');
    utl_file.fclose(v_handle);
    END;

  • How to raise the event without creating Triggers

    Hi Gurus,
    here is my requirement.
    Whenever user issue the material from inventory ( on hand quantity reduced ), we have to generate a data file which contains item number, sub inventory and quantity info. for this we have created a utl file package. But here my issue is, without creating triggers / Alerts , i have to run the utl package.
    Please advice me how to do this / is there any middle ware tools available to run the package / concurrent prohram.
    We are using R12.
    Regards,
    Sreehari.

    Oracle provides various business events for material issue/transactions from inventory (For e.g.,oracle.apps.inv.miscIssue, oracle.apps.inv.subinvTransfer, oracle.apps.wip.job.material.transact, etc.).
    First check what kind of transactions happen when the On-hand is consumed. Then Go to any Workflow Admin responsibility >> Business Events: Events >> Search for the event you are looking for >>Hit Update >> Enable the event >> Navigate to Subscription and associate your PLSQL pacakge. let me know if it helps.

  • Creating a text file using pl/sql

    how can one create a text file using pl/sql?
    Say for example abcd.txt in the d: drive
    (d:\abcd.txt)
    on a windows nt server

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by bhrigu nagal ([email protected]):
    thanks for your replies
    I had already set the utl_file_dir parameter
    I tried the utl package and wrote the following code but got some errors
    declare
    filehandler UTL_FILE.FILE_TYPE;
    begin
    filehandler:=UTL_FILE.fopen('d:/intel/','myfile.txt','w');
    utl_file.put_line(filehandler,'look masjdfgsd\n');
    utl_file.fclose(filehandler);
    exception when utl_file.invalid_path then
    raise_application_error(-20023,'bhrigu ,chk the path');
    end;
    the errors
    ERROR at line 1:
    ORA-06510: PL/SQL: unhandled user-defined exception
    ORA-06512: at "SYS.UTL_FILE", line 101
    ORA-06512: at "SYS.UTL_FILE", line 157
    ORA-06512: at line 4
    if u know what this is please tell me
    thanks bhrigu
    <HR></BLOCKQUOTE>
    U need :
    1) To have UTL_FILE_DIR param in the init file of the instance with the same directory (don't forget to stop and restart the base)
    2) Handled the exceptions listed in the utl_file package (Oracle_home\rdbms\admin\utlfile.sql) in your source.
    3) Turn set serveroutput on in SQL*Plus.
    Run your procedure and see the error message to debug.
    Good luck
    null

Maybe you are looking for

  • Batch Monitor and Compressor do nothing when I submit...

    Hey, guys, I've re-install the whole OS and Final Cut Studio 2, I use Compressor to encode my video clip, after setup the format and the destination, I click the "submit" Button, the batch job send to Batch Monitor, but Compressor and Batch Monitor d

  • Multiple Albums with same content on iPod

    I just downloaded a ton of new music, from a differnt site than iTunes. When I sync the new music to my iPod nano (4 gen.), one artist in particular has some trouble. I go to them and there are 4 or 5 of the same album that say 1 song, 2 songs, 3 son

  • I cannot open iBooks on my iMac.

    When I try to open iBooks on my iMac I get the following message.  I have never been able to open iBooks from day one.  Since I haven't had a need to use it on  my iMac I just let it go, but now I would like to start using it.  What might be wrong? T

  • Displaying a form in an iView & displaying data in .pdf format in an iView

    Hi, 1)We want to show some details in an iView pertaining to the person who has logged into the portal. We are calling a function module (when a user clicks on a workset in the portal) and passing some parameters to it. The function module pulls the

  • Import from Excel - Lookup column

    Hi all, I would like to import an Excel spreadsheet to SharePoint list. One column in that spreadsheet should be lookup column which points to a column in another list in SharePoint. How could I do it? Thanks,