-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_query_data.sql
More file actions
296 lines (287 loc) · 10.2 KB
/
sample_query_data.sql
File metadata and controls
296 lines (287 loc) · 10.2 KB
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
SET DEFINE OFF;
Insert into SB_QUERY_GROUPS
(Q_ID, QG_ID, QG_DESCRIPTION)
Values
(1, 1, 'DB Cleaning');
Insert into SB_QUERY_GROUPS
(Q_ID, QG_ID, QG_DESCRIPTION)
Values
(2, 2, 'Execution');
COMMIT;
SET DEFINE OFF;
Insert into SB_QUERY_ARRAYS
(A_ID, A_ORDER_ID, Q_SEQ_FROM_ID, Q_SEQ_TO_ID)
Values
(1, 1, 1, 18);
COMMIT;
SET DEFINE OFF;
Insert into SB_QUERIES
(Q_GROUP_ID, Q_SEQUENCE_ID, Q_TEXT, Q_DESCRIPTION)
Values
(1, 1, 'begin
for i in
(
select *
from user_objects
where object_name like ''TMP_BAT_____________''
and object_type = ''TABLE''
and created < trunc(sysdate) - 1
)
loop
begin
execute immediate ''drop table '' || i.object_name || '' purge'';
exception
when others then
if sqlerrm like ''ORA-00942%'' then
--table or view does not exist
null;
else
raise;
end if;
end;
end loop;
end;', 'Dusurulmeden kalmis eski gecici tablolarin dusurulmesi');
Insert into SB_QUERIES
(Q_GROUP_ID, Q_SEQUENCE_ID, Q_TEXT, Q_DESCRIPTION)
Values
(1, 2, 'begin
for i in
(
select *
from user_objects
where object_name like ''TMP_BAT_<timestamp>____''
and object_type = ''TABLE''
)
loop
begin
execute immediate ''drop table '' || i.object_name || '' purge'';
exception
when others then
if sqlerrm like ''ORA-00942%'' then
--table or view does not exist
null;
else
raise;
end if;
end;
end loop;
end;', 'Varsa ayni isimli gecici tablolarin dusurulmesi');
Insert into SB_QUERIES
(Q_GROUP_ID, Q_SEQUENCE_ID, Q_TEXT, Q_DESCRIPTION)
Values
(2, 1, 'create table tmp_bat_<timestamp>_001
(
account_id number(7, 0)
) nologging parallel', 'Aktif urunlu accountlar tablosu');
Insert into SB_QUERIES
(Q_GROUP_ID, Q_SEQUENCE_ID, Q_TEXT, Q_DESCRIPTION)
Values
(2, 2, 'insert /*+ no_gather_optimizer_statistics */ into tmp_bat_<timestamp>_001
select distinct a.account_id
from
smp_accounts a,
smp_products b
where b.status = ''1''
and a.status = ''1''
and b.account_id = a.account_id', 'Aktif urunlu aktif accountlar');
Insert into SB_QUERIES
(Q_GROUP_ID, Q_SEQUENCE_ID, Q_TEXT, Q_DESCRIPTION)
Values
(2, 3, 'create table tmp_bat_<timestamp>_002
(
account_id number(7, 0)
) nologging parallel', 'Fatura borcu olan aktif urunlu aktif accountlar tablosu');
Insert into SB_QUERIES
(Q_GROUP_ID, Q_SEQUENCE_ID, Q_TEXT, Q_DESCRIPTION)
Values
(2, 4, 'create index tmp_bat_<timestamp>_002_01 on tmp_bat_<timestamp>_002 (account_id) nologging parallel', 'Fatura borcu olan aktif urunlu aktif accountlar tablosu index');
Insert into SB_QUERIES
(Q_GROUP_ID, Q_SEQUENCE_ID, Q_TEXT, Q_DESCRIPTION)
Values
(2, 5, 'insert /*+ no_gather_optimizer_statistics */ into tmp_bat_<timestamp>_002
select distinct a.account_id
from
tmp_bat_<timestamp>_001 a
where exists
(
select 1
from smp_invoices b
where b.account_id = a.account_id
and b.debt_amount > 0
)', 'Fatura borcu olan aktif urunlu aktif accountlar');
Insert into SB_QUERIES
(Q_GROUP_ID, Q_SEQUENCE_ID, Q_TEXT, Q_DESCRIPTION)
Values
(2, 6, 'drop table tmp_bat_<timestamp>_001 purge', 'Aktif urunlu aktif accountlar tablosunu dusurme');
Insert into SB_QUERIES
(Q_GROUP_ID, Q_SEQUENCE_ID, Q_TEXT, Q_DESCRIPTION)
Values
(2, 7, 'create table tmp_bat_<timestamp>_003
(
account_id number(7, 0),
period_to_backward number(18),
debt_amount number(24, 2)
) nologging parallel', 'Fatura borcu olan aktif urunlu aktif accountlarin borclu oldugu faturalari tablosu');
Insert into SB_QUERIES
(Q_GROUP_ID, Q_SEQUENCE_ID, Q_TEXT, Q_DESCRIPTION)
Values
(2, 8, 'create index tmp_bat_<timestamp>_003_01 on tmp_bat_<timestamp>_003 (account_id) nologging parallel', 'Fatura borcu olan aktif urunlu aktif accountlarin borclu oldugu faturalari tablosu index');
Insert into SB_QUERIES
(Q_GROUP_ID, Q_SEQUENCE_ID, Q_TEXT, Q_DESCRIPTION)
Values
(2, 9, 'insert /*+ no_gather_optimizer_statistics */ into tmp_bat_<timestamp>_003
select
b.account_id,
months_between(trunc(sysdate,''MM''), trunc(b.invoice_date, ''MM'')),
b.debt_amount
from
tmp_bat_<timestamp>_002 a,
smp_invoices b
where b.account_id = a.account_id
and b.debt_amount > 0', 'Fatura borcu olan aktif urunlu aktif accountlarin borclu oldugu faturalar');
Insert into SB_QUERIES
(Q_GROUP_ID, Q_SEQUENCE_ID, Q_TEXT, Q_DESCRIPTION)
Values
(2, 10, 'declare
v_sql varchar2(4000 char);
begin
if sbatch.check_table(''<PREPARATION_TABLE>'') = 0 then
v_sql := ''create table <PREPARATION_TABLE> '';
v_sql := v_sql || ''( '';
v_sql := v_sql || '' account_id number(7, 0) not null, '';
v_sql := v_sql || '' account_segment char(1 char), ''; --1: gold, 0: standard
v_sql := v_sql || '' account_type char(1 char), ''; --1: corporate, 0: individual
v_sql := v_sql || '' region char(1 char), ''; --local: corporate, 0: foreign
v_sql := v_sql || '' exec_proc char(1 char), ''; --0: no, 1: yes in executive proceeding
v_sql := v_sql || '' total_debt_amount number(24, 2), '';
v_sql := v_sql || '' open_inv_count number(18), '';
v_sql := v_sql || '' invoice_pattern varchar2(500), ''; --yeniden eskiye acik faturalar
v_sql := v_sql || '' oit_except_last2_underl char(1), ''; --son 2 donem haric borc limit altinda
v_sql := v_sql || '' limit_asimi char(1), '';
v_sql := v_sql || '' haric_kalma_sebebi varchar2(4000) '';
v_sql := v_sql || '') nologging parallel '';
execute immediate v_sql;
v_sql := ''create index <PREPARATION_TABLE>_01 on <PREPARATION_TABLE> (account_id) nologging parallel'';
execute immediate v_sql;
v_sql := ''create index <PREPARATION_TABLE>_02 on <PREPARATION_TABLE> (haric_kalma_sebebi, ''''null'''') nologging parallel'';
execute immediate v_sql;
else
execute immediate ''truncate table <PREPARATION_TABLE>'';
end if;
end;', 'Batch kitlesinin aktarilacagi tablo');
Insert into SB_QUERIES
(Q_GROUP_ID, Q_SEQUENCE_ID, Q_TEXT, Q_DESCRIPTION)
Values
(2, 11, 'insert /*+ no_gather_optimizer_statistics */ into <PREPARATION_TABLE>
select
a.account_id,
a.account_segment,
a.account_type,
a.region,
a.exec_proc,
null, null, null, null, null, null
from
smp_accounts a,
tmp_bat_<timestamp>_002 b
where a.account_id = b.account_id', 'Batch kitlesi');
Insert into SB_QUERIES
(Q_GROUP_ID, Q_SEQUENCE_ID, Q_TEXT, Q_DESCRIPTION)
Values
(2, 12, 'drop table tmp_bat_<timestamp>_002 purge', 'Fatura borcu olan aktif urunlu aktif accountlar tablosunu dusurme');
Insert into SB_QUERIES
(Q_GROUP_ID, Q_SEQUENCE_ID, Q_TEXT, Q_DESCRIPTION)
Values
(2, 13, 'update /*+ no_parallel no_gather_optimizer_statistics */ <PREPARATION_TABLE> a
set
(a.invoice_pattern, a.total_debt_amount, a.open_inv_count) =
(
select /*+ index(b tmp_bat_<timestamp>_003_01) */
substr(''-''||listagg(b.period_to_backward, ''-'') within group (order by b.period_to_backward asc)||''-'', 1, 500),
sum(b.debt_amount),
count(*)
from tmp_bat_<timestamp>_003 b
where b.account_id = a.account_id
)', 'Borclu olunan faturalar ile toplam fatura borcu ve adedi tespiti');
Insert into SB_QUERIES
(Q_GROUP_ID, Q_SEQUENCE_ID, Q_TEXT, Q_DESCRIPTION)
Values
(2, 14, 'update /*+ no_parallel no_gather_optimizer_statistics */ <PREPARATION_TABLE> a
set a.oit_except_last2_underl =
(
select
case when nvl(sum
(
case when b.period_to_backward > 2 then b.debt_amount else 0 end
), 0) < <LIMIT_IHMAL_EDILECEK> then 1 else 0 end
from tmp_bat_<timestamp>_003 b
where b.account_id = a.account_id
)', 'Son 2 donem haric borc toplami limit altinda durumu tespiti');
Insert into SB_QUERIES
(Q_GROUP_ID, Q_SEQUENCE_ID, Q_TEXT, Q_DESCRIPTION)
Values
(2, 15, 'drop table tmp_bat_<timestamp>_003 purge', 'Fatura borcu olan aktif urunlu aktif accountlar tablosunu dusurme');
Insert into SB_QUERIES
(Q_GROUP_ID, Q_SEQUENCE_ID, Q_TEXT, Q_DESCRIPTION)
Values
(2, 16, 'update /*+ no_parallel no_gather_optimizer_statistics */ <PREPARATION_TABLE> a
set a.limit_asimi =
(
case when
(
a.total_debt_amount
-
decode
(
a.region,
<ACC_REGION_LOCAL>, decode
(
a.account_type,
<ACC_TYPE_CORPORATE>, <LMT_LOCAL_CORPORATE>,
<ACC_TYPE_INDIVIDUAL>, decode
(
a.account_segment,
<ACC_SEGMENT_GOLD>, <LMT_LOCAL_GOLD>,
<ACC_SEGMENT_SILVER>, <LMT_LOCAL_SILVER>,
<LMT_LOCAL_STANDARD>
),
0
), decode
(
a.account_type,
<ACC_TYPE_CORPORATE>, <LMT_FOREIGN_CORPORATE>,
<ACC_TYPE_INDIVIDUAL>, decode
(
a.account_segment,
<ACC_SEGMENT_GOLD>, <LMT_FOREIGN_GOLD>,
<ACC_SEGMENT_SILVER>, <LMT_LOCAL_SILVER>,
<LMT_FOREIGN_STANDARD>
),
0
)
)
) >= 0 then ''1'' else ''0'' end
)', 'Limit asimi tespiti');
Insert into SB_QUERIES
(Q_GROUP_ID, Q_SEQUENCE_ID, Q_TEXT, Q_DESCRIPTION)
Values
(2, 17, 'update /*+ no_parallel no_gather_optimizer_statistics */ <PREPARATION_TABLE> a
set a.haric_kalma_sebebi =
(
<batch_conditions>
)', 'Batch kitlesine girmeme sebeplerinin tespiti');
Insert into SB_QUERIES
(Q_GROUP_ID, Q_SEQUENCE_ID, Q_TEXT, Q_DESCRIPTION)
Values
(2, 18, 'update /*+ no_parallel no_gather_optimizer_statistics */ smp_accounts a
set
a.exec_proc = ''2''
where exists
(
select /*+ index(b <PREPARATION_TABLE>_01) */
1
from <PREPARATION_TABLE> b
where b.account_id = a.account_id
and b.exec_proc = ''0''
and b.haric_kalma_sebebi is null
)', 'Borcu sebebiyle yasal takibe gonderileceklerin tespiti');
COMMIT;