How can I extract the data from a csv file and insert it into an Oracle table? (UTL_FILE)

Hi, please help me whit this query

Im trying to extrate the data in a file csv and im using the ULT_FILE package
I have this query that read the file and the first field, but if the field has a different length does not work as it should

For example if I had this .csv file:

1, book, laptop

2, pen, Eraser

3, notebook, paper

And in the table, I had to insert like this

ID descrption1 description2

laptop 1 book

Eraser pen 2

paper laptop 3

For now, I have this query, which displays only with DBMS:

Declare

-Variables

Cadena VARCHAR2 (32767).

Vfile UTL_FILE. TYPE_DE_FICHIER;

Dato varchar2 (200);                                             -Date

dato1 varchar2 (200);

dato2 varchar2 (200);

Identifier varchar2 (5): = ', ';                             -Identifier (en)

v_ManejadorFichero UTL_FILE. TYPE_DE_FICHIER;     -For exceptions

-Table variables

I_STATUS GL_INTERFACE. % OF STATUS TYPE.

I_LEDGER_ID GL_INTERFACE. TYPE % LEDGER_ID;

I_USER_JE_SOURCE_NAME GL_INTERFACE. TYPE % USER_JE_SOURCE_NAME;

I_ACCOUNTING_DATE GL_INTERFACE. TYPE % ACCOUNTING_DATE;

I_PERIOD_NAME GL_INTERFACE. TYPE % PERIOD_NAME;

I_CURRENCY_CODE GL_INTERFACE. CURRENCY_CODE % TYPE;

I_DATE_CREATED GL_INTERFACE. DATE_CREATED % TYPE;

I_CREATED_BY GL_INTERFACE. CREATED_BY % TYPE;

I_ACTUAL_FLAG GL_INTERFACE. TYPE % ACTUAL_FLAG;

I_CODE_COMBINATION_ID GL_INTERFACE. TYPE % CODE_COMBINATION_ID;

I_ENTERED_DR GL_INTERFACE. TYPE % ENTERED_DR;

I_ENTERED_CR GL_INTERFACE. TYPE % ENTERED_CR;

I_ACCOUNTED_DR GL_INTERFACE. TYPE % ACCOUNTED_DR;

I_ACCOUNTED_CR GL_INTERFACE. TYPE % ACCOUNTED_CR;

I_TRANSACTION_DATE GL_INTERFACE. TRANSACTION_DATE % TYPE;

I_REFERENCE1 GL_INTERFACE. REFERENCE1% TYPE;

I_REFERENCE2 GL_INTERFACE. REFERENCE2% TYPE;

I_REFERENCE3 GL_INTERFACE. REFERENCE3% TYPE;

I_REFERENCE4 GL_INTERFACE. REFERENCE4% TYPE;

I_REFERENCE5 GL_INTERFACE. REFERENCE5% TYPE;

I_REFERENCE10 GL_INTERFACE. REFERENCE10% TYPE;

I_GROUP_ID GL_INTERFACE. GROUP_ID % TYPE;

BEGIN

Vfile: = UTL_FILE. FOPEN ('CAPEX_ENVIO', 'comas.csv', 'R');

loop

UTL_FILE. GET_LINE(Vfile,Cadena,32767);

dato1: = substr (cadena, instr(cadena, identificador,1,1)-1, instr(cadena, identificador,1,1)-1);

dato2: = substr (cadena, instr (cadena, identifier, 1, 1) + 1, instr(cadena, identificador,3,1)-3);

dbms_output.put_line (dato1);

dbms_output.put_line (dato2);

-The evidence

-dbms_output.put_line (cadena);

-dbms_output.put_line (substr (dato, 3, instr(dato, identificador,1,1)-1));

-dbms_output.put_line (substr (dato, instr (dato, identifier, 1, 2) + 1, instr(dato, identificador,1,1)-1));

