string functions in SQL ujjwal matoliya.pptx

ujjwalmatoliya 61 views 20 slides Jun 16, 2023
Slide 1
Slide 1 of 20
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20

About This Presentation

SQL string functions are used primarily for string manipulation.
The initcap() function converts the first letter of each word in a string to upper case, and converts any remaining characters in each word to lowercase.

Query: SELECT initcap(ename) FROM employee;
* LCASE () is a synonym for LOWER ()...


Slide Content

ATAL BIHARI VAJPAYEE VISHWAVIDYALAYA BILASPUR (C.G.) SESSION: 2020-21 Subject:- SQL /PL-SQL Submitted by Ujjwal Matoliya

String Functions in SQL SQL string functions are used primarily for string manipulation.

Employee SELECT * FROM employee;

The initcap () function converts the first letter of each word in a string to upper case, and converts any remaining characters in each word to lowercase. Query: SELECT initcap ( ename ) FROM employee; Initcap ()

UCASE () is a synonym for UPPER (). Returns the string str with all characters changed to uppercase according to the current character set mapping. Query: SELECT UPPER( ename ) FROM employee; UPPER(str)/UCASE(str)

* LCASE () is a synonym for LOWER (). * Returns the string str with all characters changed to lowercase according to the current character set mapping. Example1: SELECT lower( ename ) from employee ; LOWER(str)/ LCASE(str)

* Returns the length of the string str measured in bytes. A multi-byte character counts as multiple bytes. This means that for a string containing five two-byte characters, LENGTH() returns 10, whereas CHAR_LENGTH() returns 5. Query: SELECT LENGTH(' ename ') from employee ; LENGTH(str)

Returns the string str with all remstr prefixes or suffixes removed. If none of the specifiers BOTH, LEADING, or TRAILING is given, BOTH is assumed. remstr is optional and, if not specified, spaces are removed. Example: SELECT TRIM(‘ reena ') from dual; TRIM ([{BOTH | LEADING | TRAILING} [ remstr ] FROM] str)/ TRIM([ remstr FROM] str)

Example: SELECT TRIM(LEADING ‘#' FROM ‘###reena###') from dual; TRIM {LEADING}

Example: SELECT TRIM(BOTH ‘#' FROM ‘###reena###') from dual; TRIM {BOTH}

Example: SELECT TRIM(TRAILING ‘#' FROM ‘###reena###'); TRIM {TRAILING}

Returns the string str with trailing space characters removed. Example: SELECT RTRIM(‘ muskan ') from dual; RTRIM(str)

Returns the string str with leading space characters removed. Example: SELECT LTRIM(‘ muskan ') from dual; LTRIM(str)

Returns the string str, left-padded with the string pad str to a length of len characters. If str is longer than len , the return value is shortened to len characters. Example: SELECT LPAD(‘11',4,’22') from dual; LPAD( str,len,padstr )

Returns the string str, right-padded with the string pad str to a length of len characters. If str is longer than len , the return value is shortened to len characters. Example: SELECT RPAD(‘11’,4, ‘22') from dual; RPAD( str,len,padstr )

Returns the string that results from concatenating the arguments. May have one or more arguments. If all arguments are non-binary strings, the result is a non-binary string. If the arguments include any binary strings, the result is a binary string. A numeric argument is converted to its equivalent binary string form; if you want to avoid that, you can use an explicit type cast, as in this: Example : SELECT CONCAT( ename , hire_date ) FROM employee; CONCAT (str1,str2,...)

Returns the string str with all occurrences of the string from_str replaced by the string to_str . REPLACE() performs a case-sensitive match when searching from_str . Example: SELECT REPLACE(‘RRR.com', ‘R', ‘Rr’) from dual; REPLACE( str,from_str,to_str )

Returns the string str with the order of the characters reversed. Example: SELECT REVERSE(' abcd ') from dual; REVERSE(str)

Returns the numeric value of the leftmost character of the string str. Returns 0 if str is the empty string. Returns NULL if str is NULL. ASCII() works for characters with numeric values from 0 to 255. Example: SELECT ASCII('2') FROM DUAL; ASCII(str)

Thank You