WITH-clause: performance- or readability enhancement?

Hi,
I was preparing for a course on with I also discuss the with-clause. Assuming it would perform better than just writing down two extra statements, I tried out the explain plan and found out that the with-clause actually performes worse. The example:
Statment including WITH-clause:
SQL> with country as
2 (select c.country_id
3 ,     c.country_name
4 ,     c.region_id
5 ,     r.region_name
6 from countries c
7 ,     regions r
8 where c.region_id = r.region_id)
9 select l.street_address
10 ,     l.city
11 ,     c.region_name
12 from locations l
13 ,     country c
14 where l.country_id = c.country_id
15 and c.country_id = 'UK'
16 union
17 select l.street_address
18 ,     l.city
19 ,     c.region_name
20 from locations l
21 ,     country c
22 where l.country_id = c.country_id
23 and c.country_id = 'NL'
24 ;
The cost of this executing is 11 as the explain plan tells me (dbms_xplan.display_cursor)
Now, without WITH-clause:
SQL> select l.street_address
2 ,     l.city
3 ,     c.region_name
4 from locations l
5 ,     (select c.country_id
6      ,     c.country_name
7      ,     c.region_id
8      ,     r.region_name
9      from countries c
10      ,     regions r
11      where c.region_id = r.region_id) c
12 where l.country_id = c.country_id
13 and c.country_id = 'UK'
14 union
15 select l.street_address
16 ,     l.city
17 ,     c.region_name
18 from locations l
19 ,     (select c.country_id
20      ,     c.country_name
21      ,     c.region_id
22      ,     r.region_name
23      from countries c
24      ,     regions r
25      where c.region_id = r.region_id) c
26 where l.country_id = c.country_id
27 and c.country_id = 'NL'
28 ;
Now explain plan tells me the cost is just 6! Why does this not perform faster. Are there examples at which it does? Or is the WITH-clause only to make the statements syntax more readable??

Ok, here's the plan for the first query (including with) PLAN_TABLE_OUTPUT                                                                                                                                                                  
Plan hash value: 744749920                                                                                                                                                         
| Id  | Operation                       | Name                     | Rows  | Bytes | Cost (%CPU)| Time     |                                                                       
|   0 | SELECT STATEMENT                |                          |       |       |    11 (100)|          |                                                                       
|   1 |  TEMP TABLE TRANSFORMATION      |                          |       |       |            |          |                                                                       
|   2 |   LOAD AS SELECT                |                          |       |       |            |          |                                                                       
|   3 |    MERGE JOIN                   |                          |    25 |   700 |     4  (25)| 00:00:01 |                                                                       
|   4 |     TABLE ACCESS BY INDEX ROWID | REGIONS                  |     4 |    56 |     2   (0)| 00:00:01 |                                                                       
|   5 |      INDEX FULL SCAN            | REG_ID_PK                |     4 |       |     1   (0)| 00:00:01 |                                                                       
PLAN_TABLE_OUTPUT                                                                                                                                                                  
|*  6 |     SORT JOIN                   |                          |    25 |   350 |     2  (50)| 00:00:01 |                                                                       
|   7 |      INDEX FULL SCAN            | COUNTRY_C_ID_PK          |    25 |   350 |     1   (0)| 00:00:01 |                                                                       
|   8 |   SORT UNIQUE                   |                          |   100 |  5100 |    11  (64)| 00:00:01 |                                                                       
|   9 |    UNION-ALL                    |                          |       |       |            |          |                                                                       
|* 10 |     HASH JOIN                   |                          |    75 |  3825 |     5  (20)| 00:00:01 |                                                                       
|  11 |      TABLE ACCESS BY INDEX ROWID| LOCATIONS                |     3 |    99 |     2   (0)| 00:00:01 |                                                                       
|* 12 |       INDEX RANGE SCAN          | LOC_COUNTRY_IX           |     3 |       |     1   (0)| 00:00:01 |                                                                       
|* 13 |      VIEW                       |                          |    25 |   450 |     2   (0)| 00:00:01 |                                                                       
|  14 |       TABLE ACCESS FULL         | SYS_TEMP_0FD9D6602_FACCC |    25 |   650 |     2   (0)| 00:00:01 |                                                                       
|* 15 |     HASH JOIN                   |                          |    25 |  1275 |     5  (20)| 00:00:01 |                                                                       
|  16 |      TABLE ACCESS BY INDEX ROWID| LOCATIONS                |     1 |    33 |     2   (0)| 00:00:01 |                                                                       
PLAN_TABLE_OUTPUT                                                                                                                                                                  
|* 17 |       INDEX RANGE SCAN          | LOC_COUNTRY_IX           |     1 |       |     1   (0)| 00:00:01 |                                                                       
|* 18 |      VIEW                       |                          |    25 |   450 |     2   (0)| 00:00:01 |                                                                       
|  19 |       TABLE ACCESS FULL         | SYS_TEMP_0FD9D6602_FACCC |    25 |   650 |     2   (0)| 00:00:01 |                                                                       
Predicate Information (identified by operation id):                                                                                                                                
   6 - access("C"."REGION_ID"="R"."REGION_ID")                                                                                                                                     
       filter("C"."REGION_ID"="R"."REGION_ID")                                                                                                                                     
  10 - access("L"."COUNTRY_ID"="C"."COUNTRY_ID")                                                                                                                                   
PLAN_TABLE_OUTPUT                                                                                                                                                                  
  12 - access("L"."COUNTRY_ID"='UK')                                                                                                                                               
  13 - filter("C"."COUNTRY_ID"='UK')                                                                                                                                               
  15 - access("L"."COUNTRY_ID"="C"."COUNTRY_ID")                                                                                                                                   
  17 - access("L"."COUNTRY_ID"='NL')                                                                                                                                               
  18 - filter("C"."COUNTRY_ID"='NL')                                                                                                                                               
                                             And this is the plan for the query WITHOUT the with-clause:
Plan hash value: 3987129437                                                                                                                                                        
| Id  | Operation                       | Name            | Rows  | Bytes | Cost (%CPU)| Time     |                                                                                
|   0 | SELECT STATEMENT                |                 |       |       |     6 (100)|          |                                                                                
|   1 |  SORT UNIQUE                    |                 |     4 |   212 |     6  (67)| 00:00:01 |                                                                                
|   2 |   UNION-ALL                     |                 |       |       |            |          |                                                                                
PLAN_TABLE_OUTPUT                                                                                                                                                                  
|   3 |    NESTED LOOPS                 |                 |     3 |   159 |     2   (0)| 00:00:01 |                                                                                
|   4 |     NESTED LOOPS                |                 |     1 |    20 |     1   (0)| 00:00:01 |                                                                                
|*  5 |      INDEX UNIQUE SCAN          | COUNTRY_C_ID_PK |     1 |     6 |     0   (0)|          |                                                                                
|   6 |      TABLE ACCESS BY INDEX ROWID| REGIONS         |     4 |    56 |     1   (0)| 00:00:01 |                                                                                
|*  7 |       INDEX UNIQUE SCAN         | REG_ID_PK       |     1 |       |     0   (0)|          |                                                                                
|   8 |     TABLE ACCESS BY INDEX ROWID | LOCATIONS       |     3 |    99 |     1   (0)| 00:00:01 |                                                                                
|*  9 |      INDEX RANGE SCAN           | LOC_COUNTRY_IX  |     3 |       |     0   (0)|          |                                                                                
|  10 |    NESTED LOOPS                 |                 |     1 |    53 |     2   (0)| 00:00:01 |                                                                                
|  11 |     NESTED LOOPS                |                 |     1 |    20 |     1   (0)| 00:00:01 |                                                                                
|* 12 |      INDEX UNIQUE SCAN          | COUNTRY_C_ID_PK |     1 |     6 |     0   (0)|          |                                                                                
|  13 |      TABLE ACCESS BY INDEX ROWID| REGIONS         |     4 |    56 |     1   (0)| 00:00:01 |                                                                                
PLAN_TABLE_OUTPUT                                                                                                                                                                  
|* 14 |       INDEX UNIQUE SCAN         | REG_ID_PK       |     1 |       |     0   (0)|          |                                                                                
|  15 |     TABLE ACCESS BY INDEX ROWID | LOCATIONS       |     1 |    33 |     1   (0)| 00:00:01 |                                                                                
|* 16 |      INDEX RANGE SCAN           | LOC_COUNTRY_IX  |     1 |       |     0   (0)|          |                                                                                
Predicate Information (identified by operation id):                                                                                                                                
   5 - access("C"."COUNTRY_ID"='UK')                                                                                                                                               
   7 - access("C"."REGION_ID"="R"."REGION_ID")                                                                                                                                     
   9 - access("L"."COUNTRY_ID"='UK')                                                                                                                                               
PLAN_TABLE_OUTPUT                                                                                                                                                                  
  12 - access("C"."COUNTRY_ID"='NL')                                                                                                                                               
  14 - access("C"."REGION_ID"="R"."REGION_ID")                                                                                                                                     
  16 - access("L"."COUNTRY_ID"='NL')                                                                                                                                               
                                                                                                                                                                                    As you can see: WITH does not appear to get me any performance enhancement...

