Skip to Main Content

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Ashiq.

Asked: May 23, 2003 - 10:46 am UTC

Last updated: July 16, 2018 - 9:13 am UTC

Version: 8.1.7

Viewed 10K+ times! This question is

You Asked

Hi Tom,

Recently I attened a inteview , I have given the questions which I'm not able to answer.

1.When using rman ,oracle will use its own processes than the OS one.the questions is what are the advantages oracle is getting by using it own process.
Though referred manual but i'm not able to get it.Can you tell me the advantages??

2.You're going to create a table (which has 60 columns with datatypes number, varchar2 , clob, and date).He asked me ,what way of order columns you will place the columns, like first numbers, then varchars,or date etc.
For this is allow i told him i don't know.
Tom is any rule we've follow for when we create a table??

3. And the last one (just for curios ) either you can answer or not.
How many hours(or average) you daily work in answering our queries or doing research and developent in ORACLE.

thanx,
A.Ashiq

and Tom said...

1) tablespaces do not need to be in hotbackup mode, resulting in less redo generation during hot backup.

rman can be throttled (limited in the amount of IO it does) so as to not kill the system with massive read requests


2) you put them in the order that makes most sense. Frequently accessed columns would perform best "first", if you have some columns that almost always will be null -- put them last.

The ones in the middle, makes no difference at all.

In general, i would put them in the order that is most pleasing to me -- at the end of the day, it isn't going to make significant difference.

3) most of it...

