Beruflich Dokumente
Kultur Dokumente
The ASCII function returns the NUMBER code that represents the
specified character in the database character set. The specification of
the ASCII function is:
Examples:
NUMBER
65
A
66
B
67
C
CONCAT
Concatenates two strings into one.
NAME SURNAME
ASET ISKAKOV ASETISKAKOV
ASEL OMAROVA
ASELOMAROVA
INITCAP
Sets the first letter of each word to uppercase. All other letters are set to
lowercase.
The INITCAP function reformats the case of the string argument, setting the
first letter of each word to uppercase and the remainder of the letters in that
word to lowercase. A word is a set of characters separated by a space or
nonalphanumeric characters (such as # or _ ). The specification of INITCAP is:
The LENGTH function returns the length of the specified string. The
specification for LENGTH follows:
Examples:
TABLE: PERSONAL
NAME SURNAME
ASET ISKAKOV
The LOWER function converts all letters in the specified string to lowercase.
The specifications for the LOWER function are:
Examples:
TABLE: PERSONAL
iskakov
UPPER
Converts all letters to uppercase.
The UPPER function converts all letters in the specified string to uppercase.
The specifications for the UPPER function are:
Examples:
TABLE: PERSONAL
ISKAKOV
TRANSLATE
Replace characters
Examples:
TABLE: P
NAME SURNAME
ASET ISKAKOV
TALGAT MIRZAYEV
TABLE: P
NAME SURNAME
ASET ISKAKOV
TALGAT MIRZAYEV
The INSTR function searches a string to find a match for the substring and, if
found, returns the position, in the source string, of the first character of that
substring. If there is no match, then INSTR returns 0. In Oracle7, if
nth_appearance is not positive (i.e., if it is 0 or negative), then INSTR always
returns 1. In Oracle8, a value of 0 or a negative number for nth_appearance
causes INSTR to raise the VALUE_ERROR exception.
SELECT INSTR(SURNAME,’a’,1,3)
FROM PERSONAL
1 2 3 4 5 6 7
abcanaa 6
1 2 3
Examples:
TABLE: PERSONAL
NAME SURNAME
abc abcanaa
SELECT INSTR(SURNAME,’a’,-1,3)
FROM PERSONAL
1 2 3 4 5 6 7
4 abcanaa
3 2 1
RTRIM
Remove characters from right
Examples:
TABLE: P
NAME SURNAME
ASET ISKAKOV
TALGAT MIRZAYEV
TABLE: P
NAME SURNAME
ASET ISKAKOV
TALGAT MIRZAYEV
Examples:
LPAD(‘SDU’,7,’A’) AAAASDU
LPAD(‘SDU’,7,’ABCDEFG’) ABCDSDU
TABLE: P
NAME SURNAME
ASET ISKAKOV
TALGAT MIRZAYEV
OKOKOKASET
SELECT LPAD(NAME,10,’OK’) FROM P;
OKOKTALGAT
RPAD
The RPAD function adds characters to the end of a character string
Examples:
RPAD(‘SDU’,7,’A’) SDUAAAA
RPAD(‘SDU’,7,’ABCDEFG’) SDUABCD
TABLE: P
NAME SURNAME
ASET ISKAKOV
TALGAT MIRZAYEV
ASETOKOKOK
SELECT RPAD(NAME,10,’OK’) FROM P;
TALGATOKOK
REPLACE
The REPLACE function returns a string in which all occurrences of a specified
match string are replaced with a replacement string
Examples:
TABLE: P
NAME SURNAME
ASET ISKAKOV
TALGAT MARATOV
ISKAKOV
SELECT REPLACE(SURNAME,’TOV’,’SIN’)
FROM P; MARASIN
TASKS
TABLE : CLASS
1-Write an SQL statement to returns name and surname separately.
STUDENT CLASS
NAME SURNAME
MULDASHEV.NURLAN 3A
-----------------------------------------------
NURUMBETOV.SYRYM 4A NURLAN MULDASHEV
SYRYM NURUMBETOV
STUDENT CLASS
Nurlan MULDASHEV 3A
Syrym NURUMBETOV 4A
3-Write an SQL statement to returns the index of the books as shown in the figure below.
TABLE : BOOKS
BOOKNAME TOTALPAGE BOOKNAME TOTALPAGE
-----------------------------------------------------------
MAGIC BOOK 520
MAGIC BOOK……………………… 520
X-MAN 400 X-MAN……………………………… 400
4-Write two SQL statement to returns the position of the third ‘or’ in the following string. (search from left and right)
Corporate Floor
5-Write an SQL statement to returns the position of the first “FOUR” from the string: Take the first four characters
6-Write an SQL statement to returns the position of the second “ten” from the string : seven ten eight nine ten one
7-Write an SQL statement to returns the position of the second “a” from the string : Take the first four characters
8-Write an SQL statement to returns the value between two commas from the STRING table below.
TABLE : string
text
---------------
Abc,def,gfh
Sd,fghjk,gh
Asdfgh,f,fghjjk
9-Write an SQL statement to returns JOBs in ascending order by its character number.
10-Write an SQL statement to returns names without any spaces from both sides.
TABLE : students
Name
----------
Nurlan
Asem
Aynura
Write an SQL statement to update ENAME column from table “EMP“ as shown below.
11-Change ‘A’ with ‘X’
12-Change ‘N’ with ‘S’ and ‘M’ with ‘9’
13-Write an SQL statement to returns the ASCII code of the third character from “ename” in EMP.
1) select substr(STUDENT,1,instr(STUDENT,'.')-1) AS NAME, substr(STUDENT,instr(STUDENT,'.')+1),LENGTH(STUDENT)) AS
SURNAME from class;
2) UPDATE CLASS SET STUDENT=SUBSTR(STUDENT,INSTR(STUDENT,'.')+1,LENGTH(STUDENT))||' '||
SUBSTR(STUDENT,1,INSTR(STUDENT,'.')-1) WHERE STUDENT IS NOT NULL;
3) select rpad(bookname,20,'.'),totalpage from books;
4)
a - select instr('Corporate floor','or',1,3) from class;
b - select instr('Corporate floor','or',-1,3) from class;