Page 190 - SQL
P. 190
SELECT DATALENGTH('Hello '); -- returns 6
It should be noted though, that DATALENGTH returns the length of the underlying byte
representation of the string, which depends, i.a., on the charset used to store the string.
DECLARE @str varchar(100) = 'Hello ' --varchar is usually an ASCII string, occupying 1 byte
per char
SELECT DATALENGTH(@str) -- returns 6
DECLARE @nstr nvarchar(100) = 'Hello ' --nvarchar is a unicode string, occupying 2 bytes per
char
SELECT DATALENGTH(@nstr) -- returns 12
Oracle
Syntax: Length ( char )
Examples:
SELECT Length('Bible') FROM dual; --Returns 5
SELECT Length('righteousness') FROM dual; --Returns 13
SELECT Length(NULL) FROM dual; --Returns NULL
See Also: LengthB, LengthC, Length2, Length4
Replace
Syntax:
REPLACE( String to search , String to search for and replace , String to place into the original string
)
Example:
SELECT REPLACE( 'Peter Steve Tom', 'Steve', 'Billy' ) --Return Values: Peter Billy Tom
LEFT - RIGHT
Syntax is:
LEFT ( string-expression , integer )
RIGHT ( string-expression , integer )
SELECT LEFT('Hello',2) --return He
SELECT RIGHT('Hello',2) --return lo
Oracle SQL doesn't have LEFT and RIGHT functions. They can be emulated with SUBSTR and
LENGTH.
SUBSTR ( string-expression, 1, integer )
https://riptutorial.com/ 172

