PHP MySql Web Hosting

PHP and MySQL Web Development

,ch04.13730 Page 172 Wednesday, November 29, 2000 4:43

Filed under: SQL in a Nutshell — webmaster @ 5:18 am

,ch04.13730 Page 174 Wednesday, November 29, 2000 4:43 PM Examples These examples generally work on any one of the four database vendors profiled in this book. Only the second Oracle example, with a negative starting position, fails on the others (assuming, of course, that Oracle s SUBSTR is translated into SUBSTRING): /* On Oracle, counting from the left */ SELECT SUBSTR(’ABCDEFG’,3,4) FROM DUAL; -> CDEF /* On Oracle, counting from the right */ SELECT SUBSTR(’ABCDEFG’,-5,4) FROM DUAL; -> CDEF /* On MySQL */ SELECT SUBSTRING(’Be vewy, vewy quiet’,5); -> ‘wy, vewy quiet'’ /* On PostgreSQL or SQL Server */ SELECT au_lname, SUBSTRING(au_fname, 1, 1) FROM authors WHERE au_lname = ‘Carson’ -> Carson C TRIM The TRIM function removes leading spaces, trailing characters, or both from a specified character string. This function also removes other types of characters from a specified character string. The default function is to trim the specified character from both sides of the character string. If no removal string is specified, TRIM removes spaces by default. SQL99 Syntax TRIM( [ [{LEADING | TRAILING | BOTH}] [removal_string] FROM ] target_string [COLLATE collation_name]) The removal_string is the character string to be stripped out. The target _string is the character string from which characters are to be taken. If a removal_string is not specified, then TRIM strips out spaces. The COLLATE clause forces the result set of the function into another preexisting collation set. MySQL, PostgreSQL, and Oracle support the SQL99 syntax of TRIM. Microsoft SQL Server (and the other vendors for that matter) provide the functions LTRIM and RTRIM to trim off leading spaces or trailing spaces, respectively. LTRIM and RTRIM cannot be used to trim other types of characters. Examples SELECT TRIM(’ wamalamadingdong ‘); -> ‘wamalamadingdong’ 174 Chapter 4 SQL Functions

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP Web Hosting services

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.

Powered by PHP MySQL Web Hosting