How can I read/write data files (text file) from PL/SQL Script
I had an oracle forms pl/sql program to read/write a data file (text file). When this code is run on a command line as a PL/SQL script using the SQL*Plus I am getting an error:
-- sample.sql
DECLARE
vLocation VARCHAR2(50) := 'r:\';
vFilename VARCHAR2(100) := 'sample.dat';
vTio TEXT_IO.FILE_TYPE;
vLinebuf VARCHAR2(2000);
vRownum NUMBER := 0;
-- use array to store data FROM each line of the text file
TYPE array_type IS VARRAY(15) OF VARCHAR2(100);
vColumn array_type := array_type('');
PROCEDURE prc_open_file(p_filename IN VARCHAR, p_access IN VARCHAR2) is
BEGIN
vTio := TEXT_IO.FOPEN(vLocation||p_filename,p_access);
EXCEPTION
WHEN OTHERS then
-- raise_application_error(-20000,'Unable to open '||p_filename);
message(sqlerrm);pause;
END;
PROCEDURE prc_close_file is
BEGIN
IF TEXT_IO.IS_OPEN(vTio) then
TEXT_IO.FCLOSE(vTio);
END IF;
END;
BEGIN
--extend AND initialize the array to 4 columns
vColumn.EXTEND(4,1);
prc_open_file(vFilename,'r');
LOOP
LTEXT_IO.GET_LINE(vTio,vLinebuf);
vColumn(1) := SUBSTR(vLineBuf, 1, 3);
vColumn(2) := SUBSTR(vLineBuf, 5, 8);
vColumn(3) := SUBSTR(vLineBuf,10,14);
Insert Into MySampleTable
Values
(vColumn(1), vColumn(2), vColumn(3));
EXIT WHEN vLinebuf IS NULL;
END LOOP;
prc_close_file;
END;
SQL> @c:\myworkspace\sql\scripts\sample.sql;
PLS-00201: identifier 'TEXT_IO.FILE_TYPE' must be declaredIt works on the oracle forms but not on the SQL*Plus. Is there an alternative method using a PL/SQL script? A simple sample would help. Thanks.
Did you ever noticed the search box at the right side of the forum?
A quick search (limited to this years entries) brought up this thread for example
Re: UTL_FILE Examples
Similar Messages
-
How to write data to text file using external tables
can anybody tell how to write data to text file using external tables concept?
Hi,
Using external table u can load the data in your local table in database,
then using your local db table and UTL_FILE pacakge u can wrrite data to text file
external table
~~~~~~~~~~~
http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_7002.htm#i2153251
UTL_FILE
~~~~~~~~~
http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_file.htm#sthref14093
Message was edited by:
Nicloei W
Message was edited by:
Nicloei W -
How can I Read/write a ascii file?
How can I Read/write a ascii file? like this:
101 0.0000 -1.0000 +
102 -0.1887 -0.9485 +
103 -0.3578 -0.8639 +
104 -0.5022 -0.7516 +
105 -0.6177 -0.6177 +
106 -0.7018 -0.4689 +
107 -0.7533 -0.3120 +
108 -0.7723 -0.1536 +
109 -0.7603 -0.0000 +
110 -0.7198 0.1432 +
111 -0.6543 0.2710 +
112 -0.5682 0.3796 +
113 -0.4660 0.4660 +
114 -0.3531 0.5284 +
115 -0.2345 0.5660 +
116 -0.1152 0.5791 +
117 -0.0000 0.5689 +
118 0.1069 0.5375 +
119 0.2020 0.4876 +
120 0.2823 0.4224 +
121 0.3457 0.3457 +
122 0.3911 0.2614 +
123 0.4180 0.1732 +import java.util.*;
import java.io.*;
class BallB{
public static void main (String args [])
throws Exception {
String str=" ";
String myString="";
try {
FileReader fr = new FileReader("test.txt");
BufferedReader br = new BufferedReader(fr);
FileWriter fw = new FileWriter("test1.txt");
while(str!=null){
myString = str+"\n";
str = br.readLine();
fw.write(myString);
br.close();
fw.close();
}catch (Exception e) {
e.printStackTrace();
} -
How can i save a data in text format
how can i save a data in text format in labwindows cvi
Message Edited by Tikoy on 04-14-2010 11:30 PM
Solved!
Go to Solution.Hi,
If your data is in an array, the easiest way is to use the ArrayToFile function.
It automatically creates a file and puts your data in it according to the format you provide.
If you have individual samples that you need to write once in a while, you can either collect them into an array and then use ArrayToFile or open a file with fopen and write them as they are acquired with fwrite.
Hope this helps,
S. Eren BALCI
www.aselsan.com.tr -
In Firefox 4 how can I cause the date on downloaded files to be the current date? (Some are and some are not. In FF3 the dates were ALWAYS the current ones.)
== This happened ==
Every time Firefox opened
== I upgraded to Firefox 4 (beta)Firefox 3.6.* and earlier set the downloaded file's modification time to the current time. In Firefox 4.0 the behavior has been changed, if a server returns a timestamp telling when the file was last modified (Last-Modified header), it is used instead.
You can revert to the previous behaviour by using the [https://addons.mozilla.org/en-US/firefox/addon/93121/ Download Timestamp] add-on. -
How can I read on my Apple Arabic files of Times New Roman or Arial fonts made in PC? when I get the files the Arabic letters are separate and not joined. Is there a common font in Arabic that can convert the Arabic PC Windows files to my Apple?
The same with email messages ,
And when I get Power Point files made in PC Windows, they are like PDF, not Power Point!
Anybody with a good suggestion?Yewtree wrote:
when I get the files the Arabic letters are separate and not joined
Do not use MS Word for Mac, it does not support Arabic. Instead use Mellel, TextEdit, Nisus Writer or OpenOffice. Try the font Geeza Pro if others do not work.
What are you using to read email?
What are you using to read powerpoint? -
How can i read the data fromtext fieldsin the form of bytes??
Hi friends,
How can i read the data fromtext fieldsin the form of byte string while using Socket connection.
I have two text fields. i need to send the data from the textfeilds to the server using a byte string.
Can anyboday help me???
KKDoes <cfdbinfo> work for Access DBs?
You might be better off asking this on a MS Access forum. It's more of an Access issue than a CF one.
Adam -
HOW CAN U CORRECT THE DATA IN UR FILE WHICH CONTAINS 1 LAKSH RECS
Hai Frnds,
i Attend an interview they asked this questions can u know the answeres . tell me .
In File to file scenario how can we reprocess records which failed records.
HOW CAN U CORRECT THE DATA IN UR FILE WHICH CONTAINS 1 LAKSH RECS
Thanks in advance
thahirHi,
Refer these links:
this might help you
Generic Approach for Validating Incoming Flat File in SAP XI - Part 1
Generic Approach for Validating Incoming Flat File in SAP XI - Part 1
validating against schema file for the output XML file
Informing the sender about bad records
Regards,
Nithiyanandam -
How can i stop transfer data to Trfc queue from a table datasource.help!!!
how can i stop transfer data to Trfc queue from a table datasource.
I create a incorrect view datasource in R3 with wrong join condition,it contain so large data,i want to stop it collect data to sm58.otherwise the system will be ...
i can't find helpful infrmation in sm50 .
in sm37 has a canceled job
Job Ln Job CreatedB Status Start date Start time Duration(sec.) Delay (sec.)
BIREQU_4EFQCFFUQL5ZOAWYOK2L0YCMF ALEREMOTE Canceled 2009-07-10 16:38:59 101,869 0
plesse help me 。Hi,
You paste the job name in source system in
Tcode :Sm37
Job name as :BIREQU_4EFQCFFUQL5ZOAWYOK2L0YCMF
User:*
Go to job details and get the PID no ,on which application number it is runnug
GO to sm51 ,here you will find the application servers,Select the appriate app server go to that PID.
On left top most you will find option as cancel with out core ..
OR
Ask basics team do the same.
Regards,
Suman
Edited by: suman on Jul 13, 2009 12:56 PM -
Using Lab view ver 6,How can I read a cell of excel file right after I write to it
How can I read a specif cell of an Excel file using Labview VI.
Hi,
Attached is a LV6.1 VI which will read a cell.
It will be looking for a sub VI found in the example C:\Program Files\National Instruments\LabVIEW\examples\comm\ExcelExamples.llb.
The returned value is a string value but there is no reason why it couldn't be a number. Just connect a numeric to the type connector of the Variant to Data function.
Hope this helps.
Regards
Ray Farmer
Regards
Ray Farmer
Attachments:
Get_Cell_Value.vi 41 KB
Write_Table_To_XL.vi 101 KB -
Write data to Text file - Column by Column
Hi,
I want to write a table of data(2D) to a text file. I acquire 1D array(6 lakh rows) of data & want to write that in text file as column 0. And next 1D array to the same text file as column 2. Is it possible todo that?
I don't want to accumulate 2D array and write at last since it consumes more memory & Labview Hangs.
Kindly share your ideas.....
Labview 8.2
Regards,
RajaHI,
I hope this works for you but this vi doesnt hanged my PC or Labview. Please check with it and let me know.
Regards,
Gita
Message Edited by AutoTEC on 10-17-2008 04:15 AM
Attachments:
Write column by column.vi 1398 KB -
How can I load my data faster? Is there a SQL solution instead of PL/SQL?
11.2.0.2
Solaris 10 sparc
I need to backfill invoices from a customer. The raw data has 3.1 million records. I have used pl/sql to load these invoices into our system (dev), however, our issue is the amount of time it's taking to run the load - effectively running at approx 4 hours. (Raw data has been loaded into a staging table)
My research keeps coming back to one concept: sql is faster than pl/sql. Where I'm stuck is the need to programmatically load the data. The invoice table has a sequence on it (primary key = invoice_id)...the invoice_header and invoice_address tables use the invoice_id as a foreign key. So my script takes advantage of knowing the primary key and uses that on the subsequent inserts to the subordinate invoice_header and invoice_address tables, respectively.
My script is below. What I'm asking is if there are other ideas on the quickest way to load this data...what am I not considering? I have to load the data in dev, qa, then production so the sequences and such change between the environments. I've dummied down the code to protect the customer; syntax and correctness of the code posted here (on the forum) is moot...it's only posted to give the framework for what I currently have.
Any advice would be greatly appreciated; how can I load the data faster knowing that I need to know sequence values for inserts into other tables?
DECLARE
v_inv_id invoice.invoice_id%TYPE;
v_inv_addr_id invoice_address.invoice_address_id%TYPE;
errString invoice_errors.sqlerrmsg%TYPE;
v_guid VARCHAR2 (128);
v_str VARCHAR2 (256);
v_err_loc NUMBER;
v_count NUMBER := 0;
l_start_time NUMBER;
TYPE rec IS RECORD
BILLING_TYPE VARCHAR2 (256),
CURRENCY VARCHAR2 (256),
BILLING_DOCUMENT VARCHAR2 (256),
DROP_SHIP_IND VARCHAR2 (256),
TO_PO_NUMBER VARCHAR2 (256),
TO_PURCHASE_ORDER VARCHAR2 (256),
DUE_DATE DATE,
BILL_DATE DATE,
TAX_AMT VARCHAR2 (256),
PAYER_CUSTOMER VARCHAR2 (256),
TO_ACCT_NO VARCHAR2 (256),
BILL_TO_ACCT_NO VARCHAR2 (256),
NET_AMOUNT VARCHAR2 (256),
NET_AMOUNT_CURRENCY VARCHAR2 (256),
ORDER_DT DATE,
TO_CUSTOMER VARCHAR2 (256),
TO_NAME VARCHAR2 (256),
FRANCHISES VARCHAR2 (4000),
UPDT_DT DATE
TYPE tab IS TABLE OF rec
INDEX BY BINARY_INTEGER;
pltab tab;
CURSOR c
IS
SELECT billing_type,
currency,
billing_document,
drop_ship_ind,
to_po_number,
to_purchase_order,
due_date,
bill_date,
tax_amt,
payer_customer,
to_acct_no,
bill_to_acct_no,
net_amount,
net_amount_currency,
order_dt,
to_customer,
to_name,
franchises,
updt_dt
FROM BACKFILL_INVOICES;
BEGIN
l_start_time := DBMS_UTILITY.get_time;
OPEN c;
LOOP
FETCH c
BULK COLLECT INTO pltab
LIMIT 1000;
v_err_loc := 1;
FOR i IN 1 .. pltab.COUNT
LOOP
BEGIN
v_inv_id := SEQ_INVOICE_ID.NEXTVAL;
v_guid := 'import' || TO_CHAR (CURRENT_TIMESTAMP, 'hhmissff');
v_str := str_parser (pltab (i).FRANCHISES); --function to string parse - this could be done in advance, yes.
v_err_loc := 2;
v_count := v_count + 1;
INSERT INTO invoice nologging
VALUES (v_inv_id,
pltab (i).BILL_DATE,
v_guid,
'111111',
'NONE',
TO_TIMESTAMP (pltab (i).BILL_DATE),
TO_TIMESTAMP (pltab (i).UPDT_DT),
'READ',
'PAPER',
pltab (i).payer_customer,
v_str,
'111111');
v_err_loc := 3;
INSERT INTO invoice_header nologging
VALUES (v_inv_id,
TRIM (LEADING 0 FROM pltab (i).billing_document), --invoice_num
NULL,
pltab (i).BILL_DATE, --invoice_date
pltab (i).TO_PO_NUMBER,
NULL,
pltab (i).net_amount,
NULL,
pltab (i).tax_amt,
NULL,
NULL,
pltab (i).due_date,
NULL,
NULL,
NULL,
NULL,
NULL,
TO_TIMESTAMP (SYSDATE),
TO_TIMESTAMP (SYSDATE),
PLTAB (I).NET_AMOUNT_CURRENCY,
(SELECT i.bc_value
FROM invsvc_owner.billing_codes i
WHERE i.bc_name = PLTAB (I).BILLING_TYPE),
PLTAB (I).BILL_DATE);
v_err_loc := 4;
INSERT INTO invoice_address nologging
VALUES (invsvc_owner.SEQ_INVOICE_ADDRESS_ID.NEXTVAL,
v_inv_id,
'BLAH INITIAL',
pltab (i).BILL_DATE,
NULL,
pltab (i).to_acct_no,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
SYSTIMESTAMP,
NULL);
v_err_loc := 5;
INSERT INTO invoice_address nologging
VALUES ( SEQ_INVOICE_ADDRESS_ID.NEXTVAL,
v_inv_id,
'BLAH',
pltab (i).BILL_DATE,
NULL,
pltab (i).TO_ACCT_NO,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
SYSTIMESTAMP,
NULL);
v_err_loc := 6;
INSERT INTO invoice_address nologging
VALUES ( SEQ_INVOICE_ADDRESS_ID.NEXTVAL,
v_inv_id,
'BLAH2',
pltab (i).BILL_DATE,
NULL,
pltab (i).TO_CUSTOMER,
pltab (i).to_name,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
SYSTIMESTAMP,
NULL);
v_err_loc := 7;
INSERT INTO invoice_address nologging
VALUES ( SEQ_INVOICE_ADDRESS_ID.NEXTVAL,
v_inv_id,
'BLAH3',
pltab (i).BILL_DATE,
NULL,
'SOME PROPRIETARY DATA',
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
SYSTIMESTAMP,
NULL);
v_err_loc := 8;
INSERT
INTO invoice_event nologging (id,
eid,
root_eid,
invoice_number,
event_type,
event_email_address,
event_ts)
VALUES ( SEQ_INVOICE_EVENT_ID.NEXTVAL,
'111111',
'222222',
TRIM (LEADING 0 FROM pltab (i).billing_document),
'READ',
'some_user@some_company.com',
SYSTIMESTAMP);
v_err_loc := 9;
INSERT INTO backfill_invoice_mapping
VALUES (v_inv_id,
v_guid,
pltab (i).billing_document,
pltab (i).payer_customer,
pltab (i).net_amount);
IF v_count = 10000
THEN
COMMIT;
END IF;
EXCEPTION
WHEN OTHERS
THEN
errString := SQLERRM;
INSERT INTO backfill_invoice_errors
VALUES (
pltab (i).billing_document,
pltab (i).payer_customer,
errString || ' ' || v_err_loc
COMMIT;
END;
END LOOP;
v_err_loc := 10;
INSERT INTO backfill_invoice_timing
VALUES (
ROUND ( (DBMS_UTILITY.get_time - l_start_time) / 100,
2)
|| ' seconds.',
(SELECT COUNT (1)
FROM backfill_invoice_mapping),
(SELECT COUNT (1)
FROM backfill_invoice_errors),
SYSDATE
COMMIT;
EXIT WHEN c%NOTFOUND;
END LOOP;
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
errString := SQLERRM;
INSERT INTO backfill_invoice_errors
VALUES (NULL, NULL, errString || ' ' || v_err_loc);
COMMIT;
END;Hello
You could use insert all in your case and make use of sequence.NEXTVAL and sequence.CURRVAL like so (excuse any typos - I can't test without table definitions). I've done the first 2 tables, so it's just a matter of adding the rest in...
INSERT ALL
INTO invoice nologging
VALUES ( SEQ_INVOICE_ID.NEXTVAL,
BILL_DATE,
my_guid,
'111111',
'NONE',
CAST(BILL_DATE AS TIMESTAMP),
CAST(UPDT_DT AS TIMESTAMP),
'READ',
'PAPER',
payer_customer,
parsed_francises,
'111111'
INTO invoice_header
VALUES ( SEQ_INVOICE_ID.CURRVAL,
TRIM (LEADING 0 FROM billing_document), --invoice_num
NULL,
BILL_DATE, --invoice_date
TO_PO_NUMBER,
NULL,
net_amount,
NULL,
tax_amt,
NULL,
NULL,
due_date,
NULL,
NULL,
NULL,
NULL,
NULL,
SYSTIMESTAMP,
SYSTIMESTAMP,
NET_AMOUNT_CURRENCY,
bc_value,
BILL_DATE)
SELECT
src.billing_type,
src.currency,
src.billing_document,
src.drop_ship_ind,
src.to_po_number,
src.to_purchase_order,
src.due_date,
src.bill_date,
src.tax_amt,
src.payer_customer,
src.to_acct_no,
src.bill_to_acct_no,
src.net_amount,
src.net_amount_currency,
src.order_dt,
src.to_customer,
src.to_name,
src.franchises,
src.updt_dt,
str_parser (src.FRANCHISES) parsed_franchises,
'import' || TO_CHAR (CURRENT_TIMESTAMP, 'hhmissff') my_guid,
i.bc_value
FROM BACKFILL_INVOICES src,
invsvc_owner.billing_codes i
WHERE i.bc_name = src.BILLING_TYPE;Some things to note
1. Don't commit in a loop - you only add to the run time and load on the box ultimately reducing scalability and removing transactional integrity. Commit once at the end of the job.
2. Make sure you specify the list of columns you are inserting into as well as the values or columns you are selecting. This is good practice as it protects your code from compilation issues in the event of new columns being added to tables. Also it makes it very clear what you are inserting where.
3. If you use WHEN OTHERS THEN... to log something, make sure you either rollback or raise the exception. What you have done in your code is say - I don't care what the problem is, just commit whatever has been done. This is not good practice.
HTH
David
Edited by: Bravid on Oct 13, 2011 4:35 PM -
How can I called java.lang.Math.sqr function from PL/SQL?
JVM is loaded and I've queried the system table showing there are more than 9000 JAVA class objects.
When I try something like:
select java.lang.Math.sqrt(9) from dual;
I get ORA-00904 (invalid column name) error. How can I invoke standard java.lang.Math methods in PL/SQL?
tiaYou need to write a PL/SQL wrapper for the java call.
Then you just call the PL/SQL function..
-------PL/SQL wrapper
FUNCTION GetFullName( code varchar2) RETURN NUMBER
AS LANGUAGE JAVA
NAME 'ResponseXml.GetPersonFullName(java.lang.String) return java.lang.String';
Now you can do
Select GetFullName( 'mycous' ) from dual; -
How can i read the data from attached file?
using javamail i receiving a mail with attachment
but unable to read the content of the file
Plz help me out
thanks in advanceThe answer is in the JavaMail FAQ.
-
Write data to text file on command using trigger
Hi there
I'm kinda new to using Labview, and i seek some advices.
I've got this program, which is used to read from a usb-device (6215). It measures the voltage at an input channel on the usb-device, and processes it, and finally writes the data to a txt file. I want to control when it writes the data (only one instance/ measurement at a time) via a trigger.
The problem is, that the trigger does not work. It always writes to the file i have specified. Can anyone help me getting this right?
Furthermore, if someone have any suggestions how to make the data in the text file more readable (i'dd suggest using colums - but how?) i would greatly appreciate it. Maybe converting to an exel-document could be the answer?
Thank you in advance, Troels
Ps:
Hope you can see past the danish text
Attachments:
Sensor.vi 12 KBYour true and false cases are identical and the file write is outside of the case statement. The boolean trigger does nothing. Why don't you try putting the file write inside the true case statement and nothing in the false case? You wouls also place the DAQmx Read inside the true case.
If you are not going to use an event structure (but you should), place a Wait (ms) function inside the loop.
Maybe you are looking for
-
Error of u0093test configurationu0094
Hi,gurus: when i do the tool->test configuration in the ID,an error occured,it displays :" Interface Mapping Runtime error java.lang.NullPointerException thrown during application mapping com/sap/xi/tf/_MM_ASC2XML_:" what's wrong whit the message map
-
IPad doesn't see iWork documents in iCloud
I bought a new 4th generation iPad yesterday and immediately installed Pages & Numbers, thinking I would be able to access all the iWork documents I have in in iCloud. Thus far I haven't been able to figure out how to do this. I have iCloud turned
-
MacBook Screen Flashes and Refreshes every 2 seconds after autoupdate
My daughter installed updates last nite (she thinks itunes, safari, quicktime?) and now her computer will turn on but the display keeps refreshing and will not completely display all her usual icons. I tried resetting the PRAM (Control Command P R) a
-
When I direct aperture to a folder on my hard drive, where I have imported some .fff and .dng files the files are unseen, even tho you can see them in the finder, just not in the import window in aperture???
-
Firefox crashes on linux mint 14
I am using firefox 30.0 on linux mint 14 - nadia. And, I am constantly experiencing sporadic crashes. About 5-6 time firefox crashes on my system. I have tried resetting the firefox, with add-ons disabled in the safe mode and also updated the flash p