-
Notifications
You must be signed in to change notification settings - Fork 1
/
oracle_sql.json
466 lines (466 loc) · 13.4 KB
/
oracle_sql.json
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
{
"APEX User reset/unlock": {
"scope": "PL/SQL",
"prefix": ["reset","pwd","unlock","user","APEX"],
"body": [
"declare",
" l_workspace varchar2(30 char) := '${1:workspace}';",
" l_username varchar2(30 char) := '${2:username}';",
"begin",
" apex_util.set_workspace ( p_workspace => l_workspace );",
" apex_util.reset_password (",
" p_user_name => l_username,",
" p_old_password => null,",
" p_new_password => '${3:password}',",
" p_change_password_on_first_use => false);",
" apex_util.unlock_account ( p_user_name => l_username);",
"end;",
"/"
],
"description": "Reset APEX user"
},
"APEX set security group": {
"scope": "PL/SQL",
"prefix": ["security","group","APEX"],
"body": [
"begin",
" for c1 in (",
" select workspace_id",
" from apex_applications",
" where application_id = ${1:100} )",
" loop",
" apex_util.set_security_group_id(p_security_group_id => c1.workspace_id);",
" end loop;",
"end;",
"/"],
"description": "Set security group for application ID"
},
"APEX send mail": {
"scope": "PL/SQL",
"prefix": ["send","mail", "APEX"],
"body": [
"declare",
" l_id NUMBER;",
"",
" l_to varchar2(100 char) := '${1:mail_to}';",
" l_from varchar2(100 char) := '${2:mail_from}';",
"begin",
" l_id := apex_mail.send(",
" p_to => l_to,",
" p_from => l_from,",
" p_subj => 'TEST',",
" p_body => 'Send from app',",
" p_body_html => 'Send from app');",
"/*",
" for c1 in (select filename, blob_content, mime_type",
" from apex_application_files",
" where id in (123,456))",
" loop",
"",
" apex_mail.add_attachment("
" p_mail_id => l_id,",
" p_attachment => c1.blob_content,",
" p_filename => c1.filename,",
" p_mime_type => c1.mime_type);",
" end loop;",
"",
"*/",
" commit;",
" apex_mail.push_queue;",
"end;",
"/"],
"description": "Send test mail with APEX_MAIL api"
},
"APEX views": {
"scope": "PL/SQL",
"prefix": ["views","disctionary", "APEX"],
"body": [
"select distinct apex_view_name",
" from apex_dictionary",
"-- where apex_view_name like '%DEBUG%'",
";"
],
"description": "Find APEX view"
},
"APEX kill session": {
"scope": "PL/SQL",
"prefix": ["session","kill","APEX"],
"body": [
"DEFINE df_p_app_workspace = '${1:workspace}';",
"",
"",
"/* Query sessions */",
" select * from apex_workspace_sessions where workspace_name = '&&df_p_app_workspace';",
"",
"/* Kill all sessions on workspace",
" declare",
" l_workspace varchar2(30 char) := '&&df_p_app_workspace';",
" begin",
" apex_util.set_workspace (",
" p_workspace => l_workspace );",
"",
" for i in (select * from apex_workspace_sessions where workspace_name = l_workspace)",
" loop",
" apex_session.delete_session (p_session_id => i.apex_session_id );",
" end loop;",
" commit;",
" end;",
" /"
"*/",
"",
"" ,
"/* Kill single session",
" declare",
" l_workspace varchar2(30 char) := '&&df_p_app_workspace';",
" l_session number := ${2:0};"
" begin",
" apex_util.set_workspace (",
" p_workspace => :l_workspace );",
"",
" apex_session.delete_session (p_session_id => l_session );",
" commit;",
" end;",
" /",
"*/"
],
"description": "Kill session/s in Oracle APEX"
},
"APEX debug Pl/SQL": {
"scope": "PL/SQL",
"prefix": ["debug","attach","APEX"],
"body": [
"declare",
" l_workspace varchar2(30 char) := '${1:workspace}';"
" l_app_id number := ${2:100};",
" l_session_id number := 0;",
"begin",
" apex_util.set_workspace (",
" p_workspace => l_workspace );",
"",
" apex_session.attach (",
" p_app_id => l_app_id,",
" p_page_id => 1,",
" p_session_id => l_session_id);",
"",
" /* -- Full debug -- */",
" apex_debug.enable(p_level=>apex_debug.c_log_level_engine_trace);",
"",
" /* -- Classic --",
" apex_debug.enable(p_level=>apex_debug.c_log_level_info);",
" */",
"",
" apex_debug.enable_dbms_output(p_prefix=>'APEX Debug-');",
"",
"end;",
"/",
"",
"",
"/* Add parameter to debugg script",
" begin",
" apex_util.set_session_state(p_name => 'P0_ID', p_value => 'TEST');",
" end;",
" /",
"*/"
"",
"",
"/* Debug messages",
" select * from apex_debug_messages;",
"*/",
"",
"/* Disable debug",
" begin",
" apex_debug.disable;",
" apex_session.detach;",
" end;",
" /",
"*/"],
"description": "Debugging in PL/SQL Oracle APEX"
},
"APEX import app": {
"scope": "PL/SQL",
"prefix": ["import","app", "APEX"],
"body": [
"declare",
" l_workspace varchar2(30 char) := '${1:workspace}';",
" l_app_id number := ${2:100};",
"",
" l_workspace_id number;"
"begin",
" l_workspace_id := apex_util.find_security_group_id (l_workspace);",
" apex_application_install.set_workspace_id (l_workspace_id);",
" apex_application_install.set_application_id(l_app_id);",
" apex_application_install.set_schema(l_workspace);",
"end;",
"/",
"",
"-- Run app install",
"-- e.g @f100.sql",
],
"description": "Install APEX app and change APEX APPLICATION ID for it"
},
"APEX get version": {
"scope": "PL/SQL",
"prefix": ["version","APEX"],
"body": [
"select *",
"from apex_release;",
"",
"select *",
" from apex_patches;"
],
"description": "Get Oracle APEX release and patch list"
},
"ORDS get version": {
"scope": "PL/SQL",
"prefix": ["version","ORDS"],
"body": [
"select ords.installed_version from dual; "
],
"description": "Get ORDS installed version"
},
"APEX download file": {
"scope": "PL/SQL",
"prefix": ["download","APEX"],
"body": [
"declare",
" l_blob blob;",
" l_filename varchar2(100 char);",
" l_mimetype varchar2(100 char);",
"begin",
" select blob_content, mimetype, filename",
" into l_blob, l_mimetype, l_filename",
" from my_image_table",
" where id = :FILE_ID;",
" --",
" sys.htp.init;",
" sys.owa_util.mime_header( l_mimetype, FALSE );",
" sys.htp.p('Content-length: ' || sys.dbms_lob.getlength( l_blob));",
" sys.htp.p('Content-Disposition: attachment; filename=\"' || l_filename || '\"' );",
" sys.owa_util.http_header_close;",
" sys.wpg_docload.download_file( l_blob );",
"",
" apex_application.stop_apex_engine;",
"",
"end;",
"/"
],
"description": "Download file with Oracle APEX"
},
"APEX split string": {
"scope": "PL/SQL",
"prefix": ["split","string","APEX"],
"body": [
"declare",
" l_string varchar2(4000) := 'P1_X:P1_Y';",
" l_page_items_arr apex_t_varchar2;",
"begin",
" l_page_items_arr := apex_string.split(p_str => l_string, p_sep => ':');",
" for i in 1..l_page_items_arr.count",
" loop",
" sys.dbms_output.put_line(l_page_items_arr(i)||':'||apex_util.get_session_state(l_page_items_arr(i)));",
" end loop;",
"end;",
"/"
],
"description": "Split string values into array"
},
"APEX collection query": {
"scope": "PL/SQL",
"prefix": ["collection","APEX"],
"body": [
"SELECT seq_id, c001, c002, c003, c004, c005, n001, d001, clob001",
" FROM APEX_collections",
" WHERE collection_name = '${1:collection_name}';"
],
"description": "Select data from Oracle APEX collection defined by name"
},
"APEX export": {
"scope": "PL/SQL",
"prefix": ["export","app","APEX"],
"body": [
"variable name varchar2(255)",
"variable contents clob",
"declare",
" l_files apex_t_export_files;",
"begin",
" l_files := apex_export.get_application(p_application_id => ${1:100});",
" :name := l_files(1).name;",
" :contents := l_files(1).contents;",
"end;",
"/",
"set feed off echo off head off flush off termout off trimspool on",
"set long 100000000 longchunksize 32767",
"col name new_val name",
"select :name name from sys.dual;",
"spool &name.",
"print contents",
"spool off",
"",
"/*",
"FUNCTION GET_APPLICATION (",
" p_application_id IN NUMBER,",
" p_split IN BOOLEAN DEFAULT FALSE,",
" p_with_date IN BOOLEAN DEFAULT FALSE,",
" p_with_ir_public_reports IN BOOLEAN DEFAULT FALSE,",
" p_with_ir_private_reports IN BOOLEAN DEFAULT FALSE,",
" p_with_ir_notifications IN BOOLEAN DEFAULT FALSE,",
" p_with_translations IN BOOLEAN DEFAULT FALSE,",
" p_with_pkg_app_mapping IN BOOLEAN DEFAULT FALSE,",
" p_with_original_ids IN BOOLEAN DEFAULT FALSE,",
" p_with_no_subscriptions IN BOOLEAN DEFAULT FALSE,",
" p_with_comments IN BOOLEAN DEFAULT FALSE,",
" p_with_supporting_objects IN VARCHAR2 DEFAULT NULL,",
" p_with_acl_assignments IN BOOLEAN DEFAULT FALSE,",
" p_components IN apex_t_varchar2 DEFAULT NULL )",
" RETURN apex_t_export_files;",
"/"
],
"description": "Select data from Oracle APEX collection defined by name"
},
"APEX JSON parse": {
"scope": "PL/SQL",
"prefix": ["json","parse","APEX"],
"body": [
"declare",
" s varchar2(32767) := '{ \"a\": 1, \"b\": [\"hello\", \"world\"]}';",
"begin",
" apex_json.parse(s);",
" sys.dbms_output.put_line('a is '||apex_json.get_varchar2(p_path => 'a'));",
"end;",
"/"
],
"description": "Parse JSON"
},
"APEX create session": {
"scope": "PL/SQL",
"prefix": ["session","APEX"],
"body": [
"apex_session.create_session(p_app_id => 100, p_page_id => 1, p_username => 'ANDREJGR');"
],
"description": "Create Oracle APEX seession"
},
"APEX OCI mail settings": {
"scope": "PL/SQL",
"prefix": ["mail","OCI","internal","APEX"],
"body": [
"begin"
" apex_instance_admin.set_parameter('SMTP_HOST_PORT', 587);",
" apex_instance_admin.set_parameter('SMTP_HOST_ADDRESS', 'smtp.email.uk-london-1.oci.oraclecloud.com');",
"",
"",
" apex_instance_admin.set_parameter('SMTP_USERNAME', '');",
" apex_instance_admin.set_parameter('SMTP_PASSWORD', '');",
" commit;",
"end;",
"/",
"",
"",
"begin",
" apex_instance_admin.validate_email_config;",
"end;",
"/",
],
"description": "Set and validate OCI APEX Mail settings"
},
"APEX add Internal user": {
"scope": "PL/SQL",
"prefix": ["internal","user","unlock","APEX"],
"body": [
"SELECT * FROM apex_workspace_apex_users; -- check users",
"",
"",
"-- Add new user as sysdba",
"begin",
"",
" apex_util.set_workspace('INTERNAL');",
"",
" apex_util.create_user(",
" p_user_name => 'ADMIN_DBA',",
" p_email_address => 'admin@right-thing.solutions',",
" p_web_password => 'password',",
" p_developer_privs => 'ADMIN:CREATE:DATA_LOADER:EDIT:HELP:MONITOR:SQL',",
" p_change_password_on_first_use => 'N'",
" );",
" commit;",
"end;",
"/",
"",
"",
"-- Unlock locked user",
"begin",
"",
" apex_util.set_workspace('INTERNAL');",
" apex_util.unlock_account(p_user_name => 'ADMIN_DBA');",
" commit;",
"end;",
"/"
],
"description": "Add new Internal admin user or unlock it"
},
"APEX list all CGI headers": {
"scope": "PL/SQL",
"prefix": ["CGI","header","APEX"],
"body": [
"-- Run in APEX SQL Workshop or app",
"begin",
" FOR i IN 1..owa.num_cgi_vars LOOP",
" htp.p(owa.cgi_var_name(i)||' : '||owa.cgi_var_val(i));",
" END LOOP;",
"end;",
"/"
],
"description": "List all CGI headers with values"
},
"APEX OCI upgrade": {
"scope": "PL/SQL",
"prefix": ["version","upgrade","OCI","APEX"],
"body": [
"select apex_instance_admin.get_parameter('UPGRADE_STATUS') as UPGRADE_STATUS from dual;",
"",
"/*",
"UPGRADE_STATUS",
"--------------",
"AVAILABLE",
"",
"If an upgrade is available, you can initiate it during the upgrade window by running:",
"*/",
"begin",
" apex_instance_admin.set_parameter('UPGRADE_STATUS', 'RUN');",
"end;",
"/"
],
"description": "Upgrade Oracle APEX on OCI instance"
},
"APEX set workspace": {
"scope": "PL/SQL",
"prefix": ["set","workspace","APEX"],
"body": [
"begin",
" apex_util.set_workspace (",
" p_workspace => :p_workspace );",
"end;",
"/",
],
"description": "Set Oracle APEX workspace"
},
"APEX context": {
"scope": "PL/SQL",
"prefix": ["context","APEX"],
"body": [
"sys_context('APEX$SESSION','APP_USER')",
"sys_context('APEX$SESSION','APP_SESSION')",
"sys_context('APEX$SESSION','WORKSPACE_ID')",
],
"description": "Display APEX contexts"
},
"APEX add error": {
"scope": "PL/SQL",
"prefix": ["error","APEX"],
"body": [
"apex_error.add_error (",
" p_message => 'This custom account is not active!',",
" p_display_location => apex_error.c_inline_in_notification );"
],
"description": "Add Oracle APEX error display"
},
}