2012-07-31

Teradata - String functions sampler


select distinct

      -- Concatenation
      'string 1' || ' string 2' as StringConcatenation
      , '[' || '   asdf   ' || ']' as ConcatenationWithSpaces

      -- Position and length
      , position( '_' in 'hamburgers_hot dogs' ) as PositionFound
      , position( 'a' in 'qwer' ) as PositionNotFound
      , position( 'a' in null ) as PositionInNull
      , lower( 'ABCdef' ) as LowerCase
      , upper( 'ABCdef' ) as AnUpperCase
      , character_length( 'asdf' ) as CharacterLength

      -- Trimming
      , '[' || trim( '   asdf    ') || ']' as DefaultTrim
      , '[' || trim( leading  ' ' from '  asdf') || ']' as TrimLeading
      , '[' || trim( trailing ' ' from 'asdf  ') || ']' as TrimTrailing
      , '[' || trim( both ' ' from '   asdf  ') || ']' as TrimBoth
      , '[' || trim( leading '0' from '0001230') || ']' as TrimLeadingZeroes
      , trim( leading '0' from '001234560' ) as TrimLeadingZeroes2
      , '[' || trim( both '0' from '0001230') || ']' as TrimZeroes

      -- Casting and formatting
      , CAST(123456789.00 AS FORMAT 'G999999999D99') as Casting
      , 123456 ( FORMAT 'G-(10)D9(2)' ) as AFormat

      -- Substring
      , substr( 'asdf', 3, 3 ) as Substring3
      , substr( 'asdf', 1, 3 ) as Left3
      , substring( 'asdfxyz' from CHARACTER_LENGTH( 'asdfxyz' ) -2 FOR 3) as Right3
      , substring( '0123456789ABCDEF' from CHARACTER_LENGTH( '0123456789ABCDEF' ) -11 FOR 12) as Right12

;

No comments:

Post a Comment