2. lower : 문자열 전체를 소문자로 변환
3. upper : 문자열 전체를 대문자로 변환
4. length : 문자열의 길이 반환
5. lengthb : 문자열의 바이트 수 반환
6. substr : 문자열 일부 추출
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 |
SQL> select tel from student;
TEL
-------------
051)781-2158
055)426-1752
055)261-8947
051)824-9637
051)742-6384
055)419-6328
055)418-9627
051)724-9618
055)296-3784
02)312-9838
051)239-4861
SQL> select substr(tel, 1, 3) as local_tel from student
LOCAL_TEL
----------
051
055
055
051
051
055
055
051
055
02) |
7. instr : 특정문자가 출현하는 문자열 위치 반환
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 |
SQL> select name , userid from student;
NAME USERID
---------- ----------
전인하 jun123
이동훈 Dals
박미경 ansel414
김영균 mandu
박동진 Ping2
김진영 simply
지은경 Gomo00
오유석 yousuk
하나리 hanal
임유진 YouJin12
서재진 seolly
윤진욱 Samba7
SQL> select name , userid from student where instr(userid, 'a' ,1,2)=5;
NAME USERID
---------- ----------
윤진욱 Samba7 |
8. lpad : 왼쪽에 지정한 문자 삽입
1
2
3
4
5 |
SQL> select lpad( 'test' ,10, '*' ) from dual
LPAD('TEST
----------
******test |
9. rpad : 오른쪽에 지정한 문자 삽입
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 |
SQL> select rpad(dept_name, 10, substr( '1234567890' , lengthb(dept_name)+1,10)) from tdept; RPAD(DEPT_NAME,10,SU -------------------- 경영지원90 재무567890 총무567890 기술지원90 H/W지원890 S/W지원890 영업567890 영업기획90 영업167890 영업267890 10 rows selected. |
10. ltrim : 왼쪽 지정 문자 삭제
1
2
3
4
5
6
7
8
9
10
11
12 |
SQL> select ltrim( '***test' , '*' ) from dual;
LTRI
----
test
SQL> select ltrim( '**12*test' , '*' ) from dual;
LTRIM('
-------
12*test |
11. rtrim : 오른쪽 지정 문자 삭제
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 |
SQL> select substr(tel, 1, 3) as local_tel from student
LOCAL_TEL
----------
051
055
055
051
051
055
055
051
055
02)
SQL> select rtrim(substr(tel, 1, 3), ')' ) as local_tel from student
LOCAL_TEL
----------
051
055
055
051
051
055
055
051
055
02 |
12. Replace : 문자열을 치환한다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93 |
SQL> select replace ( name , substr( name ,1,1), '#' ) from student; REPLACE (NA ---------- #인하 #동훈 #미경 #영균 #동진 #진영 #은경 #유석 #나리 #유진 #재진 #진욱 #광훈 #진경 #명훈 #민정 16 rows selected. SQL> select idnum from student; IDNUM ------------- 7907021369824 8312101128467 8405162123648 8103211063421 8511241639826 8206062186327 8004122298371 7709121128379 8501092378641 8301212196482 8511291186273 7904021358671 8109131276431 8302282169387 8412141254963 8108192157498 16 rows selected. SQL> select replace (idnum, substr(idnum, 7,7), '*******' ) from student; 또는 SQL> select replace (idnum, substr(idnum,-7,7), '*******' ) from student; REPLACE (IDNUM,SUBSTR(IDNUM,7,13), '*******' ) -------------------------------------------------------------------------------- 790702******* 831210******* 840516******* 810321******* 851124******* 820606******* 800412******* 770912******* 850109******* 830121******* 851129******* 790402******* 810913******* 830228******* 841214******* 810819******* 16 rows selected. SQL> select replace (tel, substr(tel, instr(tel, ')' )+1, 3), '###' )
2 from student; REPLACE (TEL,SUBSTR(TEL,INSTR(TEL, ')' )+1 --------------------------------------- 051)###-2158 055)###-1752 055)###-8947 051)###-9637 051)###-6384 055)###-6328 055)###-9627 051)###-9618 055)###-3784 02)###-9838 051)###-4861 053)###-2698 055)###-4981 052)###-3941 02)###-6984 055)###-3679 16 rows selected. |