Optimisation sql

Hi,
When i use a clause OR in my select as the optimizer can use an index.
ThanKS

user8946397 wrote:
Hi,
When i use a clause OR in my select as the optimizer can use an index.Although, you question lacks lot of information, may be this Article can help you decide better which index to use for DSS or OLTP type environment.
*Bitmap Index vs. B-tree Index: Which and When? --by Vivek Sharma+ *
http://www.oracle.com/technology/pub/articles/sharma_indexes.html
HTH
Regards
Z.K.

Similar Messages

  • Optimising SQL query (Reading data)

    Hi Experts,
    I am new to Oracle, so please bear with me as I try to explain my situation,
    We are using Oracle 10g and I asked my DBA to create db links with other Oracle DBs.
    I am trying to create table on my Oracle DB using the db links. The query takes about 40 minutes (here's the query).
    Create table prod rev
    as
    select
    /*+ PARALLEL(marquee_owner.billing_report_date@RBDW_P, 5, 2)
    PARALLEL(marquee_owner.Monthly_bill_revenue_hist@RBDW_P, 5, 2)
    PARALLEL(marquee.bis_product@RBDW_P, 5, 2)
    USE_HASH(marquee_owner.billing_report_date@RBDW_P) ORDERED
    USE_HASH(marquee_owner.Monthly_bill_revenue_hist@RBDW_P) ORDERED
    USE_HASH(marquee.bis_product@RBDW_P) ORDERED */
    a.*, c.product_code
    from
    marquee_owner.billing_report_date@RBDW_P b,
    marquee_owner.Monthly_bill_revenue_hist@RBDW_P a,
    marquee.bis_product@RBDW_P c
    where
    b.year=2008 and b.month=12 and a.SUBSCRIBER_STATUS_KEY=3 and
    a.BILLING_REPORT_DATE_KEY=b.BILLING_REPORT_DATE_KEY and
    a.product_key=c.product_key ;
    I have tried Parallel processing but "degree" on these tables are set to 1. I don't think tables support parallel processing.
    Is there a way I bring down the total time from 40 minutes to 20-30 minutes ?
    I don't have sysDBA access on my and remote Servers.
    Is there a way i can read more more records into oracle buffers while creating table ? Does this functionality exixts ?
    Your response and help would be greatly appreciated.
    Thanks in anticipation!!!!!.
    I am am very new to Oracle.

    Hi Tim,
    This is the best I could do, Wish they had a way of uploading a HTML file. APologise, if the following is still unreadable.
    STATEMENT_ID     TIMESTAMP     OPERATION     OPTIONS     OBJECT_NODE     OBJECT_OWNER     OBJECT_NAME     OBJECT_INSTANCE     OBJECT_TYPE     OPTIMIZER     SEARCH_COLUMNS     ID     PARENT_ID     POSITION
    1239653366462     13-APR-09     SELECT STATEMENT     REMOTE      .      .      .     .       .     CHOOSE           0     .      471158
    1239653366462     13-APR-09     HASH JOIN      -      .      .      .     .       .      .     .      1     0     1
    1239653366462     13-APR-09     TABLE ACCESS     FULL     RBDW_P.WORLD     MARQUEE     BIS_PRODUCT     3      .     ANALYZED     .      2     1     1
    1239653366462     13-APR-09     HASH JOIN      .      .      .      .     .       .      .     .      3     1     2
    1239653366462     13-APR-09     TABLE ACCESS     BY INDEX ROWID     RBDW_P.WORLD     MARQUEE_OWNER     BILLING_REPORT_DATE     1           ANALYZED           4     3     1
    1239653366462     13-APR-09     INDEX     RANGE SCAN     RBDW_P.WORLD     MARQUEE_OWNER     BILLING_REPORT_DATE_IE1           NON-UNIQUE     ANALYZED     2     5     4     1
    1239653366462     13-APR-09     TABLE ACCESS     FULL     RBDW_P.WORLD     MARQUEE_OWNER     MONTHLY_BILL_REVENUE_HIST     2           ANALYZED           6     3     2
    1239653419446     13-APR-09     SELECT STATEMENT     REMOTE     .     .     .     .      .     CHOOSE     .      0     .      471158
    1239653419446     13-APR-09     HASH JOIN      .      .      .      .     .       .      .     .      1     0     1
    1239653419446     13-APR-09     TABLE ACCESS     FULL     RBDW_P.WORLD     MARQUEE     BIS_PRODUCT     3           ANALYZED           2     1     1
    1239653419446     13-APR-09     HASH JOIN      .      .      .      .     .       .      .     .      3     1     2
    1239653419446     13-APR-09     TABLE ACCESS     BY INDEX ROWID     RBDW_P.WORLD     MARQUEE_OWNER     BILLING_REPORT_DATE     1           ANALYZED           4     3     1
    1239653419446     13-APR-09     INDEX     RANGE SCAN     RBDW_P.WORLD     MARQUEE_OWNER     BILLING_REPORT_DATE_IE1           NON-UNIQUE     ANALYZED     2     5     4     1
    1239653419446     13-APR-09     TABLE ACCESS     FULL     RBDW_P.WORLD     MARQUEE_OWNER     MONTHLY_BILL_REVENUE_HIST     2           ANALYZED           6     3     2
    1239653463665     13-APR-09     SELECT STATEMENT     REMOTE      .      .      .     .       .     CHOOSE     .      0     .      471158
    1239653463665     13-APR-09     HASH JOIN      .      .      .      .     .       .      .     .      1     0     1
    1239653463665     13-APR-09     TABLE ACCESS     FULL     RBDW_P.WORLD     MARQUEE     BIS_PRODUCT     3      .     ANALYZED     .      2     1     1
    1239653463665     13-APR-09     HASH JOIN      .      .      .      .     .       .      .     .      3     1     2
    1239653463665     13-APR-09     TABLE ACCESS     BY INDEX ROWID     RBDW_P.WORLD     MARQUEE_OWNER     BILLING_REPORT_DATE     1           ANALYZED           4     3     1
    1239653463665     13-APR-09     INDEX     RANGE SCAN     RBDW_P.WORLD     MARQUEE_OWNER     BILLING_REPORT_DATE_IE1           NON-UNIQUE     ANALYZED     2     5     4     1
    1239653463665     13-APR-09     TABLE ACCESS     FULL     RBDW_P.WORLD     MARQUEE_OWNER     MONTHLY_BILL_REVENUE_HIST     2           ANALYZED           6     3     2
    1239653591118     13-APR-09     SELECT STATEMENT     REMOTE      .      .      .      .     .      CHOOSE      .      .      .      .     .       .      .     .
    1239653591118     13-APR-09     HASH JOIN      .      .      .      .     .       .      .     .      1     0     1
    1239653591118     13-APR-09     TABLE ACCESS     FULL     RBDW_P.WORLD     MARQUEE     BIS_PRODUCT     3      .     ANALYZED     .      2     1     1
    1239653591118     13-APR-09     HASH JOIN      .      .      .      .     .       .      .     .      3     1     2
    1239653591118     13-APR-09     TABLE ACCESS     BY INDEX ROWID     RBDW_P.WORLD     MARQUEE_OWNER     BILLING_REPORT_DATE     1           ANALYZED           4     3     1
    1239653591118     13-APR-09     INDEX     RANGE SCAN     RBDW_P.WORLD     MARQUEE_OWNER     BILLING_REPORT_DATE_IE1           NON-UNIQUE     ANALYZED     2     5     4     1
    1239653591118     13-APR-09     TABLE ACCESS     FULL     RBDW_P.WORLD     MARQUEE_OWNER     MONTHLY_BILL_REVENUE_HIST     2           ANALYZED           6     3     2
    1239653664415     13-APR-09     SELECT STATEMENT     REMOTE      .      .      .     .            CHOOSE     .      0           471158
    1239653664415     13-APR-09     HASH JOIN      .      .      .      .     .       .      .     .      1     0     1
    1239653664415     13-APR-09     TABLE ACCESS     FULL     RBDW_P.WORLD     MARQUEE     BIS_PRODUCT     3           ANALYZED           2     1     1
    1239653664415     13-APR-09     HASH JOIN      .      .      .      .     .       .           .      3     1     2
    1239653664415     13-APR-09     TABLE ACCESS     BY INDEX ROWID     RBDW_P.WORLD     MARQUEE_OWNER     BILLING_REPORT_DATE     1      .     ANALYZED     .      4     3     1
    1239653664415     13-APR-09     INDEX     RANGE SCAN     RBDW_P.WORLD     MARQUEE_OWNER     BILLING_REPORT_DATE_IE1           NON-UNIQUE     ANALYZED     2     5     4     1
    1239653664415     13-APR-09     TABLE ACCESS     FULL     RBDW_P.WORLD     MARQUEE_OWNER     MONTHLY_BILL_REVENUE_HIST     2      .     ANALYZED     .      6     3     2

  • SQL Order of execution of AND

    Hi all,
    I have a basic doubt,
    In java and most other program languages in condition of lot of ands if one fails others wont be executed, rite?
    if(condtion1 && condtion2 && etc)
    Same way does it stop executing when one condition fails in queries?
    select * from some_table where property1='value1' and property2='value2' and property3='value3' ;
    See, I have huge of set of validation and upload procedure to be done in a small window so i was optimizing each and every bit I can.
    I had lot of queries like property1!='somevalue' and property2 in(some query);
    where property1!='somevalue' fails for half the record, about quarter of a million in one table. There are lot of tables like that.
    Some places its written like property1!='somevalue' and property2 in(some query) and other places property2 in(some query) and property1!='somevalue'
    Is the order of writing condition has any preferences in SQL?
    If yes which order they execute right to left or left to right?

    And to demonstrate Franks reply:
    The order of where conditions is not important for the cost based optimiser:
    SQL> ed
    Wrote file afiedt.buf
      1  select *
      2  from emp
      3  where 1=1
      4  and 2=2
      5* and 3=(select to_number(ename) from emp where ename = 'SCOTT')
    SQL> /
    and 3=(select to_number(ename) from emp where ename = 'SCOTT')
    ERROR at line 5:
    ORA-01722: invalid number
    SQL> ed
    Wrote file afiedt.buf
      1  select *
      2  from emp
      3  where 1=0
      4  and 2=2
      5* and 3=(select to_number(ename) from emp where ename = 'SCOTT')
    SQL> /
    no rows selected
    SQL> ed
    Wrote file afiedt.buf
      1  select *
      2  from emp
      3  where 3=(select to_number(ename) from emp where ename = 'SCOTT')
      4  and 2=2
      5* and 1=0
    SQL> /
    no rows selected
    SQL>... so in the last two queries here, the erroneous sub query is not executed because the 1=0 clause already makes the conditions false.
    With the CASE statement:
    SQL> ed
    Wrote file afiedt.buf
      1  select case when 1=1
      2               and 2=2
      3               and 3=(select to_number(ename) from emp where ename = 'SCOTT')
      4         then 'TRUE'
      5         else 'FALSE'
      6         end as val
      7  from emp
      8* where rownum = 1
    SQL> /
                 and 3=(select to_number(ename) from emp where ename = 'SCOTT')
    ERROR at line 3:
    ORA-01722: invalid number
    SQL> ed
    Wrote file afiedt.buf
      1  select case when 1=0
      2               and 2=2
      3               and 3=(select to_number(ename) from emp where ename = 'SCOTT')
      4         then 'TRUE'
      5         else 'FALSE'
      6         end as val
      7  from emp
      8* where rownum = 1
    SQL> /
    VAL
    FALSE
    SQL> ed
    Wrote file afiedt.buf
      1  select case when 3=(select to_number(ename) from emp where ename = 'SCOTT')
      2               and 2=2
      3               and 1=0
      4         then 'TRUE'
      5         else 'FALSE'
      6         end as val
      7  from emp
      8* where rownum = 1
    SQL> /
    select case when 3=(select to_number(ename) from emp where ename = 'SCOTT')
    ERROR at line 1:
    ORA-01722: invalid number
    SQL>.. you can see that putting the erroneous sub query as the first condition will cause it to raise an exception regardless of the fact there is the 1=0 condition there, but when the 1=0 condition is first then the erroneous sub query is not executed.
    ;)

  • Data Services ORA-00942 table does not exist. Source/Target same DB

    Error: u201CORA-00942: table or view does not existu201D
    Source & Target Datastores in same Oracle DB but different User/Schemas.
    I set up the Data Services Tutorial Source & Target Data bases in ONE Oracle DB using a separate User/Schema for the ODS source DB & TARGET Source DB.
    I then created
    - Source datastore for the ODS DB User/schema
    - Target datastore for the TARGET DB user/Schema.
    I have no problem reading flat files & writing to TARGET datastore tables.
    However, when I read the ODS datasttore source table CUSTOMER & write to the TARGET datastore target table CUST_DIM I get an error: ORA-00942: table or view does not exist.
    I can query the table contents from the Data Flow & see the data in the source data & see the empty target table.
    So the tables exists & there is no security issues from the DS Designer.
    I did find note 1189910 - ERROR: Error Description: An error occurred while creating the result data - Data Insight XI
    Cause
    Multiple engines are being run against the same metadata repository.
    Resolution
    Verify that only one engine is being run against a single metadata repository.
    Has anyone seen this error?
    Or has anyone created a 2 data stores on the SAME DB, but to different User/Schemas?
    Thanks
    Jay Roble

    since you are accessing 2 schema which are on same oracle database, DS engine is trying to optimize and generating an INSERT INTO ... SELECT clause. Since its the same DB, DS Engine is doing a implicit linking of the datastores
    you can see the SQL generated from the Designer, drill down into DF, from the Menu select Validation ->Display Optimised SQL
    to disable this implicit linking, right click on the Dataflow, select properties
    in the properties window, unselect the the option "use database links"

  • Data Services X-File

    Dear all,
    Let's see if anyone can help me with this, as I am stuck.
    We have two Data Services installations: DEV and PROD. Both of them DS 3.2 (no SP although I am currently downloading the last one just in case).
    DEV is working perfectly: running the jobs and inserting in the Data Warehouse the desired information.
    PROD, on the other hand is not storing the desired information. Jobs are the same 100%. I imported several times the .atl files.
    Sources from both environments are also the same, so data transforms should finish with the same output.
    The archetectural differences between both servers are the following:
    DEV is 2003 server (same machine for BOE, DS and Database). Database is 11g 32-bit.
    PROD is 2008 server only with DS and Oracle Client. Client Oracle client is 32-bit. Database is in a separate server with Windows 2008 server 64-bit.
    If I test same job in DEV with different targets (DEV Database and PROD Database) results are different using both DS instances.
    Has anyone found same problem or can help me solving it???
    Many thanks!!!
    Bea

    The trace log is the normal log you see in the designer when you execute a job.  It is also visible via the web admin console.  By the way, it might be worth comparing the monitor log too (the one with the row counts in it).  If your source data volume is the same, then the monitor logs will show this.  If your monitor logs have more or less entries(look very different), it means that the optimiser is working differently between environments.  This can happen if the datastore configuration doesn't allow optimised SQL to be generated.
    Losing rows sounds very odd.  The only way this would normally happen is when using "overflow files" (see target table options), but in that case you'd have job errors.
    Transcoders are automatically created to translate data between code pages, and in certain circumstances can cause characters to be displayed not as intended, but only when the codepages have been defined incorrectly or the default settings used in the datastores.
    Check the monitor logs and compare the row counts between environments, that'll give us more info.
    Michael

  • Optimization with logical database

    Hi all.
    I have to optimize a report, and it is using BRM logical database to get data from BKPF and BSEG. Could you say to me if it is the faster way or if it would be better to use a SELECT?
    Thanks a lot.
    Marta.

    Hello Marcin,
    Once I met with statement that good ABAPers don't use direct SELECT statement, at least they shouldn't have to.
    What?? This might be true for HR ABAP, where LDBs are used in abundance
    There are so many standard FMs which cover most of SAP db queries.
    Most of these std. FMs are generally "not released" & are not performance friendly either.The "released" BAPIs (BAPIGET) don't cater to all your requirements.
    I seldom use FMs to fetch the data. I find it easy to implement relevant authority objects & build an optimised SQL construct as per my requirement
    Let me know your comments.
    BR,
    Suhas

  • Basic ADODB Problem

    So, I want to implement a simple database project using VB 6 and Oracle 10g. A friend of mine who has done a similar project, sent me some sample of his code because I am new to DB programming. I had already implemented a simple working code. Here is the comparison:
    rs is the ADODB.recordset object
    and dbipl is the ADODB.connection object
    team is the tablename
    name is a column in the table
    His code:
    dbipl.Open "dsn=new;user id=system;password=pass;"
    rs.CursorType = adOpenStatic
    rs.CursorLocation = adUseClient
    rs.LockType = adLockOptimistic
    rs.Open "select * from team", dbipl, , , adCmdText
    Do While Not rs.EOF = True
    list.AddItem rs.Fields("name")
    rs.MoveNext
    Loop
    rs.Close
    dbipl.Close
    My Code:
    dbipl.Open "dsn=new;user id=system;password=pass;"
    set rs = db.Execute("select * from team")
    Do While Not rs.EOF = True
    list.AddItem rs("name")
    rs.MoveNext
    loop
    rs.close
    dbipl.Close
    I am not using the Fields keyword anywhere in my code. Also, he hasn't used the INSERT or UPDATE statements in his entire code because he is using something like this to update or insert records:
    rs.AddNew
    rs.Fields(0) = Text1.Text
    rs.Fields(1) = Text2.Text
    rs.Update
    I though we have to use the SQL statements like this:
    set rs = db.Execute("insert into table values (......)")
    I am guessing his advantage is that he doesn't need to use SQL statements for inserting records or updating his tables. I am completely lost and I don't know which method to use. Please clarify the difference in the two methods. Thank you for your time.

    Pratham wrote:
    Also, he hasn't used the INSERT or UPDATE statements in his entire code because he is using something like this to update or insert records:
    rs.AddNew
    rs.Fields(0) = Text1.Text
    rs.Fields(1) = Text2.Text
    rs.Update
    I though we have to use the SQL statements like this:
    set rs = db.Execute("insert into table values (......)")The AdoDB class generates that SQL itself if you do not explicitly provide a SQL statement. In fact, from long past experience doing Windows client development, drivers like AdoDB can be quite noisy and generate all kinds of SQL statements for "managing" the database client-server session - totally unbeknown to the developer whose code that AdoDB driver is executing. This can cause anything from a performance knock to unexpected run-time behaviour.
    Back then I always used the "+passthru+" option - telling the driver to bug out and only do the SQLs I explicitly coded and nothing else.
    No idea how the "modern" driver behaves... but I would think that not much have changed.
    If you do have to use SQL from your client code, then rather use explicit SQL. Code it yourself. Use bind variables (critical!). Use bulk binding. Do not rely on the driver to generate the appropriate and optimised SQL for you. It is seldom able to do it as well as hand crafted SQL.

  • Update SQL taking too much time.. hw to optimised?

    Hi,
    here is the query; this is taking time more than 3hrs to execute.
    UPDATE process_sub_step proc1
    SET process_indicator = '0',
    process_result = 'SC'
    WHERE EXISTS (SELECT *
    FROM link_trans link1
    WHERE link1.tr_leu_id = proc1.tr_leu_id AND link1.TYPE = 'S')
    AND process_substep_id = 'TR_02_03'
    AND process_indicator = '2'
    The above query is taking more than 3hrs to execuite ...!!!!!!!
    Record count in the both table is more than 10L.
    The column used in join condition has index.
    Execution Plan is : -
    UPDATE STATEMENT ALL_ROWSCost: 6                     
         5 UPDATE PROCESS_SUB_STEP
              4 NESTED LOOPS SEMI Cost: 6 Bytes: 23 Cardinality: 1           
                   1 INDEX RANGE SCAN INDEX PROC_SSTL_COMB_IDX Cost: 3 Bytes: 16 Cardinality: 1      
                   3 TABLE ACCESS BY INDEX ROWID TABLE EGR.LINK_TRANS_CONS Cost: 2 Bytes: 378 Cardinality: 54      
                        2 INDEX RANGE SCAN INDEX LTC_TYPE_IDX Cost: 1 Cardinality: 2
    What approach should I take to improve the performance......!!!!
    But same query if i write in select mode like below; it display result very quick -
    select *
    from
    process_sub_step proc1
    WHERE EXISTS (SELECT *
    FROM link_trans link1
    WHERE link1.tr_leu_id = proc1.tr_leu_id AND link1.TYPE = 'S')
    AND process_substep_id = 'TR_02_03'
    AND process_indicator = '2';
    Thanks...

    > here is the query; this is taking time more than 3hrs to execute.
    Obviously. For every single row in the process_sub_step matching the filter criteria, a sub-select has to be executed on the link_trans table.
    So if that filter criteria identified a million rows, a million exist SELECTs have to be executed. Even a unique index scan will take accumulate into a large overhead. In your case, it is an index range scan that is performed which is slower than a unique scan.
    Btw, there is no joining done here - just a nested loop process. I.e. read a row at a time from process_sub_step using a loop, and in each loop iteration, run a SELECT against link_trans.
    To optimise this specific SQL means having to do less I/O (process less rows):
    a) selecting less rows from process_sub_step to delete
    b) making the select filter on link_trans more restrictive
    Neither is likely practical. Which means you need to approach this problem with another method and not an EXIST sub-select.

  • In SQL Trace how to see which statement getting more time .

    Hi Expart,
    In SQL Trace (T-code ST05) . I am running the standard transaction . how to see which statement
    running more time and less time . suppose one statement running more time so how resolve the
    performance .
    Plz. reply me
    Regards
    Razz

    > The ones in 'RED' color are the statement which are taking a lot of time and you need to
    > optimise the same.
    No, that is incorrect, the red ones show only the ones which need several hundret milliseconds in one execution. This can even be correct for hard tasks. And there are lots of problem, which you will not see
    I have said everything here:
    SQL trace:
    /people/siegfried.boes/blog/2007/09/05/the-sql-trace-st05-150-quick-and-easy
    Go to 'Tracelist' -> Summarize by SQL statements', this is the view which you want to see!
    I summarizes all executions of the same statement.
    There are even the checks explained, the slow ones are the one which need a lot of time per record!
    See MinTime/Rec > 10.000 microseconds.
    Check all number of records, executions, buffer, identicals.
    The SE30 Tipps and Tricks will not help much.
    Siegfried

  • Performance between SQL Statement and Dynamic SQL

    Select emp_id
    into id_val
    from emp
    where emp_id = 100
    EXECUTE IMMEDIATE
    'Select '|| t_emp_id ||
    'from emp '
    'where emp_id = 100'
    into id_valWill there be more impact in performance while using Dynamic SQL?

    CP wrote:
    Will there be more impact in performance while using Dynamic SQL?All SQLs are parsed and executed as SQL cursors.
    The 2 SQLs (dynamic and static) results in the exact same SQL cursor. So both methods will use an identical cursor. There are therefore no performance differences ito of how fast that SQL cursor will be.
    If an identical SQL cursor is not found (a soft parse), the SQL engine needs to compile the SQL source code supplied, into a SQL cursor (a hard parse).
    Hard parsing burns a lot of CPU cycles. Soft parsing burns less CPU cycles and is therefore better. However, no parsing at all is the best.
    To explain: if the code creates a cursor (e.g. INSERT INTO tab VALUES( :1, :2, :3 ) for inserting data), it can do it as follows:
    while More Data Found loop
      parse INSERT cursor
      bind variables to INSERT cursor
      execute INSERT cursor
      close INSERT cursor
    end loopIf that INSERT cursor does not yet exists, it will be hard parsed and a cursor created. Each subsequent loop iteration will result in a soft parse.
    However, the code will be far more optimal as follows:
    parse INSERT cursor
    while More Data Found loop
      bind variables to INSERT cursor
      execute INSERT cursor
    end loop
    close INSERT cursorWith this approach the cursor is parsed (hard or soft), once only. The cursor handle is then used again and again. And when the application is done inserting data, the cursor handle is released.
    With dynamic SQL in PL/SQL, you cannot really follow the optimal approach - unless you use DBMS_SQL (a complex cursor interface). With static SQL, the PL/SQL's optimiser can kick in and it can optimise its access to the cursors your code create and minimise parsing all together.
    This is however not the only consideration when using dynamic SQL. Dynamic SQL makes coding a lot more complex. The SQL code can now only be checked at execution time and not at development time. There is the issue of creating shareable SQL cursors using bind variables. There is the risk of SQL injection. Etc.
    So dynamic SQL is seldom a good idea. And IMO, the vast majority of people that post problems here relating to dynamic SQL, are using dynamic SQL unnecessary. For no justified and logical reasons. Creating unstable code, insecure code and non-performing code.

  • How to insert a JPG image in a column of type "image" in sql server 7.0 ??

    hi all,
    I have a table with 2 columns.
    First col is of "Name" and second col is of type "image" .
    I am using sql server 7.0 on window 2000.
    now i have created table. I want to insert a jpg/gif image in its 2nd column.
    How can i do so ? and how i can i read the image object after insertion ?
    I am using 2nd col of type "image" and NOT Binary or varBinary.
    Any idea will be highly appreciated.
    Thanks in advance.
    AlwaysJava

    hi all,
    I have a table with 2 columns.
    First col is of "Name" and second col is of type
    "image" .
    I am using sql server 7.0 on window 2000.
    now i have created table. I want to insert a jpg/gif
    image in its 2nd column.
    How can i do so ? and how i can i read the image
    object after insertion ?
    I am using 2nd col of type "image" and NOT Binary or
    varBinary.
    Any idea will be highly appreciated.
    Thanks in advance.
    AlwaysJavaHi,
    Below are some excerpts from my program.. which was doing image insertions and retrievals also.. I have included the image insertion and retrieval portion.. retrieval can be done in more than one ways.. one of them is given.. for very large images, u can read chunks of data from the input stream and write it to the disk. for smaller ones , the given methods work very well..
    I tested the program with jdk1.4.0 and aveConnect3.0 driver. on an
    SQL server 7 machine from my box running windows 2000... and it worked..
    Im not still sure if this is the optimised way.. there can be other more optimised methods..
    hope this clears your problem..
    cheers,
    -Jer
        Connection conn = null;
        Statement stmt = null;
        ResultSet rst = null;
        PreparedStatement pstmt = null;
        FileInputStream fis = null;
        FileOutputStream fop = null;
        File file = null;
        InputStream is = null;
        String createtable = "Create table testtable (name varchar(32),_image image)";
        String inserttable = "Insert into testtable values (?,?)";
        String retrievetable = "Select _image from testtable";
        String droptable = "Drop table testtable";
        String url = "jdbc:AvenirDriver://CodeServer:1433/test";
        conn = DriverManager.getConnection(url,"test","test");
    //Create the table
        stmt = conn.createStatement();
        stmt.execute(createtable);
    //Insert the file into the table
        file = new File("input.gif");
        fis = new FileInputStream(file);
        pstmt = conn.prepareStatement(inserttable);
        pstmt.setString(1,file.getName());
    //Set the filestream to the binary stream into the image in the table
        pstmt.setBinaryStream(2,fis,fis.available());
    //Updating the table
        pstmt.executeUpdate();
    //clean up the streams and atatement
        fis.close();
        pstmt.close();
    // Retrieve the image from the table..
        pstmt =  conn.prepareStatement(retrievetable,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    // execute the Query
        rst = pstmt.executeQuery();
    //jump to the first row of the resultset
        rst.beforeFirst();
        rst.next();
    //get the inputstream from the image object in the  result set
        is = rst.getBinaryStream(1);
    //Writing the data in the inputstream into an outputfile
              //Using getbytes method from the result set
                   byte[] bytearray = rst.getBytes(1);
                   baos = new ByteArrayOutputStream();
                  baos.write(bytearray);
                  fop = new FileOutputStream ("output.gif");
                  baos.writeTo(fop);
    //using the input stream and storing the data in bytearray
    //allocating the buffer size to store the data from inpuit stream ... here whole inptstream is allocated..
    //(The buffer size can be varied if the file is too large and the reading be..
    //  ..done in loop , to read small chunks from the input stream and write it to the file)
        byte[] bytearray = new byte[is.available()];
    //to write the data in the byte array into an output file
        baos = new ByteArrayOutputStream();
        baos.write(bytearray);
        fop = new FileOutputStream ("output.gif");
        baos.writeTo(fop);

  • GeoRaptor 3.0 for SQL Developer 3.0 and 2.1 has now been released

    Folks,
    I am pleased to announce that, after 5 months of development and testing, a new release of GeoRaptor for SQL Developer 2.1 and 3.0 is now available.
    GeoRaptor for SQL Developer 3 is available via the SQL Developer Update centre. GeoRaptor 3 for SQL Developer 2.1 is being made available
    via a download fro the GeoRaptor website.
    No release notes have been compiled as the principal developer (oops, that's me!) is currently busy doing real work for a change (another 3 weeks), earning a living
    and keeping the wolves at bay. More extensive notes (with images) will be compiled when I get back. (Unless anyone is offering! See next.)
    We are still looking for people to:
    1. Provide translations of the English dialog menus etc.
    2. Write more extensive user documentation. If you use a particular part of GeoRaptor a lot and think
    you have found out all its functionality and quirks, contact us and offer to write a few pages of
    documentation on it. (Open Office or Microsoft Word is fine.) Easiest way to do this is to simply
    make screen captures and annotate with text.
    3. Conduct beta testing.
    Here are the things that are in the new release.
    New functionality:
    Overhaul of Validation Functionality.
    1. User can specify own validation SELECT SQL as long as it returns three required columns. The SQL is thus totally editable.
    2. Validation update code now allows user to associate a PL/SQL function with an error number which is applied in the UPDATE SQL.
    3. UPDATE SQL can use WHERE clause of validation SELECT SQL (1) to update specific errors.
       NOTE: The generated UPDATE statement can be manually edited. It is NEVER run by GeoRaptor. To run any UPDATE, copy the statement
       to the clipboard and run in an appropriate SQL Worksheet session within SQL Developer.
    4. Main validation table allows:
       a. Sorting (click on column header) and
       b. Filtering.
       c. Copying to Clipboard via right mouse click sub menu of:
          - Geometry's SDO_ELEM_INFO array constructor.
          - SDO_GEOMETRY constructor
          - Error + validation string.
       d. Access to Draw/Zoom functions which were previously buttons.
       e. Added a new right mouse click menu "Show Feature's Individual Errors" that gathers up all the errors
          it can process - along with the ring / element that is host to the error (if it can) - and displays
          them in the Attribute/Geometry tabs at the bottom of the Map Window (where "Identify" places its results).
          The power of this will be evident to all those who have wanted a way of stepping through errors in a geometry.
       f. Selected rows can now be deleted (select rows: press <DELETE> key or right mouse click>Delete).
       g. Table now has only one primary key column, and has a separate error column holding the actual error code.
       h. Right mouse click men added to table menu to display description of error in the new column (drawn from Oracle documentation)
       i. Optimisations added to improve performance for large error lists.
    5. Functionality now has its own validation layer that is automatically added to the correct view.
       Access to layer properties via button on validation dialog or via normal right mouse click in view/layer tree.
    Improved Rendering Options.
    1. Linestring colour can now be random or drawn from column in database (as per Fill and Point colouring)
    2. Marking of SDO_GEOMETRY objects overhauled.
       - Ability to mark or LABEL vertices/points of all SDO_GEOMETRY types with coordinate identifier and
         option {X,Y} location. Access is via Labelling tab in layer>properties. Thus, coordinate 25 of a linestring
         could be shown as: <25> or {x,y} or <25> {x,y}
       - There is a nice "stacked" option where the coordinate {x,y} can be written one line below the id.
       - For linestrings and polygons the <id> {x,y} label can be oriented to the angle between the vectors or
         edges that come in, and go out of, a vertex. Access is via "Orient" tick box in Labelling tab.
       - Uses Tools>Preferences>GeoRaptor>Visualisation>SDO_ORDINATE_ARRAY bracket around x,y string.
    3. Start point of linestring/polygon and all other vertices can be marked with user selectable point marker
       rather than previously fixed markers.
    4. Can now set a NULL point marker by selecting "None" for point marker style pulldown menu.
    5. Positioning of the arrow for linestring/polygons has extra options:
       * NONE
       * START    - All segments of a line have the arrow positioned at the start
       * MIDDLE   - All segments of a line have the arrow positioning in the middle.
       * END      - All segments of a line have the arrow positioning in the END.
       * END_ONLY - Only the last segment has an arrow and at its end.
    ScaleBar.
    1. A new graphic ScaleBar option has been added for the map of each view.
       For geographic/geodetic SRIDs distances are currently shown in meters;
       For all SRIDs an attempt is made to "adapt" the scaleBar units depending
       on the zoom level. So, if you zoom right in you might get the distance shown
       as mm, and as you zoom out, cm/m/km as appropriate.
    2. As the scaleBar is drawn, a 1:<DEMONINATOR> style MapScale value is written
       to the map's right most status bar element.
    3. ScaleBar and MapScale can be turned off/on in View>Properties right mouse
       click menu.
    Export Capabilities.
    1. The ability to export a selection from a result set table (ie result of
       executing ad-hoc SQL SELECT statement to GML, KML, SHP/TAB (TAB file
       adds TAB file "wrapper" over SHP) has been added.
    2. Ability to export table/view/materialised view to GML, KML, SHP/TAB also
       added. If no attributes are selected when exporting to a SHP/TAB file, GeoRaptor
       automatically adds a field that holds a unique row number.
    3. When exporting to KML:
       * one can optionally export attributes.
       * Web sensitive characters < > & etc for KML export are replaced with &gt; &lt; &amp; etc.
       * If a column in the SELECTION or table/view/Mview equals "name" then its value is
         written to the KML tag <name> and not to the list of associated attributes.
         - Similarly for "description" -> <description> AND "styleUrl" -> <styleUrl>
    4. When exporting to GML one can optionally export attributes in FME or OGR "flavour".
    5. Exporting Measured SDO_GEOMETRY objects to SHP not supported until missing functionality
       in GeoTools is corrected (working with GeoTools community to fix).
    6. Writing PRJ and MapInfo CoordSys is done by pasting a string into appropriate export dialog box.
       Last value pasted is remembered between sessions which is useful for users who work with a single SRID.
    7. Export directory is remembered between sessions in case a user uses a standard export directory.
    8. Result sets containing MDSYS.SDO_POINT and/or MDSYS.VERTEX_TYPE can also be written to GML/KML/SHP/TAB.
       Example:
       SELECT a.geom.sdo_point as point
         FROM (SELECT sdo_geometry(2002,null,sdo_point_type(1,2,null),sdo_elem_info_array(1,2,1),sdo_ordinate_array(1,1,2,2)) as geom
                 FROM DUAL) a;
       SELECT mdsys.vertex_type(a.x,a.y,a.z,a.w,a.v5,a.v6,a.v7,a.v8,a.v9,a.v10,a.v11,a.id) as vertex
         FROM TABLE(mdsys.sdo_util.getVertices(mdsys.sdo_geometry(2002,null,null,sdo_elem_info_array(1,2,1),sdo_ordinate_array(1,1,2,2)))) a;
    9. A dialog appears at the end of each export which details (eg total) what was exported when the exported recordset/table contains more
       than on shape type. For example, if you export only points eg 2001/3001 from a table that also contains multipoints eg 2005/3005 then
       the number of points exported, and multipoints skipped will be displayed.
    10. SHP/TAB export is "transactional". If you set the commit interval to 100 then only 100 records are held in memory before writing.
        However, this does not currently apply to the associated DBASE records.
    11. SHP/TAB export supports dBase III, dBase III + Memo, dBase IV and dBase IV + Memo.
        Note: Memo allows text columns > 255 characters to be exported. Non-Memo formats do not and any varchar2 columns will be truncated
        to 255 chars. Some GIS packages support MEMO eg Manifold GIS, some do not.
    12. Note. GeoRaptor does not ensure that the SRID of SDO_GEOMETRY data exported to KML is in the correct Google Projection.
        Please read the Oracle documentation on how to project your data is this is necessary. An example is:
        SELECT OBJECTID,
               CODIGO as name,
               NOME as description,
               MI_STYLE,
               SDO_CS.TRANSFORM(shape,'USE_SPHERICAL',4055) as shape
          FROM MUB.REGIONAL;
    13. NOTE: The SHP exporter uses the Java Topology Suite (JTS) to convert from SDO_GEOMETRY to the ESRI Shape format. JTS does not handle
        circular curves in SDO_GEOMETRY objects you must "stroke" them using sdo_util.arc_densify(). See the Oracle documentation on how
        to use this.
    Miscellaneous.
    1. Selection View - Measurement has been modified so that the final result only shows those geometry
       types that were actually measured.
    2. In Layer Properties the Miscellaneous tab has been removed because the only elements in it were the
       Geometry Output options which have now been replaced by the new GML/KML/etc export capabilities.
    3. Shapefile import's user entered tablename now checked for Oracle naming convention compliance.
    4. Identify based on SDO_NN has been removed from GeoRaptor given the myriad problems that it seems to create across versions
       and partitioned/non-partitioned tables. Instead SDO_WITHIN_DISTANCE is now used with the actual search distance (see circle
       in map display): everything within that distance is returned.
    5. Displaying/Not displaying embedded sdo_point in line/polygon (Jamie Keene), is now controlled by
       a preference.
    6. New View Menu options to switch all layers on/off
    7. Tools/Preferences/GeoRaptor layout has been improved.
    8. If Identify is called on a geometry a new right mouse click menu entry has been added called "Mark" which
       has two sub-menus called ID and ID(X,Y) that will add the labeling to the selected geometry independently of
       what the layer is set to being.
    9. Two new methods for rendering an SDO_GEOMETRY object in a table or SQL recordset have been added: a) Show geometry as ICON
       and b) Show geometry as THUMBNAIL. When the latter is chosen, the actual geometry is shown in an image _inside_ the row/column cell it occupies.
       In addition, the existing textual methods for visualisation: WKT, KML, GML etc have been collected together with ICON and THUMBNAIL in a new
       right mouse click menu.
    10. Tables/Views/MViews without spatial indexes can now be added to a Spatial View. To stop large tables from killing rendering, a new preference
        has been added "Table Count Limit" (default 1,000) which controls how many geometry records can be displayed. A table without a spatial
        index will have its layer name rendered in Italics and will write a warning message in red to the status bar for each redraw. Adding an index
        which the layer exists will be recognised by GeoRaptor during drawing and switch the layer across to normal rendering.
    Some Bug Fixes.
    * Error in manage metadata related to getting metadata across all schemas
    * Bug with no display of rowid in Identify results fixed;
    * Some fixes relating to where clause application in geometry validation.
    * Fixes bug with scrollbars on view/layer tree not working.
    * Problem with the spatial networks fixed. Actions for spatial networks can now only be done in the
      schema of the current user, as it could happen that a user opens the tree for another schema that
      has the same network as in the user's schema. Dropping a drops only the network of the current connected user.
    * Recordset "find sdo_geometry cell" code has been modified so that it now appears only if a suitable geometry object is
      in a recordset.  Please note that there is a bug in SQL Developer (2.1 and 3.0) that causes SQL Developer to not
      register a change in selection from a single cell to a whole row when one left clicks at the left-most "row number"
      column that is not part of the SELECT statements user columns, as a short cut to selecting a whole row.  It appears
      that this is a SQL Developer bug so nothing can be done about it until it is fixed. To select a whole row, select all
      cells in the row.
    * Copy to clipboard of SDO_GEOMETRY with M and Z values forgot has extraneous "," at the end.
    * Column based colouring of markers fixed
    * Bunch of performance improvements.
    * Plus (happily) others that I can't remember!If you find any bugs register a bug report at our website.
    If you want to help with testing, contact us at our website.
    My thanks for help in this release to:
    1. John O'Toole
    2. Holger Labe
    3. Sandro Costa
    4. Marco Giana
    5. Luc van Linden
    6. Pieter Minnaar
    7. Warwick Wilson
    8. Jody Garnett (GeoTools bug issues)
    Finally, when at the Washington User Conference I explained the willingness of the GeoRaptor Team to work
    for some sort of integration of our "product" with the new Spatial extension that has just been released in SQL
    Developer 3.0. Nothing much has come of that initial contact and I hope more will come of it.
    In the end, it is you, the real users who should and will decide the way forward. If you have ideas, wishes etc,
    please contact the GeoRaptor team via our SourceForge website, or start a "wishlist" thread on this forum
    expressing ideas for future functionality and integration opportunities.
    regards
    Simon
    Edited by: sgreener on Jun 12, 2011 2:15 PM

    Thank you for this.
    I have been messing around with this last few days, and i really love the feature to pinpoint the validation errors on map.
    I has always been so annoying to try pinpoint these errors using some other GIS software while doing your sql.
    I have stumbled to few bugs:
    1. In "Validate geometry column" dialog checking option "Use DimInfo" actually still uses value entered in tolerance text box.
    I found this because in my language settings , is the decimal operators
    2. In "Validate geometry column" dialog textboxs showing sql, doesn't always show everything from long lines of text (clipping text from right)
    3. In "Validate geometry column" dialog the "Create Update SQL" has few bugs:
    - if you have selected multiple rows from results and check the "Use Selected Geometries" the generated IN-clause in SQL with have same rowid (rowid for first selected result) for all entries
    Also the other generated IN clause in WHERE-clause is missing separator if you select more than one corrective function
    4. "Validate geometry column" dialog stays annoyingly top most when using "Create Update SQL" dialog

  • How to determine a sql query size to display a progress bar

    I would like to show a progress of an sql query within a jsp page.
    Background:
    I have a reporting web application, where over 500 contacts can run reports based on different criteria such as date range....
    I current display a message stating 'executng query please wait', however the users (hate users) do not seem to wait, thereofore they decide to run the query all over again which affected my reportign sever query size (eventually this crashes, stopping all reports)
    Problem:
    The progress bar is not a problem, how would I determine the size of the query at runtime therefore adding the time onto my progress bar.

    Yes it's doable (we do it) but it sure ain't easy.
    We've got about 23,500,000 features (and counting) in a geodata database. Precise spatial selection algorithms are expensive. Really expensive.
    We cannot impose arbitrary limits on search criteria. If the client requires the whole database we are contractually obligated to provide it...
    For online searches We use statistics to approximate the number of features which a given query is likely to return... more or less the same way that the query optimiser behind any half decent (not mysql (5 alteast)) database management system does.
    We have a batch job which records how many features are linked to each distinct value of each search criteria... we just do the calculations (presuming a normal (flat) distribution) and...
    ... if the answer is more than a 100,000 we inform the user that the request must be "batched", and give them a form to fill out confirming there contact details. We run the extract overnight and send the user an email containing a link which allows them to download the result the next morning.
    ... if the answer is more than a million features we inform the user that the request must batched over the weekend... same deal as above, except we do it over the weekend to (a) discourage this; and (b) the official version ensure we have enough time to run the extract without impinging upon the maintenance window.
    ... if the answer is more than 5 million we display our brilliant "subscribe to our DVD service to get the latest version of the whole shebang every three months (or so), so you can kill your own blooody server with these ridiculous searches" form.
    Edited by: corlettk on Dec 5, 2007 11:12 AM

  • Misc Basic PL/SQL Application Design/Programming Questions 101 (101.1)

    ---****** background for all these questions is at bottom of this post:
    Question 1:
    I read a little on the in and out parameters and that IN is "by reference" and OUT and IN-OUT are by value. To me "by reference" means "pointer" as in C programming. So it seems to me that I could call a function with an IN parameter and NOT put it on the right side of an assignment statement. In other words, I'm calling my function
    get_something(IN p_test1 varchar2) return varchar2;
    from SP1 which has a variable named V_TEST1.
    So.... can I do this? (method A):
    get_something(V_TEST1);
    or do I have to do this (method B):
    V_TEST1 := get_something(V_TEST1);
    Also, although this may muddy the thread (we'll see), it seems to me that IN, since its by reference, will always be more efficient. I will have many concurrent users using this program: should this affect my thinking on the above question?
    -- ******* background *******
    So Far:<< I've read and am reading all over the net, read and reading oracle books from oracle (have a full safari account), reading Feurstein's tome, have read the faq's here.
    Situation Bottom Line:<< Have an enormous amount to do in a very little time. Lots riding on this. Any and all pointers will be appreciated. After we get to some undetermined point I can re-do this venture as a pl/sql faq and submit it for posting (y'alls call). Some questions may be hare brained just because I'm freaking out a little bit.
    Situation (Long Version):<< Writing a pl/sql backend to MS Reporting Services front end. Just started doing pl/sql about 2 months ago. Took me forever to find out about ref-cursor as the pipe between oracle and all client applications. I have now created a package. I've been programming for 20 years in many languages, but brand new to pl/sql. However, pl/sql sql has freed me from myriad of limitations in MS RS's. My program is starting to get big (for me -- I do a lot in a little) pks is currently 900 lines with 15 functions so far. Currently SP (pls) is back up to 800 lines. I get stuff working in the sp then turn it into a function and move it to the package.
    What does application do?:<<<< Back End for MS Reporting Services Web front end. It will be a very controlled "ad-hoc" (or the illusion of ad-hoc) web interface. All sql queries are built at run-time and executed via "open ref cusor for -- sql statement -- end;" data returned via OUT ref_cursor. Goal is to have almost 100% of functionality in a package. Calling SP will be minimalist. Reporting Services calls the SP, passes X number of parameters, and gets the ref_cursor back.
    Oracle Version: 10.2 (moving to 11g in the next 3 months).Environment: Huge DW in a massively shared environment. Everything is locked down and requires a formal request. I had to have my authenticated for a couple dbms system packages just to starting simple pl/sql programs.

    Brad Bueche wrote:
    Question 1:
    I read a little on the in and out parameters and that IN is "by reference" and OUT and IN-OUT are by value. To me "by reference" means "pointer" as in C programming. So it seems to me that I could call a function with an IN parameter and NOT put it on the right side of an assignment statement. The IN parameter is not passing by reference. It is passing by value. This means variable/value of the caller used as parameter, is copied to the (pushed) stack of code unit called.
    An OUT parameter means that the value is copied from the called unit's stack to the caller (and the current value of the caller's variable is overwritten).
    To pass by reference, the NOCOPY clause need to be used. Note that is not an explicit compile instruction. The PL/SQL engine could very well decide to pass by value and not reference instead (depending on the data type used).
    Note that the ref cursor data type and the LOB data types are already pointers. In which case these are not passed reference as they are already references.
    The NOCOPY clause only make sense for large varchar2 variables (these can be up to 32KB in PL/SQL) and for collection/array data type variables.
    As for optimising PL/SQL code - there are a number of approaches (and not just passing by reference). Deterministic functions can be defined. PL/SQL code can be written (as pipelined tables) to run in parallel using the default Oracle Parallel Query feature. PL/SQL can be manually parallelised. Context switches to the SQL engine can be minimised using bulk processing. Etc.
    Much of the performance will however come down to 2 basic issues. How well the data structures being processed are designed. How well the code itself is modularised and written.

  • How can i make the optimiser to skip this full table scan ??

    Hi,
    I am trying to tune the below query, I have checked up all the possibilities to skip the full table scan on vhd_calldesh_archive, But am unable to find the predicate in the where clause, which is letting the optimiser to choose the full table scan on vhd_calldesk_archive table, which is very large one. how can i make the optimiser to skip this full table scan.
    Please check the below sql script and explain plan ,
    SELECT a.call_id, a.entry_date,
    NVL (INITCAP (b.full_name), caller_name) AS caller_name,
    c.description AS org_desc, a.env_id, i.env_desc, a.appl_id,
    d.appl_desc, a.module_id, e.module_desc, a.call_type_id,
    f.call_type_desc, a.priority, a.upduserid,
    INITCAP (g.full_name) AS lastupdated_username, a.call_desc, h.mode_desc,
    a.received_time,a.assignment_team, a.status,
    ROUND (lcc.pkg_com.fn_datediff ('MI',
    a.entry_date,
    a.status_date
    ) AS elapsed_time,
    ROUND (lcc.pkg_com.fn_datediff ('MI',
    a.entry_date,
    a.status_date
    ) AS resolved_min,
    CASE
    WHEN a.orgid in (1,100,200) THEN a.orgid
    ELSE j.regionorgid
    END AS region
    ,(SELECT coalesce(MAX(upddate),a.upddate) FROM lcc.vhd_callstatus stat WHERE stat.call_id = a.call_id
    ) as stat_upddate
    ,(SELECT team_desc from lcc.vhd_teams t where t.team_id = a.assignment_team) as team_desc
    ,a.eta_date
    ,coalesce(a.caller_contact, b.telephone) AS caller_contact
    ,coalesce(a.caller_email, b.email) as email
    ,a.affected_users
    ,a.outage_time
    ,a.QA_DONE
    ,a.LAST_ACTION_TEAM
    ,a.LAST_ACTION_USER
    ,INITCAP (k.full_name) AS last_action_username
    ,a.last_action_date
    ,l.team_desc as last_action_teamdesc
    ,a.refid
    ,INITCAP (lu.full_name) AS logged_name
    ,a.pmreview
    ,a.status as main_status
    FROM lcc.vhd_calldesk_archive a
    LEFT OUTER JOIN lcc.lcc_userinfo_details b ON b.user_name = a.caller_id
    INNER JOIN lcc.com_organization c ON c.code = a.orgid
    INNER JOIN lcc.vhd_applications d ON d.appl_id = a.appl_id
    INNER JOIN lcc.vhd_modules e ON e.appl_id = a.appl_id AND e.module_id = a.module_id
    INNER JOIN lcc.vhd_calltypes f ON f.call_type_id = a.call_type_id
    INNER JOIN lcc.com_rptorganization j ON j.orgid = a.orgid AND j.tree = 'HLPDK'
    LEFT OUTER JOIN lcc.lcc_userinfo_details g ON g.user_name = a.upduserid
    LEFT OUTER JOIN lcc.vhd_callmode h ON h.mode_id = a.mode_id
    LEFT OUTER JOIN lcc.vhd_environment i ON i.appl_id = a.appl_id AND i.env_id = a.env_id
    LEFT OUTER JOIN lcc.lcc_userinfo_details k ON k.user_name = a.last_action_user
    LEFT OUTER JOIN lcc.vhd_teams l ON l.team_id = a.last_action_user
    LEFT OUTER JOIN (select CALL_ID,upduserid FROM lcc.VHD_CALLDESK_HISTORY P where upddate
    in ( select min(upddate) from lcc.VHD_CALLDESK_HISTORY Q WHERE Q.CALL_ID = P.CALL_ID
    group by call_id)) ku
    ON ku.call_id = a.call_id
    LEFT OUTER JOIN lcc.lcc_userinfo_details lu ON NVL(ku.upduserid,A.upduserid) = lu.user_name;
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 2104 | 3667K| 37696 |
    | 1 | UNION-ALL | | | | |
    | 2 | NESTED LOOPS OUTER | | 2103 | 3665K| 37683 |
    | 3 | VIEW | | 2103 | 3616K| 35580 |
    | 4 | NESTED LOOPS OUTER | | 2103 | 823K| 35580 |
    | 5 | NESTED LOOPS OUTER | | 2103 | 774K| 33477 |
    | 6 | NESTED LOOPS OUTER | | 2103 | 685K| 31374 |
    | 7 | NESTED LOOPS | | 2103 | 636K| 29271 |
    | 8 | NESTED LOOPS | | 2103 | 603K| 27168 |
    | 9 | NESTED LOOPS OUTER | | 2103 | 558K| 25065 |
    | 10 | NESTED LOOPS OUTER | | 2103 | 515K| 22962 |
    | 11 | NESTED LOOPS | | 2103 | 472K| 20859 |
    | 12 | NESTED LOOPS | | 2103 | 429K| 18756 |
    | 13 | NESTED LOOPS OUTER | | 4826 | 890K| 13930 |
    | 14 | NESTED LOOPS OUTER | | 4826 | 848K| 9104 |
    | 15 | NESTED LOOPS | | 4826 | 754K| 4278 |
    |* 16 | TABLE ACCESS FULL | COM_RPTORGANIZATION | 75 | 1050 | 3 |
    | 17 | TABLE ACCESS BY INDEX ROWID | VHD_CALLDESK | 64 | 9344 | 57 |
    |* 18 | INDEX RANGE SCAN | VHD_CALLDSK_ORGID | 2476 | | 7 |
    | 19 | VIEW PUSHED PREDICATE | | 1 | 20 | 1 |
    |* 20 | FILTER | | | | |
    | 21 | TABLE ACCESS BY INDEX ROWID | VHD_CALLDESK_HISTORY | 1 | 20 | 2 |
    |* 22 | INDEX RANGE SCAN | VHD_CALLDSK_HIST_CALLID_IDX | 1 | | 1 |
    |* 23 | FILTER | | | | |
    | 24 | SORT GROUP BY NOSORT | | 1 | 12 | 2 |
    | 25 | TABLE ACCESS BY INDEX ROWID | VHD_CALLDESK_HISTORY | 1 | 12 | 2 |
    |* 26 | INDEX RANGE SCAN | VHD_CALLDSK_HIST_CALLID_IDX | 1 | | 1 |
    | 27 | TABLE ACCESS BY INDEX ROWID | VHD_CALLMODE | 1 | 9 | 1 |
    |* 28 | INDEX UNIQUE SCAN | VHD_CALLMOD_MODID_PK | 1 | | |
    | 29 | TABLE ACCESS BY INDEX ROWID | VHD_APPLICATIONS | 1 | 20 | 1 |
    |* 30 | INDEX UNIQUE SCAN | VHD_APPL_APPLID_PK | 1 | | |
    | 31 | TABLE ACCESS BY INDEX ROWID | VHD_CALLTYPES | 1 | 21 | 1 |
    |* 32 | INDEX UNIQUE SCAN | VHD_CALLTYP_ID_PK | 1 | | |
    | 33 | TABLE ACCESS BY INDEX ROWID | VHD_TEAMS | 1 | 21 | 1 |
    |* 34 | INDEX UNIQUE SCAN | VHD_TEAMID_PK | 1 | | |
    | 35 | TABLE ACCESS BY INDEX ROWID | VHD_ENVIRONMENT | 1 | 21 | 1 |
    |* 36 | INDEX UNIQUE SCAN | VHD_ENV_APLENVID_PK | 1 | | |
    | 37 | TABLE ACCESS BY INDEX ROWID | VHD_MODULES | 1 | 22 | 1 |
    |* 38 | INDEX UNIQUE SCAN | VHD_MOD_APLMOD_ID_PK | 1 | | |
    | 39 | TABLE ACCESS BY INDEX ROWID | COM_ORGANIZATION | 1 | 16 | 1 |
    |* 40 | INDEX UNIQUE SCAN | COM_ORG_PK | 1 | | |
    | 41 | TABLE ACCESS BY INDEX ROWID | LCC_USERINFO_DETAILS | 1 | 24 |
    |* 42 | INDEX UNIQUE SCAN | LCCUSERINFOIND | 1 | | |
    | 43 | TABLE ACCESS BY INDEX ROWID | LCC_USERINFO_DETAILS | 1 | 43 |
    |* 44 | INDEX UNIQUE SCAN | LCCUSERINFOIND | 1 | | |
    | 45 | TABLE ACCESS BY INDEX ROWID | LCC_USERINFO_DETAILS | 1 | 24 | 1
    |* 46 | INDEX UNIQUE SCAN | LCCUSERINFOIND | 1 | | |
    | 47 | TABLE ACCESS BY INDEX ROWID | LCC_USERINFO_DETAILS | 1 | 24 | 1
    |* 48 | INDEX UNIQUE SCAN | LCCUSERINFOIND | 1 | | |
    | 49 | NESTED LOOPS OUTER | | 1 | 1785 | 13 |
    | 50 | VIEW | | 1 | 1761 | 12 |
    | 51 | NESTED LOOPS OUTER | | 1 | 1656 | 12 |
    | 52 | NESTED LOOPS OUTER | | 1 | 1632 | 11 |
    | 53 | NESTED LOOPS OUTER | | 1 | 1608 | 10 |
    | 54 | NESTED LOOPS | | 1 | 1565 | 9 |
    | 55 | NESTED LOOPS | | 1 | 1549 | 9 |
    | 56 | NESTED LOOPS | | 1 | 1535 | 9 |
    | 57 | NESTED LOOPS OUTER | | 1 | 1513 | 8 |
    | 58 | NESTED LOOPS OUTER | | 1 | 1492 | 7 |
    | 59 | NESTED LOOPS | | 1 | 1471 | 6 |
    | 60 | NESTED LOOPS | | 1 | 1450 | 5 |
    | 61 | NESTED LOOPS OUTER | | 1 | 1430 | 4 |
    | 62 | NESTED LOOPS OUTER | | 1 | 1421 | 3 |
    | 63 | TABLE ACCESS FULL | VHD_CALLDESK_ARCHIVE | 1 | 1401 | 2 |
    | 64 | VIEW PUSHED PREDICATE | | 1 | 20 | 1 |
    |* 65 | FILTER | | | | |
    | 66 | TABLE ACCESS BY INDEX ROWID | VHD_CALLDESK_HISTORY | 1 | 20 | 2 |
    |* 67 | INDEX RANGE SCAN | VHD_CALLDSK_HIST_CALLID_IDX | 1 | | 1 |
    |* 68 | FILTER | | | | |
    | 69 | SORT GROUP BY NOSORT | | 1 | 12 | 2 |
    | 70 | TABLE ACCESS BY INDEX ROWID| VHD_CALLDESK_HISTORY | 1 | 12 | 2 |
    |* 71 | INDEX RANGE SCAN | VHD_CALLDSK_HIST_CALLID_IDX | 1 | | 1 |
    | 72 | TABLE ACCESS BY INDEX ROWID | VHD_CALLMODE | 1 | 9 | 1 |
    |* 73 | INDEX UNIQUE SCAN | VHD_CALLMOD_MODID_PK | 1 | | |
    | 74 | TABLE ACCESS BY INDEX ROWID | VHD_APPLICATIONS | 1 | 20 | 1 |
    |* 75 | INDEX UNIQUE SCAN | VHD_APPL_APPLID_PK | 1 | | |
    | 76 | TABLE ACCESS BY INDEX ROWID | VHD_CALLTYPES | 1 | 21 | 1 |
    |* 77 | INDEX UNIQUE SCAN | VHD_CALLTYP_ID_PK | 1 | | |
    | 78 | TABLE ACCESS BY INDEX ROWID | VHD_TEAMS | 1 | 21 | 1 |
    |* 79 | INDEX UNIQUE SCAN | VHD_TEAMID_PK | 1 | | |
    | 80 | TABLE ACCESS BY INDEX ROWID | VHD_ENVIRONMENT | 1 | 21 | 1 |
    |* 81 | INDEX UNIQUE SCAN | VHD_ENV_APLENVID_PK | 1 | | |
    | 82 | TABLE ACCESS BY INDEX ROWID | VHD_MODULES | 1 | 22 | 1 |
    |* 83 | INDEX UNIQUE SCAN | VHD_MOD_APLMOD_ID_PK | 1 | | |
    | 84 | TABLE ACCESS BY INDEX ROWID | COM_RPTORGANIZATION | 1 | 14 | |
    |* 85 | INDEX UNIQUE SCAN | COM_RPTORG_PK | 1 | | |
    | 86 | TABLE ACCESS BY INDEX ROWID | COM_ORGANIZATION | 1 | 16 | |
    |* 87 | INDEX UNIQUE SCAN | COM_ORG_PK | 1 | | |
    | 88 | TABLE ACCESS BY INDEX ROWID | LCC_USERINFO_DETAILS | 1 | 43 |
    |* 89 | INDEX UNIQUE SCAN | LCCUSERINFOIND | 1 | | |
    | 90 | TABLE ACCESS BY INDEX ROWID | LCC_USERINFO_DETAILS | 1 | 24 |
    |* 91 | INDEX UNIQUE SCAN | LCCUSERINFOIND | 1 | | |
    | 92 | TABLE ACCESS BY INDEX ROWID | LCC_USERINFO_DETAILS | 1 | 24 | 1
    |* 93 | INDEX UNIQUE SCAN | LCCUSERINFOIND | 1 | | |
    | 94 | TABLE ACCESS BY INDEX ROWID | LCC_USERINFO_DETAILS | 1 | 24 | 1
    |* 95 | INDEX UNIQUE SCAN | LCCUSERINFOIND | 1 | | |
    Predicate Information (identified by operation id):
    16 - filter("J"."TREE"='HLPDK')
    18 - access("J"."ORGID"="A"."ORGID")
    20 - filter( EXISTS (SELECT /*+ */ 0 FROM "LCC"."VHD_CALLDESK_HISTORY" "Q" WHERE "Q"."CALL_ID"=:B1
    "Q"."CALL_ID" HAVING MIN("Q"."UPDDATE")=:B2))
    22 - access("SYS_ALIAS_2"."CALL_ID"="A"."CALL_ID")
    23 - filter(MIN("Q"."UPDDATE")=:B1)
    26 - access("Q"."CALL_ID"=:B1)
    28 - access("H"."MODE_ID"(+)="A"."MODE_ID")
    30 - access("D"."APPL_ID"="A"."APPL_ID")
    32 - access("F"."CALL_TYPE_ID"="A"."CALL_TYPE_ID")
    34 - access("L"."TEAM_ID"(+)="A"."LAST_ACTION_TEAM")
    36 - access("I"."APPL_ID"(+)="A"."APPL_ID" AND "I"."ENV_ID"(+)="A"."ENV_ID")
    38 - access("E"."APPL_ID"="A"."APPL_ID" AND "E"."MODULE_ID"="A"."MODULE_ID")
    40 - access("C"."CODE"="A"."ORGID")
    42 - access("K"."USER_NAME"(+)="A"."LAST_ACTION_USER")
    44 - access("B"."USER_NAME"(+)="A"."CALLER_ID")
    46 - access("G"."USER_NAME"(+)="A"."UPDUSERID")
    48 - access("LU"."USER_NAME"(+)=NVL("SYS_ALIAS_4"."UPDUSERID_162","SYS_ALIAS_4"."UPDUSERID_25"))
    65 - filter( EXISTS (SELECT /*+ */ 0 FROM "LCC"."VHD_CALLDESK_HISTORY" "Q" WHERE "Q"."CALL_ID"=:B1
    "Q"."CALL_ID" HAVING MIN("Q"."UPDDATE")=:B2))
    67 - access("SYS_ALIAS_2"."CALL_ID"="SYS_ALIAS_1"."CALL_ID")
    68 - filter(MIN("Q"."UPDDATE")=:B1)
    71 - access("Q"."CALL_ID"=:B1)
    73 - access("H"."MODE_ID"(+)="SYS_ALIAS_1"."MODE_ID")
    75 - access("D"."APPL_ID"="SYS_ALIAS_1"."APPL_ID")
    77 - access("F"."CALL_TYPE_ID"="SYS_ALIAS_1"."CALL_TYPE_ID")
    79 - access("L"."TEAM_ID"(+)=TO_NUMBER("SYS_ALIAS_1"."LAST_ACTION_USER"))
    81 - access("I"."APPL_ID"(+)="SYS_ALIAS_1"."APPL_ID" AND "I"."ENV_ID"(+)="SYS_ALIAS_1"."ENV_ID")
    83 - access("E"."APPL_ID"="SYS_ALIAS_1"."APPL_ID" AND "E"."MODULE_ID"="SYS_ALIAS_1"."MODULE_ID")
    85 - access("SYS_ALIAS_1"."ORGID"="J"."ORGID" AND "J"."TREE"='HLPDK')
    87 - access("C"."CODE"="SYS_ALIAS_1"."ORGID")
    89 - access("B"."USER_NAME"(+)="SYS_ALIAS_1"."CALLER_ID")
    91 - access("SYS_ALIAS_1"."UPDUSERID"="G"."USER_NAME"(+))
    93 - access("K"."USER_NAME"(+)="SYS_ALIAS_1"."LAST_ACTION_USER")
    95 - access("LU"."USER_NAME"(+)=NVL("SYS_ALIAS_3"."UPDUSERID_162","SYS_ALIAS_3"."UPDUSERID_25"))
    Note: cpu costing is off

    I've tried to look thru your sql and changed it a bit. Of course not testet :-)
    Your problem isn't the archive table! I tried to remove the 2 selects from the select-clause. Furthermore you have a lot of nested loops in your explain, which is a performance-killer. Try getting rid of them, perhaps use /*+ USE_HASH(?,?) */.
    SELECT a.call_id, a.entry_date,
           NVL (INITCAP (b.full_name), caller_name) AS caller_name, c.description AS org_desc, a.env_id, i.env_desc, a.appl_id,
           d.appl_desc, a.module_id, e.module_desc, a.call_type_id, f.call_type_desc, a.priority, a.upduserid,
           INITCAP (g.full_name) AS lastupdated_username, a.call_desc, h.mode_desc, a.received_time, a.assignment_team, a.status,
           ROUND (lcc.pkg_com.fn_datediff ('MI', a.entry_date, a.status_date)) AS elapsed_time,
           ROUND (lcc.pkg_com.fn_datediff ('MI', a.entry_date, a.status_date)) AS resolved_min,
           CASE
              WHEN a.orgid IN (1, 100, 200)
                 THEN a.orgid
              ELSE j.regionorgid
           END AS region,
           COALESCE (stat.upddate, a.upddate) AS stat_upddate,
           t.team_desc, a.eta_date,
           COALESCE (a.caller_contact, b.telephone) AS caller_contact,
           COALESCE (a.caller_email, b.email) AS email, a.affected_users,
           a.outage_time, a.qa_done, a.last_action_team, a.last_action_user,
           INITCAP (k.full_name) AS last_action_username, a.last_action_date,
           l.team_desc AS last_action_teamdesc, a.refid,
           INITCAP (lu.full_name) AS logged_name, a.pmreview,
           a.status AS main_status
      FROM lcc.vhd_calldesk_archive a, lcc.lcc_userinfo_details b, lcc.com_organization c,
           lcc.vhd_applications d, lcc.vhd_modules e, lcc.vhd_calltypes f, lcc.com_rptorganization j,
           lcc.lcc_userinfo_details g, lcc.vhd_callmode h, lcc.vhd_environment i, lcc.lcc_userinfo_details k,
           lcc.vhd_teams l,
          (SELECT call_id, upduserid
           FROM lcc.vhd_calldesk_history p
           WHERE upddate IN (SELECT   MIN (upddate)
                             FROM lcc.vhd_calldesk_history q
                             WHERE q.call_id = p.call_id
                             GROUP BY call_id)) ku,
           lcc.lcc_userinfo_details lu,
          (SELECT call_id, MAX (upddate)
           FROM lcc.vhd_callstatus
           GROUP BY call_id) stat,
           lcc.vhd_teams t
      WHERE a.caller_id        = b.user_name(+)
        AND a.orgid            = c.code
        AND a.appl_id          = d.appl_id
        AND a.appl_id          = e.appl_id
        AND a.module_id        = e.module_id
        AND a.call_type_id     = f.call_type_id
        AND a.orgid            = j.orgid
        AND j.tree             = 'HLPDK'
        AND a.upduserid        = g.user_name(+)
        AND a.mode_id          = h.mode_id(+)
        AND a.appl_id          = i.appl_id(+)
        AND a.env_id           = i.env_id(+)
        AND a.last_action_user = k.user_name(+)
        AND a.last_action_user = l.team_id(+)
        AND a.call_id          = ku.call_id(+)
        AND NVL (ku.upduserid, a.upduserid) = lu.user_name(+)
        AND a.call_id          = stat.call_id
        AND a.assignment_team  = t.team_id;

Maybe you are looking for