Rating

  (27 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Ashiq Shamsudeen, May 23, 2003 - 12:23 pm UTC

Addon to the above questions its not interview question, but personal question about you.

When you answering our questions will you refer docs( manuals)(or syntax, and crosschecking with it what you've said is right or wrong .



Tom Kyte
May 24, 2003 - 9:33 am UTC

(my answer to #3 was "most of it")

I use documentation -- but mostly rely on tests to prove it. Documentation can be misleading or incorrect from time to time (not often) -- nothing like a test case to prove the point (or more likely, disprove the point)

LOB Last?

Jeremy Smith, May 23, 2003 - 2:05 pm UTC

Re #2:
I've frequently read that if you're going to use any kind of LOB that might be "in row", you're best off putting them last. I think the thought is that if you're looking for a non-blob column that's after the LOB, it's going to have to read through your LOB. Is this accurate?

Tom Kyte
May 24, 2003 - 9:44 am UTC

a lob is a lob locator generally, a pointer. it is small.


lobs can be inline or out of line. by default lobs are allowed to be inline, meaning that if they are under about 4000 bytes (like a varchar2 field), they will be stored "in the row". Once they exceed that threshold - they are replaced with a pointer and stored out of line -- in the lob segment elsewhere.


LONGS and LONG RAWS did not behave this way, they were always stored inline

Search command

Abdul Wahab, May 24, 2003 - 2:54 am UTC

Dear Tom,
As this thread seems to be about the interview questions,I have one question which was given to me once in an interview. The question was that if we want to find a row(datatype varchar) from a table containing a particular text, what is the command in oracle? .I said it can be done using- like '%<particular text>%'.He wasn't happy with that, then i said we can also use SOUNDEX.He was still unhappy!. Any way i didn't get the job there.Thanks god i got a better job somewhere else. But i searched a lot to find the alternate answer.Tom can you tell me is there such search command?

Tom Kyte
May 24, 2003 - 10:14 am UTC

what about the obvious answer?

select * from t where column = 'particular text';


then again, they might have been trying to get you to say "interMedia text" -- context indexing.

One more question

Reader, May 24, 2003 - 1:46 pm UTC

It is great thread. What does it mean if someone asked me to explain the concept of how application users can connect to the database as a single user or single login? What would be the benefit in doing so as against creating and managing thousands of end users in the database itself. Could you help? Thanks.

Search

Abdul Wahab, May 25, 2003 - 5:41 am UTC

Hi Tom,
no, no the 'obvious answer' is not needed here. You see i don't want to search a text as a whole in the table , but i want to retrieve a row which contains a particular string or set of words. For eg. if one row contains text as "TOM IS REALLY HELPFULL FOR THE ORACLE FANS".Now i want to retrieve this row just by specifying the condition that the row contains-"TOM" or any row that contains "FOR".
By the way you mentioned "intermedia text".Hmmmm...sounds interesting. i think this was what i was suppose to tell. Can u tell me more about it or refer me to some link.
thanx

Tom Kyte
May 25, 2003 - 10:00 am UTC

see the text application developers guide:

</code> http://docs.oracle.com/docs/cd/B10501_01/nav/docindex.htm#index-TEX <code>

when you search on asktom, you are using that technology.

REDO

Van Driessche Erik, May 27, 2003 - 9:36 am UTC

Hi Tom,

About the backup mode of a tablespace, some documentation says that there is no difference in redo generation when you put a tablespace in backup mode. When she is not, there is also redo generated .... or not ?

Kind regards

Tom Kyte
May 27, 2003 - 9:43 am UTC

show me Oracle documentation that says "the redo generation is no different after an alter tablespace begin backup has been issued"


otn.oracle.com has all of the docs, post a link to it.

Relevant

Erik, June 02, 2003 - 4:58 am UTC

Hi Tom,

I did a search on metalink, redo generation hot backup ...

but in every search I receive a ton of irrelevant documents ...

do you a otn document where I can find the necessary info.

Tom Kyte
June 02, 2003 - 7:32 am UTC

what "necessary info".

if your search is as specific as your question -- I can understand why you got lots of hits :)

RMAN

Kevin, June 02, 2003 - 9:28 pm UTC

#1 regading rman backup, ramn uses Oralce processes to backup
only used (ever been used) data blocks and maintain read-consisitency of blocks (through rbs).

Tom Kyte
June 03, 2003 - 7:20 am UTC

it doesn't maintain read consistency, the backups are fuzzy/inconsistent (unless is was "cold").. Think of the ora-1555's that would happen during a long running backup otherwise.

Documentation of Stored procedures & functions

A reader, July 22, 2003 - 3:36 am UTC

Hi Tom,
We are using database procedures for the complex business logic,in your experience what's the format, approach that should be adopted to document all the business logic.
I am thinking of a High level document which gives the interaction between procedures the Process Flow and ER diagram for a procedures or business function which it is catering for.and a low level document which gives the details of all the queries.
But i am not very sure of this, whats the kind of documents have u generally provided when handing over the project.

Thanks



Tom Kyte
July 22, 2003 - 8:24 am UTC

what tool would your company use for java? for VB? for C? use the same tool, same methodology. It is just "code"

what is handed over to a client is what the client askes to be handed. Oracle Designer is frequently used as our repository on large systems. The needs vary from situation to situation

Nice

R.Chacravarthi, July 22, 2003 - 9:34 am UTC

Dear Sir,
when there is a need for text based searches I think we can
use the contains function provided it is a long column.
for ex:
select * from emp where contains(column_name,'some text');
I hope this will work.
I have a question for you.
It is "what is the undo generated for insert statements"
Thanks.
Yours sincerely,
R.Chacravarthi

Tom Kyte
July 22, 2003 - 2:52 pm UTC

the undo generated for an insert is the sum of

a) the changes made to any indexes affected
b) a "delete rowid" entry for each inserted row (so we can "un-insert" them)

Interview question

Totu, February 15, 2005 - 9:18 am UTC

Dear Tom.
I have asked below question today and couldn't anwser:

A user is getting an ORA-00942 error yet you know you have granted them permission on the table, what else should you check?

Could you help me?

Thanks in advance.

Tom Kyte
February 15, 2005 - 3:34 pm UTC

bad synonym perhaps.

