![]() In this tutorial, you have learned how to use the PostgreSQL LEFT() function to get the n left-most characters in a string. If you want to get the n rightmost characters, please see the RIGHT() function for the details. Finally, the COUNT() function returns the number of customer for each group. Then, the GROUP BY clause groups customers by their initials. The ASCII() function returns an integer that represents the ASCII code value of the input character. If you pass a string to the ASCII() function, it will return the ASCII code of the first character. The char argument is a character that you want to get the ASCII code. In this example, first, the LEFT() function returns initials of all customers. The ASCII() function requires one argument: 1) char. The following statement uses the LEFT() function to get the initials and the COUNT() function to return the number of customers for each initial. See the following customer table in the sample database: In this example, n is -2, therefore, the LEFT() function return all character except the last 2 characters, which results in: left The following statement demonstrates how to use a negative integer: SELECT LEFT( 'ABC', -2) Code language: JavaScript ( javascript ) To get the first two characters of the string ‘ABC’, you use 2 instead of 1 for the n argument: SELECT LEFT( 'ABC', 2) Code language: JavaScript ( javascript ) The following example shows how to get the first character of a string 'ABC': SELECT LEFT( 'ABC', 1) Code language: JavaScript ( javascript ) Let’s look at some examples of using the LEFT() function. The PostgreSQL LEFT() function returns the first n characters in a string. If n is negative, the LEFT() function returns the leftmost characters in the string but last |n| (absolute) characters. Is an integer that specifies the number of left-most characters in the string should be returned. ![]() Is a string from which a number of the leftmost characters returned. The PostgreSQL LEFT() function requires two arguments: The following illustrates the syntax of the PostgreSQL LEFT() function: LEFT(string, n) Arguments In this tutorial, you have learned how to use the PostgreSQL LPAD() function to pad characters on the left of a string to a certain length.The PostgreSQL LEFT() function returns the first n characters in the string.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |