Wednesday, March 18, 2015

Understanding SQL's Null

 

Tony Hoare invented the null reference in 1965, and he considers it his "billion-dollar mistake" for the amount of trouble it has caused. Even today, SQL's null value is the cause of several common mistakes.

Let’s go over the most egregious.

Equals Null

These two queries return the exact same result on a users table with many rows:

select * from users where deleted_at = null;
-- result: 0 rows

select * from users where deleted_at != null;
-- result: 0 rows

How can that be? It's because null represents an "unknown" type. This means it doesn't make sense to compare null to anything else with normal conditional operators. Null isn't even equal to itself:

select null > 0;
-- result: null

select null < 0;
-- result: null

select null = 0;
-- result: null

select null = null;
-- result: null

The right way to compare values with null is with the is, and is not operators:

select * from users 
where deleted_at is null;
-- result: all non-deleted users

select * from users
where deleted_at is not null;
-- result: all deleted users

If you want to check if two columns are different, you can use is distinct from:

select * from users
where has_address is distinct from has_photo
-- result: users with an address or
-- photo, but not both

Not in Null

One handy way to filter rows is with a subselect. For example, if you wanted the userswho did not have any packages, you could write a query like this:

select * from users 
where id not in (select user_id from packages)

But if one of the rows in packages has a null user_id, this query will return no results! To understand why this happens we need to factor the query like the SQL compiler does. Here's a simpler example:

select * from users 
where id not in (1, 2, null)

Which translates to:

select * from users 
where id != 1 and id != 2 and id != null

As we now know, id != null is an unknown value, null. Using and on any value withnull becomes null, so all of the other and conditions fall away. No rows match the resulting query since null is not equal to true.

If the condition is inverted, the query works fine. This time we'll look for users withpackages.

select * from users 
where id in (select user_id from packages)

Which we can simplify for the example:

select * from users 
where id in (1, 2, null)

This query translates to:

select * from users 
where id = 1 or id = 2 or id = null

Since the where clause is a list of or conditions, it doesn't matter that one of them is null. That condition is simply ignored because non-true values do not change the evaluation of the rest of the clause.

Sorting Nulls

When it comes to sorting, nulls are considered the largest possible value. This can lead to some frustrating queries when trying to sort values descending, since all the nulls will be on top.

This query is meant to show the users ranked by their points, but it's putting users without any points first!

select name, points
from users
order by 2 desc;
-- null points sort above
-- any number of points!

There are two ways to deal with this. The easiest way is to get rid of those nulls in the output or the comparison using coalesce:

-- treat nulls as 0 in output
select name, coalesce(points, 0)
from users
order by 2 desc;

-- keep nulls in output, but sort as 0
select name, points
from users
order by coalesce(points, 0) desc;

And if your database supports it, you can instead tell it where to put nulls when sorting with nulls first or nulls last:

select name, coalesce(points, 0)
from users
order by 2 desc nulls last;

Of course, nulls can also be used to prevent errors. One great use of nulls is in dealing with divide by zero errors.

Divide by Zero

Divide by zero errors are especially painful. Queries that ran fine yesterday all of a sudden are failing with divide by zero errors. One common solution is to check if the denominator is 0 before dividing with a case statement:

select case when num_users = 0 then 0 
else total_sales/num_users end;

The case statement approach is verbose and duplicates the denominator. That's OK if the denominator is simple, but if it's an expression, you're likely to get more bugs if you change the query later.

Here we can use null to our advantage. Use nullif on the denominator to make the denominator null instead of zero. Rather than failing, the query will return null on days where num_users = 0.

select total_sales/nullif(num_users, 0);

If you prefer the result to be 0 or anything else instead of null, use coalesce on the previous query:

select coalesce(total_sales/nullif(num_users, 0), 0);
-- nulls results become 0

Conclusion

Tony Hoare may regret his mistake, but at least it’s easy to work around the issues that null presents. Now go forth with your new knowledge and keep null from nullifying your future query results!

