Query BP History

Hi Experts
I need a query to show me all BPs where the Payment Terms Group has been changed in the last month, ideally showing the user who changed it too.   is this possible?
Regards
Geoff

Hi ,
Try this:
declare @updatedate datetime,@dummy integer
select top 1 @dummy=T0.CardCode  from ACRD T0  where T0.UpdateDate='[%1]'
select @updatedate='[%1]'
SELECT DISTINCT T0.CardCode, T0.CardName, T0.GroupCode, T2.GroupName, T0.UpdateDate,
  (SELECT TOP 1 X0.GroupCode FROM ACRD X0
   WHERE X0.CardCode = T0.CardCode AND X0.LogInstanc = (T0.LogInstanc -1) ORDER BY X0.UpdateDate DESC)
   AS 'Old Group Code',
  (SELECT X1.GroupName FROM OCRG X1 WHERE X1.GroupCode = (SELECT TOP 1 X0.GroupCode FROM ACRD X0
   WHERE X0.CardCode = T0.CardCode AND X0.LogInstanc = (T0.LogInstanc -1) ORDER BY X0.UpdateDate DESC))
   AS 'Old Group Name',T0.UserSign ,T3.U_NAME as [UserName]
FROM ACRD T0
INNER JOIN OCRD T1 ON T0.CardCode = T1.CardCode
INNER JOIN OCRG T2 ON T0.GroupCode = T2.GroupCode
INNER JOIN OUSR T3 on T3.USERID=T0.UserSign
WHERE T0.UpdateDate = @updatedate
AND T0.GroupCode = T1.GroupCode
AND
    (SELECT TOP 1 X0.GroupCode FROM ACRD X0
     WHERE X0.CardCode = T0.CardCode AND X0.LogInstanc = (T0.LogInstanc -1) ORDER BY X0.UpdateDate DESC)
<> T1.GroupCode
Thanks,
Neetu

