Tuesday, January 10, 2017

How to find APIs?

Its difficult for a developer to find out APIs from DBA_OBJECTS table, so Oracle Corp. has come up with a web portal named Oracle Integration Repository (iRep) to access all public APIs.

Oracle® Integration Repository

Oracle Integration Repository is a compilation of information about the numerous interface endpoints exposed by Oracle applications. The full list of public APIs and the purpose of each API is available in the integration repository. It provides a complete catalog of Oracle E-Business Suite’s business interfaces, and a comprehensive view of the interface mechanisms available. You can use this tool to easily discover and deploy the appropriate business interface from the catalog for integration with any system, application, or business partner.

Release 12 Integration Repository

In Oracle EBS R12, Integration Repository is bundled as a part of EBS suite as a responsibility “Integrated SOA Gateway”.

Where are these APIs Stored?

Each API is placed in a file with extension as ‘pls'(pl/sql source code file). These pls files are stored in Unix box in the following path
$APPLICATION_TOP/patch/115/sql/

Query to find APIs

You can use the below query to find out the APIs to some extent
 SELECT SUBSTR(a.OWNER,1,20) ,
  SUBSTR(a.NAME,1,30)        ,
  SUBSTR(a.TYPE,1,20)        ,
  SUBSTR(u.status,1,10) Stat ,
  u.last_ddl_time            ,
  SUBSTR(text,1,80) Description
   FROM dba_source a,
  dba_objects u
  WHERE 2         =2
AND u.object_name = a.name
AND a.text LIKE '%Header%'
AND a.type = u.object_type
AND a.name LIKE 'PA_%API%'
ORDER BY a.owner,
  a.name;
Here PA is application short name of Project Accounting application

Thanks http://oracleappsdna.com/

Where do I find info about Oracle EBS Public APIs?

This is a question that I get multiple times each week in my role at API Wizard (a software product that leverages Oracle APIs).  

Oracle has make a huge investment, starting in Release 11 and continuing into each version of R12, in public APIs which allow you to perform nearly all of the same business processes that you can do with the Oracle forms.  You can create and update master data (customers, vendors, people, items, etc), transactional data (invoices, payments, orders, shipments, material transactions, etc), and configuration data (banks, value set values, etc).

Sounds great... and it is.  

But the question remains; how do you get a comprehensive list of available public APIs for Oracle EBS?

At a high-level, there are 4 main sources:

1) The Oracle Integration Repository
2) Oracle documenation
3) Metalink / My Oracle Support 
4) Web search

Let's break these down:

1) The Oracle Integration Repository

This is a resource that is part of every R12 system.  You access it using the seeded 'Integrated SOA Gateway' responsibility and choose the menu item 'Integration Repository'.  The Integration Repository contains about 70% of the Oracle APIs for whatever version of Oracle you're on, which doesn't sound great - but actually it's a huge accomplishment for Oracle as they have never had this information consolidated in one place before the integration repository.  

The Integration Repository provides a menu on the left broken out by module family and you can drill down to get to specific modules and then the public APIs or open interfaces available in those modules.  This is a great starting place -- but there are a few issues:

a) As mentioned above, if you don't find the API you're looking for here, it doesn't mean it doesn't exist, it just means it wasn't cataloged in the Integration Repository.
b) The Integration Repository in your environment will only list the APIs for the version of Oracle that you are running.  For example, if you are running 12.1.2 you'll see the APIs for version 12.1.2 but if you want to know if there is an API introduced in 12.1.3 (new APIs are added with each patchset), you can't determine that in your Integration Respository.
c) This is only available in R12.  The integration repository is not available in your R11 system.
d) The integration repository identifies the API and provides some information about the API parameters and a description of business process but it is not very detailed.

Oracle does maintain a version of the integration repository on their website at irep.oracle.com.  It used to contain R11 info and then was upgraded to R12 info but has been offline for the last few weeks.  It would be great if they would get that back online and provide the ability to search by version...  I am not holding my breath.

2) Oracle documenation (docs.oracle.com)

Oracle generates tons of documentation.  Each module mimimally has a user guide, an implementation guide, and a technical reference manual.  Some modules also have documents focusing solely on APIs and open interfaces, others embed this information into their other documents, and some don't document them at all.

It can be tedious work going through Oracle's documentation but worth when you find the guide that you need.  For the APIs and open interfaces which are documented, Oracle often provides sample scripts and talks about important concepts like environment initialization.

3) Metalink / My Oracle Support (support.oracle.com)

These days, good searching skills are often worth more than concrete knowledge.  There's a lot of information on metalink both in Oracle's notes/documents but also in Oracle forums, all of which you can search in one place.  I've found many an API this way.  Sometimes I get better results on google (see next bullet point) but sometimes Metalink is best.  

One thing to note is that if you have done your due dilligence but can't identfy an public API or open interface, you can raise an SR with Oracle and ask them if one exists.  Not only can they help you find it but if there is not, then can tell you if anyone has made an enhancement request for that API and you can ask them to add you to the list of customers requesting it.  That's one factor in how Oracle prioritizes its development initiatives.  

4) Web search

Not surprisingly, sometimes you get better information doing a web seach on google, bing, etc.   Actually, I often start here because if there are results I find them very quickly.  There are many forum questions (is there an Oracle EBS API for .....?) and there are many good blogs which describe working with these APIS.

~Thanks RobLepanto 

Thursday, January 5, 2017

Tips for Oracle SQL Query Writing and Performance Tuning

