Home » SQL & PL/SQL » SQL & PL/SQL » How to insert BLOB files into tables (Oracle 11g, Release 11.2.0.2.0, Red Hat)
How to insert BLOB files into tables [message #534249] Sun, 04 December 2011 20:14 Go to next message
sandy_bridge_655k
Messages: 55
Registered: November 2011
Member
Hi, I created a music database, and I'm having trouble inserting the audio, video, and lyrics (.doc) into their respective tables. I searched through the forums and found some example code, but I'm not sure how to modify it to fit my purposes.

What I need is a procedure that can insert a complete record into the track table (including an .mp3 file for each row), one that can insert a record into the lyrics table (including .doc file for each row), and a procedure that can insert a single record into the Video table (including an .mv4 file).

Here's the DDL:

CREATE TABLE Artist(
artist_id number(9),
artist_name varchar(30),
country char(2),
num_albums number(3),
num_songs number(5)
);

ALTER TABLE Artist
add CONSTRAINT artist_pk PRIMARY KEY (artist_id);

CREATE TABLE Album(
album_id number(9),
album_title varchar(45),
artist_id number(9),
genre varchar(20),
num_songs_in_album number(3)
);

ALTER TABLE Album
add CONSTRAINT album_pk PRIMARY KEY (album_id);

ALTER TABLE Album
add CONSTRAINT artist_fk FOREIGN KEY (artist_id) REFERENCES Artist(artist_id);

CREATE TABLE Track(
track_id number(9),
artist_id number(9),
album_id number(9),
content BLOB
);

ALTER TABLE Track
add CONSTRAINT track_pk PRIMARY KEY (track_id);

ALTER TABLE Track
add CONSTRAINT album_fk FOREIGN KEY (album_id) REFERENCES Album(album_id);

ALTER TABLE Track
add CONSTRAINT artist2_fk FOREIGN KEY (artist_id) REFERENCES Artist(artist_id);


CREATE TABLE Lyrics (
lyric_id number(9),
track_id number(9),
version varchar(30),
content BLOB
);

ALTER TABLE Lyrics
add CONSTRAINT lyrics_pk PRIMARY KEY ( lyric_id);

ALTER TABLE Lyrics
add CONSTRAINT track_fk FOREIGN KEY (track_id) REFERENCES Track (track_id);

CREATE TABLE Video(
Video_id number(9),
track_id number(9),
producer varchar(25),
director varchar(25),
special_guest varchar(25),
content BLOB,
type char(15)
);

ALTER TABLE Video
add CONSTRAINT video_id PRIMARY KEY (video_id);

ALTER TABLE Video
add CONSTRAiNT track_fk_2 FOREIGN KEY (track_id) REFERENCES Track (track_id);

insert into artist (artist_id, artist_name, country, num_albums, num_songs) 
values (1234,'2-PAC','US', 0, 0); 
insert into artist (artist_id, artist_name, country, num_albums, num_songs) 
values (1235, 'Blink 182' ,'US', 0, 0); 
insert into artist (artist_id, artist_name, country, num_albums, num_songs) 
values (1236,'James Durbin','US', 0, 0); 
insert into artist (artist_id, artist_name, country, num_albums, num_songs) 
values (1237, 'Jay-Z' ,'US', 0, 0); 
insert into artist (artist_id, artist_name, country, num_albums, num_songs) 
values (1238,'Katy Perry','US', 0, 0); 
insert into artist (artist_id, artist_name, country, num_albums, num_songs) 
values (1239, 'Machine Head' ,'US', 0, 0); 
insert into artist (artist_id, artist_name, country, num_albums, num_songs) 
values (1240,'Megadeth','US', 0, 0); 
insert into artist (artist_id, artist_name, country, num_albums, num_songs) 
values(1241, 'Nickelback', 'US', 0, 0);
insert into artist (artist_id, artist_name, country, num_albums, num_songs) 
values (1242,'Nirvana','US', 0, 0); 
insert into artist (artist_id, artist_name, country, num_albums, num_songs) 
values (1243, 'Outkast' ,'US', 0, 0); 
insert into artist (artist_id, artist_name, country, num_albums, num_songs) 
values (1244,'Pearl Jam','US', 0, 0); 
insert into artist (artist_id, artist_name, country, num_albums, num_songs) 
values (1245, 'Stick to Your Guns' ,'US', 0, 0); 
insert into artist (artist_id, artist_name, country, num_albums, num_songs) 
values (1246,'Switchfoot','US', 0, 0); 
insert into artist (artist_id, artist_name, country, num_albums, num_songs) 
values(1247, 'The Pharcyde', 'US', 0, 0);


insert into album (album_id, album_title, artist_id, genre, num_songs_in_album) 
values (4321, 'Me Against The World', 1234, 'Hip Hop', 0);
insert into album (album_id, album_title, artist_id, genre, num_songs_in_album) 
values (4322, 'Enema of the State', 1235, 'Alternative Rock', 0);
insert into album (album_id, album_title, artist_id, genre, num_songs_in_album) 
values (4323, 'Memories of a Beautiful Disaster', 1236, 'Alternative Rock', 0);
insert into album (album_id, album_title, artist_id, genre, num_songs_in_album) 
values (4324, 'The Blueprint', 1237, 'Hip Hop', 0);
insert into album (album_id, album_title, artist_id, genre, num_songs_in_album) 
values (4325, 'Teenage Dream', 1238, 'Pop', 0);
insert into album (album_id, album_title, artist_id, genre, num_songs_in_album) 
values (4326, 'Unto the Locust', 1239, 'Alternative Rock', 0);
insert into album (album_id, album_title, artist_id, genre, num_songs_in_album) 
values (4327, 'Th1rt3en', 1240, 'Metal', 0);
insert into album (album_id, album_title, artist_id, genre, num_songs_in_album) 
values (4328, 'Here and Now', 1241, 'Pop', 0);
insert into album (album_id, album_title, artist_id, genre, num_songs_in_album) 
values (4329, 'Nevermind', 1242, 'Alternative Rock', 0);
insert into album (album_id, album_title, artist_id, genre, num_songs_in_album) 
values (4330, 'Southernplayalisticadillacmuzik', 1243, 'Hip Hop', 0);
insert into album (album_id, album_title, artist_id, genre, num_songs_in_album) 
values (4331, 'Rearview Mirrors', 1244, 'Alternative Rock', 0);
insert into album (album_id, album_title, artist_id, genre, num_songs_in_album) 
values (4332, 'For What Its Worth', 1245, 'Alternative Rock', 0);
insert into album (album_id, album_title, artist_id, genre, num_songs_in_album) 
values (4333, 'Vice Verses', 1246, 'Rock', 0);
insert into album (album_id, album_title, artist_id, genre, num_songs_in_album) 
values (4334, 'Bizarre Ride II', 1247, 'Hip Hop', 0);

[Updated on: Sun, 04 December 2011 23:22] by Moderator

Report message to a moderator

Re: How to insert BLOB files into tables [message #534250 is a reply to message #534249] Sun, 04 December 2011 20:23 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
http://www.oracle.com/pls/db112/search?remark=quick_search&word=Oracle+Multimedia&partno=
Re: How to insert BLOB files into tables [message #534251 is a reply to message #534250] Sun, 04 December 2011 20:59 Go to previous messageGo to next message
sandy_bridge_655k
Messages: 55
Registered: November 2011
Member
I just wrote this procedure after reading a bit of literature, but I want to make sure it will execute correctly before I run it.

How do I make this procedure look inside the right directory on my client machine (i.e. the directory where the .mp3 files are stored)? I'm connected to an Amazon RDS DB instance on Amazon's AWS cloud.

CREATE OR REPLACE PROCEDURE insert_track (
track_idno number,
artist_idno number,
album_idno number,
pfname varchar2) IS

src_file BFILE;
dst_file BLOB;
lgh_file BINARY_INTEGER;
BEGIN
src_file := bfilename('TEMP', pfname);

-- insert a NULL record to lock
INSERT INTO track
(track_id, artist_id, album_id, content)
VALUES
(track_idno, artist_idno, album_idno, EMPTY_BLOB())
RETURNING content INTO dst_file;

-- lock record
SELECT content
INTO dst_file
FROM track
WHERE  artist_id = artist_idno 
AND album_id = album_idno
AND track_id = track_idno
FOR UPDATE;

-- open the file
dbms_lob.fileopen(src_file, dbms_lob.file_readonly);

-- determine length
lgh_file := dbms_lob.getlength(src_file);

-- read the file
dbms_lob.loadfromfile(dst_file, src_file, lgh_file);

-- update the blob field
UPDATE track
SET content = dst_file
WHERE track_id = track_idno
AND artist_id = artist_idno
AND album_id = album_idno;

-- close file
dbms_lob.fileclose(src_file);
END insert_track;


Will this work?

create or replace directory temp as '/home';

grant read on directory temp to username;

[Updated on: Sun, 04 December 2011 21:00]

Report message to a moderator

Re: How to insert BLOB files into tables [message #534252 is a reply to message #534251] Sun, 04 December 2011 21:05 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
PL/SQL can only access files local to the DB Server upon which it is run.
Re: How to insert BLOB files into tables [message #534253 is a reply to message #534252] Sun, 04 December 2011 21:07 Go to previous messageGo to next message
sandy_bridge_655k
Messages: 55
Registered: November 2011
Member
so how do I insert these files into this DB instance?
Re: How to insert BLOB files into tables [message #534254 is a reply to message #534253] Sun, 04 December 2011 21:13 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>so how do I insert these files into this DB instance?
The files needs to be transported to the DB Server system.

Consider the alternatives.
How does Oracle RDBMS know about which remote client system is "your" system?
How does Oracle RDBMS interact with OS security on your client system?
How would you react if any remote Oracle DB server could reach out & suck data file from your client system?
Re: How to insert BLOB files into tables [message #534255 is a reply to message #534254] Sun, 04 December 2011 21:33 Go to previous messageGo to next message
sandy_bridge_655k
Messages: 55
Registered: November 2011
Member
Any chance you know how to upload files to Amazon's RDS servers?

I was reading through the AWS forums and it appears this is not allowed.
Re: How to insert BLOB files into tables [message #534256 is a reply to message #534255] Sun, 04 December 2011 21:36 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>Any chance you know how to upload files to Amazon's RDS servers?
what is Amazon's RDS servers?
problem & solution have nothing to do with Oracle RDBMS.
Re: How to insert BLOB files into tables [message #534257 is a reply to message #534256] Sun, 04 December 2011 21:48 Go to previous messageGo to next message
sandy_bridge_655k
Messages: 55
Registered: November 2011
Member
I don't think I have permission to upload files to Amazon's Relational Database Service (RDS) where my DB instance is located, so I'm not sure how to, "transport the files to the server where the DB server is running."

Re: How to insert BLOB files into tables [message #534258 is a reply to message #534257] Sun, 04 December 2011 21:58 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Rock<=>sandy_bridge_655k<=>HardSpot
I do know that Oracle's requirement for local files will not change any time soon.
You may need to locate a different & more hospitable DB hosting site.

Does RDS support/allow DB_LINK to remote/non-RDS database?
Re: How to insert BLOB files into tables [message #534259 is a reply to message #534258] Sun, 04 December 2011 22:04 Go to previous messageGo to next message
sandy_bridge_655k
Messages: 55
Registered: November 2011
Member
I've decided to host this DB on a different server. Hopefully this one does not have weird rules like Amazon RDS.
Re: How to insert BLOB files into tables [message #534260 is a reply to message #534258] Sun, 04 December 2011 23:22 Go to previous messageGo to next message
sandy_bridge_655k
Messages: 55
Registered: November 2011
Member
OK, I transferred all the above code to my Oracle 10g XE on my desktop computer.

After building the database, I entered the follow commands at the SQL prompt:

create or replace directory temp as 
'/home/big-geek/Dropbox/Graduate work/Applied Database Technologies/Music';

Directory created.


When I ran the procedure insert_track, I received the following error:
exec insert_track(1, 1234, 4321, 'Dear-Mama.m4a');
BEGIN insert_track(1, 1234, 4321, 'Dear-Mama.m4a'); END;

*
ERROR at line 1:
ORA-22288: file or LOB operation FILEOPEN failed
Permission denied
ORA-06512: at "SYS.DBMS_LOB", line 523
ORA-06512: at "STEPHEN.INSERT_TRACK", line 30
ORA-06512: at line 1


It seems that I don't have permission to open the file. How do I grant myself this permission?

[Updated on: Mon, 05 December 2011 01:06] by Moderator

Report message to a moderator

Re: How to insert BLOB files into tables [message #534261 is a reply to message #534260] Sun, 04 December 2011 23:36 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>create or replace directory temp as '/home/big-geek/Dropbox/Graduate work/Applied Database Technologies/Music';
UNIX is not Windows & does not like space characters in directory or file names.

>How do I grant myself this permission?
issue GRANT?
Re: How to insert BLOB files into tables [message #534262 is a reply to message #534261] Sun, 04 December 2011 23:49 Go to previous messageGo to next message
sandy_bridge_655k
Messages: 55
Registered: November 2011
Member
yeah, I just realized that I specified the path wrong after looking through the directory at the terminal.

I tried the following, but received the same error:

SQL> create or replace directory temp as 
'/home/big-geek/Dropbox/Graduate\ work/Applied\ Database\ Technologies/Music';

Directory created.

SQL> exec insert_track(1, 1234, 4321, 'Dear-Mama.m4a');
BEGIN insert_track(1, 1234, 4321, 'Dear-Mama.m4a'); END;

*
ERROR at line 1:
ORA-22288: file or LOB operation FILEOPEN failed
Permission denied
ORA-06512: at "SYS.DBMS_LOB", line 523
ORA-06512: at "STEPHEN.INSERT_TRACK", line 30
ORA-06512: at line 1


SQL> create or replace directory temp as 
'/home/big-geek/Dropbox/Graduate\work/Applied\Database\Technologies/Music';

Directory created.

SQL> exec insert_track(1, 1234, 4321, 'Dear-Mama.m4a');
BEGIN insert_track(1, 1234, 4321, 'Dear-Mama.m4a'); END;

*
ERROR at line 1:
ORA-22288: file or LOB operation FILEOPEN failed
Permission denied
ORA-06512: at "SYS.DBMS_LOB", line 523
ORA-06512: at "STEPHEN.INSERT_TRACK", line 30
ORA-06512: at line 1



solution?

[Updated on: Mon, 05 December 2011 02:43] by Moderator

Report message to a moderator

Re: How to insert BLOB files into tables [message #534263 is a reply to message #534262] Sun, 04 December 2011 23:50 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
http://www.orafaq.com/forum/mv/msg/170715/505569/136107/#msg_505569
Re: How to insert BLOB files into tables [message #534266 is a reply to message #534263] Mon, 05 December 2011 00:06 Go to previous messageGo to next message
sandy_bridge_655k
Messages: 55
Registered: November 2011
Member
Thanks for the link.

I followed the steps from the existing post, but still received the same error. Is the insert_track procedure code wrong?

Enter user-name: system
Enter password: 

Connected to:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production

SQL> create or replace directory temp as 
'home/big-geek/Dropbox/Graduate\ work/Applied\ Database\ Technologies/Music';

Directory created.

SQL> grant read on directory temp to stephen;

Grant succeeded.

SQL> connect stephen/password
Connected.
SQL> exec insert_track(1, 1234, 4321, 'Dear-Mama.m4a');
BEGIN insert_track(1, 1234, 4321, 'Dear-Mama.m4a'); END;

*
ERROR at line 1:
ORA-22288: file or LOB operation FILEOPEN failed
No such file or directory
ORA-06512: at "SYS.DBMS_LOB", line 523
ORA-06512: at "STEPHEN.INSERT_TRACK", line 30
ORA-06512: at line 1


[Updated on: Mon, 05 December 2011 02:43] by Moderator

Report message to a moderator

Re: How to insert BLOB files into tables [message #534269 is a reply to message #534266] Mon, 05 December 2011 00:16 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Ready, FIRE, Aim!
What OS user accesses OS directory & file?
Does this OS user have complete & unobstructed OS access to desired OS file?
Post COPY & PASTE proof of same.
Re: How to insert BLOB files into tables [message #534272 is a reply to message #534269] Mon, 05 December 2011 00:22 Go to previous messageGo to next message
sandy_bridge_655k
Messages: 55
Registered: November 2011
Member
what commands do I issue at the OS shell prompt to generate this information (i.e. what OS user accesses OS directory & file, etc.)?
Re: How to insert BLOB files into tables [message #534273 is a reply to message #534269] Mon, 05 December 2011 00:29 Go to previous messageGo to next message
sandy_bridge_655k
Messages: 55
Registered: November 2011
Member
Is this helpful?

big-geek@big-geek-Ubuntu-11:~/Dropbox/Graduate work/Applied Database Technologies/Music$ dir
01\ When\ We\ Stand\ Together.m4a    All\ the\ Small\ Things.m4v
02\ Public\ Enemy\ No.\ 1.m4a	     Dear-Mama.m4a
03\ Izzo\ (H.O.V.A.).m4a	     Dear\ Mama.m4v
04\ Restless.m4a		     Even\ Flow.m4v
05\ Love\ Me\ Bad.m4a		     Izzo\ (H.O.V.A.).m4v
05\ Smells\ Like\ Teen\ Spirit.m4a   Locust.m4v
06\ All\ the\ Small\ Things.m4a      Love\ Me\ Bad.m4v
07\ Player's\ Ball.m4a		     Player's\ Ball.m4v
07\ This\ Is\ More.m4a		     Public\ Enemy\ No.\ 1.m4v
1-03\ Even\ Flow.m4a		     Restless.m4v
1-07\ The\ One\ That\ Got\ Away.m4a  Smells\ Like\ Teen\ Spirit.m4v
12\ Passin'\ Me\ By.m4a		     The\ One\ That\ Got\ Away.m4v
12\ When\ We\ Stand\ Together.m4v    This\ is\ More.m4v


Re: How to insert BLOB files into tables [message #534275 is a reply to message #534272] Mon, 05 December 2011 00:30 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
sandy_bridge_655k wrote on Sun, 04 December 2011 22:22
what commands do I issue at the OS shell prompt to generate this information (i.e. what OS user accesses OS directory & file, etc.)?


you have me at a severe disadvantage.
I have no idea what OS you have, so guessing at command I won't do
Re: How to insert BLOB files into tables [message #534276 is a reply to message #534275] Mon, 05 December 2011 00:33 Go to previous messageGo to next message
sandy_bridge_655k
Messages: 55
Registered: November 2011
Member
oh. I'm using Linux Ubuntu 11.04, codename: Oneiric Ocelot.
Re: How to insert BLOB files into tables [message #534281 is a reply to message #534276] Mon, 05 December 2011 01:09 Go to previous messageGo to next message
Michel Cadot
Messages: 68758
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
First, remove all spaces in your path.
Then we can talk on a sane basis.

Regards
Michel


Re: How to insert BLOB files into tables [message #534282 is a reply to message #534281] Mon, 05 December 2011 01:26 Go to previous messageGo to next message
sandy_bridge_655k
Messages: 55
Registered: November 2011
Member
All the spaces are removed at this point, and I'm still receiving the same error. I renamed all the sub directories at the OS level such that are no spaces in the path.


big-geek@big-geek-Ubuntu-11:~/Dropbox/Graduate work/Applied Database Technologies/Music$ dir
01\ When\ We\ Stand\ Together.m4a    All\ the\ Small\ Things.m4v
02\ Public\ Enemy\ No.\ 1.m4a	     Dear-Mama.m4a
03\ Izzo\ (H.O.V.A.).m4a	     Dear\ Mama.m4v
04\ Restless.m4a		     Even\ Flow.m4v
05\ Love\ Me\ Bad.m4a		     Izzo\ (H.O.V.A.).m4v
05\ Smells\ Like\ Teen\ Spirit.m4a   Locust.m4v
06\ All\ the\ Small\ Things.m4a      Love\ Me\ Bad.m4v
07\ Player's\ Ball.m4a		     Player's\ Ball.m4v
07\ This\ Is\ More.m4a		     Public\ Enemy\ No.\ 1.m4v
1-03\ Even\ Flow.m4a		     Restless.m4v
1-07\ The\ One\ That\ Got\ Away.m4a  Smells\ Like\ Teen\ Spirit.m4v
12\ Passin'\ Me\ By.m4a		     The\ One\ That\ Got\ Away.m4v
12\ When\ We\ Stand\ Together.m4v    This\ is\ More.m4v



create or replace directory temp as 
'home/big-geek/Dropbox/GraduateWork/AppliedDatabaseTechnologies/Music';

Directory created.

SQL> grant read on directory temp to stephen;

Grant succeeded.

SQL> connect stephen/4uq5LiwN2cjvy3i
Connected.
SQL> exec insert_track(1, 1234, 4321, 'Dear-Mama.m4a');
BEGIN insert_track(1, 1234, 4321, 'Dear-Mama.m4a'); END;

*
ERROR at line 1:
ORA-22288: file or LOB operation FILEOPEN failed
No such file or directory
ORA-06512: at "SYS.DBMS_LOB", line 523
ORA-06512: at "STEPHEN.INSERT_TRACK", line 30
ORA-06512: at line 1


[Updated on: Mon, 05 December 2011 02:43] by Moderator

Report message to a moderator

Re: How to insert BLOB files into tables [message #534283 is a reply to message #534282] Mon, 05 December 2011 01:36 Go to previous messageGo to next message
flyboy
Messages: 1903
Registered: November 2006
Senior Member
Just one remark: you created that directory in Oracle as relative path (probably to some Oracle one). According to its content (starting with home directory), is it not rather absolute one? Then, it should start with '/' in the Oracle definition.
Re: How to insert BLOB files into tables [message #534285 is a reply to message #534282] Mon, 05 December 2011 01:39 Go to previous messageGo to next message
Michel Cadot
Messages: 68758
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
No such file or directory

Oracle is unable to find or access the file or directory.
Which line is line 30?
Use SQL*Plus and copy and paste your session, the WHOLE session.

Regards
Michel
Re: How to insert BLOB files into tables [message #534286 is a reply to message #534283] Mon, 05 December 2011 01:48 Go to previous messageGo to next message
sandy_bridge_655k
Messages: 55
Registered: November 2011
Member
Appending '/' to the front of the path did not solve the problem:

SQL> create or replace directory temp as 
'/home/big-geek/Dropbox/GraduateWork/AppliedDatabaseTechnologies/Music';

Directory created.

SQL> grant read on directory temp to stephen;

Grant succeeded.

SQL> connect stephen/password
Connected.
SQL>  exec insert_track(1, 1234, 4321, 'Dear-Mama.m4a');
BEGIN insert_track(1, 1234, 4321, 'Dear-Mama.m4a'); END;

*
ERROR at line 1:
ORA-22288: file or LOB operation FILEOPEN failed
Permission denied
ORA-06512: at "SYS.DBMS_LOB", line 523
ORA-06512: at "STEPHEN.INSERT_TRACK", line 30
ORA-06512: at line 1

[Updated on: Mon, 05 December 2011 02:42] by Moderator

Report message to a moderator

Re: How to insert BLOB files into tables [message #534288 is a reply to message #534286] Mon, 05 December 2011 01:50 Go to previous messageGo to next message
Michel Cadot
Messages: 68758
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Still not know which line is line 30.
When as the WHOLE session, it means INCLUDING procedure creation with line numbers.

Regards
Michel
Re: How to insert BLOB files into tables [message #534289 is a reply to message #534285] Mon, 05 December 2011 01:50 Go to previous messageGo to next message
sandy_bridge_655k
Messages: 55
Registered: November 2011
Member
Line 30 is when the fileopen occurs.

insert_track (
  2  track_idno number,
  3  artist_idno number,
  4  album_idno number,
  5  pfname varchar2) IS
  6  
  7  src_file BFILE;
  8  dst_file BLOB;
  9  lgh_file BINARY_INTEGER;
 10  BEGIN
 11  src_file := bfilename('TEMP', pfname);
 12  
 13  -- insert a NULL record to lock
 14  INSERT INTO track
 15  (track_id, artist_id, album_id, content)
 16  VALUES
 17  (track_idno, artist_idno, album_idno, EMPTY_BLOB())
 18  RETURNING content INTO dst_file;
 19  
 20  -- lock record
 21  SELECT content
 22  INTO dst_file
 23  FROM track
 24  WHERE  artist_id = artist_idno
 25  AND album_id = album_idno
 26  AND track_id = track_idno
 27  FOR UPDATE;
 28  
 29  -- open the file
 30  dbms_lob.fileopen(src_file, dbms_lob.file_readonly);
 31  
 32  -- determine length
 33  lgh_file := dbms_lob.getlength(src_file);
 34  
 35  -- read the file
 36  dbms_lob.loadfromfile(dst_file, src_file, lgh_file);
 37  
 38  -- update the blob field
 39  UPDATE track
 40  SET content = dst_file
 41  WHERE track_id = track_idno
 42  AND artist_id = artist_idno
 43  AND album_id = album_idno;
 44  
 45  -- close file
 46  dbms_lob.fileclose(src_file);
 47  END insert_track;
 48  /


SQL> exit


Re: How to insert BLOB files into tables [message #534291 is a reply to message #534286] Mon, 05 December 2011 01:54 Go to previous messageGo to next message
flyboy
Messages: 1903
Registered: November 2006
Senior Member
sandy_bridge_655k wrote on Mon, 05 December 2011 08:48
Appending '/' to the front of the path did not solve the problem:

I would disagree with you. Or, are you blind not to see that the error message changed? Now it is "Permission denied", which means, Oracle (OS user oracle) cannot access that directory. What is its permission for Others group? Maybe you should change it to at least "r".
Re: How to insert BLOB files into tables [message #534293 is a reply to message #534291] Mon, 05 December 2011 02:19 Go to previous messageGo to next message
sandy_bridge_655k
Messages: 55
Registered: November 2011
Member
How do I change the permission for Others group to "r"?
Re: How to insert BLOB files into tables [message #534294 is a reply to message #534293] Mon, 05 December 2011 02:23 Go to previous messageGo to next message
flyboy
Messages: 1903
Registered: November 2006
Senior Member
sandy_bridge_655k wrote on Mon, 05 December 2011 09:19
How do I change the permission for Others group to "r"?

Using chmod command (for both directory and file/s).

Maybe you should take some Linux basics lessons. Or, better, consult it with a "big geek" (yes, your OS name sounds funny in comparison with your Linux knowledge).
Re: How to insert BLOB files into tables [message #534298 is a reply to message #534294] Mon, 05 December 2011 02:52 Go to previous messageGo to next message
sandy_bridge_655k
Messages: 55
Registered: November 2011
Member
chmod -R 0777 /home/big-geek/Dropbox/GraduateWork/AppliedDatabaseTechnologies/Music


SQL>  exec insert_track(1, 1234, 4321, 'Dear-Mama.m4a');
BEGIN insert_track(1, 1234, 4321, 'Dear-Mama.m4a'); END;

*
ERROR at line 1:
ORA-22288: file or LOB operation FILEOPEN failed
Permission denied
ORA-06512: at "SYS.DBMS_LOB", line 523
ORA-06512: at "STEPHEN.INSERT_TRACK", line 30
ORA-06512: at line 1

Re: How to insert BLOB files into tables [message #534299 is a reply to message #534298] Mon, 05 December 2011 02:54 Go to previous messageGo to next message
Michel Cadot
Messages: 68758
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
You must verified all privileges from / to /home/big-geek/Dropbox/GraduateWork/AppliedDatabaseTechnologies/Music/Dear-Mama.m4a

Post "ls -ld" for all of them.

Regards
Michel
Re: How to insert BLOB files into tables [message #534302 is a reply to message #534299] Mon, 05 December 2011 03:18 Go to previous messageGo to next message
sandy_bridge_655k
Messages: 55
Registered: November 2011
Member

big-geek@big-geek-Ubuntu-11:~$ ls -ld
drwxrwxrwx 80 big-geek big-geek 32768 2011-12-05 00:44 .

big-geek@big-geek-Ubuntu-11:~/Dropbox$ ls -ld
drwxrwxrwx 8 big-geek big-geek 4096 2011-12-05 03:54 .

big-geek@big-geek-Ubuntu-11:~/Dropbox/GraduateWork$ ls -ld
drwxrwxrwx 9 big-geek big-geek 4096 2011-12-05 01:36

big-geek@big-geek-Ubuntu-11:~/Dropbox/GraduateWork/AppliedDatabaseTechnologies$ ls -ld
drwxrwxrwx 7 big-geek big-geek 12288 2011-12-05 03:57 .

big-geek@big-geek-Ubuntu-11:~/Dropbox/GraduateWork/AppliedDatabaseTechnologies/Music$ ls -ld
drwxrwxrwx 2 big-geek big-geek 4096 2011-12-05 00:15 .

big-geek@big-geek-Ubuntu-11:~/Dropbox/GraduateWork/AppliedDatabaseTechnologies/Music$ ls -ld Dear-Mama.m4a
-rwxrwxrwx 1 big-geek big-geek 9585993 2011-12-01 00:00 Dear-Mama.m4a


SQL>  exec insert_track(1, 1234, 4321, 'Dear-Mama.m4a');

PL/SQL procedure successfully completed.



I didn't realize that I needed to change the permissions of every directory in the path. Thanks for your help, Michel Smile
Re: How to insert BLOB files into tables [message #534307 is a reply to message #534302] Mon, 05 December 2011 03:52 Go to previous messageGo to next message
Michel Cadot
Messages: 68758
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Now that you have made it work without space, try if you can make with them (only if you need it) but I didn't recommend using spaces or any non-alphanumerical characters (but _).

Regards
Michel
Re: How to insert BLOB files into tables [message #534389 is a reply to message #534307] Mon, 05 December 2011 16:07 Go to previous messageGo to next message
sandy_bridge_655k
Messages: 55
Registered: November 2011
Member
I need to create a procedure which finds all the videos of the artist, given the artist name.

I added a video_name column to the video table to make this easier (i.e avoided reading the file name of the BLOB).

I wrote the procedure below, but I think it's missing a loop. I would appreciate if anyone could help revise this procedure with any necessary corrections....

CREATE OR REPLACE PROCEDURE find_artist_videos ( 
a_name varchar2) IS 

aid number;
tid number;

BEGIN

SELECT artist_id INTO aid FROM artist
WHERE artist_name = a_name;

SELECT track_id INTO tid FROM track --there could be multiple tracks from the same artist
WHERE artist_id = aid;             --Do I need a loop around all these select statements?

SELECT video_name FROM video  
WHERE track_id = tid;



END find_artist_video;


[Updated on: Mon, 05 December 2011 16:35]

Report message to a moderator

Re: How to insert BLOB files into tables [message #534392 is a reply to message #534389] Mon, 05 December 2011 16:42 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9105
Registered: November 2002
Location: California, USA
Senior Member
You could do this using one select with joins. If you want to put that into a procedure, then you need to decide how you are going to output the results. You could open a ref cursor for the select statement or you could loop through a cursor that uses the select statement and output using dbms_output. There are other options, such as using a pipelined table function. In any case, you should start by just creating and testing the single select statement that produces the results that you want.

Re: How to insert BLOB files into tables [message #534393 is a reply to message #534392] Mon, 05 December 2011 16:57 Go to previous messageGo to next message
sandy_bridge_655k
Messages: 55
Registered: November 2011
Member
Thanks, Barbara. I was thinking maybe I could use a join, but wasn't sure.

Here is what I have so far. Can you tell me what's wrong with it? I know that I probably need a cursor, but, like you said, I want to get the SELECT statement right first.

CREATE OR REPLACE PROCEDURE find_artist_videos ( 
a_name varchar2) IS 

vnm varchar(30);

BEGIN

SELECT video.video_name INTO vnm 
FROM video  
INNER JOIN track 
INNER JOIN artist  
ON video.track_id = track.track_id = ?  --how do I complete this JOIN?  
                                                 
dbms_output.put_line(vnm);


END find_artist_videos;
Re: How to insert BLOB files into tables [message #534395 is a reply to message #534393] Mon, 05 December 2011 17:03 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9105
Registered: November 2002
Location: California, USA
Senior Member
You cannot select multiple rows into a one-row variable. You should test the select outside of the procedure first, before trying to figure out how to put it in the procedure. I find the old non-ansi syntax easier, but if you want to use the ansi syntax, then put the ON clause for each join after that join, then the next join with the next on clause.

SELECT ...
FROM   ...
JOIN   ...
ON     ...
JOIN   ...
ON     ...;

Re: How to insert BLOB files into tables [message #534396 is a reply to message #534395] Mon, 05 December 2011 17:21 Go to previous messageGo to previous message
sandy_bridge_655k
Messages: 55
Registered: November 2011
Member
OK, I wrote the select statement outside the procedure, but it returns every video_name record instead of only the one for '2-PAC'.

SELECT video.video_name                                                                                                                             FROM video  
JOIN track 
ON video.track_id = track.track_id;
JOIN artist  
ON artist.artist_name = '2-PAC'
Previous Topic: DBMS_METADATA
Next Topic: How to add range partition?
Goto Forum:
  


Current Time: Mon Jun 02 17:26:08 CDT 2025