Determine completed % for a query

Oracle 9.2.0.8
SQL*Plus
I have a huge table. If I delete some records from that table, because of a huge number it's not completing in 1 hr. then I kill the session.
Is there any way to know how may records has been processed (deleted), before I kill the session?
In this case, after 1 hr if it has processed 80% of records I can determine how much time it's going to take.
Giving generic example as I am facing this situation may times.
Thanks

Hi,
USe this query regularly and you find a big difference in used or free space.
1 SeT lines 300
2 SET verify OFF
3 SET pages 40
4 COLUMN pct_used format 999.99 heading "%|Used"
5 COLUMN pct_free format 999.99 heading "%|Free"
6 COLUMN NAME format a16 heading "Tablespace Name"
7 COLUMN mbytes format 999,999,999.99 heading "Total|MB"
8 COLUMN used format 999,999,999.99 heading "Used|MB"
9 COLUMN free format 999,999,999.99 heading "Free|MB"
10 COLUMN largest format 999,999,999.99 heading "Largest"
11 BREAK ON report
12 COMPUTE SUM OF mbytes ON report
13 COMPUTE SUM OF free ON report
14 COMPUTE SUM OF used ON report
15 -- PROMPT ORDER BY:
16 -- PROMPT 1:TABLESPACE NAME
17 -- PROMPT 2:total mbytes
18 -- PROMPT 3:used Mb
19 -- PROMPT 4:free mb
20 -- PROMPT 5:% used
21 -- PROMPT 6:% free
22 -- define orderby=5 desc
23 SELECT NVL (b.tablespace_name, NVL (a.tablespace_name, 'UNKOWN')) NAME,
24 mbytes_alloc mbytes, mbytes_alloc - NVL (mbytes_free, 0) used,
25 NVL (mbytes_free, 0) free,
26 ((mbytes_alloc - NVL (mbytes_free, 0)) / mbytes_alloc)
27 * 100 pct_used,
28 100
29 - (((mbytes_alloc - NVL (mbytes_free, 0)) / mbytes_alloc) * 100)
30 pct_free
31 FROM (SELECT SUM(BYTES) / 1024 / 1024 mbytes_free, tablespace_name
32 FROM SYS.dba_free_space
33 GROUP BY tablespace_name) a,
34 (SELECT SUM(BYTES) / 1024 / 1024 mbytes_alloc, tablespace_name
35 FROM SYS.dba_data_files
36 GROUP BY tablespace_name) b
37 WHERE a.tablespace_name(+) = b.tablespace_name
38 UNION ALL
39 SELECT f.tablespace_name,
40 SUM (ROUND((f.bytes_free + f.bytes_used) / 1024 / 1024, 2)
41 ) "total MB",
42 SUM (ROUND(NVL (p.bytes_used, 0) / 1024 / 1024, 2)) "Used MB",
43 SUM (ROUND ( ((f.bytes_free + f.bytes_used) - NVL (p.bytes_used, 0)
44 )
45 / 1024
46 / 1024,
47 2
48 )
49 ) "Free MB",
50 (SUM (ROUND (NVL (p.bytes_used, 0) / 1024 / 1024, 2)) * 100)
51 / (SUM (ROUND ((f.bytes_free + f.bytes_used) / 1024 / 1024, 2))),
52 100
53 - (SUM (ROUND (NVL (p.bytes_used, 0) / 1024 / 1024, 2)) * 100)
54 / (SUM (ROUND ((f.bytes_free + f.bytes_used) / 1024 / 1024, 2)))
55 FROM SYS.v_$temp_space_header f,
56 dba_temp_files d,
57 SYS.v_$temp_extent_pool p
58 WHERE f.tablespace_name(+) = d.tablespace_name AND f.file_id(+) = d.file_id
59 AND p.file_id(+) = d.file_id
60 GROUP BY f.tablespace_name
61 ORDER BY 5 desc.
Regards
Jafar

