Database Management System
Course-code: CSE 3103
Prepared By:
Sumaia Rahman
Asst. Prof, Dept. of CSE,
Varendra University
String Functions & Encryption Algorithm
ASCII: Return the ASCII code of given character expression.
Select ASCII (‘A’);
Output: 65
If we write Select ASCII (‘ABC’) then
Output: 65
But if we write Select ASCII (‘BC’) then what will be the output?
Output : 66
CHAR:
Converts an integer ASCII code to character.
The integer expression should be between 0 to 255.
Select CHAR (97) ;
Output: a
LTRIM:
Remove blanks on the left hand side of the given expression.
Select LTRIM(‘ students’);
Output: students
RTRIM:
Remove blanks on the right hand side of the given expression.
Select RTRIM(‘students ’);
Output: students
LOWER:
Converts all the character in the given character expression to
lowercase letters.
Select Lower (‘STUDENT’)
Output: student
UPPER:
Converts all the character in the given character expression to
uppercase letters.
Select Upper (‘student’);
Output: STUDENT
REVERSE:
Reverse all the characters in the given character expression.
Select Reverse (‘hello’);
Output: olleh
LEN:
Returns the count of total characters in the given string expression
excluding the blanks at the end of the expression.
Select Len (‘ hello’);
Output: 7
CHARINDEX
Return the starting position of the specified expression in a character
string. Remember its starts from 1 not 0.
Select charindex(‘@’, ‘example@[Link]’);
Output: 8
SUBSTRING:
Return substring (part of string) from given expression.
select substring (‘example@[Link]’,1,7)
Output: example
REPLICATE
Replace the given string to specified number of times.
Select Replicate (‘hello ’,2);
Output: hello hello
REPLACE
Replaces all occurrences of a specified string value with another
string value.
Select replace (‘example@[Link]’, ‘gmail’, ‘yahoo’);
Output: example@[Link]
Encryption Algorithm
Some algorithm for encryption
Secured Hash Algorithm 1
Secured Hash Algorithm 2
Secured Hash Algorithm 1
This is one of the secured algorithm to encrypt confidential data.
But there is no decryption algorithm of it. So we can never know which data is
encrypted.
Syntax:
insert into tblstudent values (hashbytes(‘sha1’, ‘hello’));
Now what we will see in database?!!
To know ,where we use hashbytes
insert into tblstudent values (hashbytes(‘sha1’, ‘hello’));
Data is inserted into the table with encrypted values.
Now we have to execute the following query to know where the
data is stored as encrypted value.
select * from tblstudent
where name = HASHBYTES ('sha1', ‘hello ')