Oracle External table

Source: Internet
Author: User

Sqlldr loads data into the database. The data in the External table is based on the operating system file, and the real data is not saved to the database, which is in the operating system file. Therefore, the data in the External table can only be selected. External tables can basically replace sqlldr. In the following three cases, choose sqlldr instead of External table:

1. Data must be loaded through the network, that is, the input file is not on the database server.

2. Multiple users must concurrently use the same external table to process different input files.

3. the LOB type must be used. External tables do not support logs.

Use sqlldr to generate external table scripts

  1. [Oracle @ linux sqlldr] $ pwd
  2. /U01/sqlldr
  3. [Oracle @ linux sqlldr] $ cat demo1.ctl
  4. LOADDATA
  5. INFILE *
  6. INTO TABLEDEPT
  7. FIELDS TERMINATEDBY ','
  8. (DEPTNO, DNAME, LOC)
  9. BEGINDATA
  10. 10, Sales, Virginia
  11. 20, Accounting, Virginia
  12. 30, Consulting, Virginia
  13. 40, Finance, Virginia
  14. ABC, XYZ, Hello
  15. [Oracle @ linux sqlldr] $ sqlldr ing/ing demo1.ctl external_table = generate_only
  16. SQL * Loader: Release 10.2.0.4.0-ProductionOnTuesday October 4 21:59:06 2011
  17. Copyright (c) 1982,200 7, Oracle.AllRights reserved.

View the generated log file

  1. [Oracle @ linux sqlldr] $ pwd
  2. /U01/sqlldr
  3. [Oracle @ linux sqlldr] $ cat demo1.log
  4. SQL * Loader: Release 10.2.0.4.0-ProductionOnTuesday October 4 21:59:06 2011
  5. Copyright (c) 1982,200 7, Oracle.AllRights reserved.
  6. Control File: demo1.ctl
  7. Data File: demo1.ctl
  8. Error file: demo1.bad
  9. Obsolete file: Not specified
  10. (All records can be discarded)
  11. Number of objects to be loaded:ALL
  12. Number of to be skipped: 0
  13. Allowed error: 50
  14. Continue: Unspecified
  15. Path used: External table
  16. Table DEPT, loaded from each logical record
  17. Insert option for this tableINSERTEffective
  18. Column name location length abort packaging Data Type
  19. --------------------------------------------------------------------------
  20. DEPTNOFIRST*,CHARACTER
  21. DNAMENEXT*,CHARACTER
  22. LOCNEXT*,CHARACTER
  23. File needsCREATEDIRECTORY statements
  24. ------------------------------------------------------------------------
  25. CREATEDIRECTORY SYS_SQLLDR_XT_TMPDIR_00000AS '/U01/sqlldr'
  26. -- Connect sqlldr to the database and query the data dictionary. If no appropriate directory is found, create a SYS_SQLLDR_XT_TMPDIR_00000 directory.
  27. Used for external tablesCREATE TABLEStatement:
  28. ------------------------------------------------------------------------
  29. CREATE TABLE "SYS_SQLLDR_X_EXT_DEPT"-- Create a table SYS_SQLLDR_X_EXT_DEPT
  30. (
  31. "DEPTNO"NUMBER (10 ),
  32. "DNAME"VARCHAR2 (20 ),
  33. "LOC"VARCHAR2 (20)
  34. )
  35. ORGANIZATION external-- Indicates that this is not a common table, but an External table.
  36. (
  37. TYPE oracle_loader-- Load the data type. In addition, there is a 10 Gb ORACLE_DATAPUMP that can be used to load or unload data.
  38. DEFAULTDIRECTORY SYS_SQLLDR_XT_TMPDIR_00000-- Use the previously created directory SYS_SQLLDR_XT_TMPDIR_00000
  39. ACCESS PARAMETERS
  40. (
  41. RECORDS DELIMITEDBYNewline characterset ZHS16GBK-- The Record ends with a line break by default.
  42. BADFILE'Sys _ SQLLDR_XT_TMPDIR_00000':'Demo1. bad'-- Record a bad file in the newly created directory. Records that cannot be loaded will be recorded in this file.
  43. LOGFILE'Demo1. log_xt'-- Log file.
  44. READSIZE 1048576-- Size of the cache for loading data. 1024*1024 = 1048576
  45. SKIP 6-- Skip the first six rows without loading, because the first six rows are information of the sqlldr control file.
  46. FIELDS TERMINATEDBY ","LDRTRIM-- Data is separated by commas (,). LDRTRIM indicates removing the leading and trailing spaces.
  47. REJECTROWS WITH ALL NULLFIELDS-- External tables record empty rows in bad files without loading these rows.
  48. (
  49. "DEPTNO" CHAR(255)
  50. TERMINATEDBY ",",
  51. "DNAME" CHAR(255)
  52. TERMINATEDBY ",",
  53. "LOC" CHAR(255)
  54. TERMINATEDBY ","
  55. )
  56. )
  57. Location
  58. (
  59. 'Demo1. ctl'-- Tells the name of the file loaded by oracle.
  60. )
  61. ) REJECT LIMIT UNLIMITED
  62. Used to load internal tablesINSERTStatement:
  63. ------------------------------------------------------------------------
  64. INSERT/* + Append */INTODEPT-- Load data directly from the External table.
  65. (
  66. DEPTNO,
  67. DNAME,
  68. LOC
  69. )
  70. SELECT
  71. "DEPTNO",
  72. "DNAME",
  73. "LOC"
  74. FROM "SYS_SQLLDR_X_EXT_DEPT"
  75. The statement used to clear the object created by the previous statement:
  76. ------------------------------------------------------------------------
  77. DROP TABLE "SYS_SQLLDR_X_EXT_DEPT"-- Delete an External table.
  78. DROPDIRECTORY SYS_SQLLDR_XT_TMPDIR_00000-- Delete a directory.
  79. Starting from 21:59:06, January 1, 2011, Tuesday
  80. The operation ended at 21:59:06, January 1, October 04, 2011.
  81. Elapsed time: 00: 00: 00.14
  82. CPU time: 00: 00: 00.04
  • 1
  • 2
  • Next Page

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.