[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how to put a declaration in a procedure?

Posted on 2011-10-27
5
Medium Priority
?
227 Views
Last Modified: 2012-05-12
Hello all,

I have a function that runs a select statement in oracle and mount a. txt file on my server but a business user will need to run this function and I need to place it inside a procedure and give it only permission to run this procedure. The part of creation and user permission has already been made just do not know how to put the entire command line in a procedure to be performed, following the parameters below:


declare
    ARQUIVO            UTL_FILE.FILE_TYPE;
    
    CURSOR c_Item IS
      select 
         '1' ||                                      -- Tipo de Registro
         rpad(c.cdcid,10,' ') ||                           -- Cid
         rpad(c.nocid,70,' ')                              -- Descricao do Cid
         AS reg
       from 
         cid_10 c;
begin
    ARQUIVO := UTL_FILE.FOPEN('/opt/oracle/oradata/PSController','v80_cid.txt','w');

    UTL_FILE.PUT_LINE(ARQUIVO, '018.0     ');
    FOR r_Item IN c_Item LOOP
      UTL_FILE.PUT_LINE(ARQUIVO, r_ITEM.reg);
    END LOOP;

    UTL_FILE.FCLOSE(ARQUIVO);

    EXCEPTION

  	WHEN UTL_FILE.INVALID_PATH THEN
  		DBMS_OUTPUT.PUT_LINE('Caminho Invalido!');
  		UTL_FILE.FCLOSE(ARQUIVO);

  	WHEN UTL_FILE.READ_ERROR THEN
  		DBMS_OUTPUT.PUT_LINE('Erro durante a Leitura.');
  		UTL_FILE.FCLOSE(ARQUIVO);

  	WHEN UTL_FILE.WRITE_ERROR THEN
  		DBMS_OUTPUT.PUT_LINE('Erro durante a Escrita.');
  		UTL_FILE.FCLOSE(ARQUIVO);

  	WHEN OTHERS THEN
  		DBMS_OUTPUT.PUT_LINE('Ocorreu um erro desconhecido!');
  		UTL_FILE.FCLOSE(ARQUIVO);

end;

Open in new window

0
Comment
Question by:eduardo12fox
  • 2
  • 2
5 Comments
 

Accepted Solution

by:
eduardo12fox earned 0 total points
ID: 37040201
I RESOLVED
0
 
LVL 37

Expert Comment

by:zzynx
ID: 37043247
Then please close this question by accepting your own comment
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37044397
>>Then please close this question by accepting your own comment

No.  Please delete the question.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 37044459
Of course, slightwv, you're right.  
Since the author didn't post the solution it's useless to PAQ.
0
 

Author Closing Comment

by:eduardo12fox
ID: 37068309
create or replace procedure producao.gera_arquivo_CID_versao_80 is

    ARQUIVO            UTL_FILE.FILE_TYPE;
   
    CURSOR c_Item IS
   
   
            select
               '1' || rpad(c.cdcid,10,' ') || rpad(c.nocid,70,' ') AS reg
             from cid0 c;
         
BEGIN
     ARQUIVO := UTL_FILE.FOPEN('/opt/oracle/oradata/TESTE','v80_AAA.txt','w');

    UTL_FILE.PUT_LINE(ARQUIVO, '018.0     ');
    FOR r_Item IN c_Item LOOP
      UTL_FILE.PUT_LINE(ARQUIVO, r_ITEM.reg);
    END LOOP;

    UTL_FILE.FCLOSE(ARQUIVO);

    EXCEPTION

        WHEN UTL_FILE.INVALID_PATH THEN
              DBMS_OUTPUT.PUT_LINE('Caminho Invalido!');
              UTL_FILE.FCLOSE(ARQUIVO);

        WHEN UTL_FILE.READ_ERROR THEN
              DBMS_OUTPUT.PUT_LINE('Erro durante a Leitura.');
              UTL_FILE.FCLOSE(ARQUIVO);

        WHEN UTL_FILE.WRITE_ERROR THEN
              DBMS_OUTPUT.PUT_LINE('Erro durante a Escrita.');
              UTL_FILE.FCLOSE(ARQUIVO);

        WHEN OTHERS THEN
              DBMS_OUTPUT.PUT_LINE('Ocorreu um erro desconhecido!');
              UTL_FILE.FCLOSE(ARQUIVO);


end;
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question