Write txt text in ORACLE and read data from Txt file to Modify Table Structure

Source: Internet
Author: User

Write txt text in ORACLE and read data from Txt file to Modify Table Structure

-- Create a table drop table test cascade constraints; create table test (a varchar (30), B VARCHAR (30 )); -- view the specific permission select distinct privilege from DBA_SYS_PRIVS where privilege like '% DIRECTORY %'; -- use the SYS user TO authorize scottgrant create any directory to scott; -- create or replace directory filename as 'd: \ temporary after authorization; -- query the created table SELECT * from test; -- write the TXT file declare filehandle UTL_FILE.FILE_TYPE; -- The handle BEGIN--FILENAME must be in uppercase; otherwise, the system will prompt that the directory path is invalid. ILEHANDLE: = UTL_FILE.FOPEN ('filename', 'util _ FILE. TXT ', 'w'); UTL_FILE.PUT_LINE (FILEHANDLE, 'Hello ORACLE! '); UTL_FILE.PUT_LINE (FILEHANDLE,' Hello, fat man! '); UTL_FILE.FCLOSE (FILEHANDLE); -- close the handle END; -- read the content from the TXT file and insert it into the table TEST/* set serveroutput on */declare filehandle UTL_FILE.FILE_TYPE; filebuffer varchar (200); begin filehandle: = UTL_FILE.FOPEN ('filename', 'util _ FILE. TXT ', 'R'); loop begin UTL_FILE.GET_LINE (FILEHANDLE, FILEBUFFER); insert into test (A) VALUES (FILEBUFFER); exception when NO_DATA_FOUND then exit; end loop; UTL_FILE.FCLOSE (FILEHANDLE); COMMIT; END; -- query the TABLE again SELECT * from test;/* -- modify the TABLE structure alter table stu add (NAME2 VARCHAR2 (10 )); add the new field update stu set NAME2 = SUBSTR (TRIM (NAME),); assign the value to the new field alter table stu drop (NAME ); delete the original field alter table stu rename column NAME2 to name; RENAME the new field alter table name modify Field NAME VARCHAR2 (length );*/

 


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.