HOW TO READ DATA FROM A FILE AND INSERT INTO A TABLE USING UTL_FILE
Hi..
I have a file.I want to read the data from file and load it into a table using utl_file.
how can I do it?
Any reply apreciated...
Hi,
This is not your requirment but u can try this :
CREATE OR REPLACE DIRECTORY text_file AS 'D:\TEXT_FILE\';
GRANT READ ON DIRECTORY text_file TO fah;
GRANT WRITE ON DIRECTORY text_file TO fah;
DROP TABLE load_a;
CREATE TABLE load_a
(a1 varchar2(20),
a2 varchar2(200))
ORGANIZATION EXTERNAL
(TYPE ORACLE_LOADER
DEFAULT DIRECTORY text_file
ACCESS PARAMETERS
(FIELDS TERMINATED BY ','
LOCATION ('data.txt')
select * from load_a;
CREATE TABLE A AS select * from load_a;
SELECT * FROM A
Regards
Faheem Latif
Similar Messages
-
How to get the data from a file and insert into a table
Good morning,
NEED TO READ THIS FILE sui_facturacion_alcantarillado_15085_2011_01_76845_00A.csv containing the following information
NUID,NUMERO_DE_CUENTA_CONTRATO,CÓDIGO_DANE_DEPARTAMENTO,CÓDIGO_DANE_MUNICIPIO,ZONA_IGAC,SECTOR_IGAC,MANZANA_O_VEREDA_IGAC,NÚMERO_DEL_PREDIO_IGAC,CONDICION_DE_PROPIEDAD_DEL_PREDIO_IGAC,DIRECCIÓN_DEL_PREDIO,NÚMERO_DE_FACTURA,FECHA_DE_EXPEDICIÓN_DE_LA_FACTURA,FECHA_DE_INICIO_DEL_PERÍODO_DE_FACTURACIÓN,DIAS_FACTURADOS,CÓDIGO_CLASE_DE_USO,UNIDADES_MULTIUSUARIO_RESIDENCIAL,UNIDADES_MULTIUSUARIO_NO_RESIDENCIAL,HOGAR_COMUNITARIO_O_SUSTITUTO,USUARIO_FACTURADO_CON_AFORO,USUARIO_CUENTA_CON_CARACTERIZACIÓN,CARGO_FIJO,CARGO_POR_VERTIMIENTO_BASICO,CARGO_POR_VERTIMIENTO_COMPLEMENTARIO,CARGO_POR_VERTIMIENTOSUNTUARIO,CMT,VERTIMIENTO_DEL_PERIOD_EN_METROS_CUBICOS,VALOR_FACTURADO_POR_VERTIDO,VALOR_DEL_SUBSIDIO,VALOR_DE_LA_CONTRIBUCIÓN,FACTOR_DE_SUBSIDIO_O_CONTRIBUCIÓN_CARGO_FIJO,FACTOR_DE_SUBSIDIO_O_CONTRIBUCIÓN_VERTIMIENTO,CARGOS_POR_CONEXIÓN,PAGO_ANTICIPADO_DEL_SERVICIO,DÍAS_DE_MORA,VALOR_DE_MORA,INTERESES_POR_MORA,OTROS_COBROS,CAUSAL_DE_REFACTURACIÓN,NUMERO_DE_LA_FACTURA_OBJETO_DE_REFACTURACIÓN,VALOR_TOTAL_FACTURADO,PAGOS_DEL_CLIENTE_DURANTE_EL_PERÍODO_FACTURADO
242602,242602,76,845,99,99,9999,9999,999,CLL 5 CRA 7 PEATONAL,24911920,12-01-2011,01-12-2010,30,01,,,0,0,0,1,0000000000.00,0000000000.00,0000000000.00,0000000000.00,0000000005,0000002200.00,0000000000,0000000000,0.000,0.000,0000000000.00,0000000000.00,0,0000000000.00,0000000000.00,0000000000.00,0,0,0000002201.00,0000000000.00
242604,242604,76,845,99,99,9999,9999,999,CRA 4 # 6 - 13,24911846,12-01-2011,01-12-2010,30,01,,,0,0,0,1,0000000000.00,0000000000.00,0000000000.00,0000000000.00,0000000013,0000002200.00,0000000000,0000000000,0.000,0.000,0000000000.00,0000000000.00,0,0000000000.00,0000000000.00,0000000000.00,0,0,0000002201.00,0000004411.00
242605,242605,76,845,99,99,9999,9999,999,CRA 2 CLLES 3 Y 4,24911509,12-01-2011,01-12-2010,30,01,,,0,0,0,1,0000000000.00,0000000000.00,0000000000.00,0000000000.00,0000000004,0000002200.00,0000000000,0000000000,0.000,0.000,0000000000.00,0000000000.00,0,0000000000.00,0000000000.00,0000000000.00,0,0,0000002201.00,0000002200.00
this is the function that I have
<<function_test>>
DECLARE
TOTAL_CAR NUMBER;
POS_1 NUMBER:= 0;
POS_2 NUMBER:= 0;
REST NUMBER:= 0;
ACUM NUMBER:= 0;
CADEN VARCHAR2(200);
nom_archivo varchar2(80);
v1 utl_file.file_type;
v2 varchar2(2048);
BEGIN
nom_archivo := 'sui_facturacion_alcantarillado_15085_2011_01_76845_00A.csv';
v1:= utl_file.fopen('PUBLIC_ACCESS',nom_archivo,'R',32767);
utl_file.get_line(v1,v2);
SELECT LENGTH(v2) INTO TOTAL_CAR FROM DUAL;
ACUM:=1;
POS_1:=0;
WHILE ACUM <= 60
LOOP
select instr(v2, ',', 1, ACUM) PRUEBA
INTO POS_2
FROM DUAL;
dbms_output.put_line(' TOTAL POSICION 1--> '|| POS_1);
dbms_output.put_line(' TOTAL POSICION 2--> '|| POS_2);
dbms_output.put_line(' TOTAL ACUMULADO --> '|| ACUM);
REST := (POS_2-POS_1)-1;
SELECT SUBSTR(v2,(POS_1+1),REST) PRUEBA2
INTO CADEN
FROM DUAL;
dbms_output.put_line(' CADENA SELECCIONADA --> '|| CADEN);
ACUM := ACUM + 1;
POS_1:= POS_2;
END LOOP;
utl_file.fclose(v1);
dbms_output.put_line(' -->');
dbms_output.put_line(' TOTAL POSICION 1-->'|| POS_1);
dbms_output.put_line(' TOTAL POSICION 2-->'|| POS_2);
dbms_output.put_line(' TOTAL ACUMULADO -->'|| ACUM);
dbms_output.put_line(' TOTAL DE CARACTERES -->'|| TOTAL_CAR);
dbms_output.put_line(' ');
EXCEPTION
WHEN NO_DATA_FOUND THEN
dbms_output.put_line('NO SE ENCONTRARON MAS CARACTERES');
WHEN OTHERS THEN
dbms_output.put_line('OTRO TIPO DE ERROR ');
dbms_output.put_line('CODIGO ERROR '|| SQLCODE ||' '||SQLERRM);
END;
Which must be separated by a comma and enter a table I have the following procedure in which only brings me the first line, which need not
The current role I have just read and extract data from the row number 1, I do not need information.
I need information for rows 2,3,4. In each row there are 41 fields, which I enter in a table called Dato_archivos.
how to perform this function? ...
I appreciate the cooperation and explanation ...
GOOD DAY ...
REYNEL SALAZAR MARTINEZ
COLOMBIA ...When you get an error with external tables (or sql*loader) look in the same folder as the data file and you should get a .log file and maybe a .bad file too.
The log file should indicate the nature of the error it has trying to load the data.
I've just copied your sample data from your first post to a file on my server and tried it to find that you are not specifying the required format for your dates. The below shows it now working...
CREATE TABLE tabla_prueba
(NUID NUMBER,
NUM_CUENTA_CONTRATO NUMBER,
COD_DANE_DD NUMBER,
COD_DANE_MM NUMBER,
ZONA_IGAC NUMBER,
SECTOR_IGAC NUMBER,
MANZANA_VEREDA_IGAC NUMBER,
NUM_PREDIO_IGAC NUMBER,
CONDICION_PREDIO_IGAC NUMBER,
DIRECCION_PREDIO_IGAC VARCHAR2(80),
NUM_FACTURA NUMBER,
FECHA_EXPED_FACTURA DATE,
FECHA_INI_PERIODO_FACTURACION DATE,
DIAS_FACTURADOS NUMBER,
COD_CLASE_USO NUMBER,
UNI_MULTIUSUARIO_RESIDENCIAL NUMBER,
UNI_MULTIUSUARIO_NORESIDENCIAL NUMBER,
HOGAR_COMUNITARIO NUMBER,
USUARIO_FACTURADO_AFORO NUMBER,
USUARIO_CON_CARACTERIZACION NUMBER,
CARGO_FIJO NUMBER,
CARGO_VERTIMENTO_BAS NUMBER,
CARGO_VERTIMENTO_COMP NUMBER,
CARGO_VERTIMENTO_SUNT NUMBER,
CMT NUMBER,
VLR_FACTURADO_VERTIDO NUMBER,
VLR_SUBSIDIO NUMBER,
VLR_CONTRIBUCCION NUMBER,
FACTOR_SUBS_CONTR_CARGO_FIJO NUMBER,
FACTOR_SUBS_CONTR_VERTIMENTO NUMBER,
CARGO_CONEXION NUMBER,
PAGO_ANTICIPADO_SERVICIO NUMBER,
DIAS_MORA NUMBER,
VLR_MORA NUMBER,
INTERES_MORA NUMBER,
OTROS_COBROS NUMBER,
CAUSAL_REFACTURACION NUMBER,
NUM_FACTURA_OBJ_REFACTURACION NUMBER,
VLR_TOTAL_FACTURADO NUMBER,
PAGOS_CLIENTE_DURANTE_PERIODO NUMBER
ORGANIZATION EXTERNAL
(TYPE ORACLE_LOADER
DEFAULT DIRECTORY TEST_DIR
ACCESS PARAMETERS
(RECORDS DELIMITED BY NEWLINE
SKIP 1
FIELDS TERMINATED BY ","
OPTIONALLY ENCLOSED BY '"'
(NUID,
NUM_CUENTA_CONTRATO,
COD_DANE_DD,
COD_DANE_MM,
ZONA_IGAC,
SECTOR_IGAC,
MANZANA_VEREDA_IGAC,
NUM_PREDIO_IGAC,
CONDICION_PREDIO_IGAC,
DIRECCION_PREDIO_IGAC,
NUM_FACTURA,
FECHA_EXPED_FACTURA CHAR DATE_FORMAT DATE MASK "DD-MM-YYYY",
FECHA_INI_PERIODO_FACTURACION CHAR DATE_FORMAT DATE MASK "DD-MM-YYYY",
DIAS_FACTURADOS,
COD_CLASE_USO,
UNI_MULTIUSUARIO_RESIDENCIAL ,
UNI_MULTIUSUARIO_NORESIDENCIAL,
HOGAR_COMUNITARIO ,
USUARIO_FACTURADO_AFORO ,
USUARIO_CON_CARACTERIZACION ,
CARGO_FIJO ,
CARGO_VERTIMENTO_BAS ,
CARGO_VERTIMENTO_COMP,
CARGO_VERTIMENTO_SUNT,
CMT,
VLR_FACTURADO_VERTIDO,
VLR_SUBSIDIO ,
VLR_CONTRIBUCCION ,
FACTOR_SUBS_CONTR_CARGO_FIJO ,
FACTOR_SUBS_CONTR_VERTIMENTO ,
CARGO_CONEXION ,
PAGO_ANTICIPADO_SERVICIO ,
DIAS_MORA ,
VLR_MORA ,
INTERES_MORA ,
OTROS_COBROS ,
CAUSAL_REFACTURACION ,
NUM_FACTURA_OBJ_REFACTURACION,
VLR_TOTAL_FACTURADO,
PAGOS_CLIENTE_DURANTE_PERIODO
LOCATION ('test.csv')
SQL> select * from tabla_prueba;
NUID NUM_CUENTA_CONTRATO COD_DANE_DD COD_DANE_MM ZONA_IGAC SECTOR_IGAC MANZANA_VEREDA_IGAC NUM_PREDIO_IGAC CONDICION_PREDIO_IGAC DIRECCION_PREDIO_IGAC NUM_FACTURA FECHA_EXPE FECHA_INI_
DIAS_FACTURADOS COD_CLASE_USO UNI_MULTIUSUARIO_RESIDENCIAL UNI_MULTIUSUARIO_NORESIDENCIAL HOGAR_COMUNITARIO USUARIO_FACTURADO_AFORO USUARIO_CON_CARACTERIZACION CARGO_FIJO CARGO_VERTIMENTO_BAS CARGO_VERTIMENTO_COMP CARGO_VERTIMENTO_SUNT CMT
VLR_FACTURADO_VERTIDO VLR_SUBSIDIO VLR_CONTRIBUCCION FACTOR_SUBS_CONTR_CARGO_FIJO FACTOR_SUBS_CONTR_VERTIMENTO CARGO_CONEXION PAGO_ANTICIPADO_SERVICIO DIAS_MORA VLR_MORA INTERES_MORA OTROS_COBROS CAUSAL_REFACTURACION NUM_FACTURA_OBJ_REFACTURACION
VLR_TOTAL_FACTURADO PAGOS_CLIENTE_DURANTE_PERIODO
242602 242602 76 845 99 99 9999 9999 999 CLL 5 CRA 7 PEATONAL 24911920 12-01-2011 01-12-2010
30 1 0 0 0 1 0 0 0 0
5 2200 0 0 0 0 0 0 0 0 0 0 0
0 2201
242604 242604 76 845 99 99 9999 9999 999 CRA 4 # 6 - 13 24911846 12-01-2011 01-12-2010
30 1 0 0 0 1 0 0 0 0
13 2200 0 0 0 0 0 0 0 0 0 0 0
0 2201
242605 242605 76 845 99 99 9999 9999 999 CRA 2 CLLES 3 Y 4 24911509 12-01-2011 01-12-2010
30 1 0 0 0 1 0 0 0 0
4 2200 0 0 0 0 0 0 0 0 0 0 0
0 2201
SQL>
{code} -
How to read the data from XML file and insert into oracle DB
Hi All,
I have below require ment.
I will receive data in the XML file. then i need to read that data and insert into oracle tables. please let me know how this can be handled.
Many Thanks.Sounds a lot like this question, only with less details.
how to read data from XML variable and insert into table variable
We can only help if you provide us details to help as we cannot see what you are doing and only know what you tell us. Plenty of examples abound on the forums that cover the topics you seek as well. -
Hi, extract data from xml file and insert into another exiting xml file
i am searching code to extract data from xml file and insert into another exiting xml file by a java program. I understood it is easy to extract data from a xml file, and how ever without creating another xml file. We want to insert the extracted data into another exiting xml file. Suggestions?
1st xml file which has two lines(text1.xml)
<?xml version="1.0" encoding="iso-8859-1"?>
<xs:PrintDataRequest xmlns:xs="http://com.unisys.com/Anid"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://com.unisys.com/Anid file:ANIDWS.xsd">
<xs:Person>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://com.unisys.com/Anid file:ANIDWS.xsd">
These two lines has to be inserted in the existing another xml(text 2.xml) file(at line 3 and 4)
Regards,
bubblyJadz_Core wrote:
RandomAccessFile? If you know where you want to insert it.Are you sure about this? If using this, the receiving file would have to have bytes inserted that exactly match the number of bytes replaced. I'm thinking that you'll likely have to stream through the second XML with a SAX parser and copy information (or insert new information) as you stream with an XML writer of some sort. -
Extract data from xml file and insert into another exiting xml fil
hello,
i am searching extract data from xml file and insert into another exiting xml file by a java program. I understood it is easy to extract data from a xml file, and how ever without creating another xml file. We want to insert the extracted data into another exiting xml file. Suggestions?
Regards,
ZhuozhiIf the files are small, you can load the target file in a DOM document, insert the data from the source file and persist the DOM.
If the files are large, you probably want to use a StAX or SAX. -
Reading Data from Unix file and write into an Internal table
Dear all,
I am having an requirement of reading data from unix file and write the same into an internal table..how to do that ...experts please help me in this regard.Hi,
do like this
PARAMETERS: p_unix LIKE rlgrap-filename OBLIGATORY.
DATA: v_buffer(2047) TYPE c.
DATA: BEGIN OF i_buffer OCCURS 0,
line(2047) TYPE c,
END OF i_buffer.
* Open the unix file..
OPEN DATASET p_unix FOR INPUT IN TEXT MODE.
<b>IF sy-subrc NE 0.
*** Error Message "Unable to open file.
ELSE.</b>
DO.
CLEAR: v_buffer.
READ DATASET p_unix INTO v_buffer.
IF sy-subrc NE 0.
EXIT.
ENDIF.
MOVE v_buffer TO i_buffer.
APPEND i_buffer.
ENDDO.
ENDIF.
CLOSE DATASET p_unix.
<b>Reward points if it helps,</b>
Satish -
Reading data From XML file and setting into ViewObject to Pouplate ADF UI
Hi,
I have following requirement.
I would like to read data from XML file and populate the data in ViewObject so that the data can be displayed in the ADF UI.
Also when user modifies the data in the ADF UI, it should be modified back into to ViewObject.
Here is an example - XML file contains Book Title and Author. I would like to read Book Title and Author from XML file and set it into ViewObject Attribute and then display Book title and Author in ADF UI page. Also when user modifies Book title and Author, I would like to store it back in View Object.
Please help me with this requirement and let me know if any solution exist in ADF, for populating the ADF UI screen fields with external XML file data.
ThanksRead chapter 42 http://download.oracle.com/docs/cd/E16162_01/web.1112/e16182/bcadvvo.htm of the fusion developer guide
Section 42.7, "Reading and Writing XML"
Section 42.8, "Using Programmatic View Objects for Alternative Data Sources"
Timo -
Pool data from text file and insert into database
Can anyone tell me how to pool data from a text file and insert into database?
let's say my text file is in this format
123456 Peter 22
234567 Nicholas 24
345678 Jane 20
Then I need to insert the all the value for this three column into a table which has the three column name ID, Name, Age
Anyone knows? I need to do this urgently...Thank in advanced1. Use BufferedReader and read the file line by line.
2. Loop thru the file and do the following steps with in this loop.
3. Use StringTokenizer to seperate each line into three values (columns).
4. Now create a insert statement with these values and add the statement to the batch (using addBatch() method of PreparedStatement or Statement).
5. Finally (after exiting the loop), execute these batch of statements (using ps.executeBatch()).
Sudha -
How to read the data from excel file and store into the table?
Hi All,
I have table with BLOB datatype contains a excel file. I have to read that data from excel and store into one table with all the fields in excel.
All the excel fields and my table columns are same.
Can you share with me how can acheive this using LOB's?
ThanksHi OraSuirya,
you can try with external tables .
syntax as follows
create table ext_table_csv (
i Number,
n Varchar2(20),
m Varchar2(20)
organization external (
type oracle_loader
default directory ext_dir
access parameters (
records delimited by newline
fields terminated by ','
missing field values are null
location ('file.csv')
reject limit unlimited;
For this you need to create directory
Directory Creation syntax:
create or replace directory ext_dir as 'D:\oracle\user_dir\ext_dir';
grant read, write on directory ext_dir to <User>;
please paste the excel file in the particular directory .
I hope this will help you.
Please correct me if I am wrong anywhere .
Thanks,
Tippu. -
How to read data from multiple files and append in columns in one file
Hi Guys,
I have a problem in appending data from files in different columns. I have attachement has file A and B which I am reading and not able to get data as in file Result.txt. Please comment on how can I do this
Solved!
Go to Solution.
Attachments:
Write to file.vi 13 KB
A.txt.txt 1 KB
B.txt.txt 1 KBYou cannot append columns to an existing file. Since the data is arrange line-by-line as one long linear string in the file, you can only append rows. A new row needs to be interlaced into the original file, shifting everything else. If you want to append rows, you need to build the entire output structure in memory and then write all at once.
(I also don't think you need to set the file positions, it will be remembered from the last write operation.)
Unless the files are gigantic, here's what I would do:
(Also note that some of your rows have an extra tab at the end. If this is normal, you need a little bit more code to strop out empty columns. I include cleaned up files in the attachment. I also would not call them A.txt.txt etc. A plain A.txt is probably sufficient.)
EDIT: It seems Dennis's solution is similar )
LabVIEW Champion . Do more with less code and in less time .
Attachments:
Write to fileMOD.zip 6 KB
MergeColumns.png 6 KB -
How to read data from SharePoint list and append to html table?
Hi All,
I would like to create custom view of SharePoint list, so want to append those sharepoint list items in a custom html table design using content editor webpart.
How to achieve this? thanks in advance!Content edit web part is not the right control. You can either Content Query Web Part
or Data view web part, where you need to modify xslt template using
SharePoint Designer and can render list data as per choice.
For Content Query Web Part:
Using the Content Query Web Part
Customizing the Content Query Web Part and Item Style
How to Customize SharePoint List Content Display using Content Query Web Part
For Data View Web Parts
Working with Data view Web Parts
Adnan Amin MCT, SharePoint Architect | If you find this post useful kindly please mark it as an answer. -
How to read data from a file that was formatted by excel?
Hi everyone, I'm familiar with java.io and the ability to read from files, can anyone tell me how to read data from a file that was formatted by excel? Or at least give me some web references so that I can learn about it?
http://jakarta.apache.org/poi/hssf/index.html
HSSF stands for Horrible Spreadsheet Format, but it still works! -
Read data from xml files and populate internal table
Hi.
How to read data from xml files into internal tables?
Can u tell me the classes and methods to read xml data..
Can u explain it with a sample program...<pre>DATA itab_accontextdir TYPE TABLE OF ACCONTEXTDIR.
DATA struct_accontextdir LIKE LINE OF itab_accontextdir.
DATA l_o_error TYPE REF TO cx_root.
DATA: filename type string ,
xmldata type xstring .
DATA: mr TYPE REF TO if_mr_api.
mr = cl_mime_repository_api=>get_api( ).
mr->get( EXPORTING i_url = 'SAP/PUBLIC/BC/xml_files_accontext/xml_accontextdir.xml'
IMPORTING e_content = xmldata ).
WRITE xmldata.
TRY.
CALL TRANSFORMATION id
SOURCE XML xmldata
RESULT shiva = itab_accontextdir.
CATCH cx_root INTO l_o_error.
ENDTRY.
LOOP AT itab_accontextdir INTO struct_accontextdir.
WRITE: / struct_accontextdir-context_id,
struct_accontextdir-context_name,
struct_accontextdir-context_type.
NEW-LINE.
ENDLOOP.</pre>
<br/>
Description:
In the above code snippet I am storing the data in an xml file(you know xml is used to store and transport data ) called 'xml_accontextdir.xml' that is uploaded into the MIME repository at path 'SAP/PUBLIC/BC/xml_files_accontext/xml_accontextdir.xml'.
The below API is used to read a file in MIME repo and convert it into a string that is stored in ' xmldata'. (This is just a raw data that is got by appending the each line of xml file).
mr = cl_mime_repository_api=>get_api( ).
mr->get( EXPORTING i_url = 'SAP/PUBLIC/BC/xml_files_accontext/xml_accontextdir.xml'
IMPORTING e_content = xmldata ).
Once the 'xmldata' string is available we use the tranformation to parse the xml string that we have got from the above API and convert it into the internal table.
<pre>TRY.
CALL TRANSFORMATION id
SOURCE XML xmldata
RESULT shiva = itab_accontextdir.
CATCH cx_root INTO l_o_error.
ENDTRY.</pre>
Here the trasnsformation 'id ' is used to conververt the source xml 'xmldata' to resulting internal table itab_accontextdir, that have same structure as our xml file 'xml_accontextdir.xml'. In the RESULT root of the xml file has to be specified. (In my the root is 'shiva').
Things to be taken care:
One of the major problem that occurs when reading the xml file is 'format not compatible with the internal table' that you are reading into internal table. Iin order to get rid of this issue use one more tranformation to convert the data from the internal table into the xml file.
<pre>TRY.
CALL TRANSFORMATION id
SOURCE shiv = t_internal_tab
RESULT XML xml.
CATCH cx_root INTO l_o_error.
ENDTRY.
WRITE xml.
NEW-LINE.</pre>
<br/>
This is the same transformation that we used above but the differnce is that the SOURCE and RESULT parameters are changed the source is now the internal table and result is *xml *string. Use xml browser that is available with the ABAP workbench to read the xml string displayed with proper indentation. In this way we get the format of xml file to be used that is compatable with the given internal table.
Thank you, Hope this will help you!!!
Edited by: Shiva Prasad L on Jun 15, 2009 7:30 AM
Edited by: Shiva Prasad L on Jun 15, 2009 11:56 AM
Edited by: Shiva Prasad L on Jun 15, 2009 12:06 PM -
How to read data from a file in OSB
hi guys,
Recently, I've got a problem with reading file from specific location. I've actually followed this post OSB 11g - Read or Poll File in OSB - Oracle Fusion Middleware Blog, and then
I know how to read a file. However, it does not as expected. Because, I've found no way to read data from the file. Therefore, no chance to manipulate the data like assigning to a variable, or extracting ....
Hence, is there any way to read data from file by using proxy service in OSB ??? No Java code ???
by the way, supposed that there is no way to read data from a file in OSB. So, What purposes will the way in the post above be used for?
Many thanks in advancehttp://jakarta.apache.org/poi/hssf/index.html
HSSF stands for Horrible Spreadsheet Format, but it still works! -
Read data from Excel file and diaplay in Webdynpro
Hi all,
I need some help. I have a Excel file with set of name, phonenumbers . I want to know how to display the data using Webdynpro. Could some one help me. help is appreciated and I promise to award points for right answer.
Thank you
Maruti<b>Hi
i can explain you to read data from Excel file
First You have to download the jxl.jar file. You can get this file from the Below site
</b><a href="http://www.andykhan.com/jexcelapi/download.html">jexcelapi jar</a>
It will be in Compressed Fromat So Unzip it to get the Contents
After Unzipping The File You will get a Folder (jexcelapi/jxl.jar)
Now in NWDS open web dynpro explorer, Right Click Your Project, a popup menu will appear and in that click Properties
You will get window displaying your Project Properties
On Left Side of the window You Will Find "Java Build Path"
Click That "Java Build Path" and you will get 4 Tabs Showing ( Source,Projects,Libraries,Order and Export)
Click Libraries Tab
You will find options many options buttons
In that click the Button "Add External Jars"
You will get Window in order to fecth the jxl.jar file from the location you had stored
After selecting the jxl.jar i will get displayed and click ok
Now Open Navigator
Open Your Project
You will find Lib folder
Copy the jxl.jar to that lib folder
Note : You cannot Read the Content from the excel file directly
First You Have to copy that file to the Server,
And from the Server you can get the file absolute path
With the absolute path you can read the contents of the Excel file
You have to save the Excel file as .xls Format and Not as xlsx format i will not accept that...
You have Upload the Excel file from the Server Using the File Upload UI Element
This Coding will extract 3 columns from the Xls File
Coding
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import com.sap.fileupload.wdp.IPrivateFileUpload_View;
import com.sap.tc.webdynpro.services.sal.datatransport.api.IWDResource;
public void onActionUpload_File(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
//@@begin onActionUpload_File(ServerEvent)
IPrivateFileUpload_View.IContextElement element1 = wdContext.currentContextElement();
IWDResource resource = element1.getFileResource();
element1.setFileName(resource.getResourceName());
element1.setFileExtension(resource.getResourceType().getFileExtension());
//@@end
public void onActionUpload_File_in_Server(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
//@@begin onActionUpload_File_in_Server(ServerEvent)
InputStream text=null;
int temp=0;
try
File file = new File(wdContext.currentContextElement().getFileResource().getResourceName().toString());
FileOutputStream op = new FileOutputStream(file);
if(wdContext.currentContextElement().getFileResource()!=null)
text=wdContext.currentContextElement().getFileResource().read(false);
while((temp=text.read())!=-1)
op.write(temp);
op.flush();
op.close();
path = file.getAbsolutePath();
wdComponentAPI.getMessageManager().reportSuccess(path);
catch(Exception e)
e.printStackTrace();
//@@end
public void onActionUpload_Data_into_Table(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
//@@begin onActionUpload_Data_into_Table(ServerEvent)
try
Workbook wb =Workbook.getWorkbook(new File(path));
Sheet sh = wb.getSheet(0);
//wdComponentAPI.getMessageManager().reportSuccess("Columns = "+sh.getColumns());
//wdComponentAPI.getMessageManager().reportSuccess("Rows = "+sh.getRows());
int columns = sh.getColumns();
int rows = sh.getRows();
int i=0;
for(int j=1;j<=rows;j++)
ele=wdContext.nodeTable_Data().createTable_DataElement();
Cell c1 = sh.getCell(i,j);
ele.setTab_Name(c1.getContents());
Cell c2 = sh.getCell(i+1,j);
ele.setTab_Degree(c2.getContents());
Cell c3 = sh.getCell(i+2,j);
ele.setTab_Percentage(c3.getContents());
wdContext.nodeTable_Data().addElement(ele);
catch(Exception ex)
wdComponentAPI.getMessageManager().reportSuccess(ex.toString());
//@@end
* The following code section can be used for any Java code that is
* not to be visible to other controllers/views or that contains constructs
* currently not supported directly by Web Dynpro (such as inner classes or
* member variables etc.). </p>
* Note: The content of this section is in no way managed/controlled
* by the Web Dynpro Designtime or the Web Dynpro Runtime.
//@@begin others
String path;
IPrivateFileUpload_View.ITable_DataElement ele;
//@@end
Regards
Chandran S
Maybe you are looking for
-
Return national language strings from java stored procedures
Hi, all. How does i can return String which contains national characters from java stored procedure? I.e. convert UTF java string to national language of database. It's does not processing automatically (why?). declaration of procedure: CREATE OR REP
-
Webutil - CLIENT_OLE2 for exporting to MS Word
I've done a lot of reading about this on the net, and have been unable to find the solution, perhaps someone on here knows. I am attempting to launch a word document and fill it with some text. A very simple small block of code (taken from an example
-
Unable to start Essbase app when activating JVM in Essbase.cfg
Hi, I am using Essbase 6.5.3, one of my application that uses a CDF won't start when activating the JVM in Essbase.cfg. Please help. Thanks.
-
Hello</b>, I want to create a JSP using HTMLB tag. My problem is that i'dont how to do this well ? I created some JSP exactly as in the samples I found but it doesn't work when I ran them on my EP6. The view stay empty ?! By default, NWDS don't put t
-
Problem about constraints and validation
hi I want to add new unique constraint into a table. But current data does not fit to constraint. My constraint is like this: ALTER TABLE T_STUDENT ADD CONSTRAINT UNIQ_STUDENT UNIQUE (STUDENT_NUMBER, NAME, SURNAME) DISABLE VALIDATE; I want to add con