How to use put function.my procedure is not compiling with put. but putline is working fine. i want to print in the same line
The UTL_FILE package lets your PL/SQL programs read and write operating system (OS) text files. It provides a restricted version of standard OS stream file input/output (I/O).
SQL> -- Simple PLSQL to open a file, SQL> -- write two lines into the file, SQL> -- and close the file SQL> declare 2 fhandle utl_file. file_type; 3 begin 4 fhandle := utl_file. fopen( 5 'UTL_DIR' -- File location 6 , 'test_file.
FOPEN returns a file handle, which must be passed to all subsequent procedures that operate on that file. The specific contents of the file handle are private to the UTL_FILE package, and individual components should not be referenced or changed by the UTL_FILE user. Handle to open file.
This procedure flushes the pending data identified by the file handle into the file. This procedure is useful when we want to read the file while it is still open. For example, the debugging and logging files can be read immediately once they are flushed with messages.
Here's an example of code which uses the UTL_FILE.PUT and UTL_FILE.PUT_LINE calls:
declare
fHandle UTL_FILE.FILE_TYPE;
begin
fHandle := UTL_FILE.FOPEN('my_directory', 'test_file', 'w');
UTL_FILE.PUT(fHandle, 'This is the first line');
UTL_FILE.PUT(fHandle, 'This is the second line');
UTL_FILE.PUT_LINE(fHandle, 'This is the third line');
UTL_FILE.FCLOSE(fHandle);
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Exception: SQLCODE=' || SQLCODE || ' SQLERRM=' || SQLERRM);
RAISE;
end;
The output from this looks like:
This is the first lineThis is the second lineThis is the third line
Share and enjoy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With