-dbms_output.put_line (substr (cadena, 1, length (cadena)-1));

end loop;

UTL_FILE. FCLOSE (Vfile);

-----------------------------------------------------------------------------------EXCEPTIONS------------------------------------------------------------------------------------------------------------------------------------------------------------

EXCEPTION

When no_data_found then

dbms_output.put_line ('Todo Correcto');

When utl_file.invalid_path then

UTL_FILE. FCLOSE (V_ManejadorFichero);

RAISE_APPLICATION_ERROR (-20060,'RUTA DEL ARCHIVO NULLIFIED: (');)

WHEN UTL_FILE. INVALID_OPERATION THEN

UTL_FILE. FCLOSE (V_ManejadorFichero);

RAISE_APPLICATION_ERROR ('-20061,'EL ARCHIVO NO PUDO SER ABIERTO ");

WHEN UTL_FILE. INVALID_FILEHANDLE THEN

UTL_FILE. FCLOSE (V_ManejadorFichero);

RAISE_APPLICATION_ERROR (-20062, 'INVALIDO MANAGER');

WHEN UTL_FILE. WRITE_ERROR THEN

UTL_FILE. FCLOSE (V_ManejadorFichero);

RAISE_APPLICATION_ERROR (-20063, 'ESCRITURA ERROR');

WHEN UTL_FILE. INVALID_MODE THEN

UTL_FILE. FCLOSE (V_ManejadorFichero);

RAISE_APPLICATION_ERROR (-20064, 'MODO INVALIDO');

WHEN UTL_FILE. INTERNAL_ERROR THEN

UTL_FILE. FCLOSE (V_ManejadorFichero);

RAISE_APPLICATION_ERROR (-20065, 'ERROR INTERNO');

WHEN UTL_FILE. READ_ERROR THEN

UTL_FILE. FCLOSE (V_ManejadorFichero);

RAISE_APPLICATION_ERROR (-20066, 'LECTURA ERORR');

WHEN UTL_FILE. FILE_OPEN THEN

UTL_FILE. FCLOSE (V_ManejadorFichero);

RAISE_APPLICATION_ERROR ('-20067,'EL ARCHIVO ARE ESTA ABIERTO ");

WHEN UTL_FILE. THEN ACCESS_DENIED

UTL_FILE. FCLOSE (V_ManejadorFichero);

RAISE_APPLICATION_ERROR (-20068, 'REFUSED ACCESS');

WHEN UTL_FILE. DELETE_FAILED THEN

UTL_FILE. FCLOSE (V_ManejadorFichero);

RAISE_APPLICATION_ERROR (-20069, 'OPERACIÓN BORRADO FALLO');

WHEN UTL_FILE. RENAME_FAILED THEN

UTL_FILE. FCLOSE (V_ManejadorFichero);

RAISE_APPLICATION_ERROR (-20070, 'OPERATION SOBREESCRITURA FALLO');

END;

Hello

Try something like this:

POS1: = INSTR (cadena, idntificador, 1, 1);
POS2: = INSTR (cadena, idntificador, 1, 2);

ID: = SUBSTR (cadena, 1, pos1 - 1);
description1: = SUBSTR (cadena, pos1 + 1, (pos2 - pos1)-1);
Description2: = SUBSTR (cadena, pos2 + 1);

where pos1 and pos2 are numbers.

Rather than use UTL_FILE, consider creating an external table.  You won't have to write any PL/SQL, and this means that you won't be tempted to write a bad article of EXCEPTION.

Tags: Database

Similar Questions

  • How can I get the data from the drive of barcodes to forms

    Hi Experts,

    Forms 6i

    I would like to collect data from the barcode scanner.

    No idea if you got it please share.

    Thanks in advance.

    Hello

    I think that his works even as the keyboard.  You type the code manually or you can read it from a scanner.  With the help of the keyboard that you can able to type what anyone on the position of the cursor, in the same way the barcode scanner also works.  Just like a copy and paste the scanner copies the data from the physical device and paste it into your corrent cursor position.  There is no separate program encodings necessary for this work.

  • get the name of a directory file and insert it into a table

    Hello

    I have a requirement, I need to read the name of a Linux directory file and enter the file name in a variable,

    After that, I need to insert this file name in a table.

    EX: is it a file1.txt in Yearbook of the CBA, and I read that 'file name' in the v_file_name variable and I'm going to insert this file name in a table.

    Hello

    I think you've got your request of replied by Chantal.
    Shoul you have a kind of intelience in the name of the file itself so that ODI retrieves the correct file and insert into the table.

    Thank you
    Fati

  • How can I get the data from a range of AutoFilter in Excel?

    I have a spreadsheet with a large number of lines (5000) where I want to extract data.  I have opened the workbook successfully, configure an automatic filter and filtered the data to select the data corresponding to the criteria using the nodes property of the ActiveX Excel object and invoke.  I now have to enter the selected data in a table for later processing, and this is where I am stuck.  Help Excel online seems to suggest the creation of a Range object by using special cells with the xlCellTypeVisible type.  If I Range.Count I get the right number of cells, but Range.Value2 produces a variant which contains only the first block of data (a beach filtered automatically seems to consist of several non continuous blocks).  Anyone know how I can read the contents of the range in an array of strings?

    Thanks in advance

    Ken

    IT SOLVED!

    Found a calling areas of property which returns a collection of the areas of each of them continues a range object.  Simply cycled through these areas using the earlier technique, build the table I want.  See below

    Thank you

    Ken

    PS I can KUDOS

  • This program of windows xp is on a Macbook Pro with a PC emulator. The drive needs to be replaced. How can I save the data from the side PC?

    This program of Windows XP (my wife) is on a MacBook Pro with a PC emulator (Bootcamp).  The drive needs to be replaced.  How can I save data from the PC to an external hard drive?

    Hi Alan,

    Thanks for posting in the Microsoft Community.

    I understand you are trying to backup the data on external hard drive since you replace the hard drive.

    I will definitely help you with this.

    Please visit the links; This should help you in files and backup files.

    How to use the backup utility to back up files and folders in Windows XP Home Edition

    http://support.Microsoft.com/kb/320820

    http://support.Microsoft.com/kb/308422

  • How can I extract the msi from exe to install drive?

    Usually, when I want to extract the msi file from the distribution of exe (for Group Policy) installation drive, I download from get.adobe.com/reader/enterprise and decompress the exe file using 7zip.   Then I integrate the msp inside file and I'm pretty much good to go.

    Now, when I try to extract the msi file, I get a directory full of stuff, but no msi at all.  I tried the installer and watch in C:\users\username\AppData (it works for Java), but it wasn't there.

    No idea what I am doing wrong? Or y at - it a new way to extract the msi file that I missed?

    Thank you!

    Bryan

    Hi bryan10983,

    You can visit this link to get the answer to your query: http://blogs.adobe.com/dmcmahon/2010/06/16/how-to-extract-an-msi-file-from-the-exe-for-ado be-player /

    Kind regards

    Ajlan Huda.

  • Can I copy the list of names of files and paste them into a table

    I have a list of files in a folder and here paste the titles only in a table

    You can create a list of text files by using the command prompt.

    • Open a command prompt in the folder that you want to get the list of. (You can open a command prompt and navigate to your required file, or use the Solution Explorer and press and right click on your file at the same time. Then you should see "open a command here window' in the menu - click on it.)
    • Enter the command "dir /b > filenames.txt" (without the quotes), then simply type dir /b > filenames.txtand press return/enter to transport.
    • Use Explorer to navigate to your file and you should now see a text file called filenames.txt. Open and it must contain a list of files. Then, copy and paste the list where you want to.

    If all goes well, I understood your question correctly, if so, hope it helps.




  • How can I extract an image from a .jpg file?

    Attached is a. JPG, I want to change.  I have a lot of drawing like this we would like to make a catalog.  I want to make all the doors of the thesis of the same image with transparent square bottom size.  I understand how to remove the bottom however when I try to adjust the size of my image it always adjusts my canvas size.  What I tried to do, is to have a layer of transparent background with the door image on a separate layer, but I'm not having any luck.  I'm new to PS, so my knowledge is limited.  Any help would be appreciated.  I use the extended version of CS4.

    610.jpg

    All your canvas sizes will have a consistent size? Door images too? Is this number? You can try this:

    1 make the active layer (Layer 1 instead of background) image

    2. Select the entire document outside the shape of the door (using the magic wand + add the number with lasso)

    3 remove the part of the image: it's transparent.

    4. go in picture, trim, all transparent pixels, what you're left with now is the part of the door of the image.

    5. go to the size of the image and put the dimensions in pixels of the door (hopfully not upsampling)

    6. flatten image

    7 go to the canvas size, set the size you want (as long as it is greater than the door) and a ratio of 1: 1 that you should now have a square bottom.

    I know that sounds like a lot of steps, but this can be automated into action. I do that all the time with photos of products that need to adapt to a standard window. Just another way to go, hope this helps...

  • How can I extract the files of calendar?

    Thank you for the review of this post.  I appreciate any help you can provide.

    I recently bought a new win 7.  My tech copied all my old data from the previous machine to a single folder on my new machine.

    I have a few Palm data... But it has not imported the TX model will not be installed on my Win 7 machine, so I have to achieve this through Palm Desktop.  (I have read that could be caused by the fact that I went to version 6 of the palm software and tried to import).

    Quite simply, here's my problem: I just want to really get my calendar information.  I'll probably use a program different schedule in the near future.

    How can I extract the data from the calendar since raw files?  (Calendar.dat, etc.) ???

    I have TO import or somehow go through the Palm software, or is it possible outside of Palm?

    I THINK that this cannot be something too difficult, but I am so stuck and missing an appointment every day.

    I am very grateful for your help.

    Don in Tucson

    AizA

    With the version of the data files you have, you will need to install Palm Desktop 4.1.4e or 4.2. You will need to uninstall Palm Desktop 6.2, if that's what you have installed currently. With the .dat extension files are not compatible with PD 6.2.

    Another thing to consider is the Win7 version you have installed. If you have the 64-bit version, you will only be able to sync wireless using bluetooth, infrared, or wi - fi. On your PC, go to the computer icon and right-click. Look at the page and see if it says 64 bit any where. If you have the 32-bit version, you can synchronize via USB cable method, but you must ensure that you have the correct version of installed PD.

    In PD .dat files, you will need to go to the folder of user name on the drive of the program and paste the files in the appropriate subfolder. Make sure that the PD is closed. Go to c-program files-palm and find the folder user of PD. Once you find the file, search for the subfolders of this folder for address (this is the contacts folder), calendar (calendar), memos, and tasks. Paste the address.xxx files in the folder of the address, the file datebook.xxx in the folder of the agenda, etc.. Once the files in the respective locations, open PD and see if the data is there. If this is the case, you can then set the synchronization according to your version of Win7, either wireless or USB.

  • How can I transfer my data from Microsoft Money 2001 to a newer version? What we call the new version?

    I UNDERSTAND THAT MICROSOFT MONEY VERSI0N 2011 IS DECOMMISSIONED. I AM HAPPYTO UPGRADE TO A NEWER VERSION, BUT A QUESTION AS TO HOW I CAN TRANSFER ALL DATA ON MSM 2001 TO THE NEW VERSION. WHAT WOUKLD NEW VERSION BE CALLED

    original title: MISROSOFT MONEY VERSION2001
    original title: How can I transfer my data from Microsoft Money 2001 to a newer version?

    Hello

    Check in the Microsoft Money Forum.

    Microsoft Money - Forum
    http://social.Microsoft.com/forums/en/money/threads

    Microsoft Money Solution Center - suggests alternatives
    http://support.Microsoft.com/mny

    What is Microsoft Money Plus sunset
    http://support.Microsoft.com/kb/2118008

    BING - microsoft money replacement
    http://www.bing.com/search?q=Microsoft+Money+replacement&go=&QS=n&SK=&SC=7-27&form=QBLH

    Google - microsoft money replacement
    http://www.google.com/#sclient=psy-ab&hl=en&source=hp&q=microsoft+money+replacement&pbx=1&oq=microsoft+money+replacement&aq=f&aqi=g4&aql=&gs_sm=e&gs_upl=9978l11972l2l12926l12l1l0l0l0l0l467l467l4-1l1l0&bav=on.2,or.r_gc.r_pw.,cf.osb&fp=dcc84c4c7dd2e143&biw=1024&bih=681

    I hope this helps.

    Rob Brown - Microsoft MVP<- profile="" -="" windows="" expert="" -="" consumer="" :="" bicycle=""><- mark="" twain="" said="" it="">

  • How can I extract the year of a variable?

    Hi all

    I want to extract the year of a parameter.

    I tried the following, I make mistakes.

    When I run the code below,

    SELECT TO_CHAR(:X_PRM_YR_END_DT,'YYYY') FROM dual;

    I got the following error.

    ORA-number 01722:invalid

    When I run the code below,

    SELECT TO_DATE(:X_PRM_YR_END_DT,'YYYY') FROM dual;

    SELECT to_char (TO_DATE (: X_PRM_YR_END_DT, "YYYY")) FROM dual;

    I got the following error.

    ORA-01830: date format end before you convert all of the input string

    When I run the code below,

    SELECT extract (YEAR FROM: X_PRM_YR_END_DT) FROM dual;

    SELECT extract (YEAR FROM 01/11/2013) FROM dual;

    I got the following error.

    ORA-30076: invalid field extracted from source

    How can I extract the year of a variable?

    Help me please

    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production.

    Try this,

     

    SELECT TO_CHAR (to_date (' 01/01/1980 ',' dd/mm/yyyy'), 'YYYY') FROM dual;

  • How can I extract the frequency of the FFT function?

    Hi all

    How can I extract the frequency of the FFT function in labview?  Thanks in advance

    Concerning

    If you have the f0 and df, you can find your frequency as you would find the time with a waveform based on t0 and dt.  You just need the index of the data point in that you want to get the frequency.  The frequency is then f0 + x * FD, where x is the index of the data point you are interested in.

  • Vista initilalize usb disk... How can I backup the data?

    My usb cable was disconnected during moving the files from a [URL = http://www.seagate.com/www/en-gb/products/external/expansion/expansion_desktop/] external expansion of 3 TB Seagate USB Drive. [Url] to my drive is internal. Now Vista sees is no longer the USB in the Explorer. I went in the Adim tools/disk management & demand if I want to 'initialze disc' which gives two options "use the following disk partition style" MBR or GPT. At this point, I chose to leave the application I have I'm not sure what the difference is. Either option would allow me to access the data on the disk? If this is not the case, how can I retrieve the data already stored on the disk?

    Hello

    Refer to this link and run the troubleshooter and check:

    http://Windows.Microsoft.com/en-us/Windows-Vista/tips-for-solving-problems-with-USB-devices

  • How can I erase the data on my laptop before I give it away?

    How can I erase the data on my laptop before I give it away?

    See this document.

    https://support.Apple.com/en-us/HT201065

  • How can I get the message from thunderbird to stop coming when I opened my email?

    How can I get the message from thunderbird to stop coming when I opened my email?

    Press the alt key to make the call of menu bar
    Select Tools-Options-general
    Disabled the Start Page

Maybe you are looking for