-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPLSQL 1.GUN.sql
executable file
·301 lines (218 loc) · 4.71 KB
/
PLSQL 1.GUN.sql
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
begin
dbms_output.put_line('Hello World');
end;
/
create or replace procedure yaz(x varchar2)
is
begin
dbms_otput.put_line(x);
end;
/
begin
yaz('DENEME');
end;
/
-- nls_date_format
select to_char(sysdate,'YYYY/MM/DD') from dual;
declare
v1 number;
v2 number(2);
v3 varchar2(15);
v4 date default sysdate;
v5 varchar2(5) := 'EREN';
v6 constant number :=100;
v7 number not null :=500;
begin
v1:=5;
--v6:=444;
yaz(' V1 : ' || v1);
yaz(' V2 : ' || v2);
yaz(' V3 : ' || v3);
yaz(' V4 : ' || v4);
yaz(' V5 : ' || v5);
yaz(' V6 : ' || v6);
yaz(' V7 : ' || v7);
end;
/
select commission_pct from employees;
begin
yaz(v4);
end;
/
variable b_test number;
/
begin
:b_test:=100;
end;
/
begin
yaz(:b_test);
end;
/
set serveroutput on;
print b_test;
select sysdate from dual;
select * from dual;
select last_name|| q'#'s salary is #'|| salary from employees;
select last_name|| '''s sal''ary is '|| salary from employees;
select 34567*3456 from dual;
select * from "EMPLOYEES"
where "LAST_NAME" like 'A%';
----------------------------------------------------------------
declare
v_lname employees.last_name%type;
v_sal employees.salary%type;
v_min_sal v_sal%type;
v_sum_sal number;
begin
select last_name into v_lname
from employees where employee_id=100;
end;
desc employees;
select last_name,
first_name,
last_name || first_name as "deveci armut"
from employees;
select last_name as first_name from employees;
/
Single Row Func
Char
upper /lower / initcap
substr
instr --select instr('EREN GULERYUZ','G') from dual;
length
trim
select length(trim(' test test ')) from dual;
replace
translate
select translate('Ya?mur Döngelo?lu','öç???üÖÇ???Ü','ocsiguOCSIGU') from dual;
lpad / rpad
select rpad(last_name,10,' ')||salary from employees;
Num
round
trunc
mod
Date
next_day
select next_day(sysdate,'SUNDAY') from dual;
add_months
select add_months(sysdate,1) from dual;
months_between
last_day
select to_char(last_day(sysdate),'DAY') from dual;
Conv
to_char
select last_name || salary from employees;
select last_name || to_char(salary,'$999,999,999.99') from employees;
select to_char(sysdate,'YYYY/MM/DD') from dual;
to_date
select last_name,hire_date from employees
where hire_date > to_date('21/05/07','DD/MM/YY');
to_number
select 1234*to_number('$1,234','$9,999') from dual;
General
nvl
select last_name,commission_pct,nvl(commission_pct,0) from employees;
nvl2
select last_name,commission_pct,nvl2(commission_pct,1,0) from employees;
nullif
select last_name,salary from employees
where last_name<>first_name;
coalesce
case
decode
sum avg count max min
select max(salary) from employees;
declare
v_max_sal number;
begin
select max(salary) into v_max_sal from employees;
yaz(v_max_sal);
end;
/
create sequence myseq
start with 100
increment by 3
maxvalue 150
minvalue 77
cycle
select myseq.nextval from dual;
begin
yaz(2**581);
end;
declare
x number:=0;
y boolean;
begin
y := x between 0 and 100;
end;
/
---------------------------------------------------------------------
SQL Statements
DML (Data Manipulation Lang)
Insert
Update
Delete
Merge
Select
TCL (Transaction Control Lang)
Commit
Rollback
Savepoint
DDL (Data Definition Lang)
Create
alter
drop
truncate
flashback
comment
DCL (Data Control Lang)
Grant
Revoke
Select
/
declare
v_lname employees.last_name%type;
v_fname varchar2(50);
v_sal number;
begin
select last_name,first_name,salary
into v_lname,v_fname,v_sal
from employees
where department_id=100000;
yaz(v_lname);
yaz(v_fname);
yaz(v_sal);
end;
/
create table emp as select * from employees
where department_id<>50;
update emp set salary=salary-500;
commit;
EMPLOYEES => GÜNCEL
EMP => YEDEK
select count(*) from employees; 107
select count(*) from emp; 61
select salary from employees where employee_id=100; 24000
select salary from emp where employee_id=100; 23500
begin
merge into emp yt
using employees gt
on (yt.employee_id=gt.employee_id)
when matched then
update set yt.salary=gt.salary
when not matched then
insert values (
gt.EMPLOYEE_ID
,gt.FIRST_NAME
,gt.LAST_NAME
,gt.EMAIL
,gt.PHONE_NUMBER
,gt.HIRE_DATE
,gt.JOB_ID
,gt.SALARY
,gt.COMMISSION_PCT
,gt.MANAGER_ID
,gt.DEPARTMENT_ID
);
end;