214 Part II . SQL Essentials Figure 9-41: (Disney web site)

214 Part II . SQL Essentials Figure 9-41: The ASCII and CHAR functions. Notice that when given more than one argument, the CHAR value returns the corresponding values without any separation. The LTRIM and RTRIMfunctions along with the LPAD and RPADfunctions both perform similar duties. The LTRIM and LPADfunctions operate on the left side of a string while the RTRIM and RPADfunctions operate on, you guessed it, the right side of a string. The LTRIM and RTRIMfunctions remove whitespace from a string while the LPADand RPAD functions add a specified number of characters to a string to make it a certain length. The characters to be added with LPADand RPAD can be whitespace or other characters. The total length of the string will be the length specified; any initial string longer than that length gets trimmed. (See Figure 9-42.) SELECT LTRIM( Hello World ); SELECT RTRIM( Goodbye World ); SELECT LPAD( Internet ,5, ); SELECT LPAD( Internet ,10, - ); SELECT RPAD( Another string ,16, : ); A somewhat different function for removing characters from a string is TRIM. Both the LTRIMand RTRIM functions only remove whitespace characters. However, with TRIM you can specify the character or string to remove. With TRIM you can also specify whether to remove the characters from the left side, right side, or both sides of the string. The syntax is somewhat specific for the TRIMfunction. If you include options such as BOTH, LEADING, or TRAILING, you must include the word FROM in the statement. The TRIMfunction will remove whitespace if you don t include any options such as BOTH, LEADING, TRAILING, or the string to remove. The command looks like this: TRIM ((BOTH | LEADING | TRAILING) () FROM) ; Syntax examples follow (as well as results in Figure 9-43): SELECT TRIM( Hello Rebecca ); SELECT TRIM(BOTH $ FROM $$$$Survey Says$$$$ ); SELECT TRIM(LEADING S FROM Steve Suehring );
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

Leave a Reply