Similar Messages

  • Best practices for creating and querying a history table?

    Suppose I have a table of name-value pairs, and I want to keep track of changes to them so that I can query the value of any pair at any point in time.
    A direct approach would be to use a schema like this:
    CREATE TABLE NAME_VALUE_HISTORY (
      NAME      VARCHAR2(...),
      VALUE     VARCHAR2(...),
      MODIFIED DATE
    );When a name-value pair is updated, a new row is added to this table with the date of the change.
    To determine the value associated with a name at a particular point in time, one uses a query like:
      SELECT * FROM NAME_VALUE_HISTORY
      WHERE NAME = :name
        AND MODIFIED IN (SELECT MAX(MODIFIED)
                        FROM NAME_VALUE_HISTORY
                        WHERE NAME = :name AND MODIFIED <= :time)My question is: is there a better way to accomplish this? What indexes/hints would you recommend?
    What about a two-table approach like this one? http://pratchev.blogspot.com/2007/05/keeping-history-data-in-sql-server.html
    Edited by: user10936714 on Aug 9, 2012 8:35 AM

    user10936714 wrote:
    There is one advantage... recording the change of a value is just one insert, and it is also atomic without the use of transactions.At the risk of being dumb, why is that an advantage? Oracle always and everywhere uses transactions so it's not like you're avoiding some overhead by not using transactions.
    If, for instance, the performance of reading the value of a name at a point in time is not important, then you can get by with just using one table - the history table.If you're not overly concerned with the performance implications of having the current data and the history data in the same table, rather than rolling your own solution, I'd be strongly tempted to use Workspace Manager to let Oracle keep track of the changes.
    You can create a table, enable versioning, and do whatever DML operations you'd like
    SQL> create table address(
      2    address_id number primary key,
      3    address    varchar2(100)
      4  );
    Table created.
    SQL> exec dbms_wm.enableVersioning( 'ADDRESS', 'VIEW_WO_OVERWRITE' );
    PL/SQL procedure successfully completed.
    SQL> insert into address values( 1, 'First Address' );
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> update address
      2     set address = 'Second Address'
      3   where address_id = 1;
    1 row updated.
    SQL> commit;
    Commit complete.Then you can either query the history view
    SQL> ed
    Wrote file afiedt.buf
      1  select address_id, address, wm_createtime
      2*   from address_hist
    SQL> /
    ADDRESS_ID ADDRESS                        WM_CREATETIME
             1 First Address                  09-AUG-12 01.48.58.566000 PM -04:00
             1 Second Address                 09-AUG-12 01.49.17.259000 PM -04:00Or, even cooler, you can go back to an arbitrary point in time, run a query, and see the historical information. I can go back to a point between the time that I committed the first change and the second change, query the ADDRESS view, and see the old data. This is invaluable if you want to take existing queries and/or reports and run them as of certain dates in the past when you're trying to debug a problem.
    SQL> select *
      2    from address;
    ADDRESS_ID ADDRESS
             1 First AddressYou can also do things like set savepoints which are basically named points in time that you can go back to. That lets you do things like create a savepoint for the data as soon as month-end processing is completed so you can easily go back to "July Month End" without needing to figure out exactly what time that occurred. And you can have multiple workspaces so different users can be working on completely different sets of changes simultaneously without interfering with each other. This was actually why Workspace Manager was originally created-- to allow users manipulating spatial data to have extremely long-running transactions that could span days or months-- and to be able to switch back and forth between the current live data and the data in each of these long-running scenarios.
    Justin

  • Query transaction history infotype 768

    Hi!
    Is possible create a user query for history transaction history in infotype 768?
    I don't know what is the table.
    In infotype 0768 if we press "See transaction history" button we can see this records:
    Trans.ty.     PC no     Trans.date             Send.date             State                Error code
    PB          0             23.03.2011     08.04.2011     ENVIADO        
    PA          0             24.03.2011     08.04.2011     ENVIADO        
    But when I try to indentify de origin of this information with the technical information I can't find the table and field that I should query.
    How can I find the table and fields where this data are stored to query it?
    Kind regards,
    Julian.

    Hi Julian,
    .FDI History data is held in table T599SE. You have PERNR, TYPRO and ADDAT fields to help you identify your records (among others).
    Yes you can add it in your query but you would have to enhance your infoset and add some custom ABAP.
    Cheers.
    Antoine

  • Query Run History

    Currently we are in the process of finding out queries (SQ01) executed by the users from the user groups in last 6 months. We want to remove all the unused queries from the user groups. Is there any way to find out this detail apart from reaching users for the above information.
    Many Thanks.

    There is a way, however, I don't deem it as reliable as actually saving the data in a formally structured data warehouse.  Here is the scenario:  create a report in WebI and when you save it ensure that the option "Refresh on Open" is not used.  The next time you run that report it will contain the data as it was saved with the report.  If the user hits the "refresh" button, then Webi purges the old data and new data replaces it.  If the user now saves the report then the old data is forever lost and the report and current data is saved.  A user could get crafty with this concept by running a report and ensuring it will not refresh on open, and then never hit the refresh key (or refresh, but save as with a new name), thus building up a "library" of reports and data.  The danger is in the storage of the data on the OFRS (Output File Repository Service), and if it ever gets corrrupt and was not properly backed up and now not properly restored, then the user is out-of-luck.  That is why I don't feel that the method described here is the best solution.  If a data warehouse concept is employed by the organization, then organized snapshots of the data is taken (along with proper cleansing and other activities to stabilize the data), as well as formal backup and recovery processes within the framework of an RDBMS concept.
    Thanks,
    John

  • Smart Collection & Edit History

    Is there a work around to include various states of the edit history in the smart collection. Say for example, I want to create a smart collection to contain all of my exported to Hard Drive images.
    I'm testing out Lr/Gmail plugin and seeing that there is a field where you can create a smart collection with the option of Lr/Gmail = true/false. That mean there is a way to add extra option into smart collection. Do you know any plugin out there that can do this? Thank you in advance.

    That plug-in creates a custom field and populates it. There's no way to query the History steps through Lightroom's UI or through a plug-in. One lives in hope.

  • Audits of database query

    Hello,
    I am trying to find the queries which has been run in the database by an specific user, but unable to get records. Till now it is accessible for me only for the time till session is maintain. Is there any query by which I can find the query executed history
    of a specific user. 
    Thanks.

    You may have to turn on the default trace and get the data of the trace.
    You can read hear about the default trace 
    http://msdn.microsoft.com/en-us/library/ms175513.aspx
    Satheesh
    My Blog |
    How to ask questions in technical forum

  • High cpu usage by query

    We have a table named "tbl_geodata" which has address and latitude and longitude values. We
    also have a "History" table which has only latitude and longitude values including other information. What we need is like following...
    We get a set of records based on a query from "History" (lat long values), say 5000 records
    Now we are using the following formula to calculate address from the "tbl_geodata" for each row
    (5000 rows).
        SELECT top 1 geo_street,geo_town,geo_country,( 3959 acos( cos( radians(History.lat) ) cos( radians(
    gps_latitude ) ) cos( radians( gps_longitude ) - radians(History.long) ) + sin( radians(History.lat) ) sin( radians( gps_latitude ) ) ) ) AS distance FROM tbl_geodata ORDER BY distance
    Currently we are seeing high cpu utilisation and performance issue. What would be the optimized way to do
    this

    We are using SQL Server Web Edition. We have a table which has around 120 million records (every second around 100 insertion). It has a AFTER INSERT trigger to update another table. There is following performance issue we are facing. 
    High CPU Usage
    Insertion failed (Connection Timeout Expired.  The timeout period elapsed during the post-login phase.  The connection could have timed out while waiting for server to complete the login process and respond; Or it could have timed out while attempting
    to create multiple active connections.  The duration spent while attempting to connect to this server was - [Pre-Login] initialization=0; handshake=10046; [Login] initialization=0; authentication=0; [Post-Login] complete=3999;)
    Insertion Failed (A severe error occurred on the current command.  The results, if any, should be discarded.)
    Insertion Failed (Some time we are getting connection pool error.. There is no limit set in the connection string)
    I ran sp_who2 command and found a lot of queries are in suspended mode..
    here is the "sys.dm_os_sys_info" result...
    cpu_count   hyperthread_ratio
    physical_memory_in_bytes virtual_memory_in_bytes
    8                   8
                                12853739520
                 8796092891136
    Can anyone please suggest the improvement steps...

  • How to create the web template

    Hi BW Experts,
       how to create the web template.....!
       I just want to know what is the use of Web template. i want to display the report
    in WEB-UI screen ( sap-crm 7.0 portal ) can any one help me please how to proceed ...!
    Thanks
    shahina..!

    Hiu2026
    Steps to follow to create WAD in WEB Template in 3.5 or 7.0 u2026u2026..
    Go to All programs and select your web application designer
    Select the button to create a new page in WAD
    Select the chart and place in the layout
    Next goto Data provider Target and select your query
    Give your report name in the given data provider screen
    Select your query in History/find/Favourites/Infoareas button
    Select your query in this screen and click OPEN
    Now we can see the data provider is assigned to the chart.
    To edit the chart you have to right click on the chart
    After right click on it we will find another screen where we can edit all the settings
    In this screen we can find NEXT click button to change our settings
    In this screen we can state the tasks (Title, units, values, range)
    In this screen we can change our background /validity/color
    In this screen we can add values to the chart
    In this screen we can add validity/positions/order/axis types to the chart
    In this screen we can change the global settings/and overview of the chart.
    This screen shows that we have customized the chart successfully
    After successful creation of the chart we have to save the chart
    Save your chart in your favorites by giving the description and technical name in the given block.
    Now execute your WAD by selecting the execute button
    The BEx Web Application Designer is a desktop application for creating Web applications with BW-specific contents. Using the BEx Web Application Designer, you can create an HTML page that contains contents such as various tables, charts or maps. This HTML page (Web application) provides the basis for not only Web applications with complex interaction, but also for Web cockpits and iViews.
    http://help.sap.com/saphelp_nw04/helpdata/en/1a/456a3badc1b315e10000000a114084/content.htm
    Web Application Designer for Beginners
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/749a4622-0a01-0010-36bf-b6b30a2a3a22
    Web Application Solutions: A Designer's Guide
    http://www.lukew.com/resources/webapplicationsolutions.pdf
    http://sap.ittoolbox.com/groups/technical-functional/sap-solution-manager/bw-web-application-designer-1955944
    Feautures of WAD in 7.0
    http://help.sap.com/saphelp_nw70/helpdata/en/88/4d354277dcb26be10000000a155106/frameset.htm
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/5c46376d-0601-0010-83bf-c4f5f140e3d6

  • SQL between clause & index question

    I currently have the below CTAS that uses between clause to identify the date range from the parameter table and then query a history table on a different database. The history table has index in the acct_date column. The below SQL is slow and takes a long time.
    create table temp1 as
    select acct_date,cust_ord_1,fin_fclty_2,cust_ord_ship_3,
    cust_ship_4,fin_item_5,sls_q,sls_tran_a
    from pgt.pg_orders@jtu where acct_date between
    (select value from pgm_parameters where parameter='wk_minday') and
    (select value from pgm_parameters where parameter='wk_maxday');
    Please advise of any changes that I can do to tune the script and make it execute faster. Thanks in advance.

    See:
    [url http://forums.oracle.com/forums/thread.jspa?threadID=863295] How to post a SQL tuning request
    [url http://forums.oracle.com/forums/thread.jspa?messageID=1812597] When your query takes too long
    But you might want also want to read this:
    http://jonathanlewis.wordpress.com/2008/12/05/distributed-dml/

  • From keyword not Found error

    Brief History :
    Before our application is running in websphere5.0 now i migraded to websphere 6.0.Now our application is running in websphere 6.0.In our application we have written all our quries in one .xml(SelectRepository.xml....) file.
    Problem:
    while i am going through my application(while doing searching,inserting and updating) i am getting some query problem.we are using one parser for parsing these .xml repositories.
    Problem Description :
    If our query is in 4 lines,the first line is mixed with second line,if there is no space after fist line.
    My Doubt of problem:
    we are using 3 common .jar files in websphere 5.0 and websphere 6.0
    names xalan.jar,xerces.jar,xsl.jar.
    My doubt is whether can i use same files for websphere 6.0 or i have to use some other files.
    Final description :
    Plz provide help me out in the query problem.it requires space in each line ending of every query.

    Brief History :
    Before our application is running in websphere5.0 now i migraded to websphere 6.0.Now our application is running in websphere 6.0.In our application we have written all our quries in one .xml(SelectRepository.xml....) file.
    Problem:
    while i am going through my application(while doing searching,inserting and updating) i am getting some query problem.we are using one parser for parsing these .xml repositories.
    Problem Description :
    If our query is in 4 lines,the first line is mixed with second line,if there is no space after fist line.
    My Doubt of problem:
    we are using 3 common .jar files in websphere 5.0 and websphere 6.0
    names xalan.jar,xerces.jar,xsl.jar.
    My doubt is whether can i use same files for websphere 6.0 or i have to use some other files.
    Final description :
    Plz provide help me out in the query problem.it requires space in each line ending of every query.

  • Problem with complex business logic...

    hi all,
    i have two tables 1.running_table
    2.history_table
    in my tables, for recent 30 day's data will be stored in "running_table". if 30 days completed from the entered date, all the data will be moved to "history_table".this will be done by some triggers.
    now, in my stored procedure, i will get start_date,end_date as a inputs.i have to retrieve data from two tables(running_table,history_table) depending on dates.
    conditions:
    1. if entered time pheriod is before 30 days....use running_table
    2. if entered time pheriod is after 30 days....use history_table.
    if start_date is in latest 30 days & end_date in old to 30 days ? what to do?
    how can i write condition depending on time pheriod?
    thanks in advance.....
    Edited by: user9041629 on Aug 12, 2010 3:43 AM

    I would suggest you to write 3 conditions in your pl/sql block
    1. for <= 30 days
    2. for > 30 days
    3. for range with lies in both.
    in 1 condition u may write a query with running table
    in 2 condition u may write a query with history table
    and
    in 3 condition u have to write a query with history union running table
    hope it is clear to you :)

  • Trying to make an sql statement returning 'owner, tablename, num_rows, measuredate'

    Hi, I would like to create a table with the following collumns:
    "OWNER|TABLENAME|NUM_ROWS|MEASURE_DATE"
    I can get owner, tablename and measure_date (sysdate) from
    dba_tables easily with a
    select owner, tablename, sysdate
    from dba_tables
    , but I am having trouble getting the num_rows for each table
    seperately.
    dba_tables.num_row is not an option because I am not running
    statistics on this server and can't (rather: I am told not to.
    So somehow I have to add the result of
    select count(*) from " an individual table", dynamically.
    But I am not sure how.
    Eventually the table would have to look like:
    JOHN EMP 433 12-JAN-01
    JOHN EMP 476 12-JAN-01
    MARGE LOC 198 13-JAN-01
    All help is very much appreciated,
    Mike

    HI guy's !
    Thanx for all the suggestions, I have tried them all out and its
    almost there. However your suggestions display the output on the
    screen and I would like to insert the rows into table so to be
    able to readout table growth history. I tried to alter your
    statements with a create table as select ( and here your plsql)
    but this doesnt seem to work. I am sorry that I do not know
    pl/sql. Can anyone assist me in completing the code with an
    insert into a table?
    Mohit Dubey: I am getting an ORA-00952 table or view does not
    exist with your code, do I need to edit smth I overlooked?
    Suresh: Your code works, but as mentioned above I would like to
    get the code into table instead of on the screen, could you help
    me with that? I apologize for not knowing plsql.
    Barbara: Your code works fine, but it does an update on the
    table. Therefore, I cannot query the history of the number of
    rows tables. Could you change it to do an insert instead of an
    update? I tried to but failed miserably.
    Again; thanx all for your suggestions! Now I just need a final
    push as I myself am unable to alter the codes into an insert
    statement.
    Mike

  • How to see WAD reports on browser

    Hi experts,
    We created some reports on BEx. Now we want to show them in browser.
    For this i went into WAD and gave one report as input.
    An URL is generated.  I copied that URL and pasted in the Address bar of internet explorer.
    It is giving an error as follows:
    =========================================
    Service cannot be reached
    What has happened?
    URL http://ocbomsap04:8014/sap/bw/BEx call was terminated because the corresponding service is not available.
    Note
    The termination occurred in system BP1 with error code 403 and for the reason Forbidden.
    The selected virtual host was 0 .
    What can I do?
    Please select a valid URL.
    If you do not yet have a user ID, contact your system administrator.
    ErrorCode:ICF-NF-http-c:000-u:SAPSYS-l:E-i:ocbomsap04_BP1_14-v:0-s:403-r:Forbidden
    HTTP 403 - Forbidden
    Your SAP Internet Communication Framework Team
    =================================================================
    This is the first time we are using to publish a report on browser. What the settings do we need to do to see the reports on browser ?
    Plz provide some step by step..
    Regards,
    Nishuv.

    Hi,
    Go to All programs and select your web application designer
    Select the button to create a new page in WAD
    Select the chart and place in the layout
    Next goto Data provider Target and select your query
    Give your report name in the given data provider screen
    Select your query in History/find/Favourites/Infoareas button
    Select your query in this screen and click OPEN
    Now we can see the data provider is assigned to the chart.
    To edit the chart you have to right click on the chart
    After right click on it we will find another screen where we can edit all the settings
    In this screen we can find NEXT click button to change our settings
    In this screen we can state the tasks (Title, units, values, range)
    In this screen we can change our background /validity/color
    In this screen we can add values to the chart
    In this screen we can add validity/positions/order/axis types to the chart
    In this screen we can change the global settings/and overview of the chart.
    This screen shows that we have customized the chart successfully
    After successful creation of the chart we have to save the chart
    Save your chart in your favorites by giving the description and technical name in the given block.
    Now execute your WAD by selecting the execute button
    This is the design what will be given as your out put
    Please save your LINK.
    http://epsys:50000/irj/servlet/prt/portal/prtroot/pcd!3aportal_content!2fcom.sap.pct!2fplatform_add_ons!2fcom.sap.ip.bi!2fiViews!2fcom.sap.ip.bi.bex?TEMPLATE=PRICETRENDTEST&DUMMY=0
    Now your WAD is successfully designed.
    Check this link what I have done in last month.May be this link will definitely helpful.
    Thanks==points
    Regards
    Sudheer
    Edited by: SUDHEER on Dec 19, 2008 7:28 AM
    Edited by: SUDHEER on Dec 19, 2008 7:33 AM

  • Same Techname Two Querys.

    Hi all,
    I have one query name Sales Details Tech Name (SALES_DETAILS).I save as this query same techname(SALES_DETAILS). Afterthat I
    checked my query,now I have two querys same tech name. How come this.
    Please tell me the problem.
    Regards,
    Nani

    May be u stored the query in differnt location.
    you cannot store a query with same technical name.
    I think, you stored your query in ur role, u save as query in history or favorite.
    thanks,
    senthil kumar

  • Tell oracle which plan is optimal?

    It's easy enough in 10g to get a query's history of execution plans and execution statistics, and so it's often easy to tell the bad plan from the good plan especially when user complaints coincide with the plan that uses many more gets per execution. I can see the sql_id, I can see the plan_hash_value for the efficient plan, why can't I just run a function that says "associate this plan with this sql_id always until I tell you otherwise?" Yes, I know there might be more than one optimal plan for some queries, but I have seen plenty of cases where there's one obviously better plan for all inputs - when plan B is used there are no complaints of slowness, when plan C is used users call the help desk. All I need is to get oracle to understand that sql_id A works best with plan B.
    Maybe something like:
    dbms_stats.create_profile_from_existing_plan(sql_id=> x, plan_hash_value => y );
    would get the details from dba_hist*.
    This can't be that difficult to implement, can it? Why isn't it provided/supported? How hard would it be to implement using calls to oracle functions?
    Thanks.

    user447327 wrote:
    Thanks, I'm familiar with outlines, in that I don't want to try to record one while trying to get just the right combination of sql text and statistics and inputs to get the plan I want. In this case, the optimizer has already found the good plan, but it doesn't always stick to the good plan. I could change statistics gathering techniquex, but I want a local fix. I'm familiar with the sql tuning advisor, but it never gives me good advice. I can rewrite sql, but not for applications that won't allow me to change the source code.
    If I could get that information for a good plan for a particular sql_id/plan_hash_value from v$sql* maybe I could transform a plan into an outline.
    So, I'm asking why this apparently simple feature isn't available, not for advice on how to use more complicated existing features. Which is not to say that I don't appreciate your posting that interesting URL. I think maybe I am just lazier ( in a good way, I hope ) than you are.
    The answer to my sporadic performance problem is sitting right in front of me. The optimizer has already produced the correct result, along with one or more wrong results. The right answer doesn't need to be recalculated or recosted or reparsed - it's a previously-solved problem. I want Oracle to remember the solution when I tell it that sql_id A and plan_hash_value B should always be together. The information that is already available needs to be addressible in minimal terms ( sql_id, plan_hash_value ) in such a way that the desired plan is always associated with the problem query.
    This would be useful in cases where there isn't more than one optimal plan.
    dbms_no_cbo.marry(sql_id=> x, plan_hash_value=>y);Apologies, but I saw your post only now. The desperately sought functionality is already there in 10g using Stored Outlines. Note that the CREATE_OUTLINE procedure has been added in 10g, it wasn't available in pre-10g versions.
    CREATE_OUTLINE Procedure
    This procedure generates an outline from the shared cursor identified by hash value and child number.
    DBMS_OUTLN.CREATE_OUTLINE (
       hash_value    IN NUMBER,
       child_number  IN NUMBER,
       category      IN VARCHAR2 DEFAULT 'DEFAULT');Of course, SPM in 11g supersedes this, but this should do what you're looking for in 10g.
    Another, slightly more cumbersome approach, would be creating a SQL profile using two undocumented functions/options but it allows to refer to the plans stored in the AWR which is not possible using above approach.
    The interesting feature of SQL profiles is that these allow to match SQL similar to the CURSOR_SHARING functionality, i.e. replaces literals with bind variables before attempting to match the SQL text. See the FORCE_MATCH parameter below.
    Step 1: Get the outline information from the shared pool or the AWR
    Note that the OUTLINE option is undocumented. You could also use the ADVANCED option (undocumented, too, but look here: http://jonathanlewis.wordpress.com/2008/03/06/dbms_xplan3/):
    Shared Pool:
    SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR('<sql_id>', <child_number>, 'OUTLINE');AWR:
    SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_AWR('<sql_id>', <child_number>, null, 'OUTLINE');This generates the execution plan along with the OUTLINE information which looks e.g. like that:
      /*+                                                                                               
          BEGIN_OUTLINE_DATA                                                                            
          IGNORE_OPTIM_EMBEDDED_HINTS                                                                   
          OPTIMIZER_FEATURES_ENABLE('10.2.0.3')                                                         
          OPT_PARAM('query_rewrite_enabled' 'false')                                                    
          OUTLINE_LEAF(@"SEL$2")                                                                        
          OUTLINE_LEAF(@"SEL$1")                                                                        
          INDEX(@"SEL$1" "I"@"SEL$1" "I_OBJ#")                                                          
          INDEX_RS_ASC(@"SEL$1" "IST"@"SEL$1" ("IND_STATS$"."OBJ#"))                                    
          NO_ACCESS(@"SEL$1" "C"@"SEL$1")                                                               
          LEADING(@"SEL$1" "I"@"SEL$1" "IST"@"SEL$1" "C"@"SEL$1")                                       
          USE_NL(@"SEL$1" "IST"@"SEL$1")                                                                
          USE_HASH(@"SEL$1" "C"@"SEL$1")                                                                
          INDEX_RS_ASC(@"SEL$2" "CDEF$"@"SEL$2" ("CDEF$"."OBJ#"))                                       
          END_OUTLINE_DATA                                                                              
      */                                                                                                 Step 2:
    Generate an SQL profile using above OUTLINE information. Note that the IMPORT_SQL_PROFILE procedure is undocumented.
    begin
    dbms_sqltune.import_sql_profile(
      sql_text    => '<the_full_sql_text>'
    , profile     => sqlprof_attr('<hint1>','<hint2>')
    , name        => 'PROFILE_name'
      -- use force_match => true
      -- to use CURSOR_SHARING=SIMILAR
      -- behaviour, i.e. match even with
      -- differing literals
    , force_match => false
    end;
    /A code snippet how this could be combined into an automated SQL*Plus script, parameter is the SQL_ID:
    declare
      ar_hint_table    sys.dbms_debug_vc2coll;
      ar_profile_hints sys.sqlprof_attr := sys.sqlprof_attr();
      cl_sql_text      clob;
      i                pls_integer;
    begin
      with a as (
      select
               rownum as r_no
             , a.*
      from
               table(
                 -- replace with
                 -- DBMS_XPLAN.DISPLAY_AWR
                 -- if required
                 dbms_xplan.display_cursor(
                   '&&1'
                 ,  null
                 , 'OUTLINE'
                 -- dbms_xplan.display_awr(
                 --   '&&1'
                 -- , null
                 -- , null
                 -- , 'OUTLINE'
               ) a
      b as (
      select
               min(r_no) as start_r_no
      from
               a
      where
               a.plan_table_output = 'Outline Data'
      c as (
      select
               min(r_no) as end_r_no
      from
               a
             , b
      where
               a.r_no > b.start_r_no
      and      a.plan_table_output = '  */'
      d as (
      select
               instr(a.plan_table_output, 'BEGIN_OUTLINE_DATA') as start_col
      from
               a
             , b
      where
               r_no = b.start_r_no + 4
      select
               substr(a.plan_table_output, d.start_col) as outline_hints
      bulk collect
      into
               ar_hint_table
      from
               a
             , b
             , c
             , d
      where
               a.r_no >= b.start_r_no + 4
      and      a.r_no <= c.end_r_no - 1
      order by
               a.r_no;
      select
               sql_text
      into
               cl_sql_text
      from
               -- replace with dba_hist_sqltext
               -- if required for AWR based
               -- execution
               v$sql
               -- sys.dba_hist_sqltext
      where
               sql_id = '&&1';
      -- this is only required
      -- to concatenate hints
      -- splitted across several lines
      -- and could be done in SQL, too
      i := ar_hint_table.first;
      while i is not null
      loop
        if ar_hint_table.exists(i + 1) then
          if substr(ar_hint_table(i + 1), 1, 1) = ' ' then
            ar_hint_table(i) := ar_hint_table(i) || trim(ar_hint_table(i + 1));
            ar_hint_table.delete(i + 1);
          end if;
        end if;
        i := ar_hint_table.next(i);
      end loop;
      i := ar_hint_table.first;
      while i is not null
      loop
        ar_profile_hints.extend;
        ar_profile_hints(ar_profile_hints.count) := ar_hint_table(i);
        i := ar_hint_table.next(i);
      end loop;
      dbms_sqltune.import_sql_profile(
        sql_text    => cl_sql_text
      , profile     => ar_profile_hints
      , name        => 'PROFILE_&&1'
      -- use force_match => true
      -- to use CURSOR_SHARING=SIMILAR
      -- behaviour, i.e. match even with
      -- differing literals
      , force_match => false
    end;
    /Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/
    Edited by: Randolf Geist on Mar 26, 2009 10:00 PM
    Added automated SQL profile generation

Maybe you are looking for

  • PDF file size limited to graphics memory in Reader?

    I've created a form (in LiveCycleDS) that allows for an unlimited number of photos to be loaded into it. I put an image into a subform that is duplicated every time a user clicks a button thus creating an unlimited number of images that can hold phot

  • I have an adj mydmx 2.0 software that I'm downloading is now able to open.... How can i open it?

    I have an adj mydmx 2.0 software that I'm downloading is now able to open.... How can i open it?

  • BOXIR2, How to Build and Test OLTP Connection

    Hi Everybody, In BOXIR2. I have added OLTP LIC Keys. I am not sure about how to test the OLTP connection is working or not. Please provide steps for below Items:- 1.     Steps to configure the connection for OLTP 2.     How to test the OLTP is workin

  • Bash: push a string on input

    I want to try to put a file manager in PROMPT_COMMAND, where e.g. you choose some files, press F6, and the top-level, interactive prompt then shows $PS1 mv \ /tmp/file1 \ /tmp/file2 (space) Kind of like read -e -i "ls "; eval $REPLY So far I thought

  • Crud operations

    Hi, shouldn't it be easy? A table displays a Collection of objects. I want be able to click on an 'edit' link or button and be brought to the detail screen for editing the record. I have to retrieve the ID of my objects, but I don't know how to get i