Packages that convert hex to dec

hi,
i have a table posicional which has large object on it..the column grarep(graphical representation) and attr_posn contains hexadecimal value of coordinates that is used in automated mapping
SQL>DESCRIBE POSICIONAL;
Name          Null     Type
class_id           NUMBER(10)
class_memb NUMBER(10)
codigo               NUMBER(10)
simbolo               NUMBER(10)     
xmin               NUMBER(10)
ymin               NUMBER(10)
xmax               NUMBER(10)     
grarep               BLOB
attr_posn          BLOB
usuario               VARCHAR2(30)
fecha               DATE
texto               VARCHAR2(50)
--Once i query grarep and attr_posn
SQL>SELECT grarep from posicional;
Column or attribute type cannot be displayed by SQL
--I made a function blobtochar to be able to view the data on grarep and attr_posn
CREATE OR REPLACE FUNCTION Blobtochar (field_name IN BLOB)
RETURN VARCHAR2 IS
OutputStr VARCHAR2(32767);
-- OutputStr LONG;
AmtToRead NUMBER:=4000;
Position NUMBER:=1;
LENGTH NUMBER;
BEGIN
LENGTH := DBMS_LOB.GETLENGTH(field_name);
LOOP
OutputStr := OutputStr || DBMS_LOB.SUBSTR(field_name, AmtToRead, Position);
     Position := Position + AmtToRead;
     LENGTH := LENGTH - 4000;
     EXIT WHEN LENGTH < 4000;
END LOOP;
RETURN OutputStr;
END Blobtochar;
SQL>SELECT blobtochar(grarep) from posicional
--now i can view the data in grarep..
--for example
SQL>SELECT class_memb, blobtochar(grarep) FROM posicional WHERE class_memb=111025648;
blobtochar(grarep)
00000001000000010000000606D4E833074B69EC06D4E91F074CO18406D50C58074C031E
HERES MY QUESTION,
1.how can i convert this hexadecimal coordinates so that when i query, a decimal value will appear instead of hex. this hex values are the lines in the map.heres the info about the hex value above. we need to parse or cut the hex into 8..
00000001
00000001
00000006 ==>number of coordinates(ranging from 1-F, this example means 6)
06D4E833 ==> X1
074B69EC ==> Y1
06D4E91F ==> X2
074CO184 ==> Y2
06D50C58 ==> X3
074C031E ==> Y3
connecting 4 coordinates/2points/ will make 1 line
connecting 6 coordinates/3points/ will make 2 lines
connecting 8 coordinates/4points/ will make 3 lines
connecting 10 coordinates/5points/ will make 4lines
connecting 12 coordinates/6points/ will make 5lines
connecting 14 coordinates/7points/ will make 6lines
and so on..
In the example above there are 6 coordinates
point(X1Y1), point(X2Y2), and point(X3Y3). Connecting all 3 points will make 2 lines). computing the total length by phytagorean therorem
LINE1 length=square root of X2-X1 squared + Y2-Y1 squared
LINE2 length=square root of X3-X2 squared + Y3-Y2 squared
total length = LINE1 + LINE2
how can i implement this so that when i query specific grarep and attr_posn, a computed total length in decimal value will appear instead of hex..thanks

You might enjoy reading the SQL Reference manual. Chapter 2 deals with datatypes and numeric format models - for 9i the reference you need is http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/sql_elements4a.htm#34512

Similar Messages

  • Converting hex to dec

    Hi everybody,
    I want to join this two numbers and convert them from hex to dec. I have tried using joint and conversion but I still couldn't work it. In the following screen shot I took it suppose to be 3E8 in hex which equals to 1000 in dec. I need suggestion from you how to approach this.
    Thanks
    Solved!
    Go to Solution.

    SOBGA wrote:
    As I was reading all the answers about converting Hex to Dec,I found out that many of you are making it so complicated.To make it easier for a learner or beginner,this is what it takes:
    Open a blank VI
    Click on numeric control
    Right click on the same numeric control
    Scroll down to "Representation"
    Click on "U8"
    Go to numeric indicator and repeat step 4 and 5
    Then right click again on numeric control
    Scroll down to "Properties" and click
    Click on "Data entry",if necessary,change the minimum and maximum
    Pass to "Display format" 
    Click on "Hexadecimal" then you are done.The rest is to go on the block diagram to wire the numeric control to the numeric indicator and it works.
    You can do the same process reverse for dec to hex.But you must know that what we did for "numeric control" on (Hex to Dec) will be done to "numeric indicator" on (Dec to Hex).This same process can apply to octal and binary without the use of complicated array,string while loop and so on...
    I'm a beginner in Labview and I understand that you need to explain more to understand better.
    If you really read all of the comments, you would see that Altenbach already stated this (saying it is just a cosmetic property for the indicator).
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Convert  Hex to Dec in Numbers

    Hi,
    Can some one let me know how to Convert Hex to Dec in Numbers.
    When ever I type Hex 00E0 it will appear in the cell like this 0.00E+00 ,who do i fix this.
    Thanks
    Ashan

    -+-+-+-+-+-+-+-
    Entering the Help and Terms of Use area you will read:
    *What is Apple Discussions and how can it help me?* 

    Apple Discussions is a user-to-user support forum where experts and other Apple product users get together to discuss Apple products. … You can participate in discussions about various products and topics, find solutions to help you resolve issues, ask questions, get tips and advice, and more.
    _If you have a technical question about an Apple product, be sure to check out Apple's support resources first by consulting the application Help menu on your computer and visiting our Support site to view articles and more on our product support pages_.
    I have a question or issue—how do I search for answers? _
It's possible that your question or issue has already been answered by other members so do a search before posting a question._ On most Apple Discussions pages, you'll find a Search Discussions box in the upper right corner. Enter a search term (or terms) in the field and press Return. Your results will appear as a list of links to posts below the Search Discussions Content pane.
    -+-+-+-+-+-+-+-
    Taking care of that, you would already know the response.
    Using the really cumbersome keystring "convert AND hex" as described in the forum's help returns two entries.
    One is you question.
    The other is: http://discussions.apple.com/thread.jspa?messageID=7242325
    which gives a link to:
    http://discussions.apple.com/thread.jspa?messageID=7078123
    Yvan KOENIG (from FRANCE jeudi 24 juillet 2008 09:19:34)

  • Java code to convert - Hex to Dec

    I'ld like to convert an Integer or a String from hexadecimal format to a decimal format;
    For example: 30 give 0; 50 give P and so on.
    Can any one help me sending to me a java code that do it please?
    Thanx a lot

    This doesn't convert hex to decimal, but it does convert hex to the character representation, which is what it sounds like you want. At any rate, given "30" it will print "0" and given "50" it will print "P". Also, given "P" it will print "is invalid".
            try
                int in = Integer.parseInt(s, 16);
                Character ch = new Character((char)in); // should validate range here
                System.out.println("In: " + s + ", out: " + ch);
            catch (NumberFormatException e)
                System.out.println("In: " + s + " is invalid.");
            }

  • Convert Access Module to SQL Function - Hex To Dec conversion

    I need to convert an Access Module to a SQL Function but not sure how to successfully accomplish this.
    The module has several different functions to convert hexadecimal numbers to decimal and vice versa. I am not sure if I needed to break out each module function into a seperate function in SQL or not. Any help would be appreciated.
    Here is the actual module that needs to be converted:
    Public Function MEID_DecToHex(mMEIDDec As String) As String
        'Dim mMEIDDec As String
        Dim mManNum As Double
        Dim mSerialNum As Double
        Dim mMEIDHex As String
        Dim mManHex As String
        Dim mSerialHex As String
        'mMEIDDec = "268435457304109828"
        '*** Check MEID digits, make sure it is 18 digits else return invalid
        If Len(mMEIDDec) = 18 Then
            '*** 18 digit decimal code: 1st 10 digits is for the Manufacturer and last 8 digits is for the Serial Number
            mManNum = Left(mMEIDDec, 10)
            mSerialNum = Right(mMEIDDec, 8)
            '*** Convert MEID Dec to Hex
            mManHex = DecToHex(mManNum)
            mManHex = fntPad(mManHex, "0", 8)
            mSerialHex = DecToHex(mSerialNum)
            mSerialHex = fntPad(mSerialHex, "0", 6)
            MEID_DecToHex = mManHex & mSerialHex
        ElseIf Len(mMEIDDec) = 11 Then
            '*** 11 digit decimal code: 1st 3 digits is for the Manufacturer and last 8 digits is for the Serial Number
            mManNum = Left(mMEIDDec, 3)
            mSerialNum = Right(mMEIDDec, 8)
            '*** Convert MEID Dec to Hex
            mManHex = DecToHex(mManNum)
            mManHex = fntPad(mManHex, "0", 2)
            mSerialHex = DecToHex(mSerialNum)
            mSerialHex = fntPad(mSerialHex, "0", 6)
            MEID_DecToHex = mManHex & mSerialHex
        Else
            MEID_DecToHex = "Invalid"
        End If
    End Function
    Public Function MEID_HexToDec(mMEIDHex As String) As String
        'Dim mMEIDDec As String
        Dim mManNum As String
        Dim mSerialNum As String
        'Dim mMEIDHex As String
        Dim mManDec As String
        Dim mSerialDec As String
        'mMEIDHex = "a000001937b27a"
        ' Remove any spaces befor or after the string
        mMEIDHex = Trim(mMEIDHex)
        '*** Check MEID digits, make sure it is 14 digits else return invalid
        If Len(mMEIDHex) = 14 Then
            '*** 14 hexadecimal digits: 1st 8 digits is for the Manufacturer and last 6 digits is for the Serial Number
            mManNum = Left(mMEIDHex, 8)
            mSerialNum = Right(mMEIDHex, 6)
            '*** Convert MEID Hex to Dec
            mManDec = HexToDec(mManNum)
            mManDec = fntPad(mManDec, "0", 10)
            mSerialDec = HexToDec(mSerialNum)
            mSerialDec = fntPad(mSerialDec, "0", 8)
            MEID_HexToDec = mManDec & mSerialDec
        ElseIf Len(mMEIDHex) = 8 Then
            '*** 8 digit Hex code: 1st 2 digits is for the Manufacturer and last 6 digits is for the Serial Number
            mManNum = Left(mMEIDHex, 2)
            mSerialNum = Right(mMEIDHex, 6)
            '*** Convert MEID Dec to Hex
            mManDec = HexToDec(mManNum)
            mManDec = fntPad(mManDec, "0", 3)
            mSerialDec = HexToDec(mSerialNum)
            mSerialDec = fntPad(mSerialDec, "0", 8)
            MEID_HexToDec = mManDec & mSerialDec
        Else
            MEID_HexToDec = "Invalid"
        End If
    End Function

    Try link
    you can create & use CLR function
    or you can simply convert on fly refer below link
    http://blog.sqlauthority.com/2010/02/01/sql-server-question-how-to-convert-hex-to-decimal/
    http://blog.sqlauthority.com/2012/07/26/sql-server-answer-how-to-convert-hex-to-decimal-or-int/
    decimal to hex
    http://stackoverflow.com/questions/13643729/decimal-to-hex-conversion-in-sql-server-2008

  • I have Adobe Reader XI with the package that allows me to send pdfs and convert pdfs to Word. When I open a pdf and try to search the search shows no matches even though the word I am searching for is in the document. Any suggestions how to search?

    I have Adobe Reader XI with the package that allows me to send pdfs and convert pdfs to Word. When I open a pdf and try to search the search shows no matches even though the word I am searching for is in the document. Any suggestions how to search?

    Once again, my thanks for your assistance. If I may impose on your generosity one more time, if I understand you correctly if I create a document on Word or WordPerfect, print it and scan it to create a pdf, the search function will not work. But, if I create the pdf document in Word the search function will work. Unfortunately, I am not sure how I create a pdf document in Word other than by printing it and scanning it. Could you please explain.
    William B. Kohn, Esq.
    General Counsel
    Paul V. Profeta & Associates, Inc.
    769 Northfield Avenue
    Suite 250
    West Orange, New Jersey 07052
    (973) 325 - 1300
    (973) 325 - 0376 (Facsimile)
    [email protected]<mailto:[email protected]>

  • I just paid almost $10 to create a pdf from a jpg file, but I did it so that I could edit it. Now I find out I needed a different Adobe package that would create the pdf AND let me edit it. What do I do now?

    I just paid almost $10 to create a pdf from a jpg file, but I did it so that I could edit it. Now I find out I needed a different Adobe package that would create the pdf AND let me edit it. What do I do now?

    Hi Marion,
    PDF pack is meant to convert files to pdf format, Here's the feature list : Convert Word to PDF, Convert PDF to Word & Merge PDFs | Adobe PDF Pack
    In order to Create, Convert, edit pdf files, one needs to purchase Acrobat Software, Here's a feature list of Acrobat Pro : Features, PDF documents | Acrobat XI Pro
    However, you can download a free 30 day trial of Acrobat software using the following link : https://helpx.adobe.com/acrobat/kb/acrobat-downloads.html
    Regards,
    Rahul

  • I purchased the package that allows you to export PDF files into Word files.  Whenever I try to export the PDF into a Word file it never works...  I don't know if there's something key that I'm missing but I'm pretty bummed I paid for it and it won't work

    I purchased the package that allows you to export PDF files into Word files.  Whenever I try to export the PDF into a Word file it never works...  I don't know if there's something key that I'm missing but I'm pretty bummed I paid for it and it won't work.  Can anybody help me out?

    Hello,
    I have paid for this service for a year and it never worked on my computer.  I just renewed and it finally converted the file but it will not let me edit it.  I join you in being bummed.  Either I get help with this or I am asking for a 2 year refund.   My intention was to be able to edit a pdf in MS Word. 
    pfierrorob

  • How to convert hex string to time stamp?

    Hello everyone..
    I am currently working on a project in which I have to read the data from a unit and display that data using LabVIEW. I am using serial communication for reading the data. The read data is in hex format. 
    Now, I want to convert this hex string to a time stamp value. I am reading total 16 bytes. How to convert this hex data to a time stamp value. I have developed a VI. But I want to know that the displayed time stamp is correct or not? Or suggest me some other solution. 
    I am using LabVIEW 2011.
    Thanks & Regards,
    Manisha
    Attachments:
    Test.vi ‏7 KB

    Hi mancan,
                      As Iam using LV2009 Iam unable to open your example.Anyway for converting hex to time stamp
    Thanks as kudos only

  • Is there Java package to convert docs format?

    I am involved in a project that require to convert(conversion only, no editing) from various document formats to plain text or html. Does anyone know of any packages in JAVA that can do this.
    There are software that do this, but I need java package that will do this instead. Thanks anyone who can give me some direction to look.
    I have got two link from previous other java forum
    1. Jakarta POI project (http://jakarta.apache.org/poi/)
    2. iText site (http://www.lowagie.com/iText/)
    Thanks to them both and anyone that know of the something similar.

    My advice to you:
    1. Design VB/activeX control to do what you want to do. I'm pretty sure there are easy to use activeX controls for this
    2. Wrap your control into a COM interface.
    3. Call your COM object from java.
    Or, if your vehemently anti-ms, you can try to do it all in java. My guess is that trying to do it all in java is pretty hopeless and you'll end up giving up, but it's up to you

  • Where to get a binary package that will give library libiconv.so.2

    Hello
    I have installed MediaWiki on Solaris Express build 105. When someone's try to login to MediaWiki through web browser there is a error about encoding. Function iconv() is installed but there is no library for this extension. Without this library my computer can not do convert a non utf encoding to utf encoding so mostly 'windows' hosts can not do proper login. Error message says "password is wrong. try again".
    Software that i used to install Mediawiki: apache2.2, mysql 5.0, php5.2
    Where to get a binary package that will provide a library libiconv.so.2 or something ??
    What to do to get it working ??
    Thanks for any response

    There is no need to install this library. I have made mistake. When i was doing copy-paste a password from OpenOffice then this password did not mutch with password that was type by hand into firefox. Only this was the problem.

  • Convert char to dec

    Dear all ,
        I have to convert char to dec , my requirement is to covert  12344434 to 123444.34 .
    note i don't want 12344434 to 12344434.00 .
    Thanks in advance
    Debesh

    You can try like this.
    DATA : v_tot_len TYPE i,
            v_off_len TYPE i.
    DATA : v_off_text(50) TYPE c,
            v_dec_text(2)  TYPE c,
            v_fin_text(50) TYPE c.
    PARAMETERS : p_input TYPE text20 OBLIGATORY.
    START-OF-SELECTION.
    v_tot_len = STRLEN( p_input ).
    v_off_len = v_tot_len - 2.
    v_off_text = p_input+0(v_off_len).
    v_dec_text = p_input+v_off_len(2).
    CONCATENATE v_off_text v_dec_text INTO v_fin_text SEPARATED BY '.'.
    Here I am inputting the text to be converted.

  • Is there any kind of adapter/converter that converts an older Firewire 400 to Thunderbolt?

    Is there any kind of adapter/converter that converts an older Firewire 400 to Thunderbolt?

    Is this to plug in an older FW 400 device into a Thunderbolt port on a Mac?
    Or to plug in a Thunderbolt device into a FW 400 port on a Mac? 
    The first can be done but not the second.

  • Acrobat Pro XI crashes when 'Save As' is used for a package that had been edited?

    We have a package that is opened, edited and then we try to use 'Save As' to save it and Acrobat Pro XI crashes. No error codes are displayed and nothing is logged in any event log.
    Our work around - First save the package in the final distination folder then open it, edit it and save it.
    Is there a known issue with using the 'Save As' option for a package?

    We have a package that is opened, edited and then we try to use 'Save As' to save it and Acrobat Pro XI crashes. No error codes are displayed and nothing is logged in any event log.
    Our work around - First save the package in the final distination folder then open it, edit it and save it.
    Is there a known issue with using the 'Save As' option for a package?

  • Problem with package that create mail with PDF attachment

    Hola,
    I've this problem when I use the Oracle Package called "demo_mail",
    that I have download from this forum en september.
    The code of the Package, I post bottom, now I
    write the records of the Package,
    that I believe is the core of the problem:
    demo_mail.begin_attachment( conn => conn,
    mime_type => 'application/pdf',
    inline => TRUE, filename => ''|| VC_NOMEFILE ||'',
    transfer_enc => 'base64');
    The mime_type is correct?
    Why when I open the attachment of the mail, it say me that file type
    is not correct or the file has been damneged? I need help!
    Thank's
    *********************************************************The steps that I've done:
    1. PACKAGE demo_mail
    2. PACKAGE BODY demo_mail
    3. procedure P_SPEDMAILSERVATTA (that call package) this
    Cannot write the code, because this the result. :(((
    thank's
    CREATE OR REPLACE PACKAGE demo_mail IS
    -- Customize the SMTP host, port and your domain name below.
    smtp_host VARCHAR2(256) := 'XXX.YYYY.IT';
    smtp_port PLS_INTEGER := 25;
    smtp_domain VARCHAR2(256) := 'YYYY.it';
    -- Customize the signature that will appear in the email's MIME header.
    -- Useful for versioning.
    MAILER_ID CONSTANT VARCHAR2(256) := 'Mailer by Oracle UTL_SMTP';
    --------------------- End Customizable Section ---------------------
    -- A unique string that demarcates boundaries of parts in a multi-part email
    -- The string should not appear inside the body of any part of the email.
    -- Customize this if needed or generate this randomly dynamically.
    BOUNDARY CONSTANT VARCHAR2(256) := '-----7D81B75CCC90D2974F7A1CBD';
    FIRST_BOUNDARY CONSTANT VARCHAR2(256) := '--' || BOUNDARY || utl_tcp.CRLF;
    LAST_BOUNDARY CONSTANT VARCHAR2(256) := '--' || BOUNDARY || '--' ||
    utl_tcp.CRLF;
    -- A MIME type that denotes multi-part email (MIME) messages.
    MULTIPART_MIME_TYPE CONSTANT VARCHAR2(256) := 'multipart/mixed; boundary="'||
    BOUNDARY || '"';
    MAX_BASE64_LINE_WIDTH CONSTANT PLS_INTEGER := 76 / 4 * 3;
    -- A simple email API for sending email in plain text in a single call.
    -- The format of an email address is one of these:
    -- someone@some-domain
    -- "Someone at some domain" <someone@some-domain>
    -- Someone at some domain <someone@some-domain>
    -- The recipients is a list of email addresses separated by
    -- either a "," or a ";"
    PROCEDURE mail(sender IN VARCHAR2,
              recipients IN VARCHAR2,
              subject IN VARCHAR2,
              message IN VARCHAR2);
    -- Extended email API to send email in HTML or plain text with no size limit.
    -- First, begin the email by begin_mail(). Then, call write_text() repeatedly
    -- to send email in ASCII piece-by-piece. Or, call write_mb_text() to send
    -- email in non-ASCII or multi-byte character set. End the email with
    -- end_mail().
    FUNCTION begin_mail(sender IN VARCHAR2,
              recipients IN VARCHAR2,
              subject IN VARCHAR2,
              mime_type IN VARCHAR2 DEFAULT 'text/plain',
              priority IN PLS_INTEGER DEFAULT NULL)
              RETURN utl_smtp.connection;
    -- Write email body in ASCII
    PROCEDURE write_text(conn IN OUT NOCOPY utl_smtp.connection,
              message IN VARCHAR2);
    -- Write email body in non-ASCII (including multi-byte). The email body
    -- will be sent in the database character set.
    PROCEDURE write_mb_text(conn IN OUT NOCOPY utl_smtp.connection,
                   message IN VARCHAR2);
    -- Write email body in binary
    PROCEDURE write_raw(conn IN OUT NOCOPY utl_smtp.connection,
              message IN RAW);
    -- APIs to send email with attachments. Attachments are sent by sending
    -- emails in "multipart/mixed" MIME format. Specify that MIME format when
    -- beginning an email with begin_mail().
    -- Send a single text attachment.
    PROCEDURE attach_text(conn IN OUT NOCOPY utl_smtp.connection,
                   data IN VARCHAR2,
                   mime_type IN VARCHAR2 DEFAULT 'text/plain',
                   inline IN BOOLEAN DEFAULT TRUE,
                   filename IN VARCHAR2 DEFAULT NULL,
              last IN BOOLEAN DEFAULT FALSE);
    -- Send a binary attachment. The attachment will be encoded in Base-64
    -- encoding format.
    PROCEDURE attach_base64(conn IN OUT NOCOPY utl_smtp.connection,
                   data IN RAW,
                   mime_type IN VARCHAR2 DEFAULT 'application/octet',
                   inline IN BOOLEAN DEFAULT TRUE,
                   filename IN VARCHAR2 DEFAULT NULL,
                   last IN BOOLEAN DEFAULT FALSE);
    -- Send an attachment with no size limit. First, begin the attachment
    -- with begin_attachment(). Then, call write_text repeatedly to send
    -- the attachment piece-by-piece. If the attachment is text-based but
    -- in non-ASCII or multi-byte character set, use write_mb_text() instead.
    -- To send binary attachment, the binary content should first be
    -- encoded in Base-64 encoding format using the demo package for 8i,
    -- or the native one in 9i. End the attachment with end_attachment.
    PROCEDURE begin_attachment(conn IN OUT NOCOPY utl_smtp.connection,
                   mime_type IN VARCHAR2 DEFAULT 'text/plain',
                   inline IN BOOLEAN DEFAULT TRUE,
                   filename IN VARCHAR2 DEFAULT NULL,
                   transfer_enc IN VARCHAR2 DEFAULT NULL);
    -- End the attachment.
    PROCEDURE end_attachment(conn IN OUT NOCOPY utl_smtp.connection,
                   last IN BOOLEAN DEFAULT FALSE);
    -- End the email.
    PROCEDURE end_mail(conn IN OUT NOCOPY utl_smtp.connection);
    -- Extended email API to send multiple emails in a session for better
    -- performance. First, begin an email session with begin_session.
    -- Then, begin each email with a session by calling begin_mail_in_session
    -- instead of begin_mail. End the email with end_mail_in_session instead
    -- of end_mail. End the email session by end_session.
    FUNCTION begin_session RETURN utl_smtp.connection;
    -- Begin an email in a session.
    PROCEDURE begin_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection,
                        sender IN VARCHAR2,
                        recipients IN VARCHAR2,
                        subject IN VARCHAR2,
                        mime_type IN VARCHAR2 DEFAULT 'text/plain',
                        priority IN PLS_INTEGER DEFAULT NULL);
    -- End an email in a session.
    PROCEDURE end_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection);
    -- End an email session.
    PROCEDURE end_session(conn IN OUT NOCOPY utl_smtp.connection);
    END;
    CREATE OR REPLACE PACKAGE BODY demo_mail IS
    -- Return the next email address in the list of email addresses, separated
    -- by either a "," or a ";". The format of mailbox may be in one of these:
    -- someone@some-domain
    -- "Someone at some domain" <someone@some-domain>
    -- Someone at some domain <someone@some-domain>
    FUNCTION get_address(addr_list IN OUT VARCHAR2) RETURN VARCHAR2 IS
    addr VARCHAR2(256);
    i pls_integer;
    FUNCTION lookup_unquoted_char(str IN VARCHAR2,
                        chrs IN VARCHAR2) RETURN pls_integer AS
    c VARCHAR2(5);
    i pls_integer;
    len pls_integer;
    inside_quote BOOLEAN;
    BEGIN
    inside_quote := false;
    i := 1;
    len := length(str);
    WHILE (i <= len) LOOP
         c := substr(str, i, 1);
         IF (inside_quote) THEN
         IF (c = '"') THEN
         inside_quote := false;
         ELSIF (c = '\') THEN
         i := i + 1; -- Skip the quote character
         END IF;
         GOTO next_char;
         END IF;
         IF (c = '"') THEN
         inside_quote := true;
         GOTO next_char;
         END IF;
         IF (instr(chrs, c) >= 1) THEN
         RETURN i;
         END IF;
         <<next_char>>
         i := i + 1;
    END LOOP;
    RETURN 0;
    END;
    BEGIN
    addr_list := ltrim(addr_list);
    i := lookup_unquoted_char(addr_list, ',;');
    IF (i >= 1) THEN
    addr := substr(addr_list, 1, i - 1);
    addr_list := substr(addr_list, i + 1);
    ELSE
    addr := addr_list;
    addr_list := '';
    END IF;
    i := lookup_unquoted_char(addr, '<');
    IF (i >= 1) THEN
    addr := substr(addr, i + 1);
    i := instr(addr, '>');
    IF (i >= 1) THEN
         addr := substr(addr, 1, i - 1);
    END IF;
    END IF;
    RETURN addr;
    END;
    -- Write a MIME header
    PROCEDURE write_mime_header(conn IN OUT NOCOPY utl_smtp.connection,
                   name IN VARCHAR2,
                   value IN VARCHAR2) IS
    BEGIN
    utl_smtp.write_data(conn, name || ': ' || value || utl_tcp.CRLF);
    END;
    -- Mark a message-part boundary. Set <last> to TRUE for the last boundary.
    PROCEDURE write_boundary(conn IN OUT NOCOPY utl_smtp.connection,
                   last IN BOOLEAN DEFAULT FALSE) AS
    BEGIN
    IF (last) THEN
    utl_smtp.write_data(conn, LAST_BOUNDARY);
    ELSE
    utl_smtp.write_data(conn, FIRST_BOUNDARY);
    END IF;
    END;
    PROCEDURE mail(sender IN VARCHAR2,
              recipients IN VARCHAR2,
              subject IN VARCHAR2,
              message IN VARCHAR2) IS
    conn utl_smtp.connection;
    BEGIN
    conn := begin_mail(sender, recipients, subject);
    write_text(conn, message);
    end_mail(conn);
    END;
    FUNCTION begin_mail(sender IN VARCHAR2,
              recipients IN VARCHAR2,
              subject IN VARCHAR2,
              mime_type IN VARCHAR2 DEFAULT 'text/plain',
              priority IN PLS_INTEGER DEFAULT NULL)
              RETURN utl_smtp.connection IS
    conn utl_smtp.connection;
    BEGIN
    conn := begin_session;
    begin_mail_in_session(conn, sender, recipients, subject, mime_type,
    priority);
    RETURN conn;
    END;
    PROCEDURE write_text(conn IN OUT NOCOPY utl_smtp.connection,
              message IN VARCHAR2) IS
    BEGIN
    utl_smtp.write_data(conn, message);
    END;
    PROCEDURE write_mb_text(conn IN OUT NOCOPY utl_smtp.connection,
                   message IN VARCHAR2) IS
    BEGIN
    utl_smtp.write_raw_data(conn, utl_raw.cast_to_raw(message));
    END;
    PROCEDURE write_raw(conn IN OUT NOCOPY utl_smtp.connection,
              message IN RAW) IS
    BEGIN
    utl_smtp.write_raw_data(conn, message);
    END;
    PROCEDURE attach_text(conn IN OUT NOCOPY utl_smtp.connection,
                   data IN VARCHAR2,
                   mime_type IN VARCHAR2 DEFAULT 'text/plain',
                   inline IN BOOLEAN DEFAULT TRUE,
                   filename IN VARCHAR2 DEFAULT NULL,
              last IN BOOLEAN DEFAULT FALSE) IS
    BEGIN
    begin_attachment(conn, mime_type, inline, filename);
    write_text(conn, data);
    end_attachment(conn, last);
    END;
    PROCEDURE attach_base64(conn IN OUT NOCOPY utl_smtp.connection,
                   data IN RAW,
                   mime_type IN VARCHAR2 DEFAULT 'application/octet',
                   inline IN BOOLEAN DEFAULT TRUE,
                   filename IN VARCHAR2 DEFAULT NULL,
                   last IN BOOLEAN DEFAULT FALSE) IS
    i PLS_INTEGER;
    len PLS_INTEGER;
    BEGIN
    begin_attachment(conn, mime_type, inline, filename, 'base64');
    -- Split the Base64-encoded attachment into multiple lines
    i := 1;
    len := utl_raw.length(data);
    WHILE (i < len) LOOP
    IF (i + MAX_BASE64_LINE_WIDTH < len) THEN
         -- After upgrade to Oracle 9i, replace demo_base64.encode with the
         -- native utl_encode.base64_encode for better performance:
         -- utl_smtp.write_raw_data(conn,
    -- utl_encode.base64_encode(utl_raw.substr(data, i,
         -- MAX_BASE64_LINE_WIDTH)));
         utl_smtp.write_raw_data(conn,
    utl_encode.base64_encode(utl_raw.substr(data, i,
         MAX_BASE64_LINE_WIDTH)));
    ELSE
         -- After upgrade to Oracle 9i, replace demo_base64.encode with the
         -- native utl_encode.base64_encode for better performance:
         -- utl_smtp.write_raw_data(conn,
         -- utl_encode.base64_encode(utl_raw.substr(data, i)));
         utl_smtp.write_raw_data(conn,
         utl_encode.base64_encode(utl_raw.substr(data, i)));
    END IF;
    utl_smtp.write_data(conn, utl_tcp.CRLF);
    i := i + MAX_BASE64_LINE_WIDTH;
    END LOOP;
    end_attachment(conn, last);
    END;
    PROCEDURE begin_attachment(conn IN OUT NOCOPY utl_smtp.connection,
                   mime_type IN VARCHAR2 DEFAULT 'text/plain',
                   inline IN BOOLEAN DEFAULT TRUE,
                   filename IN VARCHAR2 DEFAULT NULL,
                   transfer_enc IN VARCHAR2 DEFAULT NULL) IS
    BEGIN
    write_boundary(conn);
    write_mime_header(conn, 'Content-Type', mime_type);
    IF (filename IS NOT NULL) THEN
    IF (inline) THEN
         write_mime_header(conn, 'Content-Disposition',
         'inline; filename="'||filename||'"');
    ELSE
         write_mime_header(conn, 'Content-Disposition',
         'attachment; filename="'||filename||'"');
    END IF;
    END IF;
    IF (transfer_enc IS NOT NULL) THEN
    write_mime_header(conn, 'Content-Transfer-Encoding', transfer_enc);
    END IF;
    utl_smtp.write_data(conn, utl_tcp.CRLF);
    END;
    PROCEDURE end_attachment(conn IN OUT NOCOPY utl_smtp.connection,
                   last IN BOOLEAN DEFAULT FALSE) IS
    BEGIN
    utl_smtp.write_data(conn, utl_tcp.CRLF);
    IF (last) THEN
    write_boundary(conn, last);
    END IF;
    END;
    PROCEDURE end_mail(conn IN OUT NOCOPY utl_smtp.connection) IS
    BEGIN
    end_mail_in_session(conn);
    end_session(conn);
    END;
    FUNCTION begin_session RETURN utl_smtp.connection IS
    conn utl_smtp.connection;
    BEGIN
    -- open SMTP connection
    conn := utl_smtp.open_connection(smtp_host, smtp_port);
    utl_smtp.helo(conn, smtp_domain);
    RETURN conn;
    END;
    PROCEDURE begin_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection,
                        sender IN VARCHAR2,
                        recipients IN VARCHAR2,
                        subject IN VARCHAR2,
                        mime_type IN VARCHAR2 DEFAULT 'text/plain',
                        priority IN PLS_INTEGER DEFAULT NULL) IS
    my_recipients VARCHAR2(32767) := recipients;
    my_sender VARCHAR2(32767) := sender;
    BEGIN
    -- Specify sender's address (our server allows bogus address
    -- as long as it is a full email address ([email protected]).
    utl_smtp.mail(conn, get_address(my_sender));
    -- Specify recipient(s) of the email.
    WHILE (my_recipients IS NOT NULL) LOOP
    utl_smtp.rcpt(conn, get_address(my_recipients));
    END LOOP;
    -- Start body of email
    utl_smtp.open_data(conn);
    -- Set "From" MIME header
    write_mime_header(conn, 'From', sender);
    -- Set "To" MIME header
    write_mime_header(conn, 'To', recipients);
    -- Set "Subject" MIME header
    write_mime_header(conn, 'Subject', subject);
    -- Set "Content-Type" MIME header
    write_mime_header(conn, 'Content-Type', mime_type);
    -- Set "X-Mailer" MIME header
    write_mime_header(conn, 'X-Mailer', MAILER_ID);
    -- Set priority:
    -- High Normal Low
    -- 1 2 3 4 5
    IF (priority IS NOT NULL) THEN
    write_mime_header(conn, 'X-Priority', priority);
    END IF;
    -- Send an empty line to denotes end of MIME headers and
    -- beginning of message body.
    utl_smtp.write_data(conn, utl_tcp.CRLF);
    IF (mime_type LIKE 'multipart/mixed%') THEN
    write_text(conn, 'This is a multi-part message in MIME format.' ||
         utl_tcp.crlf);
    END IF;
    END;
    PROCEDURE end_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection) IS
    BEGIN
    utl_smtp.close_data(conn);
    END;
    PROCEDURE end_session(conn IN OUT NOCOPY utl_smtp.connection) IS
    BEGIN
    utl_smtp.quit(conn);
    END;
    END;
    PROMPT     **********************************************************
    PROMPT     CREAZIONE PROCEDURA P_SPEDMAILSERVATTA
    PROMPT     **********************************************************
    create or replace procedure P_SPEDMAILSERVATTA( VC_DESCDENOAZIE IN VARCHAR2,
                                  VC_DESCINDIEMAI IN VARCHAR2,
                                  VC_NUMEBOLL     IN VARCHAR2,
                                  VC_PATHFILE     IN VARCHAR2,
                                  VC_NOMEFILE     IN VARCHAR2,
                                  VC_DESCINDIEMAIMITT IN VARCHAR2)
    IS
    conn utl_smtp.connection;
    req utl_http.req;
    resp utl_http.resp;
    data RAW(200);
    BEGIN
    conn := demo_mail.begin_mail(
    sender => 'SIAG srl <'|| VC_DESCINDIEMAIMITT ||'>',
    recipients => ''|| VC_DESCDENOAZIE ||' '||'<'|| VC_DESCINDIEMAI ||'>'||'',
    subject => 'Invio Bollettino n.'|| VC_NUMEBOLL ||'',
    mime_type => demo_mail.MULTIPART_MIME_TYPE);
    demo_mail.attach_text(
    conn => conn,
    data => 'Spett.le <b>'|| VC_DESCDENOAZIE ||'</b> <br> in allegato Le invio il Bollettino n. '|| VC_NUMEBOLL ||'.<br> <br> Distinti Saluti <br><br> <hr align="left" width="20%"> ',
    mime_type => 'text/html');
    demo_mail.begin_attachment(
    conn => conn,
    mime_type => 'application/pdf',
    inline => TRUE,
    filename => ''|| VC_NOMEFILE ||'',
    transfer_enc => 'base64');
    -- In writing Base-64 encoded text following the MIME format below,
    -- the MIME format requires that a long piece of data must be splitted
    -- into multiple lines and each line of encoded data cannot exceed
    -- 80 characters, including the new-line characters. Also, when
    -- splitting the original data into pieces, the length of each chunk
    -- of data before encoding must be a multiple of 3, except for the
    -- last chunk. The constant demo_mail.MAX_BASE64_LINE_WIDTH
    -- (76 / 4 * 3 = 57) is the maximum length (in bytes) of each chunk
    -- of data before encoding.
    req := utl_http.begin_request('http://localhost/'|| VC_PATHFILE ||'/'|| VC_NOMEFILE ||'');
    resp := utl_http.get_response(req);
    BEGIN
    LOOP
    utl_http.read_raw(resp, data, demo_mail.MAX_BASE64_LINE_WIDTH);
    demo_mail.write_raw(
    conn => conn,
    message => utl_encode.base64_encode(data));
    END LOOP;
    EXCEPTION
    WHEN utl_http.end_of_body THEN
    utl_http.end_response(resp);
    END;
    demo_mail.end_attachment( conn => conn );
    demo_mail.end_mail( conn => conn );
    END;
    Message was edited by:
    mosquito70
    Message was edited by:
    mosquito70

    Hola, I've this problem when I use the Oracle Package called "demo_mail",
    that I have download from this forum en september.
    The code of the Package, I post bottom, now I
    write the records of the Package,
    that I believe is the core of the problem:
    demo_mail.begin_attachment( conn => conn,
    mime_type => 'application/pdf',
    inline => TRUE, filename => ''|| VC_NOMEFILE ||'',
    transfer_enc => 'base64');
    The mime_type is correct?
    Why when I open the attachment of the mail, it say me that file type
    is not correct or the file has been damneged? I need help!
    Thank's
    The steps that I've done:
    1. PACKAGE demo_mail
    2. PACKAGE BODY demo_mail
    3. procedure P_SPEDMAILSERVATTA (that call package)
    I cannot post the code :((

Maybe you are looking for

  • Publish one site at a time

    If I have two "sites" on my iweb, how do I publish one at a time. I keep getting messges that I can't connect to iweb. This was during the time I was uploading new pages and each one was going fine. I thought this was because I had too many pages, so

  • Error in the instructions for performing a silent install

    There's an error in the instructions for performing a silent install of Photoshop Elements: http://helpx.adobe.com/photoshop-elements/kb/silent-install-instructions-photoshop-element s-1.html In step 9, the instructions say to use the following comma

  • Need to reinstall Bridge CS 3 2.1.1.9

    I have a disastrous installation of Mavericks and am preparing to revert back to Snow Leopard.  I have registered three versions of PhotoShop Elements, but am currently running PE 11.  I greatly prefer Bridge for working with images and don't like Or

  • Audio problem in Adobe After Effects CS6

    When ever i import a clip into adobe after effects cs6 the program does not read my clips audio i know how to ram preview its just the program doesnt read the audio what so ever but when i preview the clip on my desktop using windows media player it

  • After updating numbers and pages I can no longer copy multiple cells from numbers and paste and match style to pages.

    After updating numbers and pages I can no longer copy multiple cells from numbers and paste and match style to pages.  I used to be able to select multipule cells in a row (such as company name, address, etc.) then paste and match style on to a pages