they did a alter session set current_schema=something_else perhaps (so select * frm t isn't select * from t, it is from something_else.t, not the t you thought)

A reader, February 01, 2011 - 10:25 am UTC

Good Day Tom,

First of all thanks for your help to oracle community!!!

Recently I attended interview for DBA and they ask me below two question

(1) How to do capacity planning?

(2) How to do performance tunning?

what will be the suitable answer for the above

Many thanks


Tom Kyte
February 01, 2011 - 5:21 pm UTC

(1) that is a hard/ambiguous question to answer.

Do they mean capacity planning for a system that doesn't exist yet, one you are going to build? (many do).

In which case my answer is "tell me how much money you have and I'll buy all of the equipment I can with that much money and we'll see after it is done if it will work". I've not seen anyone really be able to spec out what they need before they build it. No one can answer things like "how many transactions", "how big are the transactions", "how many concurrent transactions" and so on.

Do they mean capacity planning for a 3rd party product that hasn't been implemented yet?

In which case my answer is "ask the vendor for a system sizer - they can answer the above questions - we cannot - and you need to know those answers"

Do they mean capacity planning for an existing application that has been running for a while?

Then I want access to AWR and ASH information - so I can discover the answers to those questions. It'd be nice to have access to the change management pack too so I could see growth rates and stuff. In other words - it takes a million metrics to plan for capacity and you'd have to have been gathering them for a while - as the database does (as long as you have access to it)


(2) The only answer to this is "it depends".

Please give me a scenario. They are all different. The answer might be "turn on sql trace, run the application, find the slowest sql, tune it". The answer might be "give me a statspack/awr and let's see what we see".

The process would be:

(a) define what the performance issue is and who is affected by it.
(b) identify the root cause of the performance issue (and the ways to do that are many - it depends on the performance issue)
(c) address the root cause.


For example, if a single screen is "slow", discover the code behind the screen - and see if the time is spent in the database or in the application. Once you determine it is in the database - tune it. Tune the application approach to the database (the algorithms), the sql, whatever it is that is causing it to be slow.


There is no "ten step list to tuning"

How to acheive the reverse data in stored procedure?

charankumar, July 11, 2011 - 2:22 am UTC

Hi Tom,

i got somany solution in orable by you.thanks
i need to create one stored procedure that is related to reverse data.how to achieve this scenario?
my fields are system,rate ,a,b,c,d, in my table,but a=123,b=abc,c=july,d=date this data contained.if system=1 and rate =1 condition success we get a= 321,b=cba,c=yluj .d= etad will be appeared?how to write the stored procedu for this scenario.please give me suggestion.

Tom Kyte
July 12, 2011 - 7:31 am UTC

you can either

a) write your own function to reverse a string and call it

b) use the undocumented (and hence, possibly unsafe to use) reverse function.
ops$tkyte%ORA11GR2> select reverse( 'abc' ), reverse( '123' ) from dual;

REV REV
--- ---
cba 321


Performance

AK, July 12, 2011 - 10:53 am UTC

Hi Tom,

Greetings,
Thank a lot for all your help.
Since one question regarding performance is there, i am asking another in this thread.

Question: Is there a way to find
when a request is received by an oracle database(listener) first and
when the first bit of data started to be sent back to requester and
when was the request finally completed by the database ?

The reason i am asking is to differentiate at an early stage in investigation
where the response time lies the most, whether at the application server level or with the database.


Many Thanks

Tom Kyte
July 13, 2011 - 2:00 pm UTC

the listener does NOT receive sql requests. the listener just redirects you to a database and gets out of the conversation.


If you just enable sql trace - we'll tell you EXACTLY how much time is spent in the database - we record that very very exactly. So, just trace it.


not good

venkata, July 12, 2011 - 3:44 pm UTC

Charankumar,

You know Tom doesn't like typos so you very cleverly typed something similar to typos hmmm and i don't think INDIANs can be dump as you have represented here
Tom Kyte
July 13, 2011 - 2:10 pm UTC

I don't care about typos, I make typo's.

I care when people speak like 12 year old children - using "u", "ur" and the like. It just makes you look "not smart". I've seen it on resumes, cover letters, emails, posting in forums like this. It is not very professional, it makes you sound "not smart". It is insulting to the person reading it. Nothing good comes from it.


I don't care if your are Indian, French, Spanish, Australian, Martian or whatever - if you cannot take the time to type out actual words - why should I bother answering you or even giving you a modicum of respect? You gave us none by using 'text speak'


By the way, you have a typo, it isn't 'dump', it is dumb - but that is OK - a typo is an accident. Text speak is on purpose.


