Need output for an oracle query

77 views Asked by At

I've a table and in that customer name column have some records. I need output as below

Table:
-------
Cname                     Cno
------                    ---
Ramesh babu                1
james k bold               2
Raghu manipati             3
uppu sukanya               4

Expected Output

cname:
------
babu
bold
manipati
sukanya
2

There are 2 answers

0
Maheswaran Ravisankar On

You need a combination of SUBSTR() and INSTR().

Search for the position of space from last and extract all the characters after that.

SUBSTR(CNAME , INSTR(CNAME,' ',-1) + 1)

0
Lalit Kumar B On

Simple use SUBSTR and INSTR.

For example,

SQL> SELECT full_name,
  2    SUBSTR(full_name, instr(full_name, ' ', -1, 1) +1) last_name,
  3    id
  4  FROM t;

FULL_NAME      LAST_NAME              ID
-------------- -------------- ----------
Ramesh babu    babu                    1
james k bold   bold                    2
Raghu manipati manipati                3
uppu sukanya   sukanya                 4

SQL>