Reading Text Files using Oracle PL/SQL and UTL_FILE

Hi, experts. I tried to read a text file into oracle. Here is what i did:
1. Create a text file in the directory: C:\temp\New Text Document.txt
2. Run the following SQL in PL/SQL:
CREATE or replace DIRECTORY sampledata AS 'C:\temp\';
grant read, write on directory sampledata to public;
3. When I run the following code, it caused an error: ora-29280: invalid directory path. I have alread checked the directory path, it is correct. Would someone know what wrong is my code?
declare
f utl_file.file_type;
s varchar2(3000);
begin
f := utl_file.fopen('sampledata','New Text Document.txt','R');
utl_file.get_line(f,s);
utl_file.fclose(f);
dbms_output.put_line(s);
end;
Thank you

Try with a filename without spaces:No problem with spaces
SQL> declare
  2  f utl_file.file_type;
  3  s varchar2(3000);
  4  begin
  5  f := utl_file.fopen('SAMPLEDATA','New Text Document.txt','R');
  6  utl_file.get_line(f,s);
  7  utl_file.fclose(f);
  8  dbms_output.put_line(s);
  9  end;
10  /
line1
PL/SQL procedure successfully completed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • How to create and read text file using LabVIEW 7.1 PDA module?

    How to create and read text file using LabVIEW 7.1 PDA module? I can not create a text file and read it.
    I attach my code here.
    Attachments:
    File_IO.vi ‏82 KB

    Well my acquisition code runs perfect. The problem is reading it. I can't seem to read my data no matter what I do. My data gets saved as a string using the array to string vi but I've read that the string to array vi (which I need to convert back to array to read my data) does not work on the pda. I'm using version 8.0. So I was trying to modify the program posted in this discussion so that it would save data from my DAQ. I did that but I still can't read the data after its saved. I really don't know what else to do. All I need to do is read the data on the pda itself. I can't understand why I'm having such a hard time doing that. I found a possible solution on another discussion that talks about parsing the strings because of the bug in the "string to array" vi. However, that lead me to another problem because for some reason, the array indicators or graphs don't function on the pda. When i build the program to the pda or emulator, the array indicators are faded out on the front panel as if the function is not valid. Does this kind of help give a better picture of what I'm trying to do. Simply read data back. Thanks.

  • To read text file using utl_file

    I would like to read test_file_out.txt which is in c:\temp folder.
    create or replace create or replace directory dir_temp as 'c:\temp';
    grant read, write on directory dir_temp to system;
    then when i execute the below code i get the error .
    // to read text file using utl_file
    DECLARE
    FileIn UTL_FILE.FILE_TYPE;
    v_sql VARCHAR2 (1000);
    BEGIN
    FileIn := UTL_FILE.FOPEN ('DIR_TEMP', 'test_file_out.txt', 'R');
    UTL_FILE.PUT_LINE (FileIn, v_sql);
    dbms_output.put_line(v_sql);
    UTL_FILE.FCLOSE (FileIn);
    END;
    ERROR:
    invalid file operation
    i would like to use ult_file only and also can you let me know to read the text file and place its contents in tmp_emp table?

    Are you trying to read the contents of the file into the local variable? Or write the contents of the local variable to the file?
    Your text talks about reading the file. And you open the file in read mode. But then you call the UTL_FILE.PUT_LINE method which, as SomeoneElse points out, attempts to write data to the file. Since the file is open in read-only mode, you cannot write to the file.
    If the goal is really to read from the file, replace the UTL_FILE.PUT_LINE calls with UTL_FILE.GET_LINE. If the goal is really to write to the file, you'll need to open the file in write mode ('W' rather than 'R' in the FOPEN call).
    Justin

  • Read Text file using Java Script

    Hi,
    I am trying to read a text file using Java Script within the webroot of MII as .HTML file. I have provided the path as below but where I am not able to open the file. Any clue to provide the relative path or any changes required on the below path ?
    var FileOpener = new ActiveXObject("Scripting.FileSystemObject");
    var FilePointer = FileOpener.OpenTextFile("E:\\usr\\sap\\MID\\J00\\j2ee\\cluster\\apps\\sap.com\\xapps~xmii~ear\\servlet_jsp\\XMII\\root\\CM\\OCTAL\\TestTV\\Test.txt", 1, true);
    FileContents = FilePointer.ReadAll(); // we can use FilePointer.ReadAll() to read all the lines
    The Error Log shows as :
    Path not found
    Regards,
    Mohamed

    Hi Mohamed,
    I tried above code after importing JQuery Library through script Tag. It worked for me . Pls check.
    Note : You can place Jquery1.xx.xx.js file in the same folder where you saved this IRPT/HTML file.
    <HTML>
    <HEAD>
        <TITLE>Your Title Here</TITLE>
        <SCRIPT type="text/javascript" src="jquery-1.9.1.js"></SCRIPT>
        <script language="javascript">
    function Read()
    $.get( "http://ldcimfb.wdf.sap.corp:50100/XMII/CM/Regression_15.0/CrossTab.txt", function( data ) {
      $(".result").html(data);
      alert(data);
    // The file content is available in this variable "data"
    </script>
    </HEAD>
    <BODY onLoad="Read()">
    </BODY>
    </HTML>

  • Can't read text file using UTL_FILE

    Hi All,
    how can I read notepad file using UTL_FILE package.I have specified the UTL_FILE_DIR in the init.ora file.My objective is to when a button is clicked, the contents of the file will display in a text item.Here is my code written in WHEN_BUTTON_PRESSED trigger.
    DECLARE
         file_handle UTL_FILE.FILE_TYPE;
    data_line Varchar2(100);
    BEGIN
         file_handle := UTL_FILE.FOPEN('E:\vimal','abc.txt','R');
              message('directory created');
         UTL_FILE.GET_LINE(file_handle, data_line);
         :block2.t1 := data_line;
         UTL_FILE.FCLOSE(file_handle);
    END;

    Why don't you use text_io? Don't forget that UTL_FILE is reading directories from the database point of view. The E drive for the database is a different E then on your client pc. I presume your database is on a different computer. Are you getting any errors?

  • Read Text file using CLIENT_TEXT_IO

    Dear All Experts,
    please let us know .... How much big (in size) text file can be supported by oracle server by using below option
    1- TEXT_IO (File on the dabase server machine)
    2- CLIENT_TEXT_IO (File on the client machine side)
    please guide..
    give us any link to read about it
    Thanks alot
    Eidy

    Make sure the file you are trying to open for read is a text file and does not include any other objects, embedded in it.
    Tony

  • Read Text File In Oracle package

    Hello,
    I am writing a spec to move a desktop app and code as an Oracle packaged program. Can a stored procedure or an oracle package read from a text file stored in pc/server directory?

    Somewhere after the first sentence, it goes on to mention the GET_RAW and PUT_RAW functions.

  • Read text file using Java(streamTokenizer)

    Hi, all,
    I am lost when trying to read data from a text file to a Java prgram. The text file looks like the following:
    106,62,2322,8159,1
    106,62,3658,8333,1
    106,62,4215,8334,2
    Each number is seperated by "," and each line representing one row of data. I was thinking about using streamTokenizer to read the data into a multi-dimentional array. Since I am new to Java and just read something about the streamTokenizer from book, I would like to get some help from someone who is more experienced with that.
    Thanks for your help!
    Kevin

    Hi Kevin,
    try this:
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.StringTokenizer;
    public class Answer {
            public static void main(String[] args) {
            List data = new ArrayList();
            try {
                BufferedReader in = new BufferedReader(new FileReader("...your text file ..."));
                String line;
                // reading the file line by line
                while ((line = in.readLine()) != null) {
                    // splitting the line into token
                    StringTokenizer st = new StringTokenizer(line, ",");
                    List row = new ArrayList();
                    while (st.hasMoreTokens()) {
                        row.add(new Integer(st.nextToken()));
                    data.add(row); // adding the row of data
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            // test result
            System.out.println(data);
    }I don't like to use arrays, because when I start reading the file, I don't know yet, how many rows of data it is containing. Therefore a java.util.List is much more convenient (you don't have to initialize). Your result is now a java.util.List containing elements of java.util.List containig elements of Integer.
    Harri

  • Query on text file using Openrowset in Sql server 2012

    Hi,
    I am using below query on Sql server 2008 and sql server 2012.It is working find in 2008 but giving error in 2012.
    below is query and error on sql 2012
    select * from OpenRowset('MSDASQL', 'Driver={Microsoft Access Text Driver (*.txt, *.csv)};DefaultDir=D:\MSSQL;',
     'select * from employee1.txt')
    OLE DB provider "MSDASQL" for linked server "(null)" returned message "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified".
    Msg 7303, Level 16, State 1, Line 1
    Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "(null)".
    I have read some document on msdn and install microsoft access database engine 2010, but still it not working.
    Can anyone suggest resolution of this problem.
    Thanks
    Shitalkumar kasliwal

    Read this link
    http://calyansql.blogspot.co.il/2013/02/fix-cannot-initialize-data-source.html
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Compress Text File Using PL/Sql

    Hi All,
    My Environment is -------> Oracle 11g Database Release 1 On Windows 2003 Server SP2
    Requirement is ------------> Compress a text file using Oracle pl/sql
    I am tryring to compress a text file using below pl/sql code,
    DECLARE
    src_file BFILE;
    v_content BLOB;
    v_blob_len INTEGER;
    v_file UTL_FILE.file_type;
    v_buffer RAW(32767);
    v_amount BINARY_INTEGER := 32767;
    v_pos INTEGER := 1;
    v_blob BLOB;
    BEGIN
    src_file := BFILENAME('MY_FILES','expLive.log');
    DBMS_LOB.fileopen(src_file, dbms_lob.file_readonly);
    v_content := utl_compress.lz_compress(src_file);
    v_blob_len := DBMS_LOB.getlength(v_content);
    v_file := UTL_FILE.fopen('MY_FILES','test.log.zip','wb');
    WHILE v_pos < v_blob_len
    LOOP
    DBMS_LOB.READ(v_content, v_amount, v_pos, v_buffer);
    UTL_FILE.put_raw(v_file, v_buffer, TRUE);
    v_pos := v_pos + v_amount;
    END LOOP;
    UTL_FILE.fclose(v_file);
    EXCEPTION
    WHEN OTHERS THEN
    IF UTL_FILE.is_open(v_file) THEN
    UTL_FILE.fclose(v_file);
    END IF;
    RAISE;
    END;
    i am able to get the zip file without any problem.But the Problem here is size of the zip file, Acutal Text File Size is 520 KB and zip file size is 241KB. is there any possible way to compress little bit further to 100KB?
    Please Advice ....in case if you are have an example please share it.
    Thanks for your helps
    Shan

    is there any possible way to compress little bit furtherYou can compress better (but slower) with
    v_content := utl_compress.lz_compress(src_file, 9);
    ..

  • How to load decimal values into a file using bcp in SQL Server 2000?

    Hi everyone,
    I'm trying to load data from a database table to a text file using bcp on SQL Server 2000. When I'm loading the decimal values, the values before the decimal are not being loaded into the file. How could I load the values before decimals?
    Here are the DDLs and DMLs of what I'm trying to run:
    CREATE TABLE [dbo].[Product_Sales](
    [Year_of_Sale] [smallint] NOT NULL,
    [Product_Type] [varchar](25) NOT NULL,
    [Product_Group] [varchar](25) NOT NULL,
    [Category_Type] [varchar](25) NOT NULL,
    [Category_Group] [varchar](10) NOT NULL,
    [Product_Count] [bigint] NOT NULL,
    [Product_Amount] [decimal](19, 2) NOT NULL,
    [Category_Count] [bigint] NOT NULL,
    [Category_Amount] [decimal](19, 2) NOT NULL,
    CONSTRAINT [PK_Product_Sales] PRIMARY KEY CLUSTERED
    [Year_of_Sale] ASC,
    [Product_Type] ASC,
    [Product_Group] ASC,
    [Category_Type] ASC,
    [Category_Group] ASC
    ) ON [PRIMARY]
    ) ON [PRIMARY]
    INSERT INTO [Yearly_Sales].[dbo].[Product_Sales]
    VALUES(2010, 'Online', 'Web', 'Cameras', 'Electronics', 547, 0.00, 0, 0.00)
    EXEC [master].[dbo].[xp_cmdshell] 'bcp "SELECT * FROM [Yearly_Sales].[dbo].[Product_Sales]" queryout D:\Yearly_Sales\Product_Sales.dat -c -T -S'
    And the output I see in the file is:
    2010 Online Web Cameras Electronics 547 .00 0 .00
    The values before decimals are being truncated.
    Thanks,
    Bangaaram
    Known is a DROP, Unknown is an OCEAN.

    You can modify the decimal column(s) in the table to varchar type before export. But it does not look good.
    alter table [dbo].[Product_Sales]
    Alter column [Product_Amount] varchar(20)
    alter table [dbo].[Product_Sales]
    Alter column [Category_Amount] varchar(20)
    Does that make any sense?
    Known is a DROP, Unknown is an OCEAN.
    Basically you modify the decimal column to a varchar type before you run the bcp command for export. You can modify your source table or you can modify them on the fly. It is just a workaround.
    Modifying the source wouldn't be a good idea. Never do that if you can't get your desired output.
    Known is a DROP, Unknown is an OCEAN.

  • How to read two text files using the Read from spreadsheet.vi and then plot it

    I need to read two text files using the read from spreadsheet function and then plot these files over time.
    The file with the .res extention is the RMS values (dt and df) and the second file contains the amplitude of a frequency spectrum.
    I really appreciate any help..thanks
    Attachments:
    RMS.txt ‏1 KB
    FREQUENCY.txt ‏1 KB

    From NI Example Finder:
    Write to Text File.vi
    Read from Text File.vi
    Jean-Marc
    LV2009 and LV2013
    Free PDF Report with iTextSharp

  • How to read a whole text file into a pl/sql variable?

    Hi, I need to read an entire text file--which actually contains an email message extracted from a content management system-- into a variable in a pl/sql package, so I can insert some information from the database and then send the email. I want to read the whole text file in one shot, not just one line at a time. Shoud I use Utl_File.Get_Raw or is there another more appropriate way to do this?

    how to read a whole text file into a pl/sql variable?
    your_clob_variable := dbms_xslprocessor.read2clob('YOUR_DIRECTORY','YOUR_FILE');
    ....

  • How to load date and time from text file to oracle table through sqlloader

    hi friends
    i need you to show me what i miss to load date and time from text file to oracle table through sqlloader
    this is my data in this path (c:\external\my_data.txt)
    7369,SMITH,17-NOV-81,09:14:04,CLERK,20
    7499,ALLEN,01-MAY-81,17:06:08,SALESMAN,30
    7521,WARD,09-JUN-81,17:06:30,SALESMAN,30
    7566,JONES,02-APR-81,09:24:10,MANAGER,20
    7654,MARTIN,28-SEP-81,17:24:10,SALESMAN,30my table in database emp2
    create table emp2 (empno number,
                      ename varchar2(20),
                      hiredate date,
                      etime date,
                      ejob varchar2(20),
                      deptno number);the control file code in this path (c:\external\ctrl.ctl)
    load data
    infile 'C:\external\my_data.txt'
    into table emp2
    fields terminated by ','
    (empno, ename, hiredate, etime, ejob, deptno)this is the error :
    C:\>sqlldr scott/tiger control=C:\external\ctrl.ctl
    SQL*Loader: Release 10.2.0.1.0 - Production on Mon May 31 09:45:10 2010
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Commit point reached - logical record count 5
    C:\>any help i greatly appreciated
    thanks
    Edited by: user10947262 on May 31, 2010 9:47 AM

    load data
    infile 'C:\external\my_data.txt'
    into table emp2
    fields terminated by ','
    (empno, ename, hiredate, etime, ejob, deptno)Try
    load data
    infile 'C:\external\my_data.txt'
    into table emp2
    fields terminated by ','
    (empno, ename, hiredate, etime "to_date(:etime,'hh24:mi:ss')", ejob, deptno)
    this is the error :
    C:\>sqlldr scott/tiger control=C:\external\ctrl.ctl
    SQL*Loader: Release 10.2.0.1.0 - Production on Mon May 31 09:45:10 2010
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Commit point reached - logical record count 5
    C:\>
    That's not an error, you can see errors within log and bad files.

  • Reading an EXCEL file from Oracle PL/SQL (HP-Unix server)

    Hi,
    I have the following requirement:
    1. Get the EXCEL file from the remote FTP location
    2. Read the EXCEL file and convert it into the CSV file format.
    3. Put the CSV file into another FTP location.
    I need to get all these points done using Oracle PL/SQL procedure.
    I am using the Oracle 9i installed in HP-Unix environment.
    Please help me in getting this done.
    Thanks

    Ok, setting up Excel as an External Database connection....
    1- Go to Control Panel>Administrative Tools>Data Sources (ODBC)>System DSN and create a data source with appropriate driver. Name it EXCL.
    2- In %ORACLE_HOME%\Network\Admin\Tnsnames.ora fie add entry:
    EXCL =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.12.0.24)(PORT = 1521))
    (CONNECT_DATA =
    (SID = EXCL)
    (HS = OK)
    Here SID is the name of data source that you have just created.
    3- In %ORACLE_HOME%\Network\Admin\Listener.ora file add:
    (SID_DESC =
    (PROGRAM = hsodbc)
    (SID_NAME = <hs_sid>)
    (ORACLE_HOME = <oracle home>)
    under SID_LIST_LISTENER like:
    SID_LIST_LISTENER =
    (SID_LIST =
    (SID_DESC =
    (SID_NAME = PLSExtProc)
    (ORACLE_HOME = d:\ORA9DB)
    (PROGRAM = extproc)
    (SID_DESC =
    (GLOBAL_DBNAME = ORA9DB)
    (ORACLE_HOME = d:\ORA9DB)
    (SID_NAME = ORA9DB)
    (SID_DESC =
    (PROGRAM = hsodbc)
    (SID_NAME = EXCL)
    (ORACLE_HOME = D:\ora9db)
    Dont forget to reload the listener
    c:\> lsnrctl reload
    4- In %ORACLE_HOME%\hs\admin create init<HS_SID>.ora. For our sid EXCL we create file initexcl.ora.
    In this file set following two parameters:
    HS_FDS_CONNECT_INFO = excl
    HS_FDS_TRACE_LEVEL = 0
    5- Now connect to Oracle database and create database link with following command:
    SQL> CREATE DATABASE LINK excl
    2 USING 'excl'
    3 /
    Database link created.
    Now you can perform query against this database like you would for any remote database.
    SQL> SELECT table_name FROM all_tables@excl;
    TABLE_NAME
    DEPT
    EMP
    But you're limited to Windows based servers for this.
    As for converting Excel to CSV and doing it yourself. I hope you know the internal format of MS Excel files cos you're gonna need to know it. It would be far easier if the "user" creating the Excel file could save a copy out in CSV format for you and then it's just a case of FTP'ing the file and using external tables to read the data.

Maybe you are looking for

  • Transfering SMS from Iphone 4 to a PC for free?

    Hello, Is there a way to transfer Iphone 4 SMS messages from the phone to a PC computer for free. While maintaining the dates of the messages and possibly contact name. screen shots are not an options (alot of messages) I've looked for a few programs

  • Role-Based CLI Views with AAA method

    Hi, I'm configuring Role-Based CLI Views on a router for limiting access to users. My criteria: - There should be a local user account on the router that has the view 'service' attached to it - If the router is online and can reach the radius server,

  • Printing Pictures of materials in smartforms...

    We have a requirement here that is the following: 1 - All materials in the system will have a picture assigned to it. (tens of thousands of them) 2 - We need to print a photo catalog (using smartforms); with all these pictures. (around 30 per page) 3

  • How can I get iMovie 10 to see my iPhoto Library after I relocated it.

    How can I get iMovie 10 to see my iPhoto Library after I relocated it. I moved my iPhoto Library to a secondary hard drive, because my main SSD wasn't large enough. I then upgraded to IMove 10.0.4 and also moved my iMovie Library to the secondary har

  • CS4 menu resources in CS5

    Just realized that I need some template resource from cs4 in cs5.  Most if not all these sample CS5 resources are totally different from the earlier ones.  So whats the best way to move them over so I don't have to completely rebuild some of my older