Charankumar didn't use text speak - he may have had a typo or two, but it is clear that english is his second language and I was able to read over all of that. It is only those that have actually mastered english that can use text speak (think about that - those that are capable of putting out perfect prose are the ones that choose to speak like children on purpose???)

how move the data to one location to another location

charankumar, July 13, 2011 - 5:06 am UTC

Hi tom,

please suggetion for this scenario.i have table that data is belongs to one schema but i moved same data move to another schema.how to connectivity of these two location. please explain the solution?
Tom Kyte
July 13, 2011 - 8:17 pm UTC

in the other schema:

create table my_table as select * from the_other_schema.their_table;


then you can drop the other schema's table, that is the way to do this.

Regarding Typos

A reader, July 13, 2011 - 2:28 pm UTC

Hi Tom,

I really appreciate your views on such a topic. I must say the words are well put together and prove that you not only an experienced technical expert but a wonderful teacher, who masters nearly everything.

Nice to have some off-topic thoughts. I always wonder if you could write something about you in your blog like your hobbies, how you spend your time on weekends.. So that we could know you a bit better. But obviously in your blog when you are free.

Now back to technical forum. :)

Regarding Typos

A reader, July 13, 2011 - 7:43 pm UTC

Tom,

You are amazing. Thank you very much for the great response to Venkata. Especially this one
“By the way, you have a typo, it isn't 'dump', it is dumb - but that is OK - a typo is an accident. Text speak is on purpose.”

Venkata,

Mate, Asktom is all about technical forums and as Tom stated, English is not a first language for many Information Technology professionals who want to clarify their doubts about the technologies by asking questions to someone like Tom.

Please avoid personal and racial attacks in future. Technical forums are open for debate where you can disagree with someone’s viewpoint by benchmarking your opinion.

Again, Tom thanks heaps for setting up very nice example.

Cheers,





yup i shouldn't have been rude

venkata, July 14, 2011 - 2:37 am UTC


Value Tom Kyte's Time

Bharathkumar V, July 15, 2011 - 5:05 am UTC

Dear All,

Everyone who have been using this link must be aware
how much effort he (Mr.Tom Kyte) puts into in answering
the same.

Let us follow a professional approach in the process
of our request for help/clarification.

Go through the site before asking a question, give proper examples (a sample table with values),exact error code
with messages which will save his time to answer the question which will be useful for all of us.

His time is precious and we have to make the best use
of it.

P.S:
Watch his presentation "What Are We Still Doing Wrong"
- a very useful one. One should not miss the last but one part of the part of the presentation.

Re: Interview Questions

Nand Kishore Sagi, July 15, 2011 - 6:27 am UTC

Hi Tom,

While on interview questions, I was once asked how would we defragment a table. That kind of stumped me during the interview and answered that I don't know. I asked the interviewer if he can help me with the answer. He said that he was the one asking questions here. Ouch!

Anyways after coming back from the interview I did a bit of research I found that one way was to move the data into a backup table (maybe in different tablespace) and then drop and recreate the target table. What I am trying to understand is,

(1.) What's the impact of defragmented disk on query execution?
(2.) Will the solution noted above work ?
(3.) Are there any other approaches to achieve defragmentation?

On a side note Tom, I have seen many experienced professionals who display a lot of attitude in front of the newbies. For example I don't know what the correct etiquette is for interview with respect to questions to which you don't know the answer. Should I try to find the answer out or should I just answer what's asked of me.

Whenever I find myself on the other side of the table (As a interviewer) I generally answer the question so that they learn the concept too. Anyways now this post became more of a whining post then the actual technical post which I meant it to be.

I really want to thank you from heart for being the kind, understanding and patient guru, you have been.

Thanks a lot.

Thanks and Regards
Nand Kishore Sagi
Tom Kyte
July 18, 2011 - 9:08 am UTC

In an interview, if you don't know the answer to something, I would just state it - say "In my prior workload, I never had a need to do that"

However, if you were going for a DBA job and the DBA job required experience (it was not an entry level job) and you couldn't answer that particular question "how to defragment a table", well, that would be something I would expect almost any DBA with a year or two of experience to answer - answers could be:

a) alter table t move;
b) dbms_redefinition for an online re-organization
c) data pump export/import IF the table has a long in it (otherwise I would not want to use it)
d) alter table t shrink space compact