Similar Messages

  • Construct a Sql block using With Clause to improve the performance

    I have got four diff parametrized cursor in my Pl/Sql Procedure. As the performance of the Procedure is very pathetic,so i have been asked to tune the Select statements used in those cursors.
    So I am trying to use the With Clause in order to club all those four Select Statements.
    I would appreciate if anybody can help me to construct the Sql Block using With Clause.
    My DB version is..
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    Four Diff cursors are defined below.
    CURSOR all_iss (
          b_batch_end_date   IN   TIMESTAMP,
       IS
          SELECT isb.*
                FROM IMPLMN_STEP_BREKPN  isb
               , ISSUE iss
          WHERE isb.issue_id = iss.issue_id
           AND iss.issue_status_id  =  50738
           AND ewo_no IN
          (SELECT TO_CHAR(wo_no)
            FROM MGO_PLANT_AUDIT
           WHERE dml_status = 'U' OR dml_status = 'I')
          UNION ALL
          SELECT isb.*
           FROM IMPLMN_STEP_BREKPN  isb
            , ISSUE iss
           WHERE isb.issue_id = iss.issue_id
           AND iss.issue_status_id  =  50738
           AND CAST (isb.last_updt_timstm AS TIMESTAMP) >=
                                                                  b_batch_end_date;
          CURSOR ewo_plant  ( p_ewo_no IN  IMPLMN_STEP_BREKPN.ewo_no%TYPE)
          IS
          SELECT DISTINCT wo_no ,
          plant_code
          FROM MGO_PLANT
          WHERE TO_CHAR(wo_no) = p_ewo_no;
          CURSOR iss_ewo_plnt (
          p_issue_id IN IMPLMN_STEP_BREKPN.issue_id%TYPE ,
          p_ewo_no IN IMPLMN_STEP_BREKPN.EWO_NO%TYPE,
          p_plnt_code IN IMPLMN_STEP_BREKPN.PLT_FACLTY_ID%TYPE)
          IS
          SELECT *
          FROM IMPLMN_STEP_BREKPN
          WHERE issue_id = p_issue_id
          AND ewo_no = p_ewo_no
          AND
          (plt_faclty_id = p_plnt_code
          OR
          plt_faclty_id IS NULL);
          CURSOR iss_ewo_plnt_count (
          p_issue_id IN IMPLMN_STEP_BREKPN.issue_id%TYPE ,
          p_ewo_no IN IMPLMN_STEP_BREKPN.EWO_NO%TYPE,
          p_plnt_code IN IMPLMN_STEP_BREKPN.PLT_FACLTY_ID%TYPE)
          IS
          SELECT COUNT(*)
          FROM IMPLMN_STEP_BREKPN
          WHERE issue_id = p_issue_id
          AND ewo_no = p_ewo_no
          AND
          (plt_faclty_id = p_plnt_code
          OR
          plt_faclty_id IS NULL);

    Not tested. Some thing like below. i just made the queries as tables and given name as a,b,c and substituted columns for the parameters used in the 2nd cursor and third cursor. Try like this.
    CURSOR all_iss (
    b_batch_end_date IN TIMESTAMP,
    IS
    select a.*,b.*,c.* from
    ( SELECT isb.*
    FROM IMPLMN_STEP_BREKPN isb
    , ISSUE iss
    WHERE isb.issue_id = iss.issue_id
    AND iss.issue_status_id = 50738
    AND ewo_no IN
    (SELECT TO_CHAR(wo_no)
    FROM MGO_PLANT_AUDIT
    WHERE dml_status = 'U' OR dml_status = 'I')
    UNION ALL
    SELECT isb.*
    FROM IMPLMN_STEP_BREKPN isb
    , ISSUE iss
    WHERE isb.issue_id = iss.issue_id
    AND iss.issue_status_id = 50738
    AND CAST (isb.last_updt_timstm AS TIMESTAMP) >=
    b_batch_end_date) a,
    ( SELECT DISTINCT wo_no ,
    plant_code
    FROM MGO_PLANT
    WHERE TO_CHAR(wo_no) = p_ewo_no) b,
    ( SELECT *
    FROM IMPLMN_STEP_BREKPN
    WHERE issue_id = p_issue_id
    AND ewo_no = p_ewo_no
    plt_faclty_id IS NULL) c
    where b.wo_no = c.ewo_no and
    c.issue_id = a.issue_id ;
    vinodh
    Edited by: Vinodh2 on Jul 11, 2010 12:03 PM

  • Report with multiplying columns  and WITH clause

    Hello
    I saw sth strange in my report. I assume that it could happens very often.
    I have report with few columns which two of them ar most complicated (many joins subqueries aggreagations on joined values etc.) These two columns (i.e C3,C4) should be multiplied (C3*C4).
    When i do pure report without multiplying only columns C1,C2,C3,C4 everything is ok - duration about 15 sec. but... when I put next column on report which multiply these columns (in Answers C5=C3*C4)
    I wait 3-4 minutes and my database hungs :(. After investigation I saw that in first case to databese goes pure "SELECT" statement it means:
    "Select ... as C1, ... as C2, max(...) as C3, sum(xxx)... C4 from yyy,sss,ttt WHERE aaa"
    but in second case BI uses WITH clause it means:
    WITH SAWITH0 AS
    ( Select ... as C1, ... as C2, max(...) as C3, sum(xxx)... C4 from yyy,sss,ttt WHERE aaa )
    SELECT SAWITH0.C1 as C1,
    SAWITH0.C2 as C2,
         SAWITH0.C3 as C3,
         SAWITH0.C4 as C4,
         SAWITH0.C3*SAWITH0.C4 as C5 FROM SSS
    and this statement is long runninq query and kills my database :(.
    I checked that SQL like this:
    Select ... as C1, ... as C2, max(...) as C3, sum(xxx)... C4, max(...)*sum(xxx)... As C5 from yyy,sss,ttt WHERE aaa" -
    runs few times faster than that above
    I know that I can do this multiply in business model layer but sometimes users can multiply(or other operations) on columns in reports without my knowledge and it kills my db :(. Where is bug? Why SQLs with WITH clause takes so much db time?
    Thank you for each kind of help

    WITH clause or Subquery Factoring allows the set of data to be reused multiple times within the SQL. Oracle will usually materialize the data into a temporary table (you will see it if you take an explain plan of the SQL).
    I would be surprised if it was the actual WITH clause that was causing the performance issue, however you can test this by turning the WITH clause feature off. Go to the Physical model, right mouse click on your Database > Properties > Features Tab, scroll down to WITH_CLAUSE_SUPPORTED and switch it off.
    I'd be interested to know if you do see actual improvement.
    Good Luck.

  • Error in writing WITH CLAUSE

    i am writing these SQL Lines in my stored procedure i am using with clause i am getting error when i perform
    inner join
    With  WardItemsDtl as ( SELECT WardItemDtl_ID,
    WardTransID,
    wdDtl.ItemID,
    SUM(ItemQty) ItemQty,
    ReceivedWardID as WardID
    FROM LL_WardItems_Details wdDtl
    WHERE isposted = 0
    GROUP BY wdDtl.ItemID,WardItemDtl_ID,ReceivedWardID,WardTransID
    ORDER BY WardItemDtl_ID )
    , PartyItemsDtl AS ( SELECT WardItemDtl_ID,
    ItemID,
    SUM(IssueItemQty) IssueItemQty
    FROM LL_PartyItems_Details
    GROUP BY WardItemDtl_ID,ItemID
    ORDER BY WardItemDtl_ID )
    SELECT wdDt.WardTransID,
    wdDt.ItemID,
    itmt.ItemCode,
    itmt.ItemDescription,
    wdDt.ItemQty as TotalItemQty,
    NVL(pDtl.IssueItemQty, 0) as IssueQtyToParty,
    wdDt.WardID,
    wdmt.Ward_Name
    from WardItemsDtl wdDt,PartyItemsDtl pDtl
    inner join LLItemMst itmt
    on itmt.ItemID=wdDt.ItemID -----error in this line
    inner join ward_mst wdmt -- error in this line
    on wdmt.Ward_ID=wdDt.WardID
    error
    Error report:
    SQL Error: ORA-00904: "WDDT"."ITEMID": invalid identifier
    00904. 00000 - "%s: invalid identifier"
    *Cause:   
    *Action:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    WITH WARDITEMSDTL AS
      (SELECT WARDITEMDTL_ID,
        WARDTRANSID,
        WDDTL.ITEMID,
        SUM(ITEMQTY) ITEMQTY,
        RECEIVEDWARDID AS WARDID
      FROM LL_WARDITEMS_DETAILS WDDTL
      WHERE ISPOSTED = 0
      GROUP BY WDDTL.ITEMID,
        WARDITEMDTL_ID,
        RECEIVEDWARDID,
        WARDTRANSID
      ORDER BY WARDITEMDTL_ID
      PARTYITEMSDTL AS
      (SELECT WARDITEMDTL_ID,
        ITEMID,
        SUM(ISSUEITEMQTY) ISSUEITEMQTY
      FROM LL_PARTYITEMS_DETAILS
      GROUP BY WARDITEMDTL_ID,
        ITEMID
      ORDER BY WARDITEMDTL_ID
    SELECT WDDT.WARDTRANSID,
      WDDT.ITEMID,
      ITMT.ITEMCODE,
      ITMT.ITEMDESCRIPTION,
      WDDT.ITEMQTY              AS TOTALITEMQTY,
      NVL(PDTL.ISSUEITEMQTY, 0) AS ISSUEQTYTOPARTY,
      WDDT.WARDID,
      WDMT.WARD_NAME
    FROM WARDITEMSDTL WDDT,
      PARTYITEMSDTL PDTL,
    LLITEMMST ITMT,
    WARD_MST WDMT     
    WHERE ITMT.ITEMID=WDDT.ITEMID
    AND  WDMT.WARD_ID=WDDT.WARDID ;AND WHERE YOUR JOIN PARTYITEMSDTL PDTL

  • Since loading Lion, I've experienced much more instability than Snow Leopard. In particular, Mail crashes with regularity, full-screen apps seem to run slower and show the beach ball more often for longer, etc.  I'm disappointed with the performance. Any

    Since loading Lion, I've experienced much more instability than Snow Leopard. In particular, Mail crashes with regularity, full-screen apps seem to run slower and show the beach ball more often for longer, etc. I love the features, but I'm disappointed with the performance. Any help coming from Apple?  I've been sending them so many reports after crashes, that their file must be full!

    Summoning max. courage, I did what you advised. Here is the result. What does this tell you? My Lion 7.2 (mid 2011 iMac) has several annoying glitches (which I have so far tolerated through gritted teeth) but none that have actually stopped me working.
    BTW, I see several items involving CleanMyMac which I did not know I had. It is generally villified as a trouble-maker. Spotlight can't find an app. or a utility of that name. How can I get rid of what's there please? Just delete?
    Last login: Thu Nov  3 20:55:11 on console
    Steve-Kirkbys-iMac:~ stevekirkby$ kextstat -kl | awk ' !/apple/ { print $6 $7 } '
    com.AmbrosiaSW.AudioSupport(4.0)
    Steve-Kirkbys-iMac:~ stevekirkby$ sudo launchctl list | sed 1d | awk ' !/0x|apple|com\.vix|edu\.|org\./ { print $3 } '
    Password:
    com.openssh.sshd
    com.stclairsoft.DefaultFolderXAgent
    com.microsoft.office.licensing.helper
    com.bombich.ccc.scheduledtask.067493DB-2728-4DF3-87D8-092EF69086E8
    com.bombich.ccc
    com.adobe.SwitchBoard
    Steve-Kirkbys-iMac:~ stevekirkby$ launchctl list | sed 1d | awk ' !/0x|apple|edu\.|org\./ { print $3 } '
    com.sony.PMBPortable.AutoRun
    uk.co.markallan.clamxav.freshclam
    com.veoh.webplayer.startup
    com.macpaw.CleanMyMac.volumeWatcher
    com.macpaw.CleanMyMac.trashSizeWatcher
    com.adobe.ARM.202f4087f2bbde52e3ac2df389f53a4f123223c9cc56a8fd83a6f7ae
    com.adobe.AAM.Scheduler-1.0
    Steve-Kirkbys-iMac:~ stevekirkby$ ls -1A {,/}Library/{Ad,Compon,Ex,Fram,In,La,Mail/Bu,P*P,Priv,Qu,Scripti,Sta}* 2> /dev/null
    /Library/Components:
    /Library/Extensions:
    /Library/Frameworks:
    AEProfiling.framework
    AERegistration.framework
    ApplicationEnhancer.framework
    AudioMixEngine.framework
    FxPlug.framework
    NyxAudioAnalysis.framework
    PluginManager.framework
    ProFX.framework
    ProMetadataSupport.framework
    TSLicense.framework
    iLifeFaceRecognition.framework
    iLifeKit.framework
    iLifePageLayout.framework
    iLifeSQLAccess.framework
    iLifeSlideshow.framework
    /Library/Input Methods:
    /Library/Internet Plug-Ins:
    AdobePDFViewer.plugin
    EPPEX Plugin.plugin
    Flash Player.plugin
    Flip4Mac WMV Plugin.plugin
    JavaAppletPlugin.plugin
    Quartz Composer.webplugin
    QuickTime Plugin.plugin
    SharePointBrowserPlugin.plugin
    SharePointWebKitPlugin.webplugin
    Silverlight.plugin
    flashplayer.xpt
    iPhotoPhotocast.plugin
    nsIQTScriptablePlugin.xpt
    /Library/LaunchAgents:
    com.adobe.AAM.Updater-1.0.plist
    com.sony.PMBPortable.AutoRun.plist
    /Library/LaunchDaemons:
    com.adobe.SwitchBoard.plist
    com.apple.remotepairtool.plist
    com.bombich.ccc.plist
    com.bombich.ccc.scheduledtask.067493DB-2728-4DF3-87D8-092EF69086E8.plist
    com.microsoft.office.licensing.helper.plist
    com.stclairsoft.DefaultFolderXAgent.plist
    /Library/PreferencePanes:
    .DS_Store
    Application Enhancer.prefPane
    Default Folder X.prefPane
    DejaVu.prefPane
    Flash Player.prefPane
    Flip4Mac WMV.prefPane
    /Library/PrivilegedHelperTools:
    com.bombich.ccc
    com.microsoft.office.licensing.helper
    com.stclairsoft.DefaultFolderXAgent
    /Library/QuickLook:
    iWork.qlgenerator
    /Library/QuickTime:
    AppleIntermediateCodec.component
    AppleMPEG2Codec.component
    DesktopVideoOut.component
    DivX 6 Decoder.component
    FCP Uncompressed 422.component
    Flip4Mac WMV Advanced.component
    Flip4Mac WMV Export.component
    Flip4Mac WMV Import.component
    LiveType.component
    /Library/ScriptingAdditions:
    .DS_Store
    Adobe Unit Types.osax
    Default Folder X Addition.osax
    /Library/StartupItems:
    Library/Address Book Plug-Ins:
    Library/Frameworks:
    EWSMac.framework
    Library/Input Methods:
    .localized
    Library/Internet Plug-Ins:
    Library/LaunchAgents:
    com.adobe.AAM.Updater-1.0.plist
    com.adobe.ARM.202f4087f2bbde52e3ac2df389f53a4f123223c9cc56a8fd83a6f7ae.plist
    com.macpaw.CleanMyMac.trashSizeWatcher.plist
    com.macpaw.CleanMyMac.volumeWatcher.plist
    com.veoh.webplayer.startup.plist
    uk.co.markallan.clamxav.freshclam.plist
    Library/PreferencePanes:
    .DS_Store
    Perian.prefPane
    WindowShade X.prefPane
    Library/QuickTime:
    AC3MovieImport.component
    Perian.component
    Library/ScriptingAdditions:
    Steve-Kirkbys-iMac:~ stevekirkby$

  • Using WITH clause in Pro*Cobol

    Hi!
    I am trying to improve the performance of a query by introducing WITH clause.
    The query is in Pro*Cobol Release 9.2.0.6.0 - Production.
    I got compilation error
    WITH DPTCOST AS (
    ...............1
    PCB-S-00400, Encountered the symbol "DPTCOST" when expecting one of the following:
    END-EXEC
    ....continued
    So I wonder if we could use that clause at all with Pro*Cobol
    Here is the excerp of the code
    EXEC SQL
    DECLARE INPUT_ACTUAL CURSOR FOR
    WITH DPTCOST AS (
    SELECT /*+ rule */
    A.CODE_COMBINATION_ID,
    A.SEGMENT1, A.SEGMENT2, A.SEGMENT3,
    A.SEGMENT6,
    D.COSTING, D.PROCESS,
    D.MTL_CODE, D.FACTOR
    FROM
    GL_CODE_COMBINATION A,
    ALCGL_DEPARTMENT_COSTINGS D
    WHERE
    A.TEMPLATE_ID IS NULL
    AND A.SUMMARY_FLAG <> 'Y'
    AND A.SEGMENT1 = D.PLANT_NUMBER
    AND A.SEGMENT3 <> '6999001'
    AND A.SEGMENT3 <> '6999002'
    AND SUBSTR(A.SEGMENT2,4,3) = D.DEPARTMENT
    AND D.ACTUAL_FLAG = 'A'
    ) ... continued

    Materialized views are basically stored query results. They offer advanced functionality like query rewrite, refresh on commit, and more;
    http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_6002.htm
    Unlike a view, they actually store the results of the query - not just the query;
    SQL> create table t (cid number primary key)
    Table created.
    SQL> insert into t select object_id from dba_objects where object_id is not null
    12791 rows created.
    SQL> create materialized view mv
       as select * from t
    Snapshot created.
    SQL> select object_name, object_type from user_objects where object_name ='MV'
    OBJECT_NAME                    OBJECT_TYPE       
    MV                             TABLE             
    MV                             MATERIALIZED VIEW 
    2 rows selected.
    SQL> select segment_name, bytes from user_segments where segment_name in ('T', 'MV')
    SEGMENT_NAME                        BYTES
    T                                  196608
    MV                                 196608
    2 rows selected.Temporary tables are simply tables that are created then dropped. GLOBAL TEMPORARY TABLES have the advantage (or disadvantage) of only existing until commit or the end of the session. They results are visible to the user that inserted the data - but only temporarily;
    http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_7002.htm#sthref7483

  • WITH clause in CURSOR

    Hi,
    I was going through some docs on using WITH clause in curosr...but coulcn't understand.
    I was going through existing code for customization, that has 'WITH' clause.
    I'm trying to understand below piece of code.
    could you let me know what the below code is about..
      CURSOR CUR_CRK
      IS
      WITH PTLPM_WITH AS
        (SELECT
          /*+ INDEX(P_TR_LOAN_PAST_MONTHLY PK_P_TR_LOAN_PAST_MONTHLY) */
        FROM INF.P_TR_LOAN_PAST_MONTHLY
        WHERE POST_DATE    =P_POST_DATE
        AND TREND_GROUP_ID = 'M'
        AND APPL_ID       IN ('FL','LN')
      UIGL_INF_WITH AS
      (SELECT * FROM INF.U_IM_GALL_LOAN
      XHCC_INF_WITH as
      (SELECT * FROM DWC.XREF_HIER_COST_CENTER_11SEP12 --INF.XREF_HIER_COST_CENTER
      )Thanks.

    Perhaps a simple example will make it clear...
    SQL> ed
    Wrote file afiedt.buf
      1  select e.empno, e.ename, d.dname
      2  from        (select * from emp) e
      3         join (select * from dept) d
      4*        on   (e.deptno = d.deptno)
    SQL> /
         EMPNO ENAME      DNAME
          7369 SMITH      RESEARCH
          7499 ALLEN      SALES
          7521 WARD       SALES
          7566 JONES      RESEARCH
          7654 MARTIN     SALES
          7698 BLAKE      SALES
          7782 CLARK      ACCOUNTING
          7788 SCOTT      RESEARCH
          7839 KING       ACCOUNTING
          7844 TURNER     SALES
          7876 ADAMS      RESEARCH
          7900 JAMES      SALES
          7902 FORD       RESEARCH
          7934 MILLER     ACCOUNTING
    14 rows selected.Ok, a bit of a nonsense query in itself, but it's demonstrating that we have two subqueries that we are getting our data from.
    Now, writing the same query using a WITH clause...
    SQL> ed
    Wrote file afiedt.buf
      1  with e as (select * from emp)
      2      ,d as (select * from dept)
      3  select e.empno, e.ename, d.dname
      4* from   e join d on (e.deptno = d.deptno)
    SQL> /
         EMPNO ENAME      DNAME
          7369 SMITH      RESEARCH
          7499 ALLEN      SALES
          7521 WARD       SALES
          7566 JONES      RESEARCH
          7654 MARTIN     SALES
          7698 BLAKE      SALES
          7782 CLARK      ACCOUNTING
          7788 SCOTT      RESEARCH
          7839 KING       ACCOUNTING
          7844 TURNER     SALES
          7876 ADAMS      RESEARCH
          7900 JAMES      SALES
          7902 FORD       RESEARCH
          7934 MILLER     ACCOUNTING
    14 rows selected.As you can see, the subqueries have been moved out of the main query and put into the WITH clause, and then the main query just references those subqueries aliases.
    In the above example, there's not much point in doing this, but in more complex queries, you may have a subquery that is used several times, in which case having it in the WITH clause means that that subquery is processed just once and used many times, (you can also look at the MATERIALIZE hint to help improve performance with such subqueries if necessary)
    The difficulty with finding this in the documentation is because you will no doubt be trying to search for "WITH", which isn't a very good search term to be using as it's used in the english language too much for an accurate hit... so... when you learn it's called "Subquery Factoring" (because you are factoring out the subqueries from the main query), it then becomes easier to find...
    http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_10002.htm#i2161315
    ... and you see it's included as part of the documentation for the SQL SELECT statement.

  • How to create a view  with "WITH CLAUSE"

    Hi,
    I have a query with "WITH" CLAUSE , I need to create a view on this query. But I am getting error like
    ORA-32034 : Unsupported sue of WITH clause.
    Please help me...!!
    Please find below my query...!!
    WITH RANGE
             AS (SELECT A.MASTERMACHINEID,
                        a.startdate,
                        a.enddate,
                        a.startdate - (1 / 3) + (lvl) * 1 / 3 SHIFT_ST_DT,
                        a.startdate + (lvl) * 1 / 3 AS SHIFT_END_DT,
                        a.quantity,
                        (LEAST ( enddate, TODATE) - GREATEST ( FROMDATE, startdate)) * 24 TOTAL_HRS,
                        (enddate - startdate) * 24 AVAIL,
                       todate,
                       fromdate
                  FROM OMP A,
                       (SELECT LEVEL lvl
                          FROM (SELECT MAX (enddate - startdate) AS diff FROM OMPWORKORDER)
                        CONNECT BY LEVEL <= (diff) * 3),
                       MASTER B
                 WHERE A.MASTERMACHINEID = B.MASTERMACHINEID
                   AND lvl / 3 <=(enddate - startdate) + 1
                ORDER BY SHIFT_ST_DT)
       SELECT shift_date,
              shift_num,
              shift_hrs,
              DECODE (SIGN (SHUT_DWN_TIME), -1, 0, SHUT_DWN_TIME),
              8 - DECODE (SIGN (SHUT_DWN_TIME), -1, 0, SHUT_DWN_TIME) shift_avail_hrs,
              qty,
              total_qty
         FROM (SELECT TRUNC (SHIFT_ST_DT) shift_date,
                      ROW_NUMBER () OVER (PARTITION BY TRUNC (SHIFT_ST_DT) ORDER BY SHIFT_ST_DT) shift_num,
                      8 shift_hrs,
                      (LEAST ( SHIFT_END_DT, TODATE) - GREATEST ( FROMDATE, SHIFT_ST_DT)) * 24
                        SHUT_DWN_TIME,
                      quantity / (avail - TOTAL_HRS) qty,
                      round(((SHIFT_END_DT - SHIFT_ST_DT) * 24 - (LEAST (SHIFT_END_DT, TODATE) - GREATEST (FROMDATE, SHIFT_ST_DT)) * 24)  * QuantiTY / (AVAIL - TOTAL_HRS),2)
                         TOTAL_QTY
                 FROM RANGE A );Regards
    KPR
    Edited by: BluShadow on 17-Mar-2011 09:48
    added {noformat}{noformat} tags for readability                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Try creating view on following query, if it can help you:
    SELECT shift_date,
        shift_num,
        shift_hrs,
        decode(SIGN(shut_dwn_time),     -1,     0,     shut_dwn_time),
        8 -decode(SIGN(shut_dwn_time),     -1,     0,     shut_dwn_time) shift_avail_hrs,
        qty,
        total_qty
    FROM
            SELECT TRUNC(shift_st_dt) shift_date,
                 row_number() over(PARTITION BY TRUNC(shift_st_dt)
             ORDER BY shift_st_dt) shift_num,
                 8 shift_hrs,
                (least(shift_end_dt,      todate) -greatest(fromdate,      shift_st_dt)) *24 shut_dwn_time,
                 quantity /(avail -total_hrs) qty,
                 ROUND(((shift_end_dt -shift_st_dt) *24 -(least(shift_end_dt,      todate) -greatest(fromdate,      shift_st_dt)) *24) *quantity /(avail -total_hrs),      2) total_qty
             FROM
                  SELECT a.mastermachineid,
                     a.startdate,
                     a.enddate,
                     a.startdate -(1 / 3) +(lvl) *1 / 3 shift_st_dt,
                     a.startdate +(lvl) *1 / 3 AS
                 shift_end_dt,
                     a.quantity,
                    (least(enddate,      todate) -greatest(fromdate,      startdate)) *24 total_hrs,
                    (enddate -startdate) *24 avail,
                     todate,
                     fromdate
                 FROM omp a,
                        (SELECT LEVEL lvl
                     FROM
                        (SELECT MAX(enddate -startdate) AS
                        diff
                         FROM ompworkorder)
                    CONNECT BY LEVEL <=(diff) *3),
                     master b
                 WHERE a.mastermachineid = b.mastermachineid
                 AND lvl / 3 <=(enddate -startdate) + 1
                 ORDER BY shift_st_dt
             ) a
    ;Regards,
    Dipali.l

  • Bug in WITH clause (subquery factoring clause) in Oracle 11?

    I'm using WITH to perform a set comparison in order to qualify a given query as correct or incorrect regarding an existing solution. However, the query does not give the expected result - an empty set - when comparing the solution to itself in Oracle 11 whereas it does in Oracle 10. A minimal example os posted below as script. There are also some observations about changes to the tables or the query that make Oracle 11 returning correct results but in my opinion these changes must not change the semantics of the queries.
    Is this a bug or am I getting something wrong? The Oracle versions are mentioned in the script.
    -- Bug in WITH clause (subquery factoring clause)
    -- in Oracle Database 11g Enterprise Edition 11.2.0.1.0?
    DROP TABLE B PURGE;
    DROP TABLE K PURGE;
    DROP TABLE S PURGE;
    CREATE TABLE S (
         m     number NOT NULL,
         x     varchar2(30) NOT NULL
    CREATE TABLE K (
         k char(2) NOT NULL,
         x varchar2(50) NOT NULL
    CREATE TABLE B (
         m     number NOT NULL ,
         k char(2) NOT NULL ,
         n     number
    INSERT INTO S VALUES(1, 'h');
    INSERT INTO S VALUES(2, 'l');
    INSERT INTO S VALUES(3, 'm');
    INSERT INTO K VALUES('k1', 'd');
    INSERT INTO K VALUES('k2', 'i');
    INSERT INTO K VALUES('k3', 'm');
    INSERT INTO K VALUES('k4', 't');
    INSERT INTO K VALUES('k5', 't');
    INSERT INTO K VALUES('k6', 's');
    INSERT INTO B VALUES(1, 'k1', 40);
    INSERT INTO B VALUES(1, 'k2', 30);
    INSERT INTO B VALUES(1, 'k4', 50);
    INSERT INTO B VALUES(3, 'k1', 10);
    INSERT INTO B VALUES(3, 'k2', 20);
    INSERT INTO B VALUES(3, 'k1', 30);
    INSERT INTO B VALUES(3, 'k6', 90);
    COMMIT;
    ALTER TABLE S ADD CONSTRAINT S_pk PRIMARY KEY (m);
    ALTER TABLE K ADD CONSTRAINT K_pk PRIMARY KEY (k);
    ALTER TABLE B ADD CONSTRAINT B_S_fk
    FOREIGN KEY (m) REFERENCES S(m) ON DELETE CASCADE;
    CREATE OR REPLACE VIEW v AS
    SELECT S.m, B.n
    FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
    WHERE K.x='d'
    ORDER BY B.n DESC;
    -- Query 1: Result should be 0
    WITH q AS
    SELECT S.m, B.n
    FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
    WHERE K.x='d'
    ORDER BY B.n DESC
    SELECT COUNT(*)
    FROM
    SELECT * FROM q
    MINUS
    SELECT * FROM v
    UNION ALL
    SELECT * FROM v
    MINUS
    SELECT * FROM q
    -- COUNT(*)
    -- 6
    -- 1 rows selected
    -- Query 2: Result set should be empty (Query 1 without counting)
    WITH q AS
    SELECT S.m, B.n
    FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
    WHERE K.x='d'
    ORDER BY B.n DESC
    SELECT *
    FROM
    SELECT * FROM q
    MINUS
    SELECT * FROM v
    UNION ALL
    SELECT * FROM v
    MINUS
    SELECT * FROM q
    -- M N
    -- null 10
    -- null 30
    -- null 40
    -- 1 40
    -- 3 10
    -- 3 30
    -- 6 rows selected
    -- Observations:
    -- Incorrect results in Oracle Database 11g Enterprise Edition 11.2.0.1.0:
    -- Query 1 returns 6, Query 2 returns six rows.
    -- Correct in Oracle Database 10g Enterprise Edition 10.2.0.1.0.
    -- Correct without the foreign key.
    -- Correct if attribute x is renamed in S or K.
    -- Correct if attribute x is left out in S.
    -- Correct without the ORDER BY clause in the definition of q.
    -- Only two results if the primary key on K is left out.
    -- Correct without any change if not using WITH but subqueries (see below).
    -- Fixed queries
    -- Query 1b: Result should be 0
    SELECT COUNT(*)
    FROM
    SELECT * FROM
    SELECT S.m, B.n
    FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
    WHERE K.x='d'
    ORDER BY B.n DESC
    MINUS
    SELECT * FROM v
    UNION ALL
    SELECT * FROM v
    MINUS
    SELECT * FROM
    SELECT S.m, B.n
    FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
    WHERE K.x='d'
    ORDER BY B.n DESC
    -- COUNT(*)
    -- 0
    -- 1 rows selected
    -- Query 2b: Result set shoud be empty (Query 1b without counting)
    SELECT *
    FROM
    SELECT * FROM
    SELECT S.m, B.n
    FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
    WHERE K.x='d'
    ORDER BY B.n DESC
    MINUS
    SELECT * FROM v
    UNION ALL
    SELECT * FROM v
    MINUS
    SELECT * FROM
    SELECT S.m, B.n
    FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
    WHERE K.x='d'
    ORDER BY B.n DESC
    -- M N
    -- 0 rows selected

    You're all gonna love this one.....
    The WITH clause works. But not easily.
    Go ahead, build the query, (as noted in a recent thread, I, too, always use views), set the grants and make sure DISCOVERER and EULOWNER have SELECT privs.
    1. Log into Disco Admin as EULOWNER. Trust me.
    2. Add the view as a folder to the business area.
    3. Log into Disco Desktop as EULOWNER. Don't laugh. It gets better.
    4. Build the workbook and the worksheet (or just the worksheet if apropos)
    5. Set the appropriate "sharing" roles and such
    6. Save the workbook to the database.
    7. Save the workbook to your computer.
    8. Log out of Desktop.
    9. Log back into Desktop as whatever, whoever you usually are to work.
    10. elect "open existing workbook"
    11. Select icon for "open from my computer". See? I told you it would get better!
    12. Open the save .dis file from your computer.
    13. Save it to the database.
    14. Open a web browser and from there, you're on your own.
    Fortran in VMS. Much easier and faster. I'm convinced the proliferation of the web is a detriment to the world at large...On the other hand, I'm also waiting for the Dodgers to return to Brooklyn.

  • Select data from database tables with high performance

    hi all,
    how to select data from different database tables with high performance.
    im using for all entries instead of inner joins, even though burden on data base tables is going very high ( 90 % in se30)
    hw to increase the performance.
    kindly, reply.
    thnks

    Also Check you are not using open sql much like distict order by group by , use abap techniques on internal table to acive the same.
    also Dont use select endselect.
    if possible use up to n rows claus....
    taht will limit the data base hits.
    also dont run select in siode any loops.
    i guess these are some of the trics oyu can use to avoid frequent DATA BASE HITS AND ABVOID THE DATA BASE LAOD.

  • WITH clause in reports

    Just a quick question about Reports 10g, does it support queries using the WITH clause? i.e.
    WITH alias as (subquery)
    SELECT col1, col2...
    FROM aliasI can't find anything on the documentation on the OTN site. Reports 9iR2 croaks with this unfortunately.
    Regards,
    Steve Rooney

    That is what I have had to do. I wanted to use the WITH clause because subquery has to be done twice so that I can perform some arithmetic on the result sets. Using the WITH construct I only need to define subquery once and re-use the result set; as a result the version using the WITH clause runs twice as fast in SQL*Plus as the way I have implemented the inline views.
    Thanks anyway.
    Regards,
    Steve Rooney

  • With Clause in Pro*C?

    Is it possible to use version 9's with clause (aka
    subquery factoring) within pro*C? Queries that work
    fine in SQL*Plus cause the pre-compiler to fail. For
    example:
    SQL> with test as (select 1 one from dual)
    2 select * from test
    3 /
    ONE
    1
    Taking the same query and embedding it in a Pro*C program,
    produces the following results:
    EXEC SQL
    with test as (select 1 one from dual)
    SELECT *
    INTO :n
    FROM test;
    $ proc ora_test.pc
    Pro*C/C++: Release 9.2.0.5.0 - Production on Mon Dec 20 13:27:16 2004
    Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
    System default option values taken from: /ora/product/9.2.0/precomp/admin/pcscfg.cfg
    Syntax error at line 20, column 7, file ora_test.pc:
    Error at line 20, column 7 in file ora_test.pc
    with test as (select 1 one from dual)
    ......1
    PCC-S-02201, Encountered the symbol "with" when expecting one of the following:
    for, register, at, close, commit, connect, declare, describe,
    execute, fetch, open, prepare, rollback, select, whenever,
    alter, audit, comment, create, delete, drop, get, grant,
    insert, lock, noaudit, rename, revoke, set, update, validate,
    arraylen, allocate, cache, call, collection, context,
    deallocate, enable, free, lob, object, savepoint, analyze,
    explain, truncate,
    The symbol "alter," was substituted for "with" to continue.
    Parser error at line 22, column 15, file ora_test.pc:
    Error at line 22, column 15 in file ora_test.pc
    INTO :n
    ..............1
    PCC-S-02206, Host variables are not permitted within a DDL statement
    Error at line 0, column 0 in file ora_test.pc
    PCC-F-02102, Fatal error while doing C preprocessing

    I suppose that the 'with clause ' is a new feature of ORACLE9 ? Well, lets dive in the fabulous world of ORACLE development :
    When the parser of ORACLE9 has been enhanced to accept ORACLE9 new features and syntax (especially the SQL1999 join syntax), the parser of PRO*C and PRO*Cobol still stayed at the ORACLE8 syntax level. The parser is at the Precompiler side.
    This means that you have NO CHANCE to even precompile a ORACLE9 syntax SQL statement with any precompiler tool.
    This is not a bug (from metalink) because the Oracle Development project for the new parser has not been started yet. I the product is not developped, it is not a bug , and i understand that they cannot correct the flaw.
    This is not corrected in any known ORACLE10 version - just because the project has not yet started !!!
    The only workaround that i have found consists in using a View which contains the syntax. This works fine for JOIN queries, i do not have tested for the 'with clause'.
    Maybe other workarounds available at the metalink side.
    Regards
    Frederic

  • Syntax help needed in update using 'WITH' Clause

    Update     CP_JP_CORP_FSASA_FEEDUPLOAD_r r
                             set     (
                                   gfrn,                              
                                   tenor_code,
                                   tenor_description,
                                   exposure_category,          
                                   frr,          
                                   facility_classification,
                                   limit_amount,
                                   limit_usd,
                                   approval_ccy,
                                   approval_date,
                                   expiry_date,
                                   avail_status_code,
                                   avail_status_desc,
                                   revolving_indicator,
                                   committed_flag,
                                   committed_until_date,
                                   committed_amount,
                                   advised_flag,
                                   advised_amount,
                                   facility_long_description,
                                   booking_unit_code,
                                   extending_unit_code,
                                   extending_unit_short_desc,
                                   approving_unit_code,
                                   approving_unit_short_des,
                                   transaction_type,
                                   branch_no
                                   =
                                            With t as
                                                 Select     fac.gfrn,fac.tenor_code,fac.tenor_description,fac.exposure_category,fac.frr,
                                                      fac.facility_classification,fac.limit_amount,fac.limit_usd,fac.approval_ccy,
                                                      fac.approval_date,fac.expiry_date,fac.avail_status_code,fac.avail_status_desc,
                                                      fac.revolving_indicator,fac.committed_flag,fac.committed_until_date,fac.committed_amount,
                                                      fac.advised_flag,fac.advised_amount,fac.facility_long_description,fac.booking_unit_code,
                                                      fac.extending_unit_code,fac.extending_unit_short_desc,fac.approving_unit_code,fac.approving_unit_short_des,
                                                      /*'Check' normalflag,
                                                      cust.adjusted_orr fsasaorr1stborrower,
                                                      'Normal' category1stborrower,
                                                      cust.adjusted_orr fsasaorr2ndborrower,
                                                      'Normal' category2ndborrower,
                                                      cust.adjusted_orr fsasaorrfinal,
                                                      'Normal' categoryfinal */
                                                      txn.transaction_type,txn.branch_no,txn.gfcid,txn.transaction_id
                                                 from     cp_fsa_boj_corp_cr_fac_hist fac,
                                                           --cp_fsa_boj_corp_cr_cust_hist cust,
                                                           cp_fsa_boj_corp_cr_txn_hist txn
                                                 where     fac.gfcid = txn.gfcid
                                                           and fac.facility_id = txn.facility_id
                                                           and fac.as_of_date = txn.as_of_date
                                                           and to_char(fac.as_of_date,'yyyymm') = p_financial_period
                                                           and fac.as_of_date = last_day(fac.as_of_date)
                                            select      t.gfrn,
                                                      t.tenor_code,
                                                      t.tenor_description,
                                                      t.exposure_category,
                                                      t.frr,
                                                      t.facility_classification,
                                                      t.limit_amount,
                                                      t.limit_usd,                                             
                                                      t.approval_ccy,                                             
                                                      t.approval_date,                                             
                                                      t.expiry_date,                                             
                                                      t.avail_status_code,                                             
                                                      t.avail_status_desc,                                             
                                                      t.revolving_indicator,                                             
                                                      t.committed_flag,                                             
                                                      t.committed_until_date,                                             
                                                      t.committed_amount,                                             
                                                      t.advised_flag,                                             
                                                      t.advised_amount,                                             
                                                      t.facility_long_description                                             
                                                      t.booking_unit_code,                                             
                                                      t.extending_unit_code,                                             
                                                      t.extending_unit_short_desc,                                        
                                                      t.approving_unit_code,                                             
                                                      t.approving_unit_short_des,                                             
                                                      t.transaction_type,
                                                      t.branch_no
                                            from     t
                                       where      r.financialperiod           = p_financial_period
                                                 and exists
                                                           Select     1
                                                           from     t
                                                           where     t.transaction_id = r.ce_trans_id
                                                      )I'm facing syntax problem

    Hii All,
    This is my actual update.(I stopped performing dml operations in cursors following Karthick Arp) :-)
    Update     CP_JP_CORP_FSASA_FEEDUPLOAD_r r
                             set     (
                                   gfrn,                              
                                   tenor_code,
                                   tenor_description,
                                   exposure_category,          
                                   frr,          
                                   facility_classification,
                                   limit_amount,
                                   limit_usd,
                                   approval_ccy,
                                   approval_date,
                                   expiry_date,
                                   avail_status_code,
                                   avail_status_desc,
                                   revolving_indicator,
                                   committed_flag,
                                   committed_until_date,
                                   committed_amount,
                                   advised_flag,
                                   advised_amount,
                                   facility_long_description,
                                   booking_unit_code,
                                   extending_unit_code,
                                   extending_unit_short_desc,
                                   approving_unit_code,
                                   approving_unit_short_des,
                                   transaction_type,
                                   branch_no
                                   = (          
                                       Select     fac.gfrn,fac.tenor_code,fac.tenor_description,fac.exposure_category,fac.frr,
                                            fac.facility_classification,fac.limit_amount,fac.limit_usd,fac.approval_ccy,
                                            fac.approval_date,fac.expiry_date,fac.avail_status_code,fac.avail_status_desc,
                                            fac.revolving_indicator,fac.committed_flag,fac.committed_until_date,fac.committed_amount,
                                            fac.advised_flag,fac.advised_amount,fac.facility_long_description,fac.booking_unit_code,
                                            fac.extending_unit_code,fac.extending_unit_short_desc,fac.approving_unit_code,fac.approving_unit_short_des,
                                            txn.transaction_type,txn.branch_no
                                       from     cp_fsa_boj_corp_cr_fac_hist fac,
                                                 --cp_fsa_boj_corp_cr_cust_hist cust,
                                                 cp_fsa_boj_corp_cr_txn_hist txn
                                       where     fac.gfcid = txn.gfcid
                                                 and fac.facility_id = txn.facility_id
                                                 and fac.as_of_date = txn.as_of_date
                                                 and to_char(fac.as_of_date,'yyyymm') = p_financial_period
                                                 and fac.as_of_date = last_day(fac.as_of_date)
                             where Exists
                                                 Select     1
                                                 from     cp_fsa_boj_corp_cr_fac_hist fac,
                                                           cp_fsa_boj_corp_cr_txn_hist txn
                                                 where     fac.gfcid = txn.gfcid
                                                           and fac.facility_id = txn.facility_id
                                                           and fac.as_of_date = txn.as_of_date
                                                           and to_char(fac.as_of_date,'yyyymm') = p_financial_period
                                                           and fac.as_of_date = last_day(fac.as_of_date)
                                                           and txn.transaction_id = r.ce_trans_id
                                            )Now in my update I'm using same 'SELECT' twice once in 'SET' and again in 'EXISTS' clause. I'd like to make use of 'WITH' Clause and avoid unnecessary 'SELECT' . Please help me.

  • How to use subquery factoring ("with" clause) in OWB?

    Hi,
    Is it possible to use subquery factoring (popularly known as "with" clause) in OWB 10gR2? I have a mapping with a splitter and union-all, which generates a query that has repeated scans of the same table. Subquery Factoring would be very useful here. I think this is a very common situation, so, I hope there's a way to achieve this. (If not in this version, this would be my wishlist item for the next version.)
    Appreciate your help.
    Regards,
    Rahul

    Hi Rahul,
    I'm afraid you have to put this on your wishlist. You may put the query with the "with"-clause into a view (or table function if you need parameters) if performance is too bad. But that is somehow against the idea (and benefits) of owb.
    Another possibility is to use a temporary table and spilt the mappings into two parts: first fill the temp table, then the target table.
    Regards,
    Carsten.

  • PL/SQL WITH Clause

    Hi Gurus,
    I have been trying to find more information regarding the WITH CLAUSE, but most of the info I find is related to Forums. Do you know where i could find Oracle specific documentation on this? I really like using that clause, but i have noticed some drastic performance differences with it compared to the same query run outside of the WITH CLAUSE.
    Just wanted to find some documentation on it and can't seem to find anything.
    As always greatly appreciate the info/feedback.
      Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
      PL/SQL Release 10.2.0.3.0 - Production
      CORE     10.2.0.3.0     Production
      TNS for Linux: Version 10.2.0.3.0 - Production
      NLSRTL Version 10.2.0.3.0 - ProductionThanks,
    S

    Here it goes:
    Using With Clause:
    11g
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10578/tdpdw_sql.htm#TDPDW0073
    10g
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14223/aggreg.htm#sthref1670
    subquery_factoring_clause:
    11g
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/statements_10002.htm#SQLRF01702
    10g
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10002.htm#SQLRF01702
    Edited by: fsitja on Apr 15, 2010 5:14 PM

Maybe you are looking for

  • How to connect to my router through airport

    I can connect to my router configuration page when i use a direct ethernet connection, and use 192.168.1.1 in Safari. However, does any one know how i access this page when the router is plugged into my airport base station, and i am wirelessly conne

  • F110 - An email ID for remittance to vendors?

    When payment is done through F110, an email should go to the vendor with the payment details We have a requirement currently to send emails to vendors. I have searched in the forum got enough answers, still I have few more questions regarding the set

  • Bank reconciliation Blocking

    Dear Friends, I face a blocking situation concerning the Bank reconciliation. Indeed, the reconciliation can not be done between the advance payment made ​​during the month of January and the invoice for the month of March. Is there any workaround? T

  • Create new user like another user with select privilege???

    our user requested create another user similar to "apps" , but only "selec t" privilege to "apps" objects and other user's objects which grant to "apps". In this case they can use tool login and do some work. Does anyone know how to "create a new use

  • Change Port for OID 11.1.1.6 Admin server weblogic 10.3.6

    Hello, Want to know if there is any documentation about how to change OID Weblogic Admin Server Port (7001) to different value (weblogic 10.3.6), ina way that OID , OVD , ODSM could continue to start. Regards