Instance for reading data from the oracle utl_file package

Source: Internet
Author: User
Tags oracle materialized view

The oracle utl_file package is expected to be well understood. The following describes how to read data from the oracle utl_file package. If you are interested in the oracle utl_file package, take a look.

 
 
  1. Create or replace directory MY_DIR as '/usr/test /';
  2. Create or replace function f_exportTxt (
  3. -- Input parameters
  4. I _query in varchar2,
  5. I _separator in varchar2,
  6. I _dir in varchar2,
  7. I _filename in varchar2
  8. ) Return number
  9. Is
  10. /**
  11. ** Function name: f_exportTxt
  12. ** Parameter: 1. I _query SQL statement; 2. I _separator separator; default value ',';
  13. ** 3. I _dir directory; 4. I _filename file name. By default, yyyymmddhh24mi is added before the file name.
  14. ** Return value: If the value is greater than or equal to 0, it indicates the number of records written to the file. If the value is negative, it indicates an exception.
  15. ** Function: extract user data and generate a file to the specified directory.
  16. ** Note:
  17. ** Author: lingo
  18. ** Modification date:
  19. **/
  20. -- Define parameters
  21. V_file utl_file.file_type;
  22. V_theCursor integer default dbms_ SQL .open_cursor;
  23. V_columnValue varchar2 (2000); -- temporary (column value)
  24. V_colCnt number default 0; -- total number of Columns
  25. V_separator varchar2 (10) default ','; -- delimiter, default #@
  26. V_cnt number default 0; -- total number of records
  27. V_filename varchar2 (100); -- Time
  28. V_status integer; -- status value returned after SQL Execution
  29. V_count number default 10000; -- the number of queries each time. If the number is greater than this, data is read to the cursor multiple times.
  30. V_tmp number; -- temporary (total number of records, calculated using SQL statistics, if v_cnt is not equal to v_tmp, the export is incorrect)
  31. V_ SQL varchar2 (2000); -- combines SQL statements
  32. V_loops number; -- number of cycles
  33. Begin
  34. -- Select to_char (sysdate, 'yyyymmddhh24mi ') into v_filename from dual; -- prefix the file name by year, month, and day
  35. V_filename: = '';
  36. V_filename: = v_filename | I _filename; -- creates a file name.
  37. V_ SQL: = 'select count ('x') from ('| I _query |') '; -- total number of statistics
  38. Execute immediate v_ SQL into v_tmp;
  39. Select trunc (v_tmp/v_count) into v_loops from dual; -- number of cycles
  40. If mod (v_tmp, v_count)> 0 then
  41. V_loops: = v_loops + 1;
  42. End if;
  43. V_file: = utl_file.fopen (I _dir, v_filename, 'w'); -- open the file
  44. For I in 1 .. v_loops loop
  45. V_ SQL: = 'select * from (select m. *, rownum r fr ......

Oracle creates and deletes user instances

Entire Process of creating Oracle Materialized View

ORACLE instance creation process

Statement syntax for oracle time addition and subtraction

How to check the oracle deadlock

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.