Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Tue, 02 Jan 2007 @ 09:56:25 GMT


     
  <Prev Next>   <<First <Prev Next> Last>>  


Subj:   Re: STRING functions: Counting character occurrences
 
From:   Dieter Noeth

Kumar Veerappan wrote:

  As a newcomer to Teradata SQL is there a way of counting how many of a particular character occurs in any given string?  


This is a perfect case for a UDF.

If you don't want (or can't) write an UDF, but already installed the available Oracle-UDFs from Teradata.com, you can do it the old way:

     SELECT
        CHAR_LENGTH('AACCFFAAGRTA')
       -CHAR_LENGTH(oreplace('AACCFFAAGRTA','A',''))

  And is there a function to get the actual defined size of a column.?  


There's no function for it, but you can query dbc.columns.

For Char/Varchar ColumnLength represents the physical size:

     "char(30) charcter set LATIN" -> 30
     "char(30) charcter set UNICODE" -> 60

To calculate the maximum number of chars you have to check CharType. If you only got LATIN (1) and UNICODE (2) do a simple ColumnLength/CharType.


Dieter



     
  <Prev Next>   <<First <Prev Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 27 Dec 2016