I am working with Oracle SQL from day when I joined IT industry and I have been fascinated by number of things I have learned about SQL, different databases and its usage over the years.
In early phase of my career, I learned that writing SQL queries was not just about writing but writing so it can run efficiently. Performance of SQL queries are critical to any application that is built to use Oracle and I say Oracle because this blog is specifically for Oracle SQL.
The following is a list of some tips which can be used as guideline to write and review custom SQL queries. This is by no means an exhaustive list to get the best tuning results but can serve as a ready reference to avoid the common pitfalls while working with Oracle SQL:
1. Do not use the set operator UNION if the objective can be achieved through an UNION ALL. UNION incurs an extra sort operation which can be avoided.
2. Select ONLY those columns in a query which are required. Extra columns which are not actually used, incur more I/O on the database and increase network traffic.
3. Do not use the keyword DISTINCT if the objective can be achieved otherwise. DISTINCT incurs an extra sort operation and therefore slows your queries down.
4. If it is required to use a composite index, try to use the “Leading” column in the “WHERE” clause. Though Index skip scan is possible, it incurs extra cost in creating virtual indexes and may not be always possible depending on the cardinality of the leading columns.
5. There should not be any Cartesian product in the query unless there is a definite requirement to do so. I know this is a silly point but we all have done this mistake at one point ðŸ™‚
6. Wherever multiple tables are used, always refer to a column by either using an alias or using the fully qualified name. Do not leave the guess work for Oracle.
7. SQL statements should be formatted consistently (e.g the keywords should be in CAPS only) to aid readability. Now, this is not a performance tip really. However, it’s important and part of the practices.
8. If possible use bind variables instead of constant/literal values in the predicate filter conditions to reduce repeated parsing of the same statement.
9. Use meaningful aliases for tables/views
10. When writing sub-queries make use of the EXISTS operator where possible as Oracle knows that once a match has been found it can stop and avoid a full table scan (it does a SEMI JOIN).
11. If the selective predicate is in the sub query, then use IN.
12. If the selective predicate is in the parent query, then use EXISTS.
13. Do not modify indexed columns with functions such as RTRIM, TO_CHAR, UPPER, TRUNC as this will prevent the optimizer from identifying the index. If possible perform the modification on the constant side of the condition. If the indexed column is usually accessed through a function (e.g NVL), consider creating a function based index.
14. Try to use an index if less than 5% of the data needs to be accessed from a data set. The exception is a small table (a few hundred rows) which is usually best accessed through a FULL table scan irrespective of the percentage of data required.
15. Use equi-joins whenever possible, they improve SQL efficiency
16. Avoid the following kinds of complex expressions:
    • NVL (col1,-999) = ….
    • TO_DATE(), TO_NUMBER(), and so on
These expressions prevent the optimizer from assigning valid cardinality or selectivity estimates and can in turn affect the overall plan and the join method
17. It is always better to write separate SQL statements for different tasks, but if you must use one SQL statement, then you can make a very complex statement slightly less complex by using the UNION ALL operator
18. Joins to complex views are not recommended, particularly joins from one complex view to another. Often this results in the entire view being instantiated, and then the query is run against the view data
19. Querying from a view requires all tables from the view to be accessed for the data to be returned. If that is not required, then do not use the view. Instead, use the base table(s), or if necessary, define a new view.
20. While querying on a partitioned table try to use the partition key in the “WHERE” clause if possible. This will ensure partition pruning.
21. Consider using the PARALLEL hint (only when additional resources can be allocated) while accessing large data sets.
22. Avoid doing an ORDER BY on a large data set especially if the response time is important.
23. Consider changing the OPTIMIZER MODE to FIRST_ROWS(n) if the response time is important. The default is ALL_ROWS which gives better throughput.
24. Use CASE statements instead of DECODE (especially where nested DECODEs are involved) because they increase the readability of the query immensely.
25. Do not use HINTS unless the performance gains clear.
26. Check if the statistics for the objects used in the query are up to date. If not, use the DBMS_STATS package to collect the same.
27. It is always good to understand the data both functionally and it’s diversity and volume in order to tune the query. Selectivity (predicate) and Cardinality (skew) factors have a big impact on query plan. Use of Statistics and Histograms can drive the query towards a better plan.
28. Read explain plan and try to make largest restriction (filter) as the driving site for the query, followed by the next largest, this will minimize the time spent on I/O and execution in subsequent phases of the plan.
29. If Query requires quick response rather than good throughput is the objective, try to avoid sorts (group by, order by, etc.). For good throughput, optimizer mode should be set to ALL ROWS.
30. Queries tend to perform worse as they age due to volume increase, structural changes in the database and application, upgrades etc. Use Automatic Workload Repository (AWR) and Automatic Database Diagnostic Monitor (ADDM) to better understand change in execution plan and throughput of top queries over a period of time.
31. SQL Tuning Advisor and SQL Access Advisor can be used for system advice on tuning specific SQL and their join and access paths, however, advice generated by these tools may not be always applicable (point 28).
32. SQL Access paths for joins are an component determining query execution time. Hash Joins are preferable when 2 large tables need to be joined. Nested loops make work better when a large table is joined with a small table.
Disclaimer: Points listed above are only pointers and may not work under every circumstance. This check list can be used as a reference while fixing performance problems in the Oracle Database.
Suggested further readings
  1. Materialized Views
  2. Advanced Replication
  3. Change Data Capture (Asynchronous)
  4. Automatic Workload Repository (AWR) and Automatic Database Diagnostic Monitor (ADDM).
  5. Partitioning strategies.
Now it’s turn if have any more tips which you have used then do add them in comment section… Your feedback is very valuable and it would be useful for other viewers too.