我建了一个表tipian
create table tipian
(name char,
tupian blob)
tablespace myg;我如何插入一个图片
图片的位置在本机上目录为:f:\tupian\wangye\0079_gif.gif
我打算使用BFILENAME来指向目录和文件(需要有 DBA角色或 CREATE DIRECTORY 权限)。为了创建一个目录,要使用Create directory命令。如:
我执行下面的命令过不去
SQL> create directory '0079' for 'f:\tupian\wangye\';
create directory '0079' for 'f:\tupian\wangye\'
                 *
ERROR 位于第1行:
ORA-22929: 无效或遗失的目录名称请问如何把图片插入到表中?

解决方案 »

  1.   

    grant create any directory to scott;
    grant create any library to scott;
    create or replace directory utllobdir as 'G:\oracle';
    create table bfile_tab (bfile_column BFILE);
    create table utl_lob_test (blob_column BLOB);set serveroutput on然后执行下面语句就将G:\oracle目录下的Azul.jpg存入到utl_lob_test 
    表中的blob_column字段中了。
    declare
       a_blob  BLOB;
       a_bfile BFILE := BFILENAME('UTLLOBDIR','Azul.jpg'); 
    begin
       insert into bfile_tab values (a_bfile)
         returning bfile_column into a_bfile;
       insert into utl_lob_test values (empty_blob())
         returning blob_column into a_blob;
       dbms_lob.fileopen(a_bfile);
       dbms_lob.loadfromfile(a_blob, a_bfile, dbms_lob.getlength(a_bfile));
       dbms_lob.fileclose(a_bfile);
       commit;
    end;
    /
    select dbms_lob.getlength(blob_column) from UTL_LOB_TEST;
      

  2.   

    ORA-22929 invalid or missing directory nameCause: The required directory name is invalid or missing.Action: Specify a valid name你确定这个目录确实存在吗?
      

  3.   

    不是这样写的,应该是SQL> create directory “0079”as 'f:\tupian\wangye\';
      

  4.   

    bzszp(SongZip) 用你的方法到到系统文件大小好像和外部文件大小不一样,UTL_FILE.PUT_RAW导出文件会变型?,文件大小均没有改变。
      

  5.   

    外部文件图像格式JPG,或PDF文件均,存进数据库文件大小均和外部文件不一样,造成文件导出不能正常显示。文件大小均小于32K
      

  6.   

    对不起错了,我用JAVA过程可以正常导出文件,