Monday, March 2, 2015

TBE: Enabling General Application in Career Web Site

 

Taleo Business Edition (TBE) is Oracle's recruiting application offering for small to mid-sized companies. It does not have the full feature set available in Tale Enterprise Edition, and the system is deliberately watered down to allow quick setup and faster go-live. The system is also not well documented, and sometimes you have to hunt across the application to implement the simplest settings.

Like when we tried to turn on General Application in the Career Web Site.

1: Go to Administration -> Customize Recruit. Click on "Careers Website Pages"

tmpDE81 2:  Edit the Job Search Pages.

tmpE97A

3: In the next page, just unhide the two entries for "General Application" and its header section.

tmp723A

 

This is weird, because we expected some kind of global parameter which can be set to turn on such features. Instead, this configuration change is the only way to turn this on.

Sunday, March 1, 2015

25 Funny Situations Of A Programmer's Life

 

1. When the project manager enters the office

2. When I try to fix a bug at 3 in the morning


3. When I'm told that the module on which I have worked all the week will never be used

4. When the code that I have not tested on dev works perfectly in production

5. When the sales people announce they have sold our product to the customer

6. When sysadmin finally gives us the root access

7. When I launch my script for the first time after several hours of development

8. When I go off for the weekend while everyone else is still trying to fix bugs

9. When the boss is looking for someone to urgently fix a difficult bug

10. When a thing that worked on Friday no longer works on Monday

11. When a bug goes unnoticed during a presentation

12. When a newbie suggests to add a new feature to project

13. When I realize that I have been blocked for two hours because of a forgotten semicolon

14. When the project manager suddenly looks on my screen

15. When customer wants to change specification 2 days before pushing to production

16. When my script finally worked

17. When I'm told that my code is broken in production

18. When I find a solution without searching Google

19. When the intern tells me that "the tests are for those who can not program"

20. When I manage to replace 200 lines of the algorithm by only 10 lines

21. When I return to development of my code that wasn't commented

22. When they tell me the website has to be supported by IE6

23. When a misformed sql query actually returns me the correct results

24. When I start coding without doing analysis first

25. When project manager thinks that I can handle whole project all by myself

Oracle Cloud Support

 

Now that Oracle is a full fledged Cloud company, certain changes can be seen across their sites, letting visitors known that they tend to move to the cloud full on. If you are using an Oracle cloud product, you will see changes in their supportweb system. Logging into Suppotweb with the OPN of your cloud service takes you a new site, with the text "Oracle Cloud Support" on the top.

 

image

This new site has a minimalistic design, even the process of creating a Service Request is easier.

 

image

Clicking on the "Knowledge" tab , the search page is toned down. Users can choose to search in the realm of their cloud product, or search in "All Knowledge" for fill supportweb content.

image

Thursday, January 29, 2015

Getting started with Taleo Connect Client (TCC)

 

 

I have recently switched tracks to the cloud world of enterprise computing, and am going through Taleo. It is Oracle's recruiting/onboarding HR system, which has still not been fully integrated to HCM Cloud. Taleo Enterprise Edition runs on the web in any browser, however for batch integration purposes, it provides a standalone executable program called the Taleo Connect Client ie; TCC. (The last TCC I knew was the Turbo C Compiler from Borland Systems). If you need to import/export records in Taleo in bulk, TCC is the way you go.

 

1: First, log on to Oracle eDelivery, and choose the Taleo family of products. I am choosing the 32 bit windows version, because I can.

 

image

 

2: The current & latest version of Taleo, as of writing this, is 14A. You see, Taleo pushes three fixes in a year, and call them A,B and C. Be sure to click the link "Oracle Taleo Enterprise Editoin 14A", the other links are for older releases. The latest release came out just yesterday !

 

image

3) On the next page, you will see multiple links, and have to choose only two. Choose the windows version of the Application Installer and Data Model.

 

 