As for your specific questions

(1) typically NOTHING unless you frequently full scan the table. If you access the table solely by index - a reorganization doesn't typically do much for you (there are cases when it does, but in general it does not).

If you frequently full scan the table AND the table has large sections of "white space" (empty space, space where rows once where but have been deleted), then a reorganization could be very beneficial as it will tend to remove all of this white space.


If you frequently do large index range scans (getting more than a handful of rows via an index) and there is large amounts of white space again (lowering the number of rows per block in the table AND increasing the number of table blocks we have to inspect because of that lower number), then a reorganization might be beneficial and might knock off a couple of table IO's

If you frequently do large index range scans and when you do the reorganization, you sort the table data by the index key (improving the clustering factor of that index), you can make a real impact as well (but remember - a table can be sorted only one way - if you 'fix' one range scan - you probably broke another!)

see
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1032431852141#433021700346025909


(2) I would not use a separate table like that, just alter table t move; would do it. Much safer, faster, easier.

(3) yes, see above :)






only one best index

A reader, July 18, 2011 - 10:40 pm UTC

In the link mentioned in previous followup,I infer ony one index will be the best from CF perspective.Am I right ?
If we have composite indexes for eg
one index on columns A,B,C
other on say B C D
other on say B E F
other on say C G I
( where A,B,etc are column names)
,the one whose clustering factor is close to number of blocks is best to use >
Tom Kyte
July 19, 2011 - 7:47 am UTC

by CF I assume you mean clustering factor (why do people invent acronyms and then never define them?? Just to be purposely obtuse and confusing? Can you tell this is a huge pet peeve of mine, our industry is horrible when it comes to acronyms...)


You can have more than one index with a 'good' clustering factor. Consider a table:

create table emp( empno number primary key, hiredate date, ename varchar2(30), termination_date date );

empno is populated by emp_seq.nextval
hiredate is populated by sysdate
ename is a randomly arriving string - sometimes you hire someone with a name that starts with A, then M, then Z, then B, then X and so on...

In that table, you usually insert and update only - when you fire someone, their termination_date field is filled in (a flag delete)

It is a normal heap based table.

Given the above, you can sort of assume that the data on disk will be sort of sorted by EMPNO and also sorted by HIREDATE - since both are monotonically increasing. The clustering factor on the EMPNO column would be near the number of blocks in the table. The clustering factor on HIREDATE would probably be near the number of blocks as well. The clustering factor on ENAME and TERMINATION_DATE would likely be near the number of rows - since they are randomly arriving.



As for this comment:

,the one whose clustering factor is close to number of blocks is best to use >


that is a bit misleading. The best index to use is the one that can answer your question efficiently. Suppose the indexes are such that:

(b,c,d) has clustering factor of 1000
(b,e,f) has clustering factor of 2000
(c,g,i) has clustering factor of 1,000,000

If you have a predicate

where c = ? and g = ? and i = ?

the only index to consider would be the one on C,G,I - the other indexes would not make sense to retrieve from the table given that predicate.


The clustering factor is used to determine how many rows from a given table an index would be efficient for. The lower the clustering factor, the higher the number of rows we'll retrieve from the table - and vice versa. The indexes on b,c,d and b,e,f would not really be considered very much for this query since they do not help with the predicate and they cannot be used instead of the table to answer the question.

Re: Re: Interview Questions

A reader, July 19, 2011 - 2:10 am UTC

Hi Tom,

Thanks a lot for the info. Thanks to you I learnt something new.

By the way the interview was for senior PL/SQL developer and also as you said "In my prior workload, I never had a need to do that". I agree it is good to keep expanding your horizons but to solely ask questions out of the scope of the job necessities.....not sure what I can say to that.

Thanks a lot Tom for all your help and guidance.

Thanks and Regards
Nand Kishore Sagi
Tom Kyte
July 19, 2011 - 7:59 am UTC

I don't know why someone would ask a plsql developer how to reorganize a table.

That would be like asking them to balance the books - totally irrelevant to the job description.

I'd actually prefer a developer that didn't even know tables could be reorganized - they wouldn't ask for it to be done "just in case it makes my code go faster"

