ヘッダーをスキップ
Oracle Multimediaユーザーズ・ガイド
11gリリース1(11.1)
E05684-01
  目次
目次
索引
索引

戻る
戻る
 
次へ
次へ
 

9 Oracle Multimediaの例

この章では、Oracle Multimediaでの一般的な操作の例を示します。次のデータ・グループ別に例を示します。

これらの項には、次のような一般的な操作を実行するスクリプトが含まれています。

これらのスクリプトおよびその他の例は、次のURLで、OTN(Oracle Technology Network)のWebサイトのOracle Multimediaのサンプルコードのセクションで参照できます。

http://www.oracle.com/technology/products/multimedia/

「Oracle Multimedia Resources」の下にある「Sample Code」をクリックすると、Oracle MultimediaのサンプルコードのWebページが表示されます。表示されたページで、「Multimedia Code Samples」の下にある「Use Multimedia and PL/SQL to manage media content」を選択します。

9.1 オーディオ・データの例

Oracle Multimediaを使用するオーディオ・データの例では、次の一般的な操作を行います。

これらの例で使用するメソッドに関する参照情報は、『Oracle Multimediaリファレンス』を参照してください。

9.1.1 オブジェクト・ビューでのオーディオ型の使用

この項では、オブジェクト・ビューとともにオーディオ型を使用する方法を説明します。ビューが仮想表であることと同様、オブジェクト・ビューは仮想的なオブジェクト表です。

Oracleには、基本的なリレーショナル・ビュー・メカニズムの拡張として、オブジェクト・ビューがあります。オブジェクト・ビューを使用することによって、データベースのリレーショナル表やオブジェクト表の列に格納されている、組込み型またはユーザー定義型のいずれかのデータから、仮想的なオブジェクト表を作成できます。

オブジェクト・ビューを使用すると、データベース内のデータおよびオブジェクトに対するアクセスをカスタマイズまたは制限できます。たとえば、オブジェクト・ビューを使用して、機密性の高いデータや削除メソッドが含まれる属性を除いた従業員オブジェクト表を提供できます。また、オブジェクト・ビューを使用することによって、表を変換しなくても、オブジェクト指向のプログラミングを実行できます。オブジェクト・ビューを使用すると、リレーショナル表からオブジェクト・リレーショナル表へ段階的かつ透過的にデータを変換できます。

例9-1で、次のような(ORDAudioオブジェクトを含まない)リレーショナル表について考えてみます。

例9-1 ORDAudioオブジェクトを含まないリレーショナル表の定義

create table flat (
   id                NUMBER,
   description       VARCHAR2(4000),
   localData         BLOB,
   srcType           VARCHAR2(4000),
   srcLocation       VARCHAR2(4000),
   srcName           VARCHAR2(4000),
   upDateTime        DATE,
   local             NUMBER,
   format            VARCHAR2(31),
   mimeType          VARCHAR2(4000),
   comments          CLOB,
   encoding          VARCHAR2(256),
   numberOfChannels  NUMBER,
   samplingRate      NUMBER,
   sampleSize        NUMBER,
   compressionType   VARCHAR2(4000),
   audioDuration     NUMBER,
)
--
-- store audio data as SecureFile LOBs
--
LOB(localData) STORE AS SECUREFILE;

例9-1のリレーショナル表から、例9-2に示すオブジェクト・ビューを作成できます。

例9-2 ORDAudioオブジェクトとリレーショナル列を含むオブジェクト・ビューの定義

create or replace view object_audio_v as
  select
      id,
      ORDSYS.ORDAudio(T.description,
      ORDSYS.ORDSource(
         T.localData, T.srctype, T.srcLocation, T.srcName, T.updateTime,
         T.local),
         T.format,
         T.mimeType,
         T.comments,
         T.encoding,
         T.numberOfChannels,
         T.samplingRate,
         T.sampleSize,
         T.compressionType,
         T.audioDuration)
   from flat T;

オブジェクト・ビューを使用すると、同じリレーショナル・データまたはオブジェクト・データを、複数の方法で柔軟に表示できます。このため、データベース内のデータの格納方法を変更しなくても、メモリー内のオブジェクトを様なアプリケーションに合わせて異なる方法で表現することができます。オブジェクト・ビューの定義、使用および更新の詳細は、『Oracle Database概要』を参照してください。

9.1.2 ORDAudioオブジェクトにBLOBデータを移入するスクリプト

この項に示すスクリプトでは、データベースに格納されている既存のBLOBからOracle MultimediaのORDAudioオブジェクトに移入する方法を示します。

表9-1に、各スクリプトの名前とスクリプトが実行する操作の簡単な説明を示します。各スクリプトの詳細は、その後の項を参照してください。

表9-1 オーディオ・スクリプト

スクリプト名 実行する操作

create_mediadir.sql

例9-3

オーディオ・データをロードするディレクトリを作成します。

9.1.2.1項を参照)

create_soundtable.sql

例9-4

soundtable表を作成し、移入します。

9.1.2.2項を参照)

create_audtable.sql

例9-5

audio_table表を作成し、移入します。

9.1.2.3項を参照)

import_aud.sql

例9-6

オーディオ・データをロードします。このスクリプトは、ORDAudio import( )メソッドを使用して、オーディオ・データをsoundtable表からaudio_table表にインポートします。

9.1.2.4項を参照)

copy_audblob.sql

例9-7

SQL UPDATE文を使用して、BLOBデータをsoundtable表からaudio_table表にコピーします。

9.1.2.5項を参照)

showprop_aud.sql

例9-8

audio_table表に格納されている、ロードしたオーディオ・データのプロパティを表示します。

9.1.2.6項を参照)

setup_audsample.sql

例9-9

前述のオーディオ・スクリプトを必要な順に実行して、処理を自動化します。

9.1.2.7項を参照)

cleanup_audsample.sql

例9-10

サンプル表、ディレクトリおよびプロシージャをデータベースから削除し、処理をクリーンアップします。

9.1.2.8項を参照)


9.1.2.1 オーディオ・データをロードするディレクトリの作成

create_mediadir.sqlスクリプトは、オーディオ・データをロードするディレクトリを作成します。このスクリプトを例9-3に示します。

オーディオ・データを正常にロードするには、ディレクトリをシステムに作成しておく必要があります。例9-3では、mediadirディレクトリを使用します。このディレクトリに、サンプル・オーディオ・クリップ・ファイルを格納する必要があります。次の例では、サンプル・ファイルaud1.wavが使用されています。実際には、サポートされている任意のオーディオ・ファイルをmediadirディレクトリにコピーして、これらの例のスクリプトを実行できます。mediadirディレクトリのディレクトリ・パスおよびディスク・ドライブは、create_mediadir.sqlファイルのCREATE DIRECTORY文で指定する必要があります。


