Oracle Note 14, querying XML operations, operating system files

Source: Internet
Author: User
Tags abs create directory

--1. Random number
Select Dbms_random.value from dual;
Select mod (Dbms_random.random, ten) from dual;
--0-9 Random Number
Select ABS (mod (DBMS_RANDOM.RANDOM)) from dual;
--40-49 Random Number
Select + ABS (mod (DBMS_RANDOM.RANDOM)) from dual;
--2.xml
Declare
       Words Clob;
       Xmlstr varchar2 (32767);
       Line VARCHAR2 (2000);
       Line_no number: = 1;
Begin
     Words: = Dbms_xmlquery.getxml (' select * from Scott.emp ');
     XMLSTR: = Dbms_lob.substr (words, 32767);
     Loop
         Exit when (Xmlstr is null);
         Line: = substr (Xmlstr, 1, InStr (Xmlstr, Chr (10))-1);
         Dbms_output.put_line (Line_no | | ': ' | | line);
         XMLSTR: = substr (Xmlstr, InStr (Xmlstr, Chr (10)) + 1);
         Line_no: = line_no + 1;
     End Loop;
End
--3. File
--Define folder naming must be capitalized
Create directory My_dir as ' D:\TEMP ';
--Read the file
Declare
       Inputfile Utl_file.file_type; --File Object
       Input VARCHAR2 (2000);
Begin
     --Specify file
     --3 parameters are: Folder file open mode [R (Read) W (write) A (append)]
     Inputfile: = Utl_file.fopen (' My_dir ', ' demo.txt ', ' R ');
     Loop              
         Utl_file.get_line (inputfile, input);
         Dbms_output.put_line (input);             
     End Loop;
     --Close File
     Utl_file.fclose (Inputfile);
     exception
       When No_data_found then Dbms_output.put_line (' End of File! ');
End
--Writing files
Declare
       Inputfile Utl_file.file_type; --File Object
       Input VARCHAR2: = ' Hello world! ';
Begin
     --Specify file
     --3 parameters are: Folder file open mode [R (Read) W (write) A (append)]
     Inputfile: = Utl_file.fopen (' My_dir ', ' mydemo.txt ', ' a ');
     --Write Data
     Utl_file.put_line (inputfile, input);
     --Close File
     Utl_file.fclose (Inputfile);
     exception
       When No_data_found then Dbms_output.put_line (' End of File! ');
End

Oracle Note 14, querying XML operations, operating system files

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.