image

4) Now unzip the files and run the installers. I am going to run the top two installables in the screenshot above.

 

image

5) First install the data model. The Application installer requires the path were the data model is installed.

 

image

 

image

 

6) After running both installers, start the Taleo Connect Client.

image

 

 

image

 

7) OK, you will now get this window to start using the Tool. All the fields above need to be filled.

 

image

8)  Choose a product name from the latest version, don't worry, you can always change the product later.

The Protocol will be HTTPS.

The Host will be the address of your cloud instance. You need to register with Oracle to get this. It is also the place where you will configure and use the Taleo Application. Choose 443 as the port value.

Authentication:  I chose User Name Token authentication.

Now enter the credentials of the user allowed to use Taleo Integration Services, usually the administrator login.

 

image

9) Ahaa…Finally. The TCC window opens up.  But there is still lot of steps involved to start exporting/importing data to the system.

Saturday, January 10, 2015

Siebel BIP Performance Tuning

 

1) Increasing the amount of heap memory available to the Java Virtual Machine (JVM)

Increasing the memory available to the JVM can improve the performance of the report generation and ensure that this error is not encountered.

"C:\OraHome_1\jdk\bin\java" -XX:MaxPermSize=128m -Xms512m -Xmx512m -Duser.language=en -Duser.dir=C:\OraHome_1\oc4j_bi\bin -Duser.country=US -jar "%OC4J_JAR%" %CMDARGS%

OS

Memory Value

Windows (32-Bit)

Any value of up to 1.4GB (based on available RAM)

Windows (64-Bit)   

1.4 GB or higher (based on available RAM

2) Changing the Server Request Processor DB Polling Interval

By decreasing the polling interval the Server Request Processor can check the S_SRM_REQUEST table more regularly thereby reducing the period before the request processing is started. Once the change has been made it is necessary to shutdown and restart the affected Siebel Server before the change will take effect.It is recommended that this change be made only on the Siebel Servers hosting the XMLPReportServer component as this change will result in an increased number of queries being issued against the S_SRM_REQUEST table in the database.

change param PollIntvl=1 for comp SRProc

3) Minimize the size of Integration Objects/Components

An excessive number of unrequired fields in the report will lead to increased data generation times from the XMLPReportServer component and will result in an increased data file size for BI Publisher to process.

4) Minimal Force Active fields on  BC-

Ensuring that a minimal number of fields are flagged as Force Active will help to ensure that the number of fields being returned when querying against the Integration Component for report generation is further reduced.

5) XMLPReportServer PreloadSRF parameter to TRUE

Prelolading the SRF into the process ensures that any performance overhead during the SRF load is encountered during component startup and not during report processing. This parameter is listed under Advanced tab.

6) Inactive Web Services not used in Enterprise

Due to Bug 10587893 at present the component will load all of the active webservices configured in the enterprise rather than just those which it may access, such as PublicReportService or PublicReportService_v11. This leads to a performance overhead during the first report request for any process as these can take a significant period of time to load. In order to reduce the impact of this loading process review the webservices configured as 'Active' in the Siebel Enterprise through the Administration - WebServices > Outbound Webservices and Inbound Webservices views.  Set any webservices which are not used in the enterprise to 'Inactive'..

7) Minimize logging levels on all report generation components

This will include the requesting Object Manager, the XMLPReportServer component, the EAI Object Manager, the File System Manager component, and the BI Publisher Server itself.

8) Eliminate any un-necessary scripting during report generation

 

9) Create Separate Named Datasource For Siebel BI Publisher Reports With Large Data Volume

Generating Large Reports (over 10,000 records) - When running report generation there may be scenarios in which more than 10,000 records need to be retrieved. The standard ServerDataSrc within the Siebel Enterprise has a row limit of 10,000 for any single query and therefore in order to support large report generation a custom data source is required without this restriction.

Wednesday, January 7, 2015