Practice patience to feel the SQL’s power…

Few days back one of my peers went through a recruitment interview. He was given some SQL challenges to solve and he solved all except the following one:

 

SQL> select emp_name

  2  from employee;

 

EMP_NAME

————————————————————-

Rajesh Chakrabarti

 

 

He was told to show it like:

Rajesh

Chakrabarti

 

Somehow he was failed to solve this within the given time. Next day when he told me, we both tried it and solved it in different ways writing some clumsy code (containing more then 15 lines of PL/SQL code).

 

Then this technique came in mind…

 

SQL> select replace(emp_name,’ ‘,chr(10)) AS emp_name

  2  from employee;

 

EMP_NAME

————————————————————-

Rajesh

Charabarti

 

Simple solution, spaces are replaced by a Return [chr(10)].

 

 

The lesson we learned is: SQL’s power is sometimes ignored, we should think twice before moving toward PL/SQL.

Advertisement

One Response

  1. nice post

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.