DBE_FILE
Precautions
- DBE_FILE requires that files opened using DBE_FILE.FOPEN be encoded using the database character set. If the opened files are not encoded using the expected character set, an encoding verification error occurs when DBE_FILE.READ_LINE is used to read files. DBE_FILE requires that files opened using DBE_FILE.FOPEN_NCHAR be encoded using the UTF-8 character set. If the opened files are not encoded using the expected character set, an encoding verification error occurs when DBE_FILE.READ_LINE_NCHAR is used to read files.
- When DBE_OUTPUT.PUT_LINE is used to print the result obtained by the DBE_FILE.READ_LINE_NCHAR API, ensure that the UTF-8 character set encoding can be converted to the current database character set encoding. If the preceding conditions are met, the result can be properly output. DBE_OUTPUT.PRINT_LINE does not support this function.
- DBE_FILE requires that the character set encoding of the client be the same as that of the database.
- If the database character set encoding format is ASCII and the client character set encoding format is Chinese, when the client invokes DBE_FILE.WRITE_NCHAR or DBE_FILE.WRITE_LINE_NCHAR to write Chinese content, the written content may be in UTF-8 encoding format. An error may be reported when the DBE_FILE.READ_LINE_NCHAR is used.
Data Types
- DBE_FILE.FILE_TYPE
Defines the representation of files in the DBE_FILE package. The fields in DBE_FILE.FILE_TYPE are private fields of the DBE_FILE package. Do not change the field value of the type defined in DBE_FILE.FILE_TYPE.
1 2 3 4 5
CREATE TYPE DBE_FILE.FILE_TYPE AS( id INTEGER, datatype INTEGER, byte_mode BOOLEAN );
Table 1 DBE_FILE.FILE_TYPE columns Parameter
Description
id
File handle
datatype
File data type (CHAR, NCHAR, or binary). Currently, only CHAR and NCHAR files are supported. For a CHAR file, 1 is returned. For an NCHAR file, 2 is returned.
byte_mode
Indicates that the file is opened in binary mode (TRUE) or text mode (FALSE).
Interface Description
Table 2 lists all interfaces supported by the DBE_FILE package.
Interface |
Description |
---|---|
Opens a file based on the specified directory and file name. |
|
Checks whether a file handle is opened. |
|
Reads a line of data from an open file handle based on the specified length. |
|
Writes the data specified in the buffer to a file. |
|
Writes one or more line terminators to an open file. |
|
Writes a string from the buffer to an open file. |
|
This is a formatted PUT stored procedure similar to printf(). |
|
Reads binary data from an open file handle. |
|
Writes the input binary data to the file. |
|
Writes data from a file handle to a physical file. |
|
Closes an open file handle. |
|
Closes all file handles opened in a session. |
|
Deletes a disk file. To perform this operation, you must have required permissions. |
|
Renames files on the disk, similar to mv in Unix. |
|
Copies data in a continuous area to a new file. If start_line and end_line are omitted, the entire file is copied. |
|
Reads and returns the attributes of a disk file. |
|
Adjusts the position of a file pointer forward or backward based on the specified number of bytes. |
|
Specifies the offset of a returned file, in bytes. |
|
Opens a file based on the specified directory and file name. |
|
Writes data to an open file. |
|
Writes data to an open file and automatically appends a line terminator. |
|
Writes formatted data to an open file. It is a DBE_FILE.WRITE_NCHAR interface that allows formatting. |
|
Reads a line of a specified length from an open file. |
- DBE_FILE.OPEN
This function opens a file. You can specify the maximum number of characters in each line. A maximum of 50 files can be opened at a time. This function returns a handle of the INTEGER type.
The prototype of the DBE_FILE.OPEN function is as follows:
1 2 3 4 5 6
DBE_FILE.OPEN ( dir IN VARCHAR2, file_name IN VARCHAR2, open_mode IN VARCHAR2, max_line_size IN INTEGER DEFAULT 1024) RETURN INTEGER;
Table 3 DBE_FILE.OPEN interface parameters Parameter
Description
dir
Directory of a file. It is a string, indicating an object name.
NOTE:- Location of the file directory, which needs to be added to system catalog PG_DIRECTORY. If the input path does not match the path in PG_DIRECTORY, an error indicating that the path does not exist is reported.
- When the GUC parameter safe_data_path is enabled, you can only use an advanced package to read and write files in the file path specified by safe_data_path.
file_name
File name with an extension (file type), excluding the path name. A path contained in a file name is ignored in the OPEN function. In Unix, the file name cannot end with the combination of a slash and a dot (/.).
open_mode
File opening mode, including:- r: read text
- w: write text
- a: append text
- rb: read byte
- wb: write byte
- ab: append byte
NOTE:For the write operation, the system checks the file type. If the ELF file is written, an error is reported and the system exits.
max_line_size
Maximum number of characters in each line, including newline characters. The minimum value is 1 and the maximum is 32767. If this parameter is not specified, the default value 1024 is used.
- DBE_FILE.IS_CLOSE
This function detects a file handle to check whether the file is opened. A Boolean value is returned. If an invalid file handle is detected, the INVALID_FILEHANDLE exception is thrown.
The prototype of the DBE_FILE.IS_CLOSE function is as follows:
1 2 3
DBE_FILE.IS_CLOSE ( file IN INTEGER) RETURN BOOLEAN;
Table 4 DBE_FILE.IS_CLOSE parameters Parameter
Description
file IN INTEGER
File handle to be detected
- DBE_FILE.READ_LINE
This stored procedure reads text from an open file handle and stores the result in the buffer. The procedure reads data until a line end (excluding line terminator), file end, or the value specified by the len parameter. The length of the read data cannot exceed the value of the max_line_size parameter in the OPEN function.
The prototype of the DBE_FILE.READ_LINE function is as follows:
1 2 3 4
DBE_FILE.READ_LINE ( file IN INTEGER, buffer OUT VARCHAR2, len IN INTEGER DEFAULT NULL)
Table 5 DBE_FILE.READ_LINE parameters Parameter
Description
file
File handle opened by calling the OPEN function. The file must be opened in read mode. Otherwise, the INVALID_OPERATION exception is thrown.
buffer
Buffer used to receive data
len
Number of bytes read from a file. The default value is NULL. If the default value NULL is used, max_linesize is used to specify the line size.
- DBE_FILE.WRITE
This stored procedure writes data in the buffer to a file. The file must be opened in write mode. Line terminators are not written.
The prototype of the DBE_FILE.WRITE function is as follows:
1 2 3
DBE_FILE.WRITE ( file IN INTEGER, buffer IN TEXT);
Table 6 DBE_FILE.WRITE parameters Parameter
Description
file
This stored procedure writes data in the buffer to a file. The file must be opened in write mode. Line terminators are not written.
buffer
Text data to be written to a file. The maximum buffer size is 32767 bytes. If no value is specified in the open state, the default value is 1024 bytes. Before the writing is performed, the buffer occupied by WRITE operations cannot exceed 32767 bytes.
NOTE:For the write operation, the system checks the file type. If the ELF file is written, an error is reported and the system exits.
- DBE_FILE.NEW_LINE
This stored procedure writes one or more line terminators to an open file. The procedure is split from the WRITE function because line terminators are related to platforms.
The prototype of the DBE_FILE.NEW_LINE function is as follows:
1 2 3
DBE_FILE.NEW_LINE ( file IN INTEGER, line_nums IN INTEGER := 1);
Table 7 DBE_FILE.NEW_LINE parameters Parameter
Description
file
Opened file handle
line_nums
Number of terminators written to a file
- DBE_FILE.WRITE_LINE
This stored procedure writes strings in the buffer to an open file. The file must be opened in write mode.
The prototype of the DBE_FILE.WRITE_LINE function is as follows:
1 2 3 4
DBE_FILE.WRITE_LINE( file IN INTEGER, buffer IN TEXT, flush IN BOOLEAN DEFAULT FALSE);
Table 8 DBE_FILE.WRITE_LINE parameters Parameter
Description
file
Opened file handle
buffer
Text data to be written to a file. The maximum buffer size is 32767 bytes. If no value is specified in the open state, the default value is 1024 bytes. Before the writing is performed, the buffer occupied by PUT operations cannot exceed 32767 bytes.
NOTE:For the write operation, the system checks the file type. If the ELF file is written, an error is reported and the system exits.
flush
Whether to flush data to the disk after the writing
- DBE_FILE.FORMAT_WRITE
This is a formatted PUT stored procedure similar to printf().
The prototype of the DBE_FILE.FORMAT_WRITE function is as follows:
1 2 3 4 5 6
DBE_FILE.FORMAT_WRITE ( file IN INTEGER, format IN VARCHAR2, arg1 IN VARCHAR2 DEFAULT NULL, . . . arg6 IN VARCHAR2 DEFAULT NULL]);
Table 9 DBE_FILE.FORMAT_WRITE parameters Parameter
Description
file
Opened file handle
format
A string to be formatted, containing the text and format characters \n and %s
[arg1. . .arg6]
Six optional parameters. The parameters and the positions of characters to be formatted are in one-to-one correspondence. If the parameter corresponding to a character to be formatted is not provided, an empty string is used to replace %s.
- DBE_FILE.GET_RAW
This function reads binary data from the opened file descriptor and returns the data using r.
The prototype of the DBE_FILE.GET_RAW function is as follows:
1 2 3 4
DBE_FILE.GET_RAW ( file IN INTEGER, r OUT RAW, length IN INTEGER DEFAULT NULL);
Table 10 DBE_FILE.GET_RAW parameters Parameter
Description
file
Opened file handle
r
Output binary data
length
Length of the file to be read. The default value is NULL. All data in the file is read. The maximum length is 1 GB.
- DBE_FILE.PUT_RAW
This function writes binary data to a file.
The prototype of the DBE_FILE.PUT_RAW function is as follows:
1 2 3 4
DBE_FILE.PUT_RAW ( file IN INTEGER, r IN RAW, flush IN BOOLEAN DEFAULT FALSE);
Table 11 DBE_FILE.PUT_RAW parameters Parameter
Description
file
Opened file handle
r
Output binary data
NOTE:For the write operation, the system checks the file type. If the ELF file is written, an error is reported and the system exits.
flush
Specifies whether to flush data to a file. The default value is false.
- DBE_FILE.FLUSH
Data in a file handle must be written into a physical file. Data in the buffer must have a line terminator. Refresh is important if a file must be read when it is opened. For example, debugging information can be refreshed to a file so that it can be read immediately.
The prototype of the DBE_FILE.FLUSH function is as follows:
1 2
DBE_FILE.FLUSH ( file IN INTEGER);
Table 12 DBE_FILE.FLUSH parameters Parameter
Description
file
Opened file handle
- DBE_FILE.CLOSE
This stored procedure closes an open file handle. When the stored procedure is called, exception is thrown if there is data to be written into the buffer.
The prototype of the DBE_FILE.CLOSE function is as follows:
1 2 3
DBE_FILE.CLOSE ( file IN INTEGER )RETURN INTEGER;
Table 13 DBE_FILE.CLOSE parameters Parameter
Description
file
Opened file handle
- DBE_FILE.CLOSE_ALL
This stored procedure closes all file handles opened in a session and can be used for emergency cleanup.
The prototype of the DBE_FILE.CLOSE_ALL function is as follows:
1
DBE_FILE.CLOSE_ALL;
Table 14 DBE_FILE.CLOSE_ALL parameters Parameter
Description
None
None
- DBE_FILE.REMOVE
This stored procedure deletes a disk file. To perform this operation, you must have required permissions for the directories and files.
The prototype of the DBE_FILE.REMOVE function is as follows:
1 2 3
DBE_FILE.REMOVE ( dir IN VARCHAR2, file_name IN VARCHAR2);
Table 15 DBE_FILE.REMOVE parameters Parameter
Description
dir
File directory
NOTE:- Location of the file directory, which needs to be added to system catalog PG_DIRECTORY. If the input path does not match the path in PG_DIRECTORY, an error indicating that the path does not exist is reported.
- When the GUC parameter safe_data_path is enabled, you can only use an advanced package to operate files in the file path specified by safe_data_path.
file_name
File to be deleted
- DBE_FILE.RENAME
This function renames files on the disk, similar to mv in Unix.
The prototype of the DBE_FILE.RENAME function is as follows:
1 2 3 4 5 6
DBE_FILE.RENAME ( src_dir IN VARCHAR2, src_file_name IN VARCHAR2, dest_dir IN VARCHAR2, dest_file_name IN VARCHAR2, overwrite IN BOOLEAN DEFAULT FALSE);
Table 16 DBE_FILE.RENAME parameters Parameter
Description
src_dir
Directory of the original file (case-sensitive)
NOTE:- Location of the file directory, which needs to be added to system catalog PG_DIRECTORY. If the input path does not match the path in PG_DIRECTORY, an error indicating that the path does not exist is reported.
- When the GUC parameter safe_data_path is enabled, you can only use an advanced package to operate files in the file path specified by safe_data_path.
src_file_name
Original file to be renamed
dest_dir
Destination directory (case-sensitive)
NOTE:- Location of the file directory, which needs to be added to system catalog PG_DIRECTORY. If the input path does not match the path in PG_DIRECTORY, an error indicating that the path does not exist is reported.
- When the GUC parameter safe_data_path is enabled, you can only use an advanced package to operate files in the file path specified by safe_data_path.
dest_file_name
New file name
overwrite
The default value is false. If a file with the same name exists in the destination directory, the file will not be rewritten.
- DBE_FILE.COPY
This stored procedure copies data in a continuous area to a new file. If start_line and end_line are omitted, the entire file is copied.
The prototype of the DBE_FILE.COPY function is as follows:
1 2 3 4 5 6 7
DBE_FILE.COPY ( src_dir IN VARCHAR2, src_file_name IN VARCHAR2, dest_dir IN VARCHAR2, dest_file_name IN VARCHAR2, start_line IN INTEGER DEFAULT 1, end_line IN INTEGER DEFAULT NULL);
Table 17 DBE_FILE.COPY parameters Parameter
Description
src_dir
Directory of the original file
NOTE:- Location of the file directory, which needs to be added to system catalog PG_DIRECTORY. If the input path does not match the path in PG_DIRECTORY, an error indicating that the path does not exist is reported.
- When the GUC parameter safe_data_path is enabled, you can only use an advanced package to operate files in the file path specified by safe_data_path.
src_file_name
File to be copied
dest_dir
Directory of the destination file
NOTE:- Location of the file directory, which needs to be added to system catalog PG_DIRECTORY. If the input path does not match the path in PG_DIRECTORY, an error indicating that the path does not exist is reported.
- When the GUC parameter safe_data_path is enabled, you can only use an advanced package to operate files in the file path specified by safe_data_path.
dest_file_name
Destination file to which data is to be written
NOTE:For the write operation, the system checks the file type. If the ELF file is written, an error is reported and the system exits.
start_line
Number of the line where the copy starts. The default value is 1.
end_line
Number of the line where the copy ends. The default value is NULL, indicating the end of the file.
- DBE_FILE.GET_ATTR
This stored procedure reads and returns the attributes of a disk file.
The prototype of the DBE_FILE.GET_ATTR function is as follows:
1 2 3 4 5 6
DBE_FILE.GET_ATTR( location IN text, filename IN text, OUT fexists boolean, OUT file_length bigint, OUT block_size integer);
Table 18 DBE_FILE.GET_ATTR parameters Parameter
Description
location
File directory
NOTE:- Location of the file directory, which needs to be added to system catalog PG_DIRECTORY. If the input path does not match the path in PG_DIRECTORY, an error indicating that the path does not exist is reported.
- When the GUC parameter safe_data_path is enabled, you can only use an advanced package to operate files in the file path specified by safe_data_path.
filename
Name of the file to be checked
fexists
Whether the file exists
file_length
File length (unit: bytes). If the file does not exist, NULL is returned.
block_size
Block size of the file system (unit: byte). If the file does not exist, NULL is returned.
- DBE_FILE.SEEK
This stored procedure adjusts the position of a file pointer forward or backward based on the specified number of bytes.
The prototype of the DBE_FILE.SEEK function is as follows:
1 2 3 4
DBE_FILE.SEEK ( file IN INTEGER, absolute_start IN BIGINT DEFAULT NULL, relative_start IN BIGINT DEFAULT NULL);
Table 19 DBE_FILE.SEEK parameters Parameter
Description
file
Opened file handle
absolute_start
Absolute offset of a file. The default value is NULL.
relative_start
Relative offset of a file. A positive number indicates forward offset and a negative number indicates backward offset. The default value is NULL. If both absolute_start and this parameter are specified, the absolute_start parameter is used.
- DBE_FILE.GET_POS
This function returns file offset in bytes.
The prototype of the DBE_FILE.FGETPOS function is as follows:
1 2 3
DBE_FILE.GET_POS ( file IN INTEGER) RETURN BIGINT;
Table 20 DBE_FILE.GET_POS parameters Parameter
Description
file
Opened file handle
- DBE_FILE.FOPEN_NCHAR
Opens a file. You can specify the maximum line size. A maximum of 50 files can be opened in a session. This function returns a file handle of the DBE_FILE.FILE_TYPE type. This function opens a file in national character set mode for input or output.
The prototype of the DBE_FILE.FOPEN_NCHAR function is as follows:1 2 3 4 5 6
DBE_FILE.FOPEN_NCHAR( dir IN TEXT, file_name IN TEXT, open_mode IN TEXT, max_line_size IN INTEGER DEFAULT 1024) RETURN DBE_FILE.FILE_TYPE;
Table 21 DBE_FILE.FOPEN_NCHAR parameters Parameter
Description
dir
Directory of a file. It is a string, indicating an object name.
NOTE:- Location of the file directory, which needs to be added to system catalog PG_DIRECTORY. If the input path does not match the path in PG_DIRECTORY, an error indicating that the path does not exist is reported.
- When the GUC parameter safe_data_path is enabled, you can only use an advanced package to read and write files in the file path specified by safe_data_path.
file_name
File name with an extension (file type), excluding the path name. A path contained in a file name is ignored in the FOPEN_NCHAR function. In Unix, the file name cannot end with the combination of a slash and a dot (/.).
open_mode
File opening mode, including:
- r: read text
- w: write text
- a: append text
- rb: read byte
- wb: write byte
- ab: append byte
NOTE:For the write operation, the system checks the file type. If the ELF file is written, an error is reported and the system exits.
max_line_size
Maximum number of characters in each line, including newline characters. The minimum value is 1 and the maximum is 32767. If this parameter is not specified, the default value 1024 is used.
- DBE_FILE.WRITE_NCHAR
Writes data in the buffer to a file. The file must be opened in national character set or write mode. This operation does not write a line terminator, and the return value is always TRUE. The text string is written in the UTF8 character set format.
The prototype of the DBE_FILE.WRITE_NCHAR function is as follows:1 2 3 4
DBE_FILE.WRITE_NCHAR( file IN DBE_FILE.FILE_TYPE, buffer IN NVARCHAR2) RETURN VOID;
Table 22 DBE_FILE.WRITE parameters Parameter
Description
file
Object of the DBE_FILE.FILE_TYPE type opened using FOPEN_NCHAR. The file must be opened in write mode. This operation does not write line terminators.
buffer
Text data to be written to the file. The accumulated write length of each line cannot be greater than or equal to the value of max_line_size specified by FOPEN_NCHAR. Otherwise, an error is reported when the file is refreshed.
NOTE:For the write operation, the system checks the file type. If the ELF file is written, an error is reported and the system exits.
- DBE_FILE.WRITE_LINE_NCHAR
Writes data in the buffer to a file. The file must be opened in national character set or write mode. This operation automatically appends line terminators, and the return value is always TRUE. The text string is written in the UTF8 character set format.
The prototype of the DBE_FILE.WRITE_LINE_NCHAR function is as follows:1 2 3 4
DBE_FILE.WRITE_LINE_NCHAR( file IN DBE_FILE.FILE_TYPE, buffer IN NVARCHAR2) RETURN VOID;
Table 23 DBE_FILE.WRITE_LINE parameters Parameter
Description
file
Object of the DBE_FILE.FILE_TYPE type opened using FOPEN_NCHAR.
buffer
Text data to be written to the file. The length of each line (including the newline character) cannot be greater than the value of max_line_size specified by FOPEN_NCHAR or the default value. Otherwise, an error is reported when the file is refreshed.
NOTE:For the write operation, the system checks the file type. If the ELF file is written, an error is reported and the system exits.
- DBE_FILE.FORMAT_WRITE_NCHAR
Writes formatted data to an open file. It is a DBE_FILE.WRITE_NCHAR interface that allows formatting. The return value is always TRUE.
The prototype of the DBE_FILE.FORMAT_WRITE_NCHAR function is as follows:1 2 3 4 5 6 7
DBE_FILE.FORMAT_WRITE_NCHAR( file IN DBE_FILE.FILE_TYPE, format IN NVARCHAR2, arg1 IN NVARCHAR2 DEFAULT NULL, . . . arg5 IN NVARCHAR2 DEFAULT NULL) RETURN VOID;
Table 24 DBE_FILE.FORMAT_WRITE_NCHAR parameters Parameter
Description
file
Object of the DBE_FILE.FILE_TYPE type opened using FOPEN_NCHAR.
format
Formatted string, containing the text and format characters \n and %s.
[arg1. . .arg5]
Five optional parameters. The parameters and the positions of characters to be formatted are in one-to-one correspondence. If the parameter corresponding to a character to be formatted is not provided, an empty string is used to replace %s.
- DBE_FILE.READ_LINE_NCHAR
Reads data from an open file and stores the read result to the buffer. It reads data to the end of each line excluding the line terminator, to the end of the file, or to the size specified by the len parameter. The length of the data to be read cannot exceed the value of max_line_size specified by FOPEN_NCHAR.
The prototype of the DBE_FILE.READ_LINE_NCHAR stored procedure is as follows:1 2 3 4
DBE_FILE.READ_LINE_NCHAR( file IN DBE_FILE.FILE_TYPE, buffer OUT NVARCHAR2, len IN INTEGER DEFAULT NULL);
Table 25 DBE_FILE.READ_LINE parameters Parameter
Description
file
Object of the DBE_FILE.FILE_TYPE type opened using FOPEN_NCHAR. The file must be opened in read mode. Otherwise, the INVALID_OPERATION exception is thrown.
buffer
Buffer for receiving data.
len
Number of bytes read from the file. The default value is NULL. If the default value NULL is used, max_line_size is used to specify the line size.
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
-- Add the /temp/ directory to the PG_DIRECTORY system catalog as a system administrator. CREATE OR REPLACE DIRECTORY dir AS '/tmp/'; -- Open a file and write data into the file. DECLARE f integer; dir text := 'dir'; BEGIN f := dbe_file.open(dir, 'sample.txt', 'w'); PERFORM dbe_file.write_line(f, 'ABC'); PERFORM dbe_file.write_line(f, '123'::numeric); PERFORM dbe_file.write_line(f, '-----'); PERFORM dbe_file.new_line(f); PERFORM dbe_file.write_line(f, '*******'); PERFORM dbe_file.new_line(f, 0); PERFORM dbe_file.write_line(f, '++++++++'); PERFORM dbe_file.new_line(f, 2); PERFORM dbe_file.write_line(f, '#######'); PERFORM dbe_file.write(f, 'A'); PERFORM dbe_file.write(f, 'B'); PERFORM dbe_file.new_line(f); PERFORM dbe_file.format_write(f, '[1 -> %s, 2 -> %s, 3 -> %s, 4 -> %s, 5 -> %s]', 'gaussdb', 'dbe', 'file', 'get', 'line'); PERFORM dbe_file.new_line(f); PERFORM dbe_file.write_line(f, '1234567890'); f := dbe_file.close(f); END; / -- Read data from the file mentioned above. DECLARE f integer; dir text := 'dir'; BEGIN f := dbe_file.open(dir, 'sample.txt', 'r'); FOR i IN 1..11 LOOP RAISE INFO '[%] : %', i, dbe_file.read_line(f); END LOOP; END; / -- Offset the file handle and obtain the current file location. DECLARE l_file integer; l_buffer VARCHAR2(32767); dir text := 'dir'; abs_offset number := 100; rel_offset number := NULL; BEGIN l_file := dbe_file.open(dir => dir, file_name => 'sample.txt',open_mode => 'R'); dbe_output.print_line('before seek: current position is ' || dbe_file.get_pos(file => l_file)); -- before seek: current position is 0 dbe_file.seek(file => l_file, absolute_start=>abs_offset, relative_start=>rel_offset); dbe_output.print_line('fseek: current position is ' || dbe_file.get_pos(file => l_file)); -- seek: current position is 100 l_file := dbe_file.close(file => l_file); END; / -- NCHAR read/write API cases DECLARE f DBE_FILE.FILE_TYPE; buffer NVARCHAR2; BEGIN -- Write a file. f := DBE_FILE.FOPEN_NCHAR('dir', 'sample02.txt', 'w'); DBE_FILE.WRITE_NCHAR(f, 'A'); DBE_FILE.WRITE_NCHAR(f, 'B'); DBE_FILE.WRITE_NCHAR(f, 'C'); DBE_FILE.NEW_LINE(f); DBE_FILE.WRITE_LINE_NCHAR(f, 'ABC'); DBE_FILE.FORMAT_WRITE_NCHAR(f, '[1 -> %s, 2 -> %s]\n', 'GaussDB', 'DBE_FILE'); DBE_FILE.CLOSE(f); -- Read a file. f := DBE_FILE.FOPEN_NCHAR('dir', 'sample02.txt', 'r'); DBE_FILE.READ_LINE_NCHAR(f, buffer); -- ABC DBE_FILE.READ_LINE_NCHAR(f, buffer); -- ABC DBE_FILE.READ_LINE_NCHAR(f, buffer); -- [1 -> GaussDB, 2 -> DBE_FILE] DBE_OUTPUT.PRINT_LINE(buffer); DBE_FILE.CLOSE(f); END; / |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot