Convert UPC-E to UPC-A upon insert with UDF

I have the function but I need this function to insert on the PosCode in my Products Table:
CREATE TABLE [Pricebook].[Products] (
[PosCode] [dbo].[posCode] NOT NULL,
[PosCodeFormat] AS ([dbo].[udf_PosCodeFormat]([PosCode])),
[CheckDigit] AS ([dbo].[udf_Calculate_UPCA_CheckDigit]([PosCode])),
where the PosCode is the primary key.  If the the user enters 7 digits then it should convert it to the 11 digit format in that column.  I need the returned output of @upcA to overwrite the data entered in the PosCode column....Here is the function:
CREATE function dbo.udf_UPCE_to_UPCA (@PosCode varchar(50))
-- limiting to varchar(8) only reads first 8 characters of any longer strings passed in
returns varchar(12)
as
begin
--Function to take in UPC-E, calculate and return its UPC-A.
-- local variables
declare @main_six varchar(6) -- The 6 important (middle) digits of UPCE
declare @upcA varchar(12) -- Calculated UPCA
-- Iniial settings
set @PosCode = ltrim(rtrim(isnull(@PosCode,'')))
set @upcA = ''
-- Calculate UPC-A
if (-- Required conditions for conversion: length must be 8, must start with 0 or 1
len(@PosCode) = 8
and left(@PosCode,1) in ('0','1')
and isnumeric(@PosCode) = 1
begin
set @main_six = substring(@PosCode,2,6)
if (right(@main_six,1) in ('0','1','2'))
begin
set @upcA = left(@PosCode,1)
+ left(@main_six,2)
+ right(@main_six,1)
+ '0000'
+ substring(@main_six,3,3)
+ right(@PosCode,1)
end
else if (right(@main_six,1) = '3')
begin
set @upcA = left(@PosCode,1)
+ left(@main_six,3)
+ '00000'
+ substring(@main_six,4,2)
+ right(@PosCode,1)
end
else if (right(@main_six,1) = '4')
begin
set @upcA = left(@PosCode,1)
+ left(@main_six,4)
+ '00000'
+ substring(@main_six,5,1)
+ right(@PosCode,1)
end
else
begin
set @upcA = left(@PosCode,1)
+ left(@main_six,5)
+ '0000'
+ substring(@main_six,6,1)
+ right(@PosCode,1)
end
end -- main if: Required conditions
return @upcA
end
Any help is greatly appreciated...thanks to all who offer it.

Let's take a step back.  You are using an user-defined type for PosCode in your table - and it would help to see the actual definition of the type.  Why? Because your function signature, code, and description are more than a little fuzzy and a
lack of clarity / precision is generally bad - especially when dealing with primary keys!.  Another example - your function returns varchar(12) [sidenote - variable length?  really?] but the input argument is varchar(50) and you have a comment that
says "limiting to varchar(8)".  Your text says that the function should "convert it to the 11 digit format " - where did the extra CHARACTER come from in the return value?
Next, check your function code very carefully.  You need to think about what happens when something is provided as the input argument that does not match your expectations.  That first IF statement will only execute one of those nested if/else
blocks for a limited set of values.  Everything else will be ignored and the default return value of an empty string will be returned.  Let the database engine prevent nonsense data in the first place.  If you only want to consider 8 characters
for input then you should define the input argument datatype as char(8) - I don't see any reason to make it variable. That will prevent anyone from providing anything more than 8 characters (but not less).
Next, you want to transform the value of PosCode - which is the primary key for the table - from the value provided (by a user or other system etc.) to something that meets a set of criteria.  Your system "knows" that PosCode is the PK of the table,
so imagine how an application should react when it enters a value of 'X' and then attempts to retrieve this row from the table - only to find that the row does not exist because the back-end has transformed the PK value that identifies it.  How will the
application know that the value 'X' supplied during insert is now 'Y' after transformation. 
Before you go further you should give some additional thought to this approach.  I think you should consider "validating" the value entered as PosCode in some fashion rather than transforming it since it will be difficult to implement an application
that should understand the "x becomes y" issue mentioned above. I doubt you can do this in a useful manner with the actual primary key.  Perhaps there is a better and different approach - I can't say since that requires a better understanding of what
data is entered, what is expected of that data in term of validity, the reasons for your transformation, etc.

Similar Messages

  • Leopard crashes upon Insertion of USF 1.02 formatted Disk

    Hi Folks,
    Here is the latest issue – OS X crashed last night on my macbook.
    Reason – Infra Recorder is an open source utility to burn disks fast in windows – it burns in UDF 1.02 format.
    Vista peacefully recognizes and plays – on mac – upon insertion of the disk – OS X just crashes.
    The send to apple stuff says : mount error – driver issue and driver is UDF driver, as far as I can see it.
    This leaves me frustrated – not that I can not burn ISO – I certainly can – but the question is why it should not run 1.02 UDF?
    Question – is there any free UDF drivers available on Leopard? And why crash?
    In Case Vista can do that - Why Leopard Can not? And Vista does not crash - even with 3rd party softwares - I am a living proof of it. Now with built in software Leopard crashes. WHY?
    I already sent issue to apple - this is a serious and blocking issue for me.
    I am yet to receive any response!

    Right. A little more on the issue.
    It would appear that I can burn them to a DVD and mount it but it would appear that there is something amiss. That said it does not crash my system, the just refuse to open and tell me that, 'this is not a movie file/this is corrupt/etc,etc'
    Now, with the 4.26GB DVD I burned it would appear that almost everything is corrupt.
    But the same file in the disc where the total burn size is 22MB is OK.
    A boundary issue like you suggested perhaps?
    If movie DVDs are burned in the same format though and they play OK maybe it's the Infracorder that's the problem.
    OK, more. I have put the 4.26GB DVD back into my laptop, (HP nw8240), and it also refuses to play most of the files, though it can see them. Have you tried remounting them in Windows?
    Message was edited by: gumsie

  • Running an application upon inserting a microSD card

    I am currently looking for a way to run an application which sits on the microSD card upon inserting the card in to the device. Form all the different posts what I have gathered is that running an app from microSD is not supported. But is there a way that upon inserting a microSD card, the file is transferred to the device memeory and executed?
    Windows Mobile has similar functionality where it allows an app called autorun.exe to run from the microSD card which there after can transfer content to the device, execute an app and configure the app. 

    public final static int DAY = 86400000;
    private Timer timerDay = new Timer(DAY, new ActionListener()
    public void actionPerformed(ActionEvent evt)
    //What you want it to do
    to activate it:
    timerDay.start();
    to stop it:
    timerDay.stop();

  • WS-C6509-E not supporting 256 MB disk. upon inserting message pops up but "no such device" error comes when runing "sh disk0/1:"

    WS-C6509-E not supporting 256 MB disk. upon inserting message pops up but "no such device" error comes when runing "sh disk0/1:"
    SUP = 720 and 720-3B
    00:08:03: %FILESYS-SP-5-DEV: PCMCIA flash card inserted into disk1
    Router#
    Router#
    Router#
    Router#sh disk1
    %Error show disk1: (No such device)
    Router#
    Its working fine with 128 MB Disk

    but my 128MB disk is working fine in both SUP and both slots..
    And this only proves that the PCMCIA slot is not at fault.  So this means that:
    256mb PCMCIA card is dead; or 
    256mb PCMCIA card is not standard (non-Cisco)
    I do not believe the 256 mb PCMCIA card is not working because it's not formated.  Even if it's not formated properly the error message would've been different.

  • Multi-table INSERT with PARALLEL hint on 2 node RAC

    Multi-table INSERT statement with parallelism set to 5, works fine and spawns multiple parallel
    servers to execute. Its just that it sticks on to only one instance of a 2 node RAC. The code I
    used is what is given below.
    create table t1 ( x int );
    create table t2 ( x int );
    insert /*+ APPEND parallel(t1,5) parallel (t2,5) */
    when (dummy='X') then into t1(x) values (y)
    when (dummy='Y') then into t2(x) values (y)
    select dummy, 1 y from dual;
    I can see multiple sessions using the below query, but on only one instance only. This happens not
    only for the above statement but also for a statement where real time table(as in table with more
    than 20 million records) are used.
    select p.server_name,ps.sid,ps.qcsid,ps.inst_id,ps.qcinst_id,degree,req_degree,
    sql.sql_text
    from Gv$px_process p, Gv$sql sql, Gv$session s , gv$px_session ps
    WHERE p.sid = s.sid
    and p.serial# = s.serial#
    and p.sid = ps.sid
    and p.serial# = ps.serial#
    and s.sql_address = sql.address
    and s.sql_hash_value = sql.hash_value
    and qcsid=945
    Won't parallel servers be spawned across instances for multi-table insert with parallelism on RAC?
    Thanks,
    Mahesh

    Please take a look at these 2 articles below
    http://christianbilien.wordpress.com/2007/09/12/strategies-for-rac-inter-instance-parallelized-queries-part-12/
    http://christianbilien.wordpress.com/2007/09/14/strategies-for-parallelized-queries-across-rac-instances-part-22/
    thanks
    http://swervedba.wordpress.com

  • I subscribed to Adobe PDF Pack, why can't I convert Pdf files to doc and/or jepg with my acrobat reader XI

    I subscribed to Adobe PDF Pack, why can't I convert Pdf files to doc and/or jepg with my acrobat reader XI
    I purchased the Pack three days ago, asked to sign in. when I try to sign in, I am led to a page to purchase the program.
    What do I need to do to activate my subscribtion, so it will work with my reader XI?

    Hi helmutb86458194,
    Did you have an update for us? Your response came through blank...
    Best,
    Sara

  • How can i open a downloaded mp4 file that is zipped?  Witch will not open.   And, Convert that mp4 to play on my iMac with Maverick osx ?   I there an app or apps i need to buy ?

    how can i open a downloaded mp4 file that is zipped?  Witch will not open.   And, Convert that mp4 to play on my iMac with Maverick osx ?   I there an app or apps i need to buy ?

    You should be able to open the zipped file by double clicking on it.
    http://www.videolan.org/vlc/index.html
    This link is for a VLC Player it can play just about everything.
    Cheers
    Don

  • My goal: "convert into pdf" -- the file is instantly saved with the same name as pdf. feasible?

    Good evening dear experts,
    i use Adobe Acrobat 9 pro extend to convert word, ppt, jepgs etc. into pdfs.
    No if i
    1) convert a ppt into a pdf: it asks --> "save as" --> converts --> opens the file
    2) convert a jpeg into a pdf: it instantly --> opens the file as pdf --> i need to save it manual under "save as"
    In both cases i want to
    my goal: "convert into pdf" --> the file is instantly saved with the same name as pdf
    WITHOUT asking me "save as" + "opening of the file".
    Is the possible, and if yes, HOW ?
    A fast answer is very very much appreciated, for i have to convert hundreds of files tonight in order to get it into 1 pdf
    Thx and greetings from Germany,
    Julia

    We are nearly there!
    A] - righclick "convert-to-method": @Bill: thx again, your approach worked for ppt, doc-files etc.
    2 problems:
    1) exception: for jpegs/bmps it doesn't work (the file is still opened after conversion, strange).
    2) the output-folder. it only accepts the standard "output-folder documents/*.pdf" (which is a step further but not my end-goal). If i choose another output-folder via "browse", this setting is NOT SAVED (even after clicking on "accept" + "ok").
    my goal: the the file should be automatically saved in THE SAME folder the original file is in (seems that can't be achieved and the standard folder is the only thing where to convert in?).
    Personal background for understanding: i have many folders with several ppts in it. Once i send it out to a customer, i always have to convert it into a pdf. thats why i want to save time (i know that i can convert it directly + send per mail, but i want an up-to-date copy of the pdf in the folder as well).
    B] - "the automated solution"- @Sandeep:
    i just watched your link http://tv.adobe.com/watch/acrobat-tips-and-tricks/automating-tasks-in-acrobat/
    about batch processing and i think its really helpful if i want to convert ALL of the files in one folder.
    1 question regarding this: are the subfolders also affected?
    As i understood from the video, i choose 1 "watched folder" and a "destination folder" (can be the same). E.g i have 1 big folder "designs" with many subfolders. I create a batch converting ppts to pdf to "the same folder" Once i run my batch, it converts ppts in the chosen folder "designs" + all subfolders into the same folder, right?
    If this is the case, i get too many pdfs, for i only need the latest ppt-version to be converted (copies of old ppts are also in the files) ;(.
    Do you have an idea how can i solve this?
    Now we are very near to the end-solution of my goal:
    i need this option "to the same folder" in my general settings when i convert a file via right-click. ATM it only works with the standard-folder documents/*.pdf
    In A], my files are now instantly saved with the same name in 1 specific folder. I would be completely happy, if this folder would be alwys the same as the one with the original file (and not 1 specific folder)
    2nd problem with a]: it does not apply to picture files (bmp, jpegs..)
    So if we could solve this, i would be a completely happy girl
    Guys, you are great, thx again for the whole struggle with my concerns!!

  • Cannot convert webpages to pdf using Acrobat X Pro with IE9 and Windows 7, worked fine until a few m

    Cannot convert webpages to pdf using Acrobat X Pro with IE9 and Windows 7, worked fine until a few months and updates ago

    I tried your suggestion, not knowing that the direct pdf printer would also "save as" PDF, but when I try your suggestion and use the Adobe PDF printer that is a direct creation of the PDF from the browser (IE9), instead of the "black out" areas I get when I use the "Convert to" button, I get missing blocks of the resulting PDF, and only get the first 1/4 to 1/3 of the webpage.
    Just to clarify, when I said I print the webpage and then scan, that is a work around I have to do if I need a scanned version of the way a webpage appears on a particular date and time, instead of the one step process I used to be able to do when Adobe Acrobat would actually convert the webpage to a pdf without blackout areas or, if I try your suggestion, blank spots with a partial webpage. But the idea was one I had not thought of and I appreciated the thought.
    Yes, Acrobat was updated, and is updated, and was working fine until a few months ago, Win 7 and Office 32 bit versions, Office 2010

  • Convert Screen(spool) to PDF file sending mail with attach file

    Hi :
    I'd like convert spool list to pdf and sending file...
    so, I read thread about spool convert to PDF before,
    and know how to convert Spool to PDF file and send mail with attach file.
    but I have a problem.
    my solution as:
    step 1. Call function: "CONVERT_ABAPSPOOLJOB_2_PDF"
    step 2. Call function: "SO_NEW_DOCUMENT_ATT_SEND_API1"
    then, I got a mail with attached PDF file, but the PDF file display limited 255 line.( SO_NEW_DOCUMENT_ATT_SEND_API1 limited)
    I want to showing word is wider that 255.
    and then I find a manual method as:
    After program finished.
    Function Menu -> system -> List -> Send
    use Prog: "Create Document and Send"
    I use this prog sending mail and attached file ,
    PDF file do <b>NOT</b> have 255 word limit !
    finally. my question is, If I want sending mail as Prog: "Create Document and Send", how to do?
    which Function I have to use?...
    Please help me, Thanks!

    Hi,
    Check this sample code of sending spool as attachment to an email address..
    Parameters.
    PARAMETERS: p_email(50) LOWER CASE.
    PARAMETERS: p_spool LIKE tsp01-rqident.
    Data declarations.
    DATA: plist         LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
    DATA: document_data LIKE sodocchgi1.
    DATA: so_ali        LIKE soli OCCURS 100 WITH HEADER LINE.
    DATA: real_type     LIKE soodk-objtp.
    DATA: sp_lang       LIKE tst01-dlang.
    DATA: line_size     TYPE i VALUE 255.
    DATA: v_name        LIKE soextreci1-receiver.
    DATA rec_tab        LIKE somlreci1 OCCURS 1 WITH HEADER LINE.
    Get the spool data.
    CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
         EXPORTING
              rqident              = p_spool
              first_line           = 1
              last_line            = 0
              desired_type         = '   '
         IMPORTING
              real_type            = real_type
              sp_lang              = sp_lang
         TABLES
              buffer               = so_ali
         EXCEPTIONS
              no_such_job          = 1
              job_contains_no_data = 2
              selection_empty      = 3
              no_permission        = 4
              can_not_access       = 5
              read_error           = 6
              type_no_match        = 7
              OTHERS               = 8.
    IF sy-subrc <> 0.
      MESSAGE s208(00) WITH 'Error'.
      LEAVE LIST-PROCESSING.
    ENDIF.
    Prepare the data.
    plist-transf_bin = 'X'.
    plist-head_start = 0.
    plist-head_num = 0.
    plist-body_start = 0.
    plist-body_num = 0.
    plist-doc_type = 'RAW'.
    plist-obj_descr = 'Test ALV'.
    APPEND plist.
    plist-transf_bin = 'X'.
    plist-head_start = 0.
    plist-head_num = 0.
    plist-body_start = 1.
    DESCRIBE TABLE so_ali LINES plist-body_num.
    plist-doc_type = real_type.
    Get the size.
    READ TABLE so_ali INDEX plist-body_num.
    plist-doc_size = ( plist-body_num - 1 ) * line_size
                     + STRLEN( so_ali ).
    APPEND plist.
    Move the receiver address.
    MOVE: p_email  TO rec_tab-receiver,
          'U'      TO rec_tab-rec_type.
    APPEND rec_tab.
    IF NOT sp_lang IS INITIAL.
      document_data-obj_langu = sp_lang.
    ELSE.
      document_data-obj_langu = sy-langu.
    ENDIF.
    v_name = sy-uname.
    Send the email.
    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
         EXPORTING
              document_data              = document_data
              sender_address             = v_name
              sender_address_type        = 'B'
         TABLES
              packing_list               = plist
              contents_bin               = so_ali
              receivers                  = rec_tab
         EXCEPTIONS
              too_many_receivers         = 1
              document_not_sent          = 2
              document_type_not_exist    = 3
              operation_no_authorization = 4
              parameter_error            = 5
              x_error                    = 6
              enqueue_error              = 7
              OTHERS                     = 8.
    IF sy-subrc <> 0.
      MESSAGE e208(00) WITH 'Error'.
    ENDIF.
    COMMIT WORK.
    Send the email immediately.
    SUBMIT rsconn01
    WITH mode = 'INT'
    AND RETURN.
    Thanks,
    Naren

  • My CLOB insert with PreparedStatements WORKS but is SLOOOOWWW

    Hi All,
    I am working on an application which copies over a MySQL database
    to an Oracle database.
    I got the code to work including connection pooling, threads and
    PreparedStatements. For tables with CLOBs in them, I go through the
    extra process of inserting the CLOBs according to Oracle norm, i.e.
    getting locator and then writing to that:
    http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/advanced/LOBSample/LOBSample.java.html (Good Example for BLOBs, CLOBs)
    However, for tables with such CLOBs, I only get a Record per second insert
    of about 1/sec!!! Tables without CLOBs (and thus, without the round-about-way)
    of inserting CLOBs are approx. 10/sec!!
    How can I improve the speed of my clob inserts / improve the code? At the moment, for
    a table of 30,000 records (with CLOBs) it takes about 30,000 which is 8 hours!!!!
    Here is my working code, which is run when my application notices that the table has
    CLOBs. The record has already been inserted with all non-clob fields and the "EMPTY_BLOB()"
    blank for the CLOB. The code then selects that row (the one just inserted), gets a handle on the
    EMPTY_BLOB location and writes the my CLOB content (over 4000 characters) to that handles
    and then closes the handle. At the very end, I do conn.commit().
    Any tips for improving speed?
    conn.setAutoCommit(false);
    * This first section is Pseudo-Code. The actual code is pretty straight
    * forward. (1) I create the preparedStatement, (2) I go record by record
    * - for each record, I (a) loop through each column and run the corresponding
    * setXXX to set the preparedStatement parameters, (b) run
    * preparedStatement.executeUpdate(), and (c) if CLOB is present, run below
    * actual code.
    * During insertion of the record (executeUpdate), if I notice that
    * a Clob needs to be inserted, I insert a "EMPTY_CLOB()" placeholder and set
    * the flag "clobInTheHouse" to true. Once the record is inserted, if "clobInTheHouse"
    * is actually "true," I go to the below code to insert the Blob into that
    * newly created record's "EMPTY_CLOB()" placeholder
    // clobSelect = "SELECT * FROM tableName WHERE "uniqueRecord" LIKE '1'
    // I create the above for each record I insert and have this special uniqueRecord value to
    // identify what record that is so I can get it below. clobInTheHouse is true when, where I
    // insert the records, I find that there is a CLOB that needs to be inserted.
    if(clobInTheHouse){
         ResultSet lobDetails = stmt.executeQuery(clobSelect);
         ResultSetMetaData rsmd = lobDetails.getMetaData();
         if(lobDetails.next()){
              for(int i = 1; i <= rsmd.getColumnCount(); i++){
                 // if column name matches clob name, then go and do the rest
                   if(clobs.contains(rsmd.getColumnName(i))){
                        Clob theClob = lobDetails.getClob(i);
                        Writer clobWriter = ((oracle.sql.CLOB)theClob).getCharacterOutputStream();
                        StringReader clobReader = new StringReader((String) clobHash.get(rsmd.getColumnName(i)));
                        char[] cbuffer = new char[30* 1024]; // Buffer to hold chunks of data to be written to Clob, the slob
                        int nread = 0;
                        try{
                             while((nread=clobReader.read(cbuffer)) != -1){
                                  clobWriter.write(cbuffer,0,nread);
                        }catch(IOException ioe){
                           System.out.println("E: clobWriter exception - " + ioe.toString());
                        }finally{
                             try{
                                  clobReader.close();
                                  clobWriter.close();
                                  //System.out.println("   Clob-slob entered for " + tableName);
                             }catch(IOException ioe2){
                                  System.out.println("E: clobWriter close exception - " + ioe2.toString());
         try{
              stmt.close();
         }catch(SQLException sqle2){
    conn.commit();

    Can you use insert .. returning .. so you do not have to select the empty_clob back out.
    [I have a similar problem but I do not know the primary key to select on, I am really looking for an atomic insert and fill clob mechanism, somone said you can create a clob fill it and use that in the insert, but I have not seen an example yet.]

  • Insert with Where Clause

    Hi,
    Can we write Insert with 'Where' clause? I'm looking for something similar to the below one (which is giving me an error)
    insert into PS_AUDIT_OUT (AUDIT_ID, EMPLID, RECNAME, FIELDNAME, MATCHVAL, ERRORMSG)
    Values ('1','10000139','NAMES','FIRST_NAME',';','')
    Where AUDIT_ID IN
    (  select AUDIT_ID from PS_AUDIT_FLD where AUDIT_ID ='1' and RECNAME ='NAMES'
    AND FIELDNAME = 'FIRST_NAME' AND MATCHVAL = ';' );
    Thanks
    Durai

    It is not clear what are you trying to do, but it looks like:
    insert
      into PS_AUDIT_OUT(
                        AUDIT_ID,
                        EMPLID,
                        RECNAME,
                        FIELDNAME,
                        MATCHVAL,
                        ERRORMSG
    select  '1',
            '10000139',
            'NAMES',
            'FIRST_NAME',
      from  PS_AUDIT_FLD
      where AUDIT_ID = '1'
        and RECNAME ='NAMES'
        and FIELDNAME = 'FIRST_NAME'
        and MATCHVAL = ';'
    SY.

  • INSERT with Dreamweaver

    Can somebody explain to me how to use the SQLstatement INSERT
    with dremweaver 8.
    Before i should SELECT i should be able to INSERT details
    from a .asp into 'i my case' database.mdb.
    please can somebody explain to me how Dreamweaver 8 goes over
    this issue and how to do it
    Thanks in advance

    http://www.aspwebpro.com/aspscripts/records/insertnew.asp
    Something like this?
    Dan Mode
    --> Adobe Community Expert
    *Flash Helps*
    http://www.smithmediafusion.com/blog/?cat=11
    *THE online Radio*
    http://www.tornadostream.com
    *Must Read*
    http://www.smithmediafusion.com/blog
    "thebold" <[email protected]> wrote in
    message
    news:eptack$nmb$[email protected]..
    > Can somebody explain to me how to use the SQLstatement
    INSERT with
    > dremweaver 8.
    > Before i should SELECT i should be able to INSERT
    details from a .asp into
    > 'i
    > my case' database.mdb.
    > please can somebody explain to me how Dreamweaver 8 goes
    over this issue
    > and
    > how to do it
    >
    > Thanks in advance
    >

  • Performance of insert with spatial index

    I'm writing a test that inserts (using OCI) 10,000 2D point geometries (gtype=2001) into a table with a single SDO_GEOMETRY column. I wrote the code doing the insert before setting up the index on the spatial column, thus I was aware of the insert speed (almost instantaneous) without a spatial index (with layer_gtype=POINT), and noticed immediately the performance drop with the index (> 10 seconds).
    Here's the raw timing data of 3 runs in each 3 configuration (the clock ticks every 14 or 15 or 16 ms, thus the zero when it completes before the next tick):
                                       truncate execute commit
    no spatial index                     0.016   0.171   0.016
    no spatial index                     0.031   0.172   0.000
    no spatial index                     0.031   0.204   0.000
    index (1000 default for batch size)  0.141  10.937   1.547
    index (1000 default for batch size)  0.094  11.125   1.531
    index (1000 default for batch size)  0.094  10.937   1.610
    index SDO_DML_BATCH_SIZE=10000       0.203  11.234   0.359
    index SDO_DML_BATCH_SIZE=10000       0.094  10.828   0.344
    index SDO_DML_BATCH_SIZE=10000       0.078  10.844   0.359As you can see, I played with SDO_DML_BATCH_SIZE to change the default of 1,000 to 10,000, which does improve the commit speed a bit from 1.5s to 0.35s (pretty good when you only look at these numbers...), but the shocking part of the almost 11s the inserts are now taking, compared to 0.2s without an index: that's a 50x drop in peformance!!!
    I've looked at my table in SQL Developer, and it has no triggers associated, although there has to be something to mark the index as dirty so that it updates itself on commit.
    So where is coming the huge overhead during the insert???
    (by insert I mean the time OCIStmtExecute takes to run the array-bind of 10,000 points. It's exactly the same code with or without an index).
    Can anyone explain the 50x insert performance drop?
    Any suggestion on how to improve the performance of this scenario?
    To provide another data point, creating the index itself on a populated table (with the same 10,000 points) takes less than 1 second, which is consistent with the commit speeds I'm seeing, and thus puzzles me all the more regarding this 10s insert overhead...
    SQL> set timing on
    SQL> select count(*) from within_point_distance_tab;
      COUNT(*)
         10000
    Elapsed: 00:00:00.01
    SQL> CREATE INDEX with6CDF1526$point$idx
      2            ON within_point_distance_tab(point)
      3    INDEXTYPE IS MDSYS.SPATIAL_INDEX
      4    PARAMETERS ('layer_gtype=POINT');
    Index created.
    Elapsed: 00:00:00.96
    SQL> drop index WITH6CDF1526$POINT$IDX force;
    Index dropped.
    Elapsed: 00:00:00.57
    SQL> CREATE INDEX with6CDF1526$point$idx
      2            ON within_point_distance_tab(point)
      3    INDEXTYPE IS MDSYS.SPATIAL_INDEX
      4    PARAMETERS ('layer_gtype=POINT SDO_DML_BATCH_SIZE=10000');
    Index created.
    Elapsed: 00:00:00.98
    SQL>

    Thanks for your input. We are likely to use partioning down the line, but what you are describing (partition exchange) is currently beyond my abilities in plain SQL, and how this could be accomplished from an OCI client application without affecting other users and keep the transaction boundaries sounds far from trivial. (i.e. can it made transparent to the client application, and does it require privileges the client does have???). I'll have to investigate this further though, and this technique sounds like one accessible to a DBA only, not from a plain client app with non-privileged credentials.
    The thing that I fail to understand though, despite your explanation, is why the slow down is not entirely on the commit. After all, documentation for the SDO_DML_BATCH_SIZE parameter of the Spatial index implies that the index is updated on commit only, where new rows are fed 1,000 or 10,000 at a time to the indexing engine, and I do see time being spent during commit, but it's the geometry insert that slow down the most, and that to me looks quite strange.
    It's so much slower that it's as if each geometry was indexed one at a time, when I'm doing a single insert with an array bind (i.e. equivalent to a bulk operation in PL/SQL), and if so much time is spend during the insert, then why is any time spent during the commit. In my opinion it's one or the other, but not both. What am I missing? --DD                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to insert with select in table with object types

    I am in the proces of redesigning some tables, as i have upgraded from
    personal oracle 7 to personal oracle 8i.
    I have constructed an object type Address_type, which is one of the columns
    in a table named DestTable.
    The object type is created as follows:
    CREATE OR REPLACE TYPE pub.address_type
    AS OBJECT
    Street1 varchar2(50),
    Street2 varchar2(50),
    ZipCode varchar2(10));
    The table is created as follows:
    CREATE TABLE pub.DestTable
    (id INTEGER PRIMARY KEY,
    LastName varchar2(30),
    FirstName varchar2(25),
    Address pub.address_type);
    Inserting a single row is ok as i use the following syntax:
    Insert into DestTable(1, '******* ', 'Lawrence', pub.address_type(
    '500 Oracle Parkway', 'Box 59510', '95045'));
    When i try to insert values into the table by selecting from another table i
    cannot do it and cannot figure out what is wrong
    I have used the following syntax:
    Insert into DestTable
    id, name, pub.address_type(Street1, Street2, ZipCode))
    select
    id, lastname, firstname, street1, street2, ZipCode
    from SourceTable;
    I have also tried the following syntax:
    Insert into DestTable
    id, name, pub.address_type(Address.Street1, Address.Street2,Address.ZipCode))
    select
    id, lastname, firstname, street1, street2, ZipCode
    from SourceTable;
    What is wrong here ?
    null

    Magnus,
    1. Check out the examples on 'insert with subquery' in http://otn.oracle.com/docs/products/oracle8i/doc_library/817_doc/server.817/a85397/state21b.htm#2065648
    2. Correct your syntax that repeated the column definition after "insert into ..."
    Insert into DestTable
    id, name, pub.address_type(Street1, Street2, ZipCode))
    select
    id, lastname, firstname, street1, street2, ZipCode
    from SourceTable;
    Regards,
    Geoff
    null

Maybe you are looking for