Stored procedure to read the data from the BFILE into the clob clob and display the new clob contents. : bfilename « Large Objects « Oracle PL/SQL Tutorial

Oracle PL/SQL Tutorial
1. Introduction
2. Query Select
3. Set
4. Insert Update Delete
5. Sequences
6. Table
7. Table Joins
8. View
9. Index
10. SQL Data Types
11. Character String Functions
12. Aggregate Functions
13. Date Timestamp Functions
14. Numerical Math Functions
15. Conversion Functions
16. Analytical Functions
17. Miscellaneous Functions
18. Regular Expressions Functions
19. Statistical Functions
20. Linear Regression Functions
21. PL SQL Data Types
22. PL SQL Statements
23. PL SQL Operators
24. PL SQL Programming
25. Cursor
26. Collections
27. Function Procedure Packages
28. Trigger
29. SQL PLUS Session Environment
30. System Tables Data Dictionary
31. System Packages
32. Object Oriented
33. XML
34. Large Objects
35. Transaction
36. User Privilege
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Oracle PL/SQL Tutorial » Large Objects » bfilename 
34. 12. 3. Stored procedure to read the data from the BFILE into the clob clob and display the new clob contents.
SQL>
SQL> create table myTable
  2  (key NUMBER PRIMARY KEY
  3  ,col_blob BLOB
  4  ,col_clob CLOB);

Table created.

SQL>
SQL> INSERT INTO myTable (key, col_blob, col_clob)
  2  VALUES (1, HEXTORAW('101F'), 'ZYXW');

row created.

SQL>
SQL>
SQL> ALTER TABLE myTable add (col_bfile BFILE);

Table altered.

SQL>
SQL> CREATE OR REPLACE PROCEDURE sp_bfile_read
  2  IS
  3      v_fileloc   BFILE;
  4      v_col_clob  CLOB;
  5      v_filename  VARCHAR2(2000);
  6      v_amount    NUMBER := 80;
  7      v_offset    NUMBER := 1;
  8      v_buffer    VARCHAR2(80);
  9
 10      v_dir   VARCHAR2(80:= 'INFILE';
 11
 12  BEGIN
 13      v_fileloc := BFILENAME (v_dir, 'b_file.txt');
 14
 15      DBMS_LOB.FILEOPEN (v_fileloc, DBMS_LOB.FILE_READONLY);
 16
 17      SELECT col_clob
 18      INTO v_col_clob
 19      FROM myTable
 20      WHERE key = 2
 21      FOR UPDATE;
 22
 23      DBMS_LOB.LOADFROMFILE (v_col_clob, v_fileloc, DBMS_LOB.GETLENGTH (v_fileloc) );
 24      DBMS_LOB.READ (v_col_clob, v_amount, v_offset, v_buffer);
 25
 26      DBMS_OUTPUT.PUT_LINE (v_buffer);
 27
 28      DBMS_LOB.FILECLOSE (v_fileloc);
 29   EXCEPTION
 30      WHEN NO_DATA_FOUND THEN
 31      DBMS_LOB.FILECLOSEALL;
 32      RAISE_APPLICATION_ERROR(-20001'No data found!');
 33
 34      WHEN VALUE_ERROR THEN
 35      DBMS_LOB.FILECLOSEALL;
 36      RAISE_APPLICATION_ERROR(-20001'Value Error!');
 37
 38      WHEN DBMS_LOB.INVALID_ARGVAL THEN
 39      DBMS_LOB.FILECLOSEALL;
 40      RAISE_APPLICATION_ERROR(-20001'Read only mode not specified');
 41
 42      WHEN OTHERS THEN
 43      DBMS_LOB.FILECLOSEALL;
 44      RAISE_APPLICATION_ERROR(-20009'Other exception raised: ' || SQLCODE);
 45  END;
 46  /

Procedure created.

SQL>
SQL> exec sp_bfile_read



SQL>
SQL> drop table myTable;

Table dropped.

SQL>
34. 12. bfilename
34. 12. 1. bfilename function
34. 12. 2. Use the file named b_file.txt and attach it to the myTable table in the col_bfile column.
34. 12. 3. Stored procedure to read the data from the BFILE into the clob clob and display the new clob contents.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.