Similar Messages

  • Strategy for ensuring replication is complete before initating query from source system

    Hi,
    I am using HANA as a side-car scenario with reports running in SAP ECC being accelerated by querying replicated tables in SAP HANA instead. This works well, however I don't have a good mechanism to validate before running a report whether the underlying data has already been replicated to HANA or is still queued up.
    Often users would want to run the reports soon after large data changes have been made in the source tables. It is unknown, based on the overall workload, how long it might take for the most recently written records to get replicated to the corresponding HANA table.
    What is a good practice approach to handle this. I have seen some separate threads on doing record counts between HANA and ECC. I think that is not a good idea at all. Firstly, for large tables, the time overhead of doing the record count is very large. In the time it takes for me to query the record count in ECC, the HANA report could have run 10 times over. But more importantly, for very large source tables, I may have opted to only replicate more recent data, leaving old historical data from ECC un-replicated to HANA.
    I know this is not a new problem. SAP must have already addressed it a number of ways for their own delivered application accelerators. The COPA accelerator for instance must be doing something along these lines. Possibly querying most recent records in ECC and comparing them to the most recent records in HANA for the same tables might be a way to go.
    Does anyone else have insights into how to best approach this? Does SLT expose a mechanism to check whether replication is completed for any given table?
    thanks,
    Nitin Goel

    Hi Nitin,
    SLT can never confirm whether replication is completed for any given table..Replication is a continous process,if records are there in the logging table of ECC then that will be replicated via SLT.
    So the best way to check Replication completion is :
    1. Go to SE16(ECC)--give the Logging table for which you want to check the replication.Copy the Logginng table from LTRC.If the number of entries is 0,then nothing is there in the logging table.
    You can verify the replication in LTRC(SLT)--Expert functions to check replication is working fine or not.
    2. Then go toi SE16(ECC)--Check the number of entries of the original table
    3. Check in HANA--The number of entries should be same as the source table.
    It takes a minute to verfify each table replication,not more than that.
    Regards,
    Joydeep.

  • Could not determine value for variable 0P_FVAEX (or 0P_CTPCA)

    I get the below error while accessing a query on the planning Info Cube. I used the SAP Exit variable Most Current Data (Transactional InfoCube) (0S_RQTRA) in the query for the Characteristic - Request ID (0REQUID) to extract the data from the yellow request too.
    I do not use the below variables as in the below eror in my query at all. Please assist.
    Diagnosis
    This error diagnosis is specific only to the variables 0P_FVAEX or 0P_CTPCA !
    Termination message BRAIN 632 appears:
    Could not determine value for variable 0P_FVAEX (or 0P_CTPCA).
    System Response
    1.     Operation method of SAP-Exit-Variables 0P_FVAEX or 0P_CTPCA
    With queries from the CO application, both SAP-Exit-Variables look for an entry for 'controlling area'. With this controlling area from the selection screen, the SAP-Exit-Variables program reads the attributes for InfoObject 0CO_AREA (controlling area).
    With queries from the FI application, the SAP Exit Variable 0P_FVAEX looks for an entry for 'company code'. With this company code from the selection screen, the SAP Exit Variables program reads the attributes for InfoObject 0COMP_CODE (Company Code).
    0P_FVAEX determines the fiscal year variant (attribute 0FISCVARNT) from the attributes for 0CO_AREA (CO queries) or 0COMP_CODE (FI queries). 0P_CTPCA determines the currency type of the profit center local currency (attribute 0CURTP_PCA) from the attributes for 0CO_AREA.

    Hello,
    you need to take a closer look at your query. Somewhere you used one of the 0P_* exit variables, which work only for controlling related InfoCubes. Use your own variables.
    Regards,
    Marc
    SAP NetWeaver RIG

  • "Partner Determination Steps  for Customer Master" clarification

    Hi,
    Let me clear myself at the outset itself, that I searched SDN for my below mentioned query, however I could not find any answer to my satisfaction....here I am posting again
    In "Partner Determination for Customer Master", the following steps are undertaken -
    Step 1:
    1.a.) Create New Partner Determination Procedure 
    1.b.) For each Partner Determination Procedure, different Partner Functions, which are applicable for that specific determination procedure, are assigned. (along with other properties like if the PF is mandatory, not modifiable )
    Step2:
    "Partner Determination Procedure Assignment", here we assign different Partner Determination Procedure to different Account Groups. In other words, indirectly, we assign the partner functions to account groups. Right? (Please correct me if I am wrong)
    Step3:
    "Partner Function". Here we define new partner functions, (which are used in Step 1...)
    Step4:
    "Account Group- Function Assignment" - Here we assign the Partner Functions to Account Groups
    Now My Question
    (A) Since the Partner Functions are assigned (via partner determination procedure) to account groups in Step 1, then why Partner Functions are assigned AGAIN to account groups in Step 4. What is the significance of this assignment in Step 4.
    (B) Is there is particular sequence of Steps (1 to 5), one should follow when somebody has to create new customer account group and/or new partner function.
    Thanking you all in advance.

    Dear SR
    Leave SAP Partner Determination screen for 2 minutes and first understand the logic
    1. Create the new partner functions
    2. Create the new determination procedure
    3. Link the new  partner functions to the  new determination procedure and add mandatory, non modifiable ,optional creteria
    4. Assign the new  determination procedure to the document type or account group at appropriate level
    This is essence and this is for all  8 levels like CMR,sales doc header,item etc
    Now coming to your qn
    When you define a new account group ( you might be aware account group controls partner functions of CMR) you will say that your  new account group  will carry out patner functions like SP,SH,BP,PY
    That is ACCOUNT GROUPS  function assignment
    Whenever you create a new account group  you will do field selection in OBD2 like suppress optional.reqd etc,create no ranges and assign no ranges and also mainly this activity partner determination
    These are must settings for a new account group
    AG is the german key for sold to party Partner determination procedure
    This is step 1
    Then in next step you will tell AG will carry out such and such partner functions Step 2 like mandatory not modifiable etc
    Step 3 is link the AG to your account group
    Step 4 is partner functions say if you want to create a new partner function say SB special stock partner
    (in concept this is the firststep)
    Step 5 is once again partner function account group  assignment
    So when you create a new partner function you will do step 4 first and step 5 and then 1 and 2 and 3 
    when you create a new account group you will do step 5 and then 1 and 2 and 3
    Hope you understand now
    Partner functions are relatives in your family
    Say in a family we have Father ,mother sister, brother (these 4 partner functions)
    This is called as Happy Family  and this Happy Family  is the Partner determination procedure in SAP
    This Happy Family  is linked to the account group
    So Happy family means there are 4 partner functions
    So whenever you create a CMR in the account group this father.mother,brother,sister will come as default
    Suppose you add another partner function say Uncle
    First you have to create uncle
    Then you have to tell this account group will accept uncle
    Then link the uncle in the happy family that is determination procedure of SAP along with the 4
    Then assign  happy family  to the account group
    Now when you create a CMR along with father.mother,brother,sister  along with that uncle will also come
    Regards
    Raja

  • Error in ALE service 29 Could not determine recipients for message type MAT

    Hi Experts,
    While transferring the material using ALE am getting  error 29 ie   'Error in ALE service'  and message is 'Could not determine recipients for message type MATFET'.
    Also i ve recieved the materials with the proper status al the end am getting the above error.
    Kindly help me out.
    Thanks in advance.

    Hi ,
    Status 29 means " partner profile not found " . Please check if the recieving partner is configured properly  in WE20 in sender system.
    Also make sure that the Port and RFC definations are also completed. If the IDoc is manually triggered then please make sure that control record parameters of the idoc are properly filled - if we miss the details ( like wrong port given , wrong basic type for message type - or extended message type ) then also the idoc will fail in status 29 even though the partner profile is properly configured .
    Since your idoc is getting generated i think no issues with BD64 since already interested recipeints were populated in control record of idoc.
    Regards
    Vikas Chaudhary

  • ORA-27078: unable to determine limit for open files

    I installed Oracle XE on my Gengoooraclexe@ghost ~ $ lsnrctl
    LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 25-JUN-2011 16:51:29
    Copyright (c) 1991, 2005, Oracle. All rights reserved.
    Welcome to LSNRCTL, type "help" for information.
    LSNRCTL> status
    Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE)))
    STATUS of the LISTENER
    Alias LISTENER
    Version TNSLSNR for Linux: Version 10.2.0.1.0 - Production
    Start Date 25-JUN-2011 10:03:30
    Uptime 0 days 6 hr. 48 min. 1 sec
    Trace Level off
    Security ON: Local OS Authentication
    SNMP OFF
    Default Service XE
    Listener Parameter File /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/network/admin/listener.ora
    Listener Log File /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/network/log/listener.log
    Listening Endpoints Summary...
    (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_XE)))
    (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ghost.emacs.com)(PORT=1521)))
    Services Summary...
    Service "PLSExtProc" has 1 instance(s).
    Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
    The command completed successfully
    LSNRCTL>
    Poraclexe@ghost ~ $ sqlplus "/as sysdba"
    SQL*Plus: Release 10.2.0.1.0 - Production on Sat Jun 25 07:19:58 2011
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Connected to an idle instance.
    SQL> show user
    USER is "SYS"
    SQL> startup
    ORA-27078: unable to determine limit for open files
    Linux Error: 1: Operation not permitted
    Additional information: 1
    Additional information: 1
    Additional information: -2958340
    SQL> startup force
    ORA-27078: unable to determine limit for open files
    Linux Error: 1: Operation not permitted
    Additional information: 1
    Additional information: 1
    Additional information: -3378372
    SQL> startup
    ORA-03113: end-of-file on communication channel
    SQL> exit
    Disconnected

    unable to determine limit for open filessee http://download.oracle.com/docs/cd/B25329_01/doc/install.102/b25144/toc.htm#BABJFAIA
    Is that a debian flavored distro?

  • How to clear Local-Cache Entries for a Query in BW?

    Hi There,
    i`m student und i need please your help for my Thesis!!
    I execute the same Query many times in BEx Web Analyzer und note a Query Response Time under ST03N using each time a different READ Mode and Cache Mode is inactiv (Query Monitor RSRT).
    First time i exectue the Query, it reads also from database, second time it uses the local Cache and  that `s okay!
    My problem is:
    When i change the Read mode and execute the Query again, it uses for the first run also the old entries from the Cache so i get wrong response time for the first run!!
    I know that while the mode cache inactiv , the local cache will still be used, so how can i delete the local cache entries each
    time i change the read mode and execute the Query? In Cache monitor (rsrcache) i find only entries for Global cache etc..
    I've already tried to close the session and login in to the System again but it doesn`t solve the Problem!!
    i don't have a permission (access rights) to switch off the complete Cache (local and global ).
    Any idea please??
    Thanks und Best Regards,
    Rachidoo
    P.S: sorry for my bad english!! i have to refresh it soon:)

    Hi Praba,
    the entries stored in RSRCACHE are for global cache, there is no entry for my query in Cache monitor!
    i execute the query in RSRT using java web button and cache mode inactiv so, the results will be stored in local cache.
    this is as below what i want to do for my performance tests in my Thesis:
    1. run a query for the first time with cache inactiv and note runtime of it
    2. run the query again with cache inactiv and note runtime of it
    3. clear the local cache (i don't know how to do it??)
    4. change the read mode of query in RSRT then run the same query for the first time and note runtime of it
    5. run the query again and note runtime of it.
    i'm doing the same procedure for each Read mode.
    the problem is in step 4 , The olap Processor gets the old results form the cache so i get wrong runtime for my tests.
    Generate the report doesn't help, any idea please?

  • Account determination procedure for cash billing & payment cards

    HI experts
    i want to know know what are the configuration steps of account determination procedure for cash billing & payment cards

    Hi Surya,
    Have you assigned Billing type For Ex: F2 or F1 to respective Sales Order Type in Sales Document Type controls VOV8.
    Assign these F2 against Delivery Related billing and F1 is for Order Related billing.
    Assign KOFI0000 to respective Billing Types F2 and F1.
    And check, hope issue may resolve.
    Revert if u have any query.
    Regards
    Durga sana.

  • Significant difference in response times for same query running on Windows client vs database server

    I have a query which is taking a long time to return the results using the Oracle client.
    When I run this query on our database server (Unix/Solaris) it completes in 80 seconds.
    When I run the same query on a Windows client it completes in 47 minutes.
    Ideally I would like to get a response time equivalent on the Windows client to what I get when running this on the database server.
    In both cases the query plans are the same.
    The query and plan is shown below :
    {code}
    SQL> explain plan
      2  set statement_id = 'SLOW'
      3  for
      4  SELECT DISTINCT /*+ FIRST_ROWS(503) */ objecttype.id_object
      5  FROM documents objecttype WHERE objecttype.id_type_definition = 'duotA9'
      6  ;
    Explained.
    SQL> select * from table(dbms_xplan.display('PLAN_TABLE','SLOW','TYPICAL'));
    PLAN_TABLE_OUTPUT
    | Id  | Operation          | Name      | Rows  | Bytes |TempSpc| Cost (%CPU)|
    |   0 | SELECT STATEMENT   |           |  2852K|    46M|       | 69851   (1)|
    |   1 |  HASH UNIQUE       |           |  2852K|    46M|   153M| 69851   (1)|
    |*  2 |   TABLE ACCESS FULL| DOCUMENTS |  2852K|    46M|       | 54063   (1)|
    {code}
    Are there are configuration changes that can be done on the Oracle client or database to improve the response times for the query when it is running from the client?
    The version on the database server is 10.2.0.1.0
    The version of the oracle client is also 10.2.0.1.0
    I am happy to provide any further information if required.
    Thank you in advance.

    I have a query which is taking a long time to return the results using the Oracle client.
    When I run this query on our database server (Unix/Solaris) it completes in 80 seconds.
    When I run the same query on a Windows client it completes in 47 minutes.
    There are NO queries that 'run' on a client. Queries ALWAYS run within the database server.
    A client can choose when to FETCH query results. In sql developer (or toad) I can choose to get 10 rows at a time. Until I choose to get the next set of 10 rows NO rows will be returned from the server to the client; That query might NEVER complete.
    You may get the same results depending on the client you are using. Post your question in a forum for whatever client you are using.

  • Help for a query to add columns

    Hi,
    I need for a query where I should add each TableC value as an additional column.
    Please suggest...
    I have 3 tables (TableA, TableB, TableC). TableB stores TableA Id and TableC stores TableB Id
    Considering Id of TableA.
    Sample data
    TableA     :          
    ID     NAME     TABLENAME     ETYPE
    23     Name1     TABLE NAMEA     Etype A
    TableB     :          
    ID     A_ID     RTYPE     RNAME
    26     23     RTYPEA     RNAMEA
    61     23     RTYPEB     RNAMEB
    TableC     :          
    ID     B_ID     COMPNAME     CONC
    83     26     Comp Name AA     1.5
    46     26     Comp Name BB     2.2
    101     61     Comp Name CC     4.2
    Scenario 1: AS PER ABOVE SAMPLE DATA Put each TableC value as an additional column.
    For an Id in TableA(23) where TableB contains 2 records of A_ID (26, 61) and TableC contains 2 records for 26 and 1 record for 61.
    Output required: Put each TABLEC value as an additional column
    TableA.NAME TableA.ETYPE TableB.RTYPE TableC_1_COMPNAME     TableC_1_CONC TableC_2_COMPNAME     TableC_2_CONC     
    Name1 EtypeA RTypeA Comp Name AA 1.5 Comp Name BB 2.2     so on..
    Name1 EtypeA RTypeB Comp Name CC 4.2 NULL NULL     
    Scenario 2: If Table C contains ONLY 1 row for each Id in TableB, output should be somewhat
    Output:
    TableA.NAME TableA.ETYPE TableB.RTYPE TableC_1_COMPNAME
    TableC_1_CONCvalue     value     value     value               value

    Hi,
    Welcome to the forum!
    Do you want the data from TableC presented
    (1) in one column, or
    (2) in several columns (a different column of results for each row in the original TableC)?
    (1) Is called String Aggregation and is easier than (2).
    The best way to do this is with a user-defined aggregate function (STRAGG) which you can copy from asktom.
    Ignoring TableA for now, you could get what you want by saying
    SELECT    b.rtype
    ,         STRAGG (   c.compname
                     || ' '
                     || c.conc
                     )  AS c_data
    FROM      TableB  b
    JOIN      TableC  c  ON b.id  = c.b_id
    GROUP BY  b.rtype;(2) Presenting N rows of TableC as it they were N columns of the same row is called a pivot. Search for "pivot" or "rows to columns" to find examples of how to do this.
    The number of columns in a result set is hard-coded into the query. If you don't know ahead of time how many rows in TableC will match a row in TableB, you can:
    (a) guess high (for example, hard-code 20 columns and let the ones that never contain a match be NULL) or,
    (b) use Dynamic SQL to write a query for you, which has exactly as many columns as you need.
    The two scripts below contain basic information on pivots.
    This first script is similar to what you would do for case (a):
    --     How to Pivot a Result Set (Display Rows as Columns)
    --     For Oracle 10, and earlier
    --     Actually, this works in any version of Oracle, but the
    --     "SELECT ... PIVOT" feature introduced in Oracle 11
    --     is better.  (See Query 2, below.)
    --     This example uses the scott.emp table.
    --     Given a query that produces three rows for every department,
    --     how can we show the same data in a query that has one row
    --     per department, and three separate columns?
    --     For example, the query below counts the number of employess
    --     in each departent that have one of three given jobs:
    PROMPT     ==========  0. Simple COUNT ... GROUP BY  ==========
    SELECT     deptno
    ,     job
    ,     COUNT (*)     AS cnt
    FROM     scott.emp
    WHERE     job     IN ('ANALYST', 'CLERK', 'MANAGER')
    GROUP BY     deptno
    ,          job;
    Output:
        DEPTNO JOB              CNT
            20 CLERK              2
            20 MANAGER            1
            30 CLERK              1
            30 MANAGER            1
            10 CLERK              1
            10 MANAGER            1
            20 ANALYST            2
    PROMPT     ==========  1. Pivot  ==========
    SELECT     deptno
    ,     COUNT (CASE WHEN job = 'ANALYST' THEN 1 END)     AS analyst_cnt
    ,     COUNT (CASE WHEN job = 'CLERK'   THEN 1 END)     AS clerk_cnt
    ,     COUNT (CASE WHEN job = 'MANAGER' THEN 1 END)     AS manager_cnt
    FROM     scott.emp
    WHERE     job     IN ('ANALYST', 'CLERK', 'MANAGER')
    GROUP BY     deptno;
    --     Output:
        DEPTNO ANALYST_CNT  CLERK_CNT MANAGER_CNT
            30           0          1           1
            20           2          2           1
            10           0          1           1
    --     Explanation
    (1) Decide what you want the output to look like.
         (E.g. "I want a row for each department,
         and columns for deptno, analyst_cnt, clerk_cnt and manager_cnt)
    (2) Get a result set where every row identifies which row
         and which column of the output will be affected.
         In the example above, deptno identifies the row, and
         job identifies the column.
         Both deptno and job happened to be in the original table.
         That is not always the case; sometimes you have to
         compute new columns based on the original data.
    (3) Use aggregate functions and CASE (or DECODE) to produce
         the pivoted columns. 
         The CASE statement will pick
         only the rows of raw data that belong in the column.
         If each cell in the output corresponds to (at most)
         one row of input, then you can use MIN or MAX as the
         aggregate function.
         If many rows of input can be reflected in a single cell
         of output, then use SUM, COUNT, AVG, STRAGG, or some other
         aggregate function.
         GROUP BY the column that identifies rows.
    PROMPT     ==========  2. Oracle 11 PIVOT  ==========
    WITH     e     AS
    (     -- Begin sub-query e to SELECT columns for PIVOT
         SELECT     deptno
         ,     job
         FROM     scott.emp
    )     -- End sub-query e to SELECT columns for PIVOT
    SELECT     *
    FROM     e
    PIVOT     (     COUNT (*)
              FOR     job     IN     ( 'ANALYST'     AS analyst
                             , 'CLERK'     AS clerk
                             , 'MANAGER'     AS manager
    NOTES ON ORACLE 11 PIVOT:
    (1) You must use a sub-query to select the raw columns.
    An in-line view (not shown) is an example of a sub-query.
    (2) GROUP BY is implied for all columns not in the PIVOT clause.
    (3) Column aliases are optional. 
    If "AS analyst" is omitted above, the column will be called 'ANALYST' (single-quotes included).
    {code}
    The second script, below, shows one way of doing a dynamic pivot in SQL*Plus:
    {code}
    How to Pivot a Table with a Dynamic Number of Columns
    This works in any version of Oracle
    The "SELECT ... PIVOT" feature introduced in Oracle 11
    is much better for producing XML output.
    Say you want to make a cross-tab output of
    the scott.emp table.
    Each row will represent a department.
    There will be a separate column for each job.
    Each cell will contain the number of employees in
         a specific department having a specific job.
    The exact same solution must work with any number
    of departments and columns.
    (Within reason: there's no guarantee this will work if you
    want 2000 columns.)
    Case 0 "Basic Pivot" shows how you might hard-code three
    job types, which is exactly what you DON'T want to do.
    Case 1 "Dynamic Pivot" shows how get the right results
    dynamically, using SQL*Plus. 
    (This can be easily adapted to PL/SQL or other tools.)
    PROMPT     ==========  0. Basic Pivot  ==========
    SELECT     deptno
    ,     COUNT (CASE WHEN job = 'ANALYST' THEN 1 END)     AS analyst_cnt
    ,     COUNT (CASE WHEN job = 'CLERK'   THEN 1 END)     AS clerk_cnt
    ,     COUNT (CASE WHEN job = 'MANAGER' THEN 1 END)     AS manager_cnt
    FROM     scott.emp
    WHERE     job     IN ('ANALYST', 'CLERK', 'MANAGER')
    GROUP BY     deptno
    ORDER BY     deptno
    PROMPT     ==========  1. Dynamic Pivot  ==========
    --     *****  Start of dynamic_pivot.sql  *****
    -- Suppress SQL*Plus features that interfere with raw output
    SET     FEEDBACK     OFF
    SET     PAGESIZE     0
    SPOOL     p:\sql\cookbook\dynamic_pivot_subscript.sql
    SELECT     DISTINCT
         ',     COUNT (CASE WHEN job = '''
    ||     job
    ||     ''' '     AS txt1
    ,     'THEN 1 END)     AS '
    ||     job
    ||     '_CNT'     AS txt2
    FROM     scott.emp
    ORDER BY     txt1;
    SPOOL     OFF
    -- Restore SQL*Plus features suppressed earlier
    SET     FEEDBACK     ON
    SET     PAGESIZE     50
    SPOOL     p:\sql\cookbook\dynamic_pivot.lst
    SELECT     deptno
    @@dynamic_pivot_subscript
    FROM     scott.emp
    GROUP BY     deptno
    ORDER BY     deptno
    SPOOL     OFF
    --     *****  End of dynamic_pivot.sql  *****
    EXPLANATION:
    The basic pivot assumes you know the number of distinct jobs,
    and the name of each one.  If you do, then writing a pivot query
    is simply a matter of writing the correct number of ", COUNT ... AS ..."\
    lines, with the name entered in two places on each one.  That is easily
    done by a preliminary query, which uses SPOOL to write a sub-script
    (called dynamic_pivot_subscript.sql in this example).
    The main script invokes this sub-script at the proper point.
    In practice, .SQL scripts usually contain one or more complete
    statements, but there's nothing that says they have to.
    This one contains just a fragment from the middle of a SELECT statement.
    Before creating the sub-script, turn off SQL*Plus features that are
    designed to help humans read the output (such as headings and
    feedback messages like "7 rows selected.", since we do not want these
    to appear in the sub-script.
    Turn these features on again before running the main query.
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Message no. B1003""Could not determine recipients for message type ACPJMM""

    Hi  All,
    While posting GR in MIGO, an error is showing. I am attaching the error description.
    ""Could not determine recipients for message type ACPJMM""
    Message no. B1003
    Diagnosis
    An IDoc of message type ACPJMM was passed to the ALE layer, but the three receiver fields in the header record were not filled. In this case the ALE layer tries to determine the receivers from the entries in the distribution model. There are no entries available in the distribution model for the above message type.
    Procedure
    Define the receivers in your distribution model for this message type or deactivate distribution for these message types.
    Yesterday it was not coming and GR was getting posted.. I was doing configurations for CIN and day before yesterday everything was done,all the registers were getting updated. For that I did many customisation in SPRO. I did settings in tax ion goods monement. and in Material master to assign screen sequence for foreign trade data screen. Is any customozation triggerring IDoc? Earlier also this came, that time we got client copy, but the problem is recurring. Its very urgent as we are going to transport SPRO settings to production.
    Solutions will be rewarded.
    regards
    B Shar
    Edited by: Ian Wong on Jul 4, 2008 4:48 PM

    Hi
    If you are not working with ALE & this message comes, then somone has mistakenly activated ALE linkages for IDoc Output in Accounting.
    if you want to keep this active & go forward, you need to complete the Distribution model customizng in BD64.
    Thanks & Regards
    Kishore

  • Count number of colums for that query.

    Hi all,
    I need to return the number of columns for that query, the columns are not known...dynamic columns.
    i.e
    1) Example 1
    select column1, column2
    from dual;
    Result should return counter = 2
    2) Example 2:
    select column1, column2,column3,column4, column5
    from dual;
    Result should return counter = 5
    from dual;
    Result should return counter = 2
    Thanks.

    qwestion wrote:
    I need to return the number of columns for that query, the columns are not known...dynamic columns.For this you'll need to use the DBMS_SQL package:
    e.g.
    SQL> ed
    Wrote file afiedt.buf
      1  CREATE OR REPLACE procedure query_col_count(p_sql IN VARCHAR2) IS
      2    c NUMBER;
      3    rec_tab DBMS_SQL.DESC_TAB;
      4    col_cnt INTEGER;
      5  BEGIN
      6    c := DBMS_SQL.OPEN_CURSOR;
      7    DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
      8    DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
      9    DBMS_SQL.CLOSE_CURSOR(c);
    10    DBMS_OUTPUT.PUT_LINE('Number of columns: '||col_cnt);
    11* END;
    SQL> /
    Procedure created.
    SQL> exec query_col_count('select empno, ename from emp');
    Number of columns: 2
    PL/SQL procedure successfully completed.
    SQL> exec query_col_count('select * from emp');
    Number of columns: 8
    PL/SQL procedure successfully completed.
    SQL>

  • Correct wat to determine if the XPath Query resulted in a match

    What is the correct way to determine of the XPath Query
    (using e4x syntax) returned matching nodes?
    The result is never a null reference even if there are no
    matches found, and I can't seem to find a way to determine if the
    XMLList returned has any nodes except for a convoluted way like so:
    var matchingRecords:XMLList =
    xmlData.dataTable[0].dataRow.(@someAttribute == someVariable);
    var record:XML = matchingRecords[0]; //This is the part I
    don't like to have to do.
    if (record == null)
    //This means no matches were found.
    else
    //This means atleast one match was found.

    "...they feel they've done it all too perfectly ..."
    I've been working with Flex since it was beta, and I must
    disagree with this. In my experience, the Adobe/MM folks are paying
    very close attention to what we say.
    You need to understand that you do not modify/release
    commercial software casually. It will take months to years. Be
    patient, or find a workaround, they exist.
    Be sure to log your wishes/bugs on the wishform. I know for a
    fact that they monitor that. I have been contacted for
    clarifications on my posts there.
    http://www.macromedia.com/support/email/wishform/
    Tracy

  • Help for a query with minus clause

    I want to write a query like this:
    select a.field
    from table_1 a
    minus
    select b.field
    from table_2 b
    where not exists (select 1
    from table_3 c
    where c.field = a.field);
    Unfortunately I get:
    ERROR at line 8:
    ORA-00904: invalid column name
    Can you help me?
    Thanks!

    Hi,
    Mark1970 wrote:
    I want to write a query like this:
    select a.field
    from table_1 a
    minus
    select b.field
    from table_2 b
    where not exists (select 1
    from table_3 c
    where c.field = a.field);
    Unfortunately I get:
    ERROR at line 8:
    ORA-00904: invalid column name
    Can you help me?
    Thanks!Table_1 and its alias, a, are only in scope in the first branch of the query, before the keyword MINUS. The second branch, after MINUS, must be a complete self-contained query.
    There are many ways to re-write the query, including:
    select     a.field
    from      table_1          a1
        minus
    select     b.field
    from     table_2          b
    where      not exists      (
                           select     1
                       from      table_3     c
                       JOIN     table_1     a     ON     c.field = a.field
                   );It's suspicious that the EXISTS sub-query does not depend on anything in table_2. Are you sure this is what you want to do?
    If you'd like help, post a little sample data (CREATE TABLE and INSERT statements for all three tables) and the results you want from that data.

  • Transport failing for BEX query? URGENT

    Hi All
    When i am transporting query, i am getting below error. I have made the errors in BOLD. Please help me out. How to find that missing element. I already retransported this query 2 times and getting same error. 
       Execution of programs after import (XPRA)
       Transport request   : SCDK900909
       System              : SCQ
       tp path             : tp
       Version and release: 371.02.23 700
       Post-import methods for change/transport request: SCDK900909
          on the application server: sapapqas01
       Post-import method RS_AFTER_IMPORT started for ELEM L, date and time: 20070823152931
       <b>Start of the after-import method RS_ELEM_AFTER_IMPORT for object type(s) ELEM (Activation Mode)
       Error when activating element D1ITRZCYGUMFZ44QD3JFETS84
       Element D1DXYOIH9OVW7HRNDJCPF3NS4 is missing in version M</b>   Start of the after-import method RS_ELEM_AFTER_IMPORT for object type(s) ELEM (Delete Mode)
       <b>Errors occurred during post-handling RS_AFTER_IMPORT for ELEM L</b>   RS_AFTER_IMPORT belongs to package RS
       <b>The errors affect the following components:
          BW-WHM (Warehouse Management)</b>   Post-import method RS_AFTER_IMPORT completed for ELEM L, date and time: 20070823152931
       Post-import methods of change/transport request SCDK900909 completed
            Start of subsequent processing ... 20070823152931
            End of subsequent processing... 20070823152931
       Execute reports for change/transport request: SCDK900909
          on the application server: sapapqas01
       Reports for change/transport request SCDK900909 have been executed
            Start of................ 20070823152931
            End of.................. 20070823152931
       Execution of programs after import (XPRA)
       End date and time : 20070823152931
       <b>Ended with return code:  ===> 8 <===</b>   ######################################<b></b>

    Hi
    I have a doubt. This query is in favourites in DEV system and from there i am transporting. Do i need to assign to an infoarea or role?

Maybe you are looking for