Sort column without using ORDER BY

Ravi B, June 28, 2018 - 6:00 pm UTC

Today i had an interview with one of the social media sites. The only question they asked me was how do you sort a column without using ORDER BY clause?

I was told it is a database agnostic question. Any DB vendor specific functions,features should not be used.

create table test_sort(id number, amt number);

insert into test_sort values(10, 100);
insert into test_sort values(20, 300);
insert into test_sort values(30, 50);
insert into test_sort values(40, 10);
insert into test_sort values(50, 400);

Expected output for AMT column:

10
50
100
300
400

Thanks!
Chris Saxon
June 29, 2018 - 9:27 am UTC

The only way to guarantee your rows appear in a given sequence is to use an order by.

Other operations may give the appearance of sorting, but this is an illusion. For example, older versions of Oracle Database implemented group by using a sort. Which lead some people believe that group by => order by. So were surprised when we switched to group by hash, "breaking" the sort.

So the answer is: there isn't one!

Sort column without using ORDER BY

Ravi B, July 01, 2018 - 4:48 am UTC

Thanks for the reply. I tried to explain this with the interviewer. This is for facebook by the way. Apparently there "might" be a way to do this otherwise they would not have asked me this question. They only "hint" they gave me is "can you try and use max or min in the SQL based on which way you are trying to sort?" I tried to explain the "possible" answers using self join, correlated sub query, analytical functions etc. They said they don't work. This was the only question I was asked and they sent a feedback that I am no good in SQL. They ended the interview in 15 minutes, needless to say, i did not get the job :)
Connor McDonald
July 01, 2018 - 9:12 am UTC

Man this kind of crap really gets me riled up.

(I stress - this is directed at the interviewer and interview process, not at you).

I mean seriously...what a bunch of rubbish. When I went for my car license test I don't recall them saying: "Now then....lets assume you didn't have a steering wheel...what are your options for turning?"

I've seen this question on the internet and there's always answers like "use clustered tables/indexes" (for certain platforms), or recursive with etc etc...

For example, here's a "solution" that uses scalar queries:

SQL> with idx as
  2   ( select
  3       rownum r ,
  4       x ,
  5       ( select count(*) from t t_inner
  6         where t_inner.x <= t.x
  7       ) seq
  8     from t
  9   )
 10  select idx.* ,
 11   ( select x
 12     from  idx idx_inner
 13     where idx_inner.seq = idx.r
 14   ) sorted
 15  from idx;

         R          X        SEQ     SORTED
---------- ---------- ---------- ----------
         1         32          3          4
         2         96         10         19
         3         62          5         32
         4         39          4         39
         5         74          7         62
         6         19          2         67
         7          4          1         74
         8         95          9         76
         9         67          6         95
        10         76          8         96


But *all* such solutions are:

- ridiculous because they have no real world application

- wrong! Because no matter HOW you write an SQL, there is NEVER any means to completely predict the order WITHOUT an order by clause. This is a fundamental premise on how database are implemented - the *optimizer* and execution engines decide on how to access the data.

Be happy you didn't get the job. If the job is anything like the interview there's a lack of fundamental understanding how relational databases work.

Sort column without using ORDER BY

Ravi, July 01, 2018 - 10:22 pm UTC

Thank you very much for response and well said.

Yes i felt the same way, I would not have accepted the offer even they gave me one. I did not see any point of this question. Had I been on the other side of the table, i could have also asked them some gotcha questions and try and make them miserable. Gladly, my self image does not depend on those guys :) I think it shows their low self image or something or they think they or on a pedestal because they work for FB or Google, not sure :)

Sort column without using ORDER BY

siva, July 15, 2018 - 2:49 pm UTC

To get sorting column without using ORDER BY ,I achieved this with below query .

select mgr ,empno from emp
union
select mgr,empno from emp where 1=2;

But i want to know the disadvantage of this query.Can you please help .
Chris Saxon
July 16, 2018 - 9:13 am UTC

There's no guarantee that the database will implement the union using a sort. This could change.

More to Explore

CLOB/BLOB/etc

Complete documentation on Securefiles and Large Objects here