Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Another interview question
Very interesting analysis. One correction, though: the required solution has to prevent users from entering non-integers into the column, not change non-integer values already in the column into integers.
The solution I came up with (not at the interview, though): use the following CHECK constraint on the column:
ALTER TABLE <table_name> ADD CONSTRAINT <constraint_name> CHECK (<column_name>=TRUNC(<column_name>)) EXCEPTIONS INTO <exception_table>;
Using ROUND instead of TRUNC achieves the same result.
Impact on the application: add a few lines of codes to trap the ORAerror message for constraint violation and display a meaningful message to the user (for most developers I worked with, this is optional). No index required, no disk space used up (except for the data dictionary).
Easy to implement (and as soon as possible): How good are your typing skills ? (mine are lousy ). Seriously now, you can implement it any time the table is not in use (late at night (??), or maybe I could have done it during the interview if I could have come up with the solution then) with no impact on production.
Flexible: If they have to accept non-integers later on, DISABLE or DROP the constraint.
Generic: implemented in standard SQL DDL.
BTW, did the thought ever cross your mind that maybe they pay you too much ? Never heard of a "very well-paid consultant" who would tell his/her clients that "it cannot be done". I thought the opposite was true: they always tell their clients it can be done, for the right price, of course (otherwise known as "bullshitting the client"). I am a DBA, and I just added your name to the list of people I would not want to have as a developer (hey, I just realized how long the list has grown !)
Michael Serbanescu
![]() |
![]() |