Read a CSV file via PLSQL Code

Dúvidas, dicas e truques de PL/SQL. Aqui também vão assuntos relacionados a pacotes, triggers, funções, Java-Stored Procedures, etc
Post Reply
carlynhos77
Rank: Analista Sênior
Rank: Analista Sênior
Posts: 172
Joined: Mon, 24 Oct 2016 7:20 pm

Hello, good afternoon ...

Friends, once again I need help, I need to read a particular .csv file ... Read and save in table

] I found a post on the net, I am trying to adjust it in my application, as a test, I am using the names of the columns equal to the example, to facilitate ... but it is not working, speaks that the path of the file is not found .. .

See the code

Select all

DECLARE 
      F UTL_FILE.FILE_TYPE; 
      V_LINE VARCHAR2 (1000); 
      V_EMPNO NUMBER(4); 
      V_ENAME VARCHAR2(10); 
      V_SAL NUMBER(7,2); 
      V_DNAME VARCHAR2(14); 
    BEGIN 
      F := UTL_FILE.FOPEN ('D:\', 'LIC_TESTE.CSV', 'R'); 
    IF UTL_FILE.IS_OPEN(F) THEN 
      LOOP 
        BEGIN 
          UTL_FILE.GET_LINE(F, V_LINE, 1000); 
          IF V_LINE IS NULL THEN 
            EXIT; 
          END IF; 
          V_EMPNO := REGEXP_SUBSTR(V_LINE, '[^,]+', 1, 1); 
          V_ENAME := REGEXP_SUBSTR(V_LINE, '[^,]+', 1, 2); 
          V_SAL := REGEXP_SUBSTR(V_LINE, '[^,]+', 1, 3); 
          V_DNAME := REGEXP_SUBSTR(V_LINE, '[^,]+', 1, 4); 
          INSERT INTO LIC_TESTE VALUES(V_EMPNO, V_ENAME, V_SAL, V_DNAME); 
          COMMIT; 
        EXCEPTION 
        WHEN NO_DATA_FOUND THEN 
          EXIT; 
        END; 
      END LOOP; 
   END IF; 
  UTL_FILE.FCLOSE(F); 
 END; 
I created the table in my bank called LIC_TESTE ... I created a worksheet called LIC_TESTE

The names of the fields and columns are equal to the example

I put the spreadsheet at the root of the drive "D"

I already made several attempts with the Name of the way, however, no one works

I am using the Apex Oracle 19
I created a button, with a dynamic action, in the Run PL / SQL code

could help me make this code work? appreciate
User avatar
dr_gori
Moderador
Moderador
Posts: 5024
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

Is this file on the Oracle server?
UTL_File runs inside the Oracle server.

Here is an example to create a Data Loader in Apex. https://jeffkemponoracle.com/2018/11/lo ... into-apex/
carlynhos77
Rank: Analista Sênior
Rank: Analista Sênior
Posts: 172
Joined: Mon, 24 Oct 2016 7:20 pm

Hello,

No, it's external, in the same micro ... I'll take a look again at this data loader, but I tried some examples, but I could not make it work with the Data Loader
User avatar
dr_gori
Moderador
Moderador
Posts: 5024
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

carlynhos77
Rank: Analista Sênior
Rank: Analista Sênior
Posts: 172
Joined: Mon, 24 Oct 2016 7:20 pm

Hello, good morning

I think for lack of knowledge still, in the Apex already exists something practical, I used [color=# 0000ff] "Apex Data Charger Wizard" / color] , then I adjusted the certinha screen with the fields, it worked perfectly ... the user who will do the data load, so in this way, each one makes his load ne

I used the Dr.Gori tip, searching this link
https://jeffkemponoracle.com/2018/11/lo ... into-apex/
Thank you very much for the tip and help ...
carlynhos77
Rank: Analista Sênior
Rank: Analista Sênior
Posts: 172
Joined: Mon, 24 Oct 2016 7:20 pm




Data from a table?

Does this without having to create function with codes, pick up something like the wizard
??
User avatar
dr_gori
Moderador
Moderador
Posts: 5024
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

I'm without apex here, but from what I know, there's that natively.
I think you can set that a table is "exportable".

I think this link has what you need: https://docs.oracle.com/en/database/ora ... kshop.html
carlynhos77
Rank: Analista Sênior
Rank: Analista Sênior
Posts: 172
Joined: Mon, 24 Oct 2016 7:20 pm

Hello,
Yes, there is native, but to export I only found in development mode, an end user of the application would not have access to the workshop ... in the assistant to import data, Created pages, where the user can navigate to realize the import ... I thought of something like import, where the user would access a page to generate the CSV
User avatar
dr_gori
Moderador
Moderador
Posts: 5024
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

From what I know, all reports in Apex has an option to download.
Is not that what you're looking for? See:

How to configure the download option [[0] https://docs.oracle.com/cd/E23903_01/do ... m#BABFIECH
Screen Shot 2019-04-25 at 10.05.41 AM.png
Screen Shot 2019-04-25 at 10.06.01 AM.png
carlynhos77
Rank: Analista Sênior
Rank: Analista Sênior
Posts: 172
Joined: Mon, 24 Oct 2016 7:20 pm

Hello, yes I saw this option and did some tests ... but I still could not download a file, based on a query, that created a formatted CSV file ....

is the following , at the beginning of the post I was looking for an option to import data from a CSV file ne as it is, this file to be imported will be the same as the user will generate before ...

Bendatory, sort, the tenderer picks up the edict and we give an Excel spreadsheet so that it puts its initial prices for the items to be tendered, this worksheet already has to go in a standard formatting so that on the day of the bidding the pregoir take this worksheet Import the data

That's why I have to generate her in a correct standard, because I'm going to use the same LA on the day of the bidding ...

It's the following, if I could download this download at Excel, I would easily format the columns, I left it right for the front I used to import the data again, D After that the tenderer put their values ??for items ... It turns out that I have to consider that the final user, and this is real, has no knowledge to mess with Excel, much less format in the standard that the system needs ...

so I have to ensure that the worksheet is generated correct, so that the importation occurs on the day of the bidding without errors

but I will give one more a funciation in this download , try to set better
User avatar
dr_gori
Moderador
Moderador
Posts: 5024
Joined: Mon, 03 May 2004 3:08 pm
Location: Portland, OR USA
Contact:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

But CSV has no special formatting.
CSV is a text file delimited by some signal :,; or another.

What do you mean by formatted file?
carlynhos77
Rank: Analista Sênior
Rank: Analista Sênior
Posts: 172
Joined: Mon, 24 Oct 2016 7:20 pm

Next, when I download a CSV, it comes with the name of the columns, equal to the name of the database fields .. it already picks up the first of the csv pro title and from the second line, it already comes the data ...

But when I say something formatted, it is because I need to play in other specific cells, other values, besides the list of items, type:

Number of bidding
Year of the bidding
Proponent's code
CNPJ of the tenderer

I need to have this data for moment that the tenderer give me back this spreadsheet, at the time of import, I need to identify for which bidding and for which proponent I will import the items ...

I already do this in the system in visual Basic, fero the spreadsheet with the items, with the extra identifications, when I will import, this extra data I do the identification

then, the formatting, not exactly decorate column titles, the formatting is at the moment that Generate the worksheet, have the option to insert other data, besides the APEX grid q is displayed for download
carlynhos77
Rank: Analista Sênior
Rank: Analista Sênior
Posts: 172
Joined: Mon, 24 Oct 2016 7:20 pm

I believe that in this download option I will not be able to generate this csv, the way I need, will have to be via code even, so I can have option to determine cells with extra data
carlynhos77
Rank: Analista Sênior
Rank: Analista Sênior
Posts: 172
Joined: Mon, 24 Oct 2016 7:20 pm

In fact, the way I currently use on the system in Visual Basic, I have a "proposed_base.xls" file, via code, I do not create a new worksheet, I fill out this base file ... then then the identification data already go for each cell specifies, and from such a line, it starts the item ratio, see the model q use in the image

as I have a model to be filled automatically, I can give a finish Better, however, the issue of finishing is not the main, the main is the identification in return, and ensure that columns are not excluded, etc ... Keep the standard
Attachments
tela gerar XLS.jpg
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 33 guests