注意:

このスクリプトを実行するには、CREATE ANY DIRECTORY権限が必要です。オーディオ・データをロードするディレクトリの以前のインスタンスを削除する場合は、DROP ANY DIRECTORY権限も必要です。CREATE DIRECTORY文のディレクトリ・パスを変更するには、create_mediadir.sqlファイルを編集する必要があります。他のデモ・スクリプトを実行したユーザーとは異なるユーザーでcreate_mediadir.sqlスクリプトを実行する場合は、GRANT READ文のユーザーも変更する必要があります。手順の詳細は、次のスクリプトを参照してください。

例9-3 create_mediadir.sql

-- create_mediadir.sql
-- You must have the CREATE ANY DIRECTORY privilege to run this script.
--
-- You must edit this script to:
--  o replace the directory path in the CREATE DIRECTORY statement
--    with your own (see below for details)
--  o uncomment the GRANT READ ON DIRECTORY statement and grant to the
--    user under which you will run this demo

SET SERVEROUTPUT ON;
SET ECHO ON;

-- You need DROP ANY DIRECTORY privilege to delete a directory. If there
-- is no need to delete the directory, then leave the next line
-- commented out.
-- DROP DIRECTORY mediadir;

-- Create the mediadir load directory, the directory where the image
-- clips reside. You must specify the disk drive and path in the
-- CREATE DIRECTORY statement below. Edit this file to replace the
-- directory specification with your own.
CREATE OR REPLACE DIRECTORY mediadir AS 'C:/mediadir';

-- If you intend to run this demo under a user other than the user
-- that just created this directory, edit the following grant to grant
-- READ on the directory just created to the user under which you will
-- run the demo scripts.  For example, if you will run the demo scripts
-- under user 'SCOTT', then replace the string "<USER>" with "SCOTT".
-- Then uncomment the following GRANT statement.  There is no need to
-- do this if the user creating the directory will also be used to run
-- the other demo scripts.
-- GRANT READ ON DIRECTORY mediadir TO <USER>;

9.1.2.2 soundtable表の作成および移入

create_soundtable.sqlスクリプトは、soundtable表を作成し、移入します。この表には、BLOB列が含まれます。BLOB列を含む表から、Oracle Multimedia ORDAudio列を表に移入する方法を示します。soundtable表は、デモ目的にのみ作成されます。このスクリプトを例9-4に示します。

BLOB列を含む表から、Oracle Multimedia ORDAudio列を表に移入する方法を示すには、まず、BLOB列を含む表が必要です。soundtable表は、BLOB列を含むサンプル表です。このスクリプトでは、soundtable表を作成し、空のBLOBからなる1行を挿入し、その行にオーディオ・データを含むBLOBをロードした後、BLOBデータ長をチェックします。

create_soundtable.sqlスクリプト内のデータ・ファイル名は、使用するデータ・ファイルの名前に合わせて変更してください。


注意:

このスクリプトは、必ずCREATE TABLE権限を持つユーザーが実行してください。

例9-4 create_soundtable.sql

-- create_soundtable.sql
--
-- This script must be run from a user with CREATE TABLE privilege.
--
-- Create the soundtable table.  This table is used ONLY to show
-- how to copy data from a BLOB column to an ORDAudio column.
--
-- Insert a row into the table with an empty BLOB.
-- Load the row with BLOB data by pointing to the audio file to
-- be loaded from the directory specified using the BFILE data
-- type.
-- Close the files and commit the transaction.
-- Check the length of the BLOB loaded. Is the length
-- what you are expecting?
--

SET SERVEROUTPUT ON;
SET ECHO ON;

DROP TABLE soundtable PURGE;
CREATE TABLE soundtable ( id number,
                         sound BLOB
       default EMPTY_BLOB() )
--
-- store audio data as SecureFile LOBs
--
LOB(sound) STORE AS SECUREFILE;
--
INSERT INTO soundtable(id, sound) VALUES (1, EMPTY_BLOB());
COMMIT;
DECLARE
   f_lob BFILE := BFILENAME('MEDIADIR','aud1.wav');
   b_lob BLOB;
   Lob BLOB;
   Length INTEGER;
BEGIN

  SELECT sound INTO b_lob FROM soundtable WHERE id=1 FOR UPDATE;

-- Open the LOBs.
  dbms_lob.open(f_lob, dbms_lob.file_readonly);
  dbms_lob.open(b_lob, dbms_lob.lob_readwrite);

-- Populate the BLOB from the 'aud1.wav' file in the BFILE
  dbms_lob.loadfromfile
     (b_lob, f_lob, dbms_lob.getlength(f_lob));

-- Close the LOBs.
  dbms_lob.close(b_lob);
  dbms_lob.close(f_lob);
  COMMIT;

-- Select the LOB:
  SELECT sound INTO Lob FROM soundtable
      WHERE ID = 1;

-- Opening the LOB is optional.
  DBMS_LOB.OPEN (Lob, DBMS_LOB.LOB_READONLY);
-- Get the length of the LOB and verify length is not null.
  length := DBMS_LOB.GETLENGTH(Lob);
  IF length IS NULL THEN
    DBMS_OUTPUT.PUT_LINE('LOB is null.');
  ELSE
    DBMS_OUTPUT.PUT_LINE('The length is ' || length);
  END IF;
-- Closing the LOB is mandatory if you have opened it.
  DBMS_LOB.CLOSE (Lob);
END;
/

9.1.2.3 audio_table表の作成および移入

create_audtable.sqlスクリプトは、audio_table表を作成し、移入します。この表には、ORDAudio列が含まれます。このスクリプトは、2列(idおよびaudio)のaudio_table表を作成し、その表に2行を挿入してaudio列を初期化します。このスクリプトを例9-5に示します。


注意:

ORDAudio.init( )メソッドをコールすることによって、ORDAudioオブジェクトのBLOB属性が初期化されます。初期化は、BLOBにデータを移入するために必要です。

このスクリプトは、必ずCREATE TABLE権限を持つユーザーが実行してください。


例9-5 reate_audtable.sql

-- create_audtable.sql
--
-- This script must be run from a user with the CREATE TABLE privilege.
--
-- Create the audio_table table.
-- Insert two rows with empty BLOBs and initialize object attributes.


SET SERVEROUTPUT ON;
SET ECHO ON;

DROP TABLE audio_table PURGE;


CREATE TABLE audio_table ( id NUMBER,
                       audio ORDAudio )
LOB(audio.source.localData) STORE AS SECUREFILE;


-- Insert rows with an empty BLOB and initialize the object attributes.

INSERT INTO audio_table VALUES(1,ORDAudio.init());
INSERT INTO audio_table VALUES(2,ORDAudio.init());

COMMIT;

9.1.2.4 オーディオ・データのロード

import_aud.sqlスクリプトは、ORDAudio import( )メソッドを使用して、オーディオ・ファイル(soundtable表内)からaudio_table表のORDAudio列に、オーディオ・データをインポートします。オーディオ・クリップが格納されるBLOB属性にデータをインポートするには、行のオーディオ列が更新用に選択されている必要があります。このスクリプトを例9-6に示します。

このスクリプトを正常に実行するには、このスクリプトで指定した名前を使用して、1つのオーディオ・クリップをmediadirディレクトリにコピーするか、またはオーディオ・クリップのファイル名と一致するように、このスクリプトを変更する必要があります。

このスクリプトでは、create_soundtable.sqlスクリプトによってロードされたものと同じオーディオ・クリップをロードする必要があります。このスクリプトは、import( )メソッドでロードされたデータが、soundtable表のBLOB列からコピーされたデータと一致することを示すために、後でshowprop_aud.sqlスクリプトで使用されます。


注意:

このスクリプトは、例9-4および例9-5のスクリプトを実行したユーザーが実行してください。

例9-6 import_aud.sql

--import_aud.sql

DECLARE
  obj ORDAUDIO;
  ctx RAW(64) := NULL;

BEGIN

  -- selects the audio column for update
  SELECT audio INTO obj FROM audio_table WHERE id = 1 FOR UPDATE;

  --import audio clip aud1.wav from mediadir
  obj.setSource('FILE','MEDIADIR','aud1.wav');
  obj.import(ctx);

  --set properties
  obj.setProperties(ctx);

  --update table with audio object
  UPDATE audio_table SET audio = obj WHERE id = 1;


  COMMIT;

END;
/

9.1.2.5 ORDAudioオブジェクトへのBLOBデータのコピー

copy_audblob.sqlスクリプトは、soundtable表のsound列にあるオーディオ・データを、audio_table表のORDAudioオブジェクト列のid=2の列にコピーします。このスクリプトは、soundtable表のBLOBデータをaudio_table表のT.audio.source.localData属性にコピーするために、SQL UPDATE文を使用します。このSQL UPDATE文がコピー操作を実行します。また、このスクリプトでは、ORDAudioオブジェクトに格納された新しいBLOBに対して、プロパティの設定およびタイムスタンプの更新を行います。このスクリプトを例9-7に示します。


注意:

このスクリプトは、例9-4例9-5および例9-6のスクリプトを実行したユーザーが実行してください。

例9-7 copy_audblob.sql

--copy_audblob.sql
--

SET SERVEROUTPUT ON;
SET ECHO ON;

-- Use the SQL UPDATE statement to set the contents of
-- T.audio.source.localData to be the same as the BLOB stored
-- in the sound column of the soundtable table. This is an easy way
-- to copy a BLOB stored in the database into a row containing
-- a column defined as an interMedia ORDAudio object type.
--
-- In this case, the BLOB (an audio clip), which was stored in
-- a row in the soundtable table containing a sound column
-- defined as a BLOB data type for an ID=1 is copied to a row
-- in the audio_table table containing an audio column defined as
-- an ORDAudio object type in which the ID=2. The audio
-- clip is referenced through the source attribute of the
-- ORDAudio object type to the underlying localData attribute
-- of the ORDSource object type.
--
-- Then (1) Call setProperties() and (2) call setUpdateTime()
-- for this new BLOB stored in the ORDAudio object type.
-- Create a procedure to do this.

CREATE OR REPLACE PROCEDURE update_proc IS

  obj ORDAudio;
  ctx RAW(64) :=NULL;

BEGIN
  UPDATE audio_table T SET T.audio.source.localData = (SELECT sound FROM
         soundtable S WHERE S.id = 1) WHERE T.id=2;
  COMMIT;

  SELECT audio INTO obj FROM audio_table WHERE id = 2 FOR UPDATE;
  obj.setProperties(ctx);
  obj.setUpdateTime(SYSDATE);
  UPDATE audio_table SET audio = obj WHERE id = 2;
  COMMIT;

EXCEPTION
  WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Operation failed');

END;
/

EXECUTE UPDATE_PROC;

9.1.2.6 ロードしたオーディオ・データのプロパティの表示

showprop_aud.sqlスクリプトは、audio_table表のid=1およびid=2の列に格納されているオーディオ・データ・クリップのプロパティを表示します。これらのプロパティは、同一である必要があります。soundtable表の同じオーディオ・クリップは、異なるロード・メソッドを使用して、audio_table表の2つの列にロードされています。このスクリプトは、ORDAudio import( )メソッドを使用してロードされたオーディオ・データが、soundtable表のBLOB列からコピーされたオーディオ・データと一致することを確認します。このスクリプトを例9-8に示します。


注意:

このスクリプトは、例9-4例9-5例9-6および例9-7のスクリプトを実行したユーザーが実行してください。

例9-8 showprop_aud.sql

-- showprop_aud.sql
--

SET SERVEROUTPUT ON;
SET ECHO ON;

--Query audio_table for ORDAudio content.
--
-- This script verifies that the properties of the audio data
-- in the row with ID=1 (which was populated with the ORDAudio
-- import() method), match the properties of the audio data
-- in the row with ID-2 (which was populated by copying data
-- from a BLOB in the soundtable table.
--

DECLARE
  audio ORDAudio;
  idnum integer;
  properties_match BOOLEAN;
  ctx RAW(64) :=NULL;

BEGIN
-- Check the properties of the audio data clip imported into the
-- ORDAudio object type. Properties for ID=1 should be identical
-- with ID=2.

  dbms_output.put_line(' Properties of these audio clips are identical:');

  SELECT id, audio INTO idnum, audio FROM audio_table WHERE id=1;
  dbms_output.put_line('Properties for id: ' || idnum);

  dbms_output.put_line('audio encoding: ' || audio.getEncoding);
  dbms_output.put_line('audio number of channels: ' ||
                        audio.getNumberOfChannels);
  dbms_output.put_line('audio MIME type: ' || audio.getMimeType);
  dbms_output.put_line('audio file format: ' || audio.getFormat);
  dbms_output.put_line('BLOB Length: ' ||
                        TO_CHAR(audio.getContentLength(ctx)));
  dbms_output.put_line
        ('----------------------------------------------');

-- Check the properties of the audio data clip copied into the
-- ORDAudio object type from a BLOB stored in the database.
-- Properties for ID=1 should be identical with ID=2.

  SELECT id, audio INTO idnum, audio FROM audio_table WHERE id=2;
  dbms_output.put_line('Properties for id: ' || idnum);
  dbms_output.put_line('audio encoding: ' || audio.getEncoding);
  dbms_output.put_line('audio number of channels: ' ||
                        audio.getNumberOfChannels);
  dbms_output.put_line('audio MIME type: ' || audio.getMimeType);
  dbms_output.put_line('audio file format: ' || audio.getFormat);
  dbms_output.put_line('BLOB Length: ' ||
                        TO_CHAR(audio.getContentLength(ctx)));
  dbms_output.put_line
        ('----------------------------------------------');

END;
/

スクリプトshowprop_aud.sqlを実行すると、格納されている各オーディオ・クリップのプロパティが同一であるという結果が表示されます。

Properties of these audio clips are identical:

      Properties for  id:           1

audio encoding:        MS_PCM
audio number of channels:  1
audio MIME type:       audio/x-wav
audio file format:     WAVE
BLOB Length:           15932
----------------------------------------------
      Properties for id:           2

audio encoding:        MS_PCM
audio number of channels:  1
audio MIME type:       audio/x-wav
audio file format:     WAVE
BLOB Length:           15932
----------------------------------------------

PL/SQL procedure successfully completed.

9.1.2.7 ORDAudioの例の自動化

setup_audsample.sqlスクリプトは、前述のオーディオ・スクリプトをそれぞれ適切な順序で実行し、処理を自動化します。このスクリプトを例9-9に示します。


注意:

このスクリプトは、必ずCREATE ANY DIRECTORY特権およびCREATE TABLE権限を持つユーザーが実行してください。

例9-9 setup_audsample.sql

-- setup_audsample.sql
--
-- This script automates the demo by invoking each script in
-- the required order.
--

-- Create the mediadir load directory
@create_mediadir.sql

-- Create a soundtable table and populate it with
-- an audio clip:
@create_soundtable.sql

-- Create an audtable table
@create_audtable.sql

--import an audio clip
@import_aud.sql

-- Copy a BLOB into an ORDAudio object, set the properties,
-- and update the time:
@copy_audblob.sql

-- Check the properties of the audio clips. The properties
-- should be identical:
@showprop_aud.sql

--exit;

9.1.2.8 ORDAudioの例のクリーンアップ

cleanup_audsample.sqlスクリプトは、前述のオーディオ・スクリプトによって作成されたサンプル表、ディレクトリおよびプロシージャを、データベースから削除します。このスクリプトを例9-10に示します。


注意:

このスクリプトは、必ずDROP ANY DIRECTORY権限を持つユーザーが実行してください。前述のオーディオ・スクリプトを実行したユーザーがこのスクリプトを実行してください。

例9-10 cleanup_audsample.sql

-- cleanup_audsample.sql
--
-- This script removes all tables, procedures, and directories
-- created by this demonstration.  You must have the DROP ANY
-- DIRECTORY privilege to drop the audio load directory.  This
-- script should be run under the same user as the demo was run
-- under.

-- drop the audio load directory.
DROP DIRECTORY mediadir;

-- Drop the tables created by the demo.
DROP TABLE soundtable PURGE;
DROP TABLE audio_table PURGE;

-- Drop the Update procedure.
DROP PROCEDURE update_proc;

commit;

9.2 メディア・データの例

Oracle Multimediaを使用するメディア・データの例では、異機種間データに対して次の一般的な操作を行います。

これらの例で使用するメソッドに関する参照情報は、『Oracle Multimediaリファレンス』を参照してください。

9.2.1 ファイル・データ・ソースからORDDocオブジェクトへの移入に使用するスクリプト

この項に示すスクリプトでは、既存のファイルからORDDocオブジェクトに移入する方法を示します。

表9-2に、各スクリプトの名前とスクリプトが実行する操作の簡単な説明を示します。各スクリプトの詳細は、その後の項を参照してください。

表9-2 メディア・スクリプト

スクリプト名 実行する操作

create_mediadir.sql

例9-11

メディア・データをロードするディレクトリを作成します。

9.2.1.1項を参照)

create_doctable.sql

例9-12

doc_table表を作成し、移入します。

9.2.1.2項を参照)

import_doc.sql

例9-13

メディア・データをロードします。このスクリプトは、ORDDoc import( )メソッドを使用して、メディア・データをdoc_table表にインポートします。

9.2.1.3項を参照)

read_doc.sql

例9-14

ストアド・プロシージャを使用して、BLOBからメディア・データを読み込みます。

9.2.1.4項を参照)

showprop_doc.sql

例9-15

doc_table表に格納されている、ロードしたメディア・データのプロパティを表示します。

9.2.1.5項を参照)

setup_docsample.sql

例9-16

前述のメディア・スクリプトを必要な順に実行して、処理を自動化します。

9.2.1.6項を参照)

cleanup_docsample.sql

例9-17

サンプル表、ディレクトリおよびプロシージャをデータベースから削除し、処理をクリーンアップします。

9.2.1.7項を参照)


9.2.1.1 メディア・データをロードするディレクトリの作成

create_mediadir.sqlスクリプトは、メディア・データをロードするディレクトリを作成します。このスクリプトを例9-11に示します。

メディア・データを正常にロードするには、ディレクトリをシステムに作成しておく必要があります。例9-11では、mediadirディレクトリを使用します。このディレクトリに、サンプル・オーディオ・メディア・ファイルを格納する必要があります。次の例では、サンプル・ファイルaud1.wavおよびaud2.mp3が使用されています。実際には、サポートされている任意のメディア・ファイルをmediadirディレクトリにコピーして、これらの例のスクリプトを実行できます。mediadirディレクトリへのディレクトリ・パスおよびディスク・ドライブは、create_mediadir.sqlファイルのCREATE DIRECTORY文で指定する必要があります。


注意:

このスクリプトを実行するには、CREATE ANY DIRECTORY権限が必要です。メディア・データをロードするディレクトリの以前のインスタンスを削除する場合は、DROP ANY DIRECTORY権限も必要です。CREATE DIRECTORY文のディレクトリ・パスを変更するには、create_mediadir.sqlファイルを編集する必要があります。他のデモ・スクリプトを実行したユーザーとは異なるユーザーでcreate_mediadir.sqlスクリプトを実行する場合は、GRANT READ文のユーザーも変更する必要があります。手順の詳細は、次のスクリプトを参照してください。

例9-11 create_mediadir.sql

-- create_mediadir.sql
-- You must have the CREATE ANY DIRECTORY privilege to run this script.
--
-- You must edit this script to:
--  o replace the directory path in the CREATE DIRECTORY statement
--    with your own (see below for details)
--  o uncomment the GRANT READ ON DIRECTORY statement and grant to the
--    user under which you will run this demo

SET SERVEROUTPUT ON;
SET ECHO ON;

-- You need DROP ANY DIRECTORY privilege to delete a directory. If there
-- is no need to delete the directory, then leave the next line
-- commented out.
-- DROP DIRECTORY mediadir;

-- Create the mediadir load directory, the directory where the media
-- data resides. You must specify the disk drive and path in the
-- CREATE DIRECTORY statement below. Edit this file to replace the
-- directory specification with your own.
CREATE OR REPLACE DIRECTORY mediadir AS 'C:/mediadir';

-- If you intend to run this demo under a user other than the user
-- that just created this directory, edit the following grant to grant
-- READ on the directory just created to the user under which you will
-- run the demo scripts.  For example, if you will run the demo scripts
-- under user 'SCOTT', then replace the string "<USER>" with "SCOTT".
-- Then uncomment the following GRANT statement.  There is no need to
-- do this if the user creating the directory will also be used to run
-- the other demo scripts.
-- GRANT READ ON DIRECTORY mediadir TO <USER>;

9.2.1.2 doc_table表の作成および移入

create_doctable.sqlスクリプトは、doc_table表を作成し、移入します。この表には、ORDDoc列が含まれます。このスクリプトは、2列(idおよびdocument)のdoc_table表を作成し、その表に2行を挿入してdocument列を初期化します。このスクリプトを例9-12に示します。


注意:

ORDDoc.init( )メソッドをコールすることによって、ORDDocオブジェクトのBLOB属性が初期化されます。初期化は、BLOBにデータを移入するために必要です。

このスクリプトは、必ずCREATE TABLE権限を持つユーザーが実行してください。


例9-12 create_doctable.sql

-- create_doctable.sql
--
-- This script must be run from a user with the CREATE TABLE privilege.
--
-- Create the doc_table table.
-- Insert two rows with empty ORDDoc columns.
--

SET SERVEROUTPUT ON;
SET ECHO ON;

DROP TABLE doc_table PURGE;
CREATE TABLE doc_table ( id NUMBER,
                       document ORDDoc )
LOB(document.source.localData) STORE AS SECUREFILE;

-- Insert a row with an empty ORDDoc object.
INSERT INTO doc_table VALUES(1,ORDDoc.init());
-- Insert a row with an empty BLOB.
INSERT INTO doc_table VALUES(2,ORDDoc.init());

COMMIT;

9.2.1.3 メディア・データのロード

import_doc.sqlスクリプトは、ORDDoc import( )メソッドを使用して、メディア・ファイルからdoc_table表のORDDoc列に、メディア・データをインポートします。メディア・データが格納されるBLOB属性にデータをインポートするには、行のdocument列が更新用に選択されている必要があります。このスクリプトを例9-13に示します。

このスクリプトを正常に実行するには、このスクリプトで指定した名前を使用して、2つのメディア・ファイルをmediadirディレクトリにコピーするか、またはメディア・ファイルのファイル名と一致するように、このスクリプトを変更する必要があります。


注意:

このスクリプトは、例9-12のスクリプトを実行したユーザーが実行してください。

例9-13 import_doc.sql

-- import_doc.sql
--
-- This script uses the import method to load the media data into the
-- ORDDoc column.  It then extracts properties from the media using
-- the setProperties method.
--
-- To successfully run this script, you must copy two media files to your
-- MEDIADIR directory using the names specified in this script, or modify
-- this script to match the file names of your media.
--

SET SERVEROUTPUT ON;
SET ECHO ON;

DECLARE
  obj ORDDOC;
  ctx RAW(64) := NULL;

BEGIN
-- This imports the audio file aud1.wav from the MEDIADIR directory
-- on a local file system (srcType=file) and sets the properties.

  SELECT document INTO obj FROM doc_table WHERE id = 1 FOR UPDATE;
  obj.setSource('FILE','MEDIADIR','aud1.wav');
  obj.import(ctx,TRUE);

  UPDATE doc_table SET document = obj WHERE id = 1;
  COMMIT;

-- This imports the audio file aud2.mp3 from the MEDIADIR directory
-- on a local file system (srcType=file) and sets the properties.
  SELECT document INTO obj FROM doc_table WHERE id = 2 FOR UPDATE;
  obj.setSource('FILE','MEDIADIR','aud2.mp3');
  obj.import(ctx,TRUE);

  UPDATE doc_table SET document = obj WHERE id = 2;
  COMMIT;
END;
/

9.2.1.4 メディア・データのBLOBからの読込み

read_doc.sqlスクリプトは、ストアド・プロシージャreaddocumentを作成することで、BLOBからメディア・データを読み込みます。このプロシージャでは、特定のオフセットから開始して、指定したすべての量のメディア・データが読み込まれるまで、メディア・データをBLOB属性から読み込みます。このスクリプトを例9-14に示します。


注意:

このスクリプトは、例9-12および例9-13のスクリプトを実行したユーザーが実行してください。

例9-14 read_doc.sql

--read_doc.sql


SET SERVEROUTPUT ON
SET ECHO ON

----Read from the OrdDoc object column in the doc_table.
create or replace procedure readdocument as
obj ORDDoc;
buffer RAW (32767);
numBytes BINARY_INTEGER := 32767;
startpos integer := 1;
read_cnt integer := 1;
ctx RAW(64) := NULL;
BEGIN
  select document into obj from doc_table where id = 1;
  LOOP
    obj.readFromSource(ctx,startPos,numBytes,buffer);
    DBMS_OUTPUT.PUT_LINE('BLOB Length: ' || TO_CHAR(obj.getContentLength()));
    DBMS_OUTPUT.PUT_LINE('start position: '|| startPos);
    DBMS_OUTPUT.PUT_LINE('doing read: ' || read_cnt);
    startpos := startpos + numBytes;
    read_cnt := read_cnt + 1;
   END LOOP;

   -- Note: Add your own code here to process the media data being read;
   -- this routine just reads the data into the buffer 32767 bytes
   -- at a time, then reads the next chunk, overwriting the first
   -- buffer full of data.
   EXCEPTION
     WHEN NO_DATA_FOUND THEN
       DBMS_OUTPUT.PUT_LINE('End of data ');
     WHEN ORDSYS.ORDSourceExceptions.METHOD_NOT_SUPPORTED THEN
       DBMS_OUTPUT.PUT_LINE('ORDSourceExceptions.METHOD_NOT_SUPPORTED caught');
     WHEN OTHERS THEN
       DBMS_OUTPUT.PUT_LINE('EXCEPTION caught');
END;
/
show errors

ストアド・プロシージャを実行するには、次のSQL文を入力します。

SQL> set serveroutput on;
SQL> execute readdocument
Content Length: 93594
start position: 1
doing read: 1
start position: 32768
doing read: 2
start position: 65535
doing read: 3
----------------
End of data

PL/SQL procedure successfully completed.

9.2.1.5 ロードしたメディア・データのプロパティの表示

showprop_doc.sqlスクリプトは、doc_table表にロードしたメディア・データのプロパティを表示します。このスクリプトを例9-15に示します。


注意:

このスクリプトは、例9-12例9-13および例9-14のスクリプトを実行したユーザーが実行してください。

例9-15 showprop_doc.sql

-- showprop_doc.sql
--

SET SERVEROUTPUT ON;
SET ECHO ON;

--
-- Query doctable for ORDDoc.

DECLARE
  document ORDDoc;
  idnum integer;
  ctx RAW(64) := NULL;
BEGIN
  FOR I IN 1..2 LOOP
  SELECT id, document INTO idnum, document FROM doc_table WHERE id=I;
  dbms_output.put_line('document id: '|| idnum);
  dbms_output.put_line('document MIME type: '|| document.getMimeType());
  dbms_output.put_line('document file format: '|| document.getFormat());
  dbms_output.put_line('BLOB Length: '|| TO_CHAR(document.getContentLength()));
  dbms_output.put_line('----------------------------------------------');
  END loop;
END;
/

showprop_doc.sqlスクリプトを実行すると、次の出力結果が表示されます。

SQL> @showprop_doc.sql
document id:          1
document MIME type:       audio/xwav
document file format:     WAVE
BLOB Length:           93594
----------------------------------------------
document id:          2
document MIME type:       audio/mpeg
document file format:     MPGA
BLOB Length:           51537
----------------------------------------------
PL/SQL procedure successfully completed.

9.2.1.6 ORDDocの例の自動化

setup_docsample.sqlスクリプトは、前述のメディア・スクリプトをそれぞれ適切な順序で実行し、処理を自動化します。このスクリプトを例9-16に示します。


注意:

このスクリプトは、必ずCREATE ANY DIRECTORY特権およびCREATE TABLE権限を持つユーザーが実行してください。

例9-16 setup_docsample.sql

-- setup_docsample.sql
--
-- This script automates the demo by invoking each script in
-- the required order.
--

-- Create the mediadir load directory
@create_mediadir.sql

-- Create the media table:
@create_doctable.sql

--Import 2 media clips and set properties:
@import_doc.sql

--Display the properties of the media clips:
@showprop_doc.sql

--create stored procedure to read from ordDoc
@read_doc.sql

--Execute stored procedure
execute readdocument

--exit;

9.2.1.7 ORDDocの例のクリーンアップ

cleanup_docsample.sqlスクリプトは、前述のメディア・スクリプトによって作成されたサンプル表、ディレクトリおよびプロシージャを、データベースから削除します。このスクリプトを例9-17に示します。


注意:

このスクリプトは、必ずDROP ANY DIRECTORY権限を持つユーザーが実行してください。前述のメディア・スクリプトを実行したユーザーがこのスクリプトを実行してください。

例9-17 cleanup_docsample.sql

-- cleanup_docsample.sql
--
-- This script removes all tables and directories created by this
-- demonstration.  You must have the DROP ANY DIRECTORY privilege
-- to drop the doc load directory.  This script should be run under
-- the same user as the demo was run under.

-- drop the doc load directory.
DROP DIRECTORY mediadir;

-- Drop the table created by the demo.
DROP TABLE doc_table PURGE;

9.3 イメージ・データの例

Oracle Multimediaを使用するイメージ・データの例では、次の一般的な操作を行います。

これらの例で使用するメソッドに関する参照情報は、『Oracle Multimediaリファレンス』を参照してください。

9.3.1 ファイル・データ・ソースからORDImageオブジェクトに移入するスクリプト

この項に示すスクリプトでは、既存のファイルからOracle Multimedia ORDImageオブジェクトに移入する方法を示します。

表9-3に、各スクリプトの名前とスクリプトが実行する操作の簡単な説明を示します。各スクリプトの詳細は、その後の項を参照してください。

表9-3 イメージ・スクリプト

スクリプト名 実行する操作

create_mediadir.sql

例9-18

イメージ・データをロードするディレクトリを作成します。

9.3.1.1項を参照)

create_imgtable.sql

例9-19

image_table表を作成し、移入します。

9.3.1.2項を参照)

import_img.sql

例9-20

イメージ・データをロードします。このスクリプトは、ORDImage import( )メソッドを使用して、イメージ・データをimage_table表にインポートします。

9.3.1.3項を参照)

read_image.sql

例9-21

ストアド・プロシージャを使用して、BLOBからイメージ・データを読み込みます。

9.3.1.4項を参照)

showprop_img.sql

例9-22

image_table表に格納されている、ロードしたイメージ・データのプロパティを表示します。

9.3.1.5項を参照)

setup_imgsample.sql

例9-23

前述のイメージ・スクリプトを必要な順に実行して、処理を自動化します。

9.3.1.6項を参照)

cleanup_imgsample.sql

例9-24

サンプル表、ディレクトリおよびプロシージャをデータベースから削除し、処理をクリーンアップします。

9.3.1.7項を参照)


9.3.1.1 イメージ・データをロードするディレクトリの作成

create_mediadir.sqlスクリプトは、イメージ・データをロードするディレクトリを作成します。このスクリプトを例9-18に示します。

イメージ・データを正常にロードするには、mediadirディレクトリをシステムに作成しておく必要があります。このディレクトリに、サンプル・イメージ・メディア・ファイルimg71.gifおよびimg50.gifを格納する必要があります。このファイルは、<ORACLE_HOME>/ord/img/demoディレクトリにインストールされています。実際には、サポートされている任意のイメージ・ファイルをmediadirディレクトリにコピーして、このスクリプトを実行できます。このディレクトリ・パスおよびディスク・ドライブは、create_mediadir.sqlファイルのCREATE DIRECTORY文で指定する必要があります。


注意:

このスクリプトを実行するには、CREATE ANY DIRECTORY権限が必要です。イメージ・データをロードするディレクトリの以前のインスタンスを削除する場合は、DROP ANY DIRECTORY権限も必要です。CREATE DIRECTORY文のディレクトリ・パスを変更するには、create_mediadir.sqlファイルを編集する必要があります。他のデモ・スクリプトを実行したユーザーとは異なるユーザーでcreate_mediadir.sqlスクリプトを実行する場合は、GRANT READ文のユーザーも変更する必要があります。手順の詳細は、次のスクリプトを参照してください。

例9-18 create_mediadir.sql

-- create_mediadir.sql
-- You must have the CREATE ANY DIRECTORY privilege to run this script.
--
-- You must edit this script to:
--  o replace the directory path in the CREATE DIRECTORY statement
--    with your own (see below for details)
--  o uncomment the GRANT READ ON DIRECTORY statement and grant to the
--    user under which you will run this demo

SET SERVEROUTPUT ON;
SET ECHO ON;

-- You need DROP ANY DIRECTORY privilege to delete a directory. If there
-- is no need to delete the directory, then leave the next line
-- commented out.
-- DROP DIRECTORY mediadir;

-- Create the mediadir load directory, the directory where the image
-- clips reside. You must specify the disk drive and path in the
-- CREATE DIRECTORY statement below. Edit this file to replace the
-- directory specification with your own.
CREATE OR REPLACE DIRECTORY mediadir AS 'C:/mediadir';

-- If you intend to run this demo under a user other than the user
-- that just created this directory, edit the following grant to grant
-- READ on the directory just created to the user under which you will
-- run the demo scripts.  For example, if you will run the demo scripts
-- under user 'SCOTT', then replace the string "<USER>" with "SCOTT".
-- Then uncomment the following GRANT statement.  There is no need to
-- do this if the user creating the directory will also be used to run
-- the other demo scripts.
-- GRANT READ ON DIRECTORY mediadir TO <USER>;

9.3.1.2 image_table表の作成および移入

create_imgtable.sqlスクリプトは、image_table表を作成し、移入します。この表には、ORDImage列が含まれます。このスクリプトは、2列(idおよびimage)のimage_table表を作成し、その表に2行を挿入してimage列を初期化します。このスクリプトを例9-19に示します。


注意:

ORDImage.init( )メソッドをコールすることによって、ORDImageオブジェクトのBLOB属性が初期化されます。初期化は、BLOBにデータを移入するために必要です。

このスクリプトは、必ずCREATE TABLE権限を持つユーザーが実行してください。


例9-19 create_imgtable.sql

-- create_imgtable.sql
--
-- This script must be run from a user with the CREATE TABLE privilege.
--
-- Create the image_table table.
-- Insert two  rows with empty OrdImage columns  and initialize object attributes.

SET SERVEROUTPUT ON;
SET ECHO ON;

DROP TABLE image_table PURGE;
CREATE TABLE image_table ( id NUMBER,
                       image ORDImage )
LOB(image.source.localData) STORE AS SECUREFILE;


-- Insert rows with empty OrdImage columns and initialize the object attributes.

INSERT INTO image_table VALUES(1,ORDImage.init());
INSERT INTO image_table VALUES(2,ORDImage.init());

COMMIT;

9.3.1.3 イメージ・データのロード

import_img.sqlスクリプトは、ORDImage import( )メソッドを使用して、イメージ・ファイルからimage_table表のORDImage列に、イメージ・データをインポートします。イメージが格納されるBLOB属性にデータをインポートするには、行のimage列が更新用に選択されている必要があります。このスクリプトを例9-20に示します。

このスクリプトを正常に実行するには、このスクリプトで指定した名前を使用して、2つのイメージ・ファイルをmediadirディレクトリにコピーするか、またはイメージ・ファイルのファイル名と一致するように、このスクリプトを変更する必要があります。


注意:

このスクリプトは、例9-19のスクリプトを実行したユーザーが実行してください。

例9-20 import_img.sql

-- import_img.sql
--
SET SERVEROUTPUT ON
SET ECHO ON

-- Import the two files into the database.

DECLARE
  obj ORDIMAGE;
  ctx RAW(64) := NULL;
BEGIN
-- This imports the image file img71.gif from the MEDIADIR directory
-- on a local file system (srcType=file).
-- the import method  also sets the object properties by reading the image blob.
  select Image into obj from image_table where id = 1 for update;
  obj.setSource('file','MEDIADIR','img71.gif');
  obj.import(ctx);
  update image_table set image = obj where id = 1;
commit;

-- This imports the image file img50.gif from the MEDIADIR directory
select Image into obj from image_table where id = 2 for update;
obj.setSource('file','MEDIADIR','img50.gif');
obj.import(ctx);
update image_table set image = obj where id = 2;
commit;
END;
/

9.3.1.4 イメージ・データのBLOBからの読込み

read_image.sqlスクリプトは、ストアド・プロシージャreadimageを作成することで、BLOBからイメージ・データを読み込みます。このプロシージャでは、特定のオフセットから開始して、指定したすべての量のイメージ・データが読み込まれるまで、イメージ・データをBLOB属性から読み込みます。このスクリプトを例9-21に示します。


注意:

このスクリプトは、例9-19および例9-20のスクリプトを実行したユーザーが実行してください。

例9-21 read_image.sql

-- read_image.sql
set serveroutput on
set echo on
create or replace procedure readimage as
-- Note: ORDImage has no readFromSource method like ORDAudio
-- and ORDVideo; therefore, you must use the DBMS_LOB package to
-- read image data from a BLOB.
buffer RAW (32767);
src BLOB;
obj ORDImage;
amt BINARY_INTEGER := 32767;
pos integer := 1;
read_cnt integer := 1;
BEGIN
  Select t.image.getcontent() into src from image_table t where t.id = 1;
  Select image into obj from image_table t where t.id = 1;
DBMS_OUTPUT.PUT_LINE('Content length is: '||      TO_CHAR(obj.getContentLength()));
LOOP
DBMS_LOB.READ(src,amt,pos,buffer);
DBMS_OUTPUT.PUT_LINE('start position: '|| pos);
DBMS_OUTPUT.PUT_LINE('doing read '|| read_cnt);
pos := pos + amt;
read_cnt := read_cnt + 1;
-- Note: Add your own code here to process the image data being read;
-- this routine just reads data into the buffer 32767 bytes
-- at a time, then reads the next chunk, overwriting the first
-- buffer full of data.
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('----------------');
DBMS_OUTPUT.PUT_LINE('End of data ');
END;
/
show errors

ストアド・プロシージャを実行するには、次のSQL文を入力します。

SQL> set serveroutput on;
SQL> execute read_image;
Content length is: 1124
start position: 1
doing read  1
----------------
End of data

PL/SQL procedure successfully completed.

9.3.1.5 ロードしたイメージ・データのプロパティの表示

showprop_img.sqlスクリプトは、image_table表にロードしたイメージ・データのプロパティを表示します。このスクリプトを例9-22に示します。


注意:

このスクリプトは、例9-19例9-20および例9-21のスクリプトを実行したユーザーが実行してください。

例9-22 showprop_img.sql

-- showprop_img.sql
--


SET SERVEROUTPUT ON;
SET ECHO ON;

-- This script displays properties of the image stored in image_table
--

DECLARE
 image ORDImage;
 idnum integer;
 rowcount integer;
BEGIN

  FOR I IN 1..2 LOOP
    SELECT id, image into idnum, image from image_table where id=I;
    dbms_output.put_line('Image properties:');
    dbms_output.put_line('image id: '|| idnum);
    dbms_output.put_line('image height: '|| image.getHeight());
    dbms_output.put_line('image width: '|| image.getWidth());
    dbms_output.put_line('image MIME type: '|| image.getMimeType());
    dbms_output.put_line('image file format: '|| image.getFileFormat());
    dbms_output.put_line('BLOB Length: '|| TO_CHAR(image.getContentLength()));
    dbms_output.put_line('-------------------------------------------');
  END loop;
END;
/

showprop_img.sqlスクリプトを実行すると、次の出力結果が表示されます。

SQL> @showprop_img.sql
image id:          1

image height:      15
image width:       43
image MIME type:   image/gif
image file format: GIFF
BLOB Length:       1124
-------------------------------------------
image id:          2

image height:      32
image width:       110
image MIME type:   image/gif
image file format: GIFF
BLOB Length:       686
-------------------------------------------

PL/SQL procedure successfully completed.

9.3.1.6 ORDImageの例の自動化

setup_imgsample.sqlスクリプトは、前述のイメージ・スクリプトをそれぞれ適切な順序で実行し、処理を自動化します。このスクリプトを例9-23に示します。


注意:

このスクリプトは、必ずCREATE ANY DIRECTORY特権およびCREATE TABLE権限を持つユーザーが実行してください。

例9-23 setup_imgsample.sql

-- setup_imgsample.sql
--
-- This script automates the demo by invoking each script in
-- the required order.
--

-- Create the imgdir load directory
@create_mediadir.sql

-- Create image table:
@create_imgtable.sql

--Import images into image_table
@import_img.sql

--Show properties of images
@showprop_img.sql

--create stored procedure to read from ordImage
@read_image.sql

--Execute stored procedure
execute readimage

--exit;

9.3.1.7 ORDImageの例のクリーンアップ

cleanup_imgsample.sqlスクリプトは、前述のイメージ・スクリプトによって作成されたサンプル表、ディレクトリおよびプロシージャを、データベースから削除します。このスクリプトを例9-24に示します。


注意:

このスクリプトは、必ずDROP ANY DIRECTORY権限を持つユーザーが実行してください。前述のイメージ・スクリプトを実行したユーザーがこのスクリプトを実行してください。

例9-24 cleanup_imgsample.sql

-- cleanup_imgsample.sql
--
-- This script removes all tables, procedures, and directories
-- created by this demonstration.  You must have the DROP ANY
-- DIRECTORY privilege to drop the image load directory.  This
-- script should be run under the same user as the demo was run
-- under.

-- drop the image load directory.
DROP DIRECTORY mediadir;

-- Drop the tables created by the demo.
DROP TABLE image_table PURGE;

-- Drop the Update procedure.
DROP PROCEDURE read_image;

commit;
exit;

9.3.2 HTTPデータ・ソースからイメージ表をロードするスクリプト

import_imghttp.sqlスクリプトは、HTTPデータ・ソースからイメージ・データをインポートします。このスクリプトでは、image_table表に2行を挿入し、指定されたHTTPデータ・ソース(ソース・タイプHTTP、URL位置およびHTTPオブジェクト名)からイメージ・データをロードします。このスクリプトを例9-25に示します。

このスクリプトを正常に実行するには、Webサイトに存在する2つのイメージを指すようにスクリプトを変更する必要があります。

例9-25 import_imghttp.sql Script

--import_imghttp.sql
-- Import the two HTTP images from a Web site into the database.
-- PreRequisites:
--    You will need to do the following  before running this script
--        1. Run create_imgdir.sql
--        2. Run create_imgtable.sql
--        3. Modify the HTTP URL and object name to point to two images on
--           your own Web site.

SET SERVEROUTPUT ON
SET ECHO ON

-- Import two images from HTTP source URLs.


-- Insert two rows with an empty BLOB.
-- See above section on pre requisites
insert into image_table values (7,ORDImage.init(
'http','http://your_website/images','image1.jpg'));

insert into image_table values (8,ORDImage.init(
'http','http://your_website/images','image2.gif'));

commit;

DECLARE
  obj ORDIMAGE;
  ctx RAW(64) := NULL;
BEGIN
-- This imports the image file image1.gif from the HTTP source URL
-- (srcType=HTTP), and automatically sets the properties.
  select Image into obj from image_table where id = 7 for update;
  obj.import(ctx);
  update image_table set image = obj where id = 7;
  commit;
-- This imports the image file image2.gif from the HTTP source URL
-- (srcType=HTTP), and automatically sets the properties.
  select Image into obj from image_table where id = 8 for update;
  obj.import(ctx);
  update image_table set image = obj where id = 8;
  commit;
END;
/

9.3.3 グローバリゼーション・サポートの問題点への対処

例9-26に、カンマを小数点として使用する言語設定でprocessCopy( )メソッドを使用する方法を示します。たとえば、地域がFRANCEである場合、小数点はカンマであることが予想されます。scaleに指定された",75"に注意してください。この例は、グローバリゼーション・サポートの問題点に対処します。

例9-26 グローバリゼーション・サポートの問題点への対処

ALTER SESSION SET NLS_LANGUAGE = FRENCH;
ALTER SESSION SET NLS_TERRITORY = FRANCE;
DECLARE
myimage ORDImage;

BEGIN

SELECT image into myimage from image_table where id=1 for update;


myimage.process('scale=",75"');
UPDATE image_table SET image = myimage where id=1;
COMMIT;
END;
/

showprop_img.sqlスクリプトを実行して、スケール変更されたイメージのプロパティを確認します。

9.4 ビデオ・データの例

ビデオ・データの例については、『Oracle Multimedia リファレンス』を参照してください。