Store image files to Oracle stored procedures

xiaoxiao2021-03-06  45

Test environment: Win2000 Oracle92

A process of storing image files, any development tool can store image text into the database by calling procedures.

detailed steps:

Microsoft Windows 2000 [Version 5.00.2195]

(C) All rights reserved 1985-2000 Microsoft Corp.

C: / Documents and Settings / Chanet> CD /

C: /> SQLPLUS / NOLOG

SQL * Plus: Release 9.2.0.1.0 - Production on Wednesday, January 19 14:46:21 2005

CopyRight (C) 1982, 2002, Oracle Corporation. All Rights Reserved.

SQL> Connect ChanaT / Chanet @ ORADB;

connected.

SQL> CREATE TABLE Image_LOB (T_ID VARCHAR2 (5) Not Null, T_Image Blob Not NULL

The table has been created.

SQL> Create or Replace Directory images as 'c: / oracle'; - Picture Directory

The directory has been created.

SQL> Create or Replace Procedure IMG_INSERT (Tid Varchar2, FileName Varchar2) AS

2 f_lob bfile;

3 b_lob blob;

4 Begin

5 INSERT INTO Image_LOB (T_ID, T_IMAGE)

6 VALUES (TID, EMPTY_BLOB ()) RETURN T_IMAGE INTO B_LOB;

7 f_lob: = bfileName ('Images', filename);

8 dBMS_LOB.FILEOPEN (F_LOB, DBMS_LOB.FILE_READOONLY);

9 dBMS_LOB.LOADFROMFILE (B_LOB, F_LOB,

10 dBMS_LOB.GETLENGTH (F_LOB));

11 dBMS_LOB.FileClose (f_lob);

12 commit;

13 End;

14 /

The process has been created.

SQL> - Example SQL> EXEC IMG_INSERT ('1', 'f_test.jpg');

The PL / SQL process has been successfully completed.

转载请注明原文地址:https://www.9cbs.com/read-67105.html

New Post(0)