Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

Find position of a character in a string - response (6) by dnoeth

$
0
0

You can modify the query i posted at
http://forums.teradata.com/forum/database/stored-procedures-need-help-with-massaging-data-within-an-input-parameter

WITH RECURSIVE cte
 (groupcol,
  len,
  remaining,
  word,
  pos
 ) AS (
  SELECT
    GroupCol,
    POSITION('_' IN String || '_') - 1 AS len,
    SUBSTRING(String || '_' FROM len + 2) AS remaining,
    SUBSTRING(String FROM 1 FOR len) AS word,
    1
  FROM strings
  UNION ALL
  SELECT
    GroupCol,
    POSITION('_' IN remaining)- 1 AS len_new,
    SUBSTRING(remaining FROM len_new + 2),
    SUBSTRING(remaining FROM 1 FOR len_new),
    pos + 1
  FROM cte
  WHERE remaining <> ''
  AND pos <= 4
 )
SELECT
  groupcol,
  pos,
  word
FROM cte
WHERE pos = 4
ORDER BY
  groupcol, pos;

 
But a UDF is still the best solution, you might ask your DBA to install one. Most DBA don't like UDFs as they are written in a unknown language (C) and the Oracle functions (http://downloads.teradata.com/download/extensibility/teradata-udfs-for-popular-oracle-functions) are not officially supported, but when you switch to TD14 they will be included and you could start using them right now.
Or use those ebay functions found at http://developer.teradata.com/blog/madmac/2010/03/a-few-basic-scalar-string-udfs, they're definitely tested a lot and probably use the fastest possible code.
Dieter
Dieter


Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>