Tuesday 3 June 2014

Query to find the first word from a string

 WITH qry
AS
(
   SELECT NULL field_name FROM dual
      UNION ALL
   SELECT 'AMAR' FROM dual
      UNION ALL
   SELECT 'AMAR ALAM' FROM dual
      UNION ALL
   SELECT 'Abdul M Faheem' FROM dual
      UNION ALL
   SELECT 'Sravan P. Kumar' FROM dual
      UNION ALL
   SELECT 'IBM India Pvt, Ltd' FROM dual
      UNION ALL
   SELECT 'IBM India Pvt, Ltd.' FROM dual
      UNION ALL
   SELECT 'IBM India Pvt Ltd' FROM dual
)
SELECT field_name,
       REGEXP_REPLACE(field_name, '^(\w+)(.*?)(\w*$)', '\1')  exp1,
       REGEXP_REPLACE(field_name, '^(\w+)(.*?)(\w*$)', '\2')  exp2,
       REGEXP_REPLACE(field_name, '^(\w+)(.*?)(\w*$)', '\3')  exp3
  FROM qry;




Ur's
AmarAlam

1 comments:

Praveen Kumar said...

Great post, thank you for sharing this usefull information.It is very easy to understand.Keep regular update with your blogs.

Crm Software Companies in Bangalore | Crm Software Development Company Bangalore

Post a Comment