Skip to Main Content
  • Questions
  • how to send file with any type to directory on the server

Breadcrumb

May 4th

Question and Answer

Tom Kyte

Thanks for the question, belal.

Asked: July 21, 2002 - 10:09 am UTC

Last updated: March 15, 2007 - 7:14 am UTC

Version: 817

Viewed 1000+ times

You Asked

hello Mr tom
I'm very glad to write to you

I've two questions :
1)I use local PC and i need to write a pl/sql code that to move or copy a file from my local pc to aspecified directory on server(c:\temp\) that defined by the followin Statment:
create or replace directory my_files as 'c:\temp\';
if it possiple how can i do it?
-------------
2)i try to send mail with attachment using pl/sql with out java or other tools so what possiple mime_type of file that i can send it as attachment

Thank you Mr Tom and really I'm very happy that i could write to you
bye

and Tom said...

Not easily with 817 (with 9iR2 and updates to the UTL_FILE package -- you can).

Suggest however that you not use Oracle as a "ftp" server in this case. Use the OS networking facilities provided to "mount" c:\temp\ and just copy the file. Much easier.

You can send an attachment of any type in the world you want to. It is just an attachment. Search for

javamail

on this site for examples.

Rating

  (5 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

I need not to use Oracle as a "ftp" server

belal, July 21, 2002 - 10:44 am UTC

hello Mr tom
the reason of asking first question is that
i need to send mail with attachment and i success just using pl/sql code with out using any java code but the problem is that when i try to send attachment i need first to put the attached file in the created directory in the database serve....so i need the user to select the file from his local pc and internaly by the oracle the file will saved in database directory and then the file will be sent.....I need not to use Oracle as a "ftp" server ........thank u sir :o)

Tom Kyte
July 21, 2002 - 11:16 am UTC

No you don't (need to put the file on the server)

You can send it directly. See

</code> http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:1739411218448 <code>

for example (or even easier, use javamail)

In any case, you can use the UTL_FILE_DIR, set it to c:\temp\, and then proceed to use UTL_FILE to write to a file on the server using your stored procedure. UTL_FILE only supports TEXT files (eg: a .doc or .ppt file is binary and WON'T work). If you need support for binary files, you'll be using either a C external procedure OR a java stored procedure (or you'll get 9iR2)

What is new with regards Binary File in R2

A reader, July 22, 2002 - 3:19 am UTC

Hi,

<Quote>
If you need support for binary files, you'll be using either a C
external procedure OR a java stored procedure (or you'll get 9iR2)
</Quote>

Can u pls eloborate on the above. What is new in R2 that allows me to read Binary Files ??

Regards,
Ganesh R

Tom Kyte
July 22, 2002 - 9:40 am UTC

In 9iR2 utl_file supports reading and writing binary files from PLSQL (there is a get and put raw API)

as well as lots of other new functions in UTL_FILE. goto otn.oracle.com and read the supplied packages guide for 9iR2 for details

Using UTL_SMTP for Reporting

Rahul Dutta, November 30, 2005 - 11:10 pm UTC

Tom,

Let me first start with explaining the problem and then the workaround I've done. I would need your expert view on this.

Problem:
I've to take daily export of 5 schema's in different Instances which I've scheduled at particular point of time. This is working fine. But, when I want to report the result of the export, I'm facing some problem.

Solution:
I've configured UTL_SMTP to report the sucesss or failure of the export. But my requirement is to send the entire export log file. The one way I could think of is attaching the export log file but for this I've use JAVA API along with UTL_SMTP. Correct me if I'm wrong?

Question:
Is there any way I can read the log file and send it using UTL_SMTP as text/html?

Thanks for helping me out...

Rahul

Tom Kyte
December 01, 2005 - 12:23 pm UTC

well, utl mail in 10g is to have support for attachments (have not used it), but sure, you can send attachments if you want to write the code to do so. you would have to figure out what the "spec" is for encoding attachments and then write that out with utl_smtp, similar to what tyler did here for html:

</code> http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:1739411218448 <code>

How to do it in (iR2

Hashmat, March 14, 2007 - 1:26 pm UTC

Sir, how to create files in DIRECTORY object from client from forms6i in 9iR2? The file is a word document (.doc) and is created on the client and should be moved to DIRECTORY object (server's local directory)?
Tom Kyte
March 15, 2007 - 7:14 am UTC

you can always use a stored procedure calling dbms_lob to accept the data you read in your client (dbms_lob.writeAppend to a lob locator you create)

You might ask other forms users however for the best way for forms to do this - otn.oracle.com -> discussion forums.

A reader, March 16, 2010 - 2:40 am UTC


More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library