-
Notifications
You must be signed in to change notification settings - Fork 1
/
bvc_tokenizer_body.sql
1974 lines (1899 loc) · 66.1 KB
/
bvc_tokenizer_body.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
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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-----------------------------------------------------------------------------------------
-- Bind Variables Checker: Tokenizer, and Statement Binder
-- Author: Alberto Dell'Era
-- Copyright: (c) 2003 - 2018 Alberto Dell'Era http://www.adellera.it
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
-- "Statement Tokenizer": a routine that takes a SQL statement and breaks
-- it into its tokens.
-- For example:
-- SQL> exec bvc_tokenizer_pkg.debug_print_tokens ('select /*+ first_rows */ a from t where x + +1.e-123 > :ph');
-- keyword "select"
-- conn " "
-- hint "/*+ first_rows */"
-- conn " "
-- ident "a"
-- conn " "
-- keyword "from"
-- conn " "
-- ident "t"
-- conn " "
-- keyword "where"
-- conn " "
-- ident "x"
-- conn " + "
-- number "+1.e-123"
-- conn " > "
-- bind ":ph"
-- See the package header for additional comments and details.
--
-----------------------------------------------------------------------------------------
-- "Statement Binder": a routine that takes a SQL statement and
-- replaces all literals with bind variables, normalizing the
-- statement as well (in lowercase, without redundant whitespace, etc).
-- For example:
-- SQL> select bvc_tokenizer_pkg.bound_stmt ('SELECT * FROM T WHERE ID = +1.2e+1 AND Y = ''PIPPO'' AND Z = :B1') bound_stmt from dual;
-- BOUND_STMT
-- --------------------------------------------
-- select*from t where id=:n and y=:s and z=:b
--
-- The Statement Binder uses the Tokenizer to parse the statement, then basically "pretty prints" it.
-- See the package header for additional comments and details.
--
-- Note : about the motivation for normalizing numbers in identifiers in bound_stmt.
-- If p_normalize_numbers_in_ident is 'Y' (the default), numbers contained in identifier
-- such as object names, aliases, and bind variables names (and hints) are normalized:
-- select * from t123 t123 where id='pippo' and (c4=1 or c4=2) and id3=:ph1
-- becomes
-- select*from t{0} t{0} where id=:s and(c{1}=:n or c{1}=:n)and id{2}=:b
-- This is to detect some coding horrors contained in mainstream "database independent"
-- libraries, that generate code such as
-- select * from t t1 where t1.x =
-- select * from t t2 where t2.x =
-- select * from t t3 where t3.x =
-- Please note that equal numbers in identifier are substituted with the same number:
-- select * from t123 t123 --> select*from t{0} t{0}
-- and (c4=1 or c4=2) --> and(c{1}=:n or c{1}=:n)
-- i.e. every occurrence of t123 is substituted with t{0}, c4 with c{1} and so on.
-- Obviously this permits to understand where the same identifier is referenced in
-- the bound-statement.
--
-- If p_normalize_partition_names is 'Y' (the default), partition names are normalized with "#<progressive>";
-- partitions with the same name gets the same normalizing identifier.
--
-- If p_strip_hints is 'Y' (default is 'N'), hints are removed
--
-- Author: Alberto Dell'Era, first version: 28th of July 2003
----------------------------------------------------------
-- set logging mode (log to dbms_output)
procedure set_log (p_value boolean default true)
is
begin
g_log := p_value;
end set_log;
----------------------------------------------------------
-- prints in l_chunk_size chunks
procedure print (p_msg varchar2)
is
l_chunk_size int := 240;
l_pos int := 1;
l_msg_length int := length (p_msg);
begin
loop
dbms_output.put_line (substr (p_msg, l_pos, l_chunk_size));
l_pos := l_pos + l_chunk_size;
exit when l_pos > l_msg_length;
end loop;
end;
----------------------------------------------------------
procedure log (p_msg varchar2)
is
begin
if g_log then
print (p_msg);
end if;
end log;
----------------------------------------------------------
-- populates the keywords map
-- generating statement:
-- select ' g_keywords('''||lower(keyword)||''') := null;' from v$reserved_words;
-- then get rid of pseudo columns such as sysdate, rowid, rownum, level, etc, and
-- frequently-used column names such as "id"
procedure populate_g_keywords
is
begin
g_keywords('abort') := null;
g_keywords('access') := null;
g_keywords('accessed') := null;
g_keywords('account') := null;
g_keywords('activate') := null;
g_keywords('add') := null;
g_keywords('admin') := null;
g_keywords('administer') := null;
g_keywords('administrator') := null;
g_keywords('advise') := null;
g_keywords('after') := null;
g_keywords('algorithm') := null;
g_keywords('alias') := null;
g_keywords('all') := null;
g_keywords('all_rows') := null;
g_keywords('allocate') := null;
g_keywords('allow') := null;
g_keywords('alter') := null;
g_keywords('always') := null;
g_keywords('analyze') := null;
g_keywords('ancillary') := null;
g_keywords('and') := null;
g_keywords('any') := null;
g_keywords('apply') := null;
g_keywords('archive') := null;
g_keywords('archivelog') := null;
g_keywords('array') := null;
g_keywords('as') := null;
g_keywords('asc') := null;
g_keywords('associate') := null;
g_keywords('at') := null;
g_keywords('attribute') := null;
g_keywords('attributes') := null;
g_keywords('audit') := null;
g_keywords('authenticated') := null;
g_keywords('authid') := null;
g_keywords('authorization') := null;
g_keywords('auto') := null;
g_keywords('autoallocate') := null;
g_keywords('autoextend') := null;
g_keywords('automatic') := null;
g_keywords('availability') := null;
g_keywords('backup') := null;
g_keywords('become') := null;
g_keywords('before') := null;
g_keywords('begin') := null;
g_keywords('behalf') := null;
g_keywords('between') := null;
g_keywords('bfile') := null;
g_keywords('binding') := null;
g_keywords('bitmap') := null;
g_keywords('bits') := null;
g_keywords('blob') := null;
g_keywords('block') := null;
g_keywords('blocksize') := null;
g_keywords('block_range') := null;
g_keywords('body') := null;
g_keywords('bound') := null;
g_keywords('both') := null;
g_keywords('broadcast') := null;
g_keywords('buffer_pool') := null;
g_keywords('build') := null;
g_keywords('bulk') := null;
g_keywords('by') := null;
g_keywords('byte') := null;
g_keywords('cache') := null;
g_keywords('cache_instances') := null;
g_keywords('call') := null;
g_keywords('cancel') := null;
g_keywords('cascade') := null;
g_keywords('case') := null;
g_keywords('cast') := null;
g_keywords('category') := null;
g_keywords('certificate') := null;
g_keywords('cfile') := null;
g_keywords('chained') := null;
g_keywords('change') := null;
g_keywords('char') := null;
g_keywords('char_cs') := null;
g_keywords('character') := null;
g_keywords('check') := null;
g_keywords('checkpoint') := null;
g_keywords('child') := null;
g_keywords('choose') := null;
g_keywords('chunk') := null;
g_keywords('class') := null;
g_keywords('clear') := null;
g_keywords('clob') := null;
g_keywords('clone') := null;
g_keywords('close') := null;
g_keywords('close_cached_open_cursors') := null;
g_keywords('cluster') := null;
g_keywords('coalesce') := null;
g_keywords('collect') := null;
g_keywords('column') := null;
g_keywords('columns') := null;
g_keywords('column_value') := null;
g_keywords('comment') := null;
g_keywords('commit') := null;
g_keywords('committed') := null;
g_keywords('compatibility') := null;
g_keywords('compile') := null;
g_keywords('complete') := null;
g_keywords('composite_limit') := null;
g_keywords('compress') := null;
g_keywords('compute') := null;
g_keywords('conforming') := null;
g_keywords('connect') := null;
g_keywords('connect_time') := null;
g_keywords('consider') := null;
g_keywords('consistent') := null;
g_keywords('constraint') := null;
g_keywords('constraints') := null;
g_keywords('container') := null;
g_keywords('contents') := null;
g_keywords('context') := null;
g_keywords('continue') := null;
g_keywords('controlfile') := null;
g_keywords('convert') := null;
g_keywords('corruption') := null;
g_keywords('cost') := null;
g_keywords('cpu_per_call') := null;
g_keywords('cpu_per_session') := null;
g_keywords('create') := null;
g_keywords('create_stored_outlines') := null;
g_keywords('cross') := null;
g_keywords('cube') := null;
g_keywords('current') := null;
g_keywords('current_date') := null;
g_keywords('current_schema') := null;
g_keywords('current_time') := null;
g_keywords('current_timestamp') := null;
g_keywords('current_user') := null;
g_keywords('cursor') := null;
g_keywords('cursor_specific_segment') := null;
g_keywords('cycle') := null;
g_keywords('dangling') := null;
g_keywords('data') := null;
g_keywords('database') := null;
g_keywords('datafile') := null;
g_keywords('datafiles') := null;
g_keywords('dataobjno') := null;
g_keywords('date') := null;
g_keywords('date_mode') := null;
g_keywords('day') := null;
g_keywords('dba') := null;
g_keywords('dbtimezone') := null;
g_keywords('ddl') := null;
g_keywords('deallocate') := null;
g_keywords('debug') := null;
g_keywords('dec') := null;
g_keywords('decimal') := null;
g_keywords('declare') := null;
g_keywords('default') := null;
g_keywords('deferrable') := null;
g_keywords('deferred') := null;
g_keywords('defined') := null;
g_keywords('definer') := null;
g_keywords('degree') := null;
g_keywords('delay') := null;
g_keywords('delete') := null;
g_keywords('demand') := null;
g_keywords('dense_rank') := null;
g_keywords('rowdependencies') := null;
g_keywords('deref') := null;
g_keywords('desc') := null;
g_keywords('detached') := null;
g_keywords('determines') := null;
g_keywords('dictionary') := null;
g_keywords('dimension') := null;
g_keywords('directory') := null;
g_keywords('disable') := null;
g_keywords('disassociate') := null;
g_keywords('disconnect') := null;
g_keywords('disk') := null;
g_keywords('diskgroup') := null;
g_keywords('disks') := null;
g_keywords('dismount') := null;
g_keywords('dispatchers') := null;
g_keywords('distinct') := null;
g_keywords('distinguished') := null;
g_keywords('distributed') := null;
g_keywords('dml') := null;
g_keywords('double') := null;
g_keywords('drop') := null;
g_keywords('dump') := null;
g_keywords('dynamic') := null;
g_keywords('each') := null;
g_keywords('element') := null;
g_keywords('else') := null;
g_keywords('enable') := null;
g_keywords('encrypted') := null;
g_keywords('encryption') := null;
g_keywords('end') := null;
g_keywords('enforce') := null;
g_keywords('entry') := null;
g_keywords('error_on_overlap_time') := null;
g_keywords('escape') := null;
g_keywords('estimate') := null;
g_keywords('events') := null;
g_keywords('except') := null;
g_keywords('exceptions') := null;
g_keywords('exchange') := null;
g_keywords('excluding') := null;
g_keywords('exclusive') := null;
g_keywords('execute') := null;
g_keywords('exempt') := null;
g_keywords('exists') := null;
g_keywords('expire') := null;
g_keywords('explain') := null;
g_keywords('explosion') := null;
g_keywords('extend') := null;
g_keywords('extends') := null;
g_keywords('extent') := null;
g_keywords('extents') := null;
g_keywords('external') := null;
g_keywords('externally') := null;
g_keywords('extract') := null;
g_keywords('failed_login_attempts') := null;
g_keywords('failgroup') := null;
g_keywords('false') := null;
g_keywords('fast') := null;
g_keywords('file') := null;
g_keywords('filter') := null;
g_keywords('final') := null;
g_keywords('finish') := null;
g_keywords('first') := null;
g_keywords('first_rows') := null;
g_keywords('flagger') := null;
g_keywords('flashback') := null;
g_keywords('float') := null;
g_keywords('flob') := null;
g_keywords('flush') := null;
g_keywords('following') := null;
g_keywords('for') := null;
g_keywords('force') := null;
g_keywords('foreign') := null;
g_keywords('freelist') := null;
g_keywords('freelists') := null;
g_keywords('freepools') := null;
g_keywords('fresh') := null;
g_keywords('from') := null;
g_keywords('full') := null;
g_keywords('function') := null;
g_keywords('functions') := null;
g_keywords('generated') := null;
g_keywords('global') := null;
g_keywords('globally') := null;
g_keywords('global_name') := null;
g_keywords('global_topic_enabled') := null;
g_keywords('grant') := null;
g_keywords('group') := null;
g_keywords('grouping') := null;
g_keywords('groups') := null;
g_keywords('guaranteed') := null;
g_keywords('guard') := null;
g_keywords('hash') := null;
g_keywords('hashkeys') := null;
g_keywords('having') := null;
g_keywords('header') := null;
g_keywords('heap') := null;
g_keywords('hierarchy') := null;
g_keywords('hour') := null;
--g_keywords('id') := null;
g_keywords('identified') := null;
g_keywords('identifier') := null;
g_keywords('idgenerators') := null;
g_keywords('idle_time') := null;
g_keywords('if') := null;
g_keywords('immediate') := null;
g_keywords('in') := null;
g_keywords('including') := null;
g_keywords('increment') := null;
g_keywords('incremental') := null;
g_keywords('index') := null;
g_keywords('indexed') := null;
g_keywords('indexes') := null;
g_keywords('indextype') := null;
g_keywords('indextypes') := null;
g_keywords('indicator') := null;
g_keywords('initial') := null;
g_keywords('initialized') := null;
g_keywords('initially') := null;
g_keywords('initrans') := null;
g_keywords('inner') := null;
g_keywords('insert') := null;
g_keywords('instance') := null;
g_keywords('instances') := null;
g_keywords('instantiable') := null;
g_keywords('instantly') := null;
g_keywords('instead') := null;
g_keywords('int') := null;
g_keywords('integer') := null;
g_keywords('integrity') := null;
g_keywords('intermediate') := null;
g_keywords('internal_use') := null;
g_keywords('internal_convert') := null;
g_keywords('intersect') := null;
g_keywords('interval') := null;
g_keywords('into') := null;
g_keywords('invalidate') := null;
g_keywords('in_memory_metadata') := null;
g_keywords('is') := null;
g_keywords('isolation') := null;
g_keywords('isolation_level') := null;
g_keywords('java') := null;
g_keywords('join') := null;
g_keywords('keep') := null;
g_keywords('kerberos') := null;
g_keywords('key') := null;
g_keywords('keyfile') := null;
g_keywords('keys') := null;
g_keywords('keysize') := null;
g_keywords('rekey') := null;
g_keywords('kill') := null;
g_keywords('<<') := null;
g_keywords('last') := null;
g_keywords('lateral') := null;
g_keywords('layer') := null;
g_keywords('ldap_registration') := null;
g_keywords('ldap_registration_enabled') := null;
g_keywords('ldap_reg_sync_interval') := null;
g_keywords('leading') := null;
g_keywords('left') := null;
g_keywords('less') := null;
--g_keywords('level') := null;
g_keywords('levels') := null;
g_keywords('library') := null;
g_keywords('like') := null;
g_keywords('like2') := null;
g_keywords('like4') := null;
g_keywords('likec') := null;
g_keywords('limit') := null;
g_keywords('link') := null;
g_keywords('list') := null;
g_keywords('lob') := null;
g_keywords('local') := null;
g_keywords('localtime') := null;
--g_keywords('localtimestamp') := null;
g_keywords('location') := null;
g_keywords('locator') := null;
g_keywords('lock') := null;
g_keywords('locked') := null;
g_keywords('log') := null;
g_keywords('logfile') := null;
g_keywords('logging') := null;
g_keywords('logical') := null;
g_keywords('logical_reads_per_call') := null;
g_keywords('logical_reads_per_session') := null;
g_keywords('logoff') := null;
g_keywords('logon') := null;
g_keywords('long') := null;
g_keywords('manage') := null;
g_keywords('managed') := null;
g_keywords('management') := null;
g_keywords('manual') := null;
g_keywords('mapping') := null;
g_keywords('master') := null;
g_keywords('materialized') := null;
g_keywords('matched') := null;
g_keywords('max') := null;
g_keywords('maxarchlogs') := null;
g_keywords('maxdatafiles') := null;
g_keywords('maxextents') := null;
g_keywords('maximize') := null;
g_keywords('maxinstances') := null;
g_keywords('maxlogfiles') := null;
g_keywords('maxloghistory') := null;
g_keywords('maxlogmembers') := null;
g_keywords('maxsize') := null;
g_keywords('maxtrans') := null;
g_keywords('maxvalue') := null;
g_keywords('method') := null;
g_keywords('min') := null;
g_keywords('member') := null;
g_keywords('memory') := null;
g_keywords('merge') := null;
g_keywords('migrate') := null;
g_keywords('minimize') := null;
g_keywords('minimum') := null;
g_keywords('minextents') := null;
g_keywords('minus') := null;
g_keywords('minute') := null;
g_keywords('minvalue') := null;
g_keywords('mirror') := null;
g_keywords('mlslabel') := null;
g_keywords('mode') := null;
g_keywords('modify') := null;
g_keywords('monitoring') := null;
g_keywords('month') := null;
g_keywords('mount') := null;
g_keywords('move') := null;
g_keywords('movement') := null;
g_keywords('mts_dispatchers') := null;
g_keywords('multiset') := null;
--g_keywords('name') := null;
g_keywords('named') := null;
g_keywords('national') := null;
g_keywords('natural') := null;
g_keywords('nchar') := null;
g_keywords('nchar_cs') := null;
g_keywords('nclob') := null;
g_keywords('needed') := null;
g_keywords('nested') := null;
g_keywords('nested_table_id') := null;
g_keywords('network') := null;
g_keywords('never') := null;
g_keywords('new') := null;
g_keywords('next') := null;
g_keywords('nls_calendar') := null;
g_keywords('nls_characterset') := null;
g_keywords('nls_comp') := null;
g_keywords('nls_nchar_conv_excp') := null;
g_keywords('nls_currency') := null;
g_keywords('nls_date_format') := null;
g_keywords('nls_date_language') := null;
g_keywords('nls_iso_currency') := null;
g_keywords('nls_lang') := null;
g_keywords('nls_language') := null;
g_keywords('nls_length_semantics') := null;
g_keywords('nls_numeric_characters') := null;
g_keywords('nls_sort') := null;
g_keywords('nls_special_chars') := null;
g_keywords('nls_territory') := null;
--g_keywords('no') := null;
g_keywords('noarchivelog') := null;
g_keywords('noaudit') := null;
g_keywords('nocache') := null;
g_keywords('nocompress') := null;
g_keywords('nocycle') := null;
g_keywords('norowdependencies') := null;
g_keywords('nodelay') := null;
g_keywords('noforce') := null;
g_keywords('nologging') := null;
g_keywords('nomapping') := null;
g_keywords('nomaxvalue') := null;
g_keywords('nominimize') := null;
g_keywords('nominvalue') := null;
g_keywords('nomonitoring') := null;
g_keywords('none') := null;
g_keywords('noorder') := null;
g_keywords('nooverride') := null;
g_keywords('noparallel') := null;
g_keywords('norely') := null;
g_keywords('norepair') := null;
g_keywords('noresetlogs') := null;
g_keywords('noreverse') := null;
g_keywords('normal') := null;
g_keywords('nosegment') := null;
g_keywords('nostrict') := null;
g_keywords('nostripe') := null;
g_keywords('nosort') := null;
g_keywords('noswitch') := null;
g_keywords('not') := null;
g_keywords('nothing') := null;
g_keywords('novalidate') := null;
g_keywords('nowait') := null;
--g_keywords('null') := null;
g_keywords('nulls') := null;
g_keywords('number') := null;
g_keywords('numeric') := null;
g_keywords('nvarchar2') := null;
g_keywords('object') := null;
g_keywords('objno') := null;
g_keywords('objno_reuse') := null;
g_keywords('of') := null;
g_keywords('off') := null;
g_keywords('offline') := null;
--g_keywords('oid') := null;
g_keywords('oidindex') := null;
g_keywords('old') := null;
g_keywords('on') := null;
g_keywords('online') := null;
g_keywords('only') := null;
g_keywords('opaque') := null;
g_keywords('opcode') := null;
g_keywords('open') := null;
g_keywords('operator') := null;
g_keywords('optimal') := null;
g_keywords('optimizer_goal') := null;
g_keywords('option') := null;
g_keywords('or') := null;
g_keywords('order') := null;
g_keywords('organization') := null;
g_keywords('outer') := null;
g_keywords('outline') := null;
g_keywords('over') := null;
g_keywords('overflow') := null;
g_keywords('overlaps') := null;
g_keywords('own') := null;
g_keywords('package') := null;
g_keywords('packages') := null;
g_keywords('parallel') := null;
g_keywords('parameters') := null;
g_keywords('parent') := null;
g_keywords('parity') := null;
g_keywords('partially') := null;
g_keywords('partition') := null;
g_keywords('partitions') := null;
g_keywords('partition_hash') := null;
g_keywords('partition_list') := null;
g_keywords('partition_range') := null;
g_keywords('password') := null;
g_keywords('password_grace_time') := null;
g_keywords('password_life_time') := null;
g_keywords('password_lock_time') := null;
g_keywords('password_reuse_max') := null;
g_keywords('password_reuse_time') := null;
g_keywords('password_verify_function') := null;
g_keywords('pctfree') := null;
g_keywords('pctincrease') := null;
g_keywords('pctthreshold') := null;
g_keywords('pctused') := null;
g_keywords('pctversion') := null;
g_keywords('percent') := null;
g_keywords('performance') := null;
g_keywords('permanent') := null;
g_keywords('pfile') := null;
g_keywords('physical') := null;
g_keywords('plan') := null;
g_keywords('plsql_debug') := null;
g_keywords('policy') := null;
g_keywords('post_transaction') := null;
g_keywords('prebuilt') := null;
g_keywords('preceding') := null;
g_keywords('precision') := null;
g_keywords('prepare') := null;
g_keywords('preserve') := null;
g_keywords('primary') := null;
g_keywords('prior') := null;
g_keywords('private') := null;
g_keywords('private_sga') := null;
g_keywords('privilege') := null;
g_keywords('privileges') := null;
g_keywords('procedure') := null;
g_keywords('profile') := null;
g_keywords('protected') := null;
g_keywords('protection') := null;
g_keywords('public') := null;
g_keywords('purge') := null;
g_keywords('px_granule') := null;
g_keywords('query') := null;
g_keywords('queue') := null;
g_keywords('quiesce') := null;
g_keywords('quota') := null;
g_keywords('random') := null;
g_keywords('range') := null;
g_keywords('rapidly') := null;
g_keywords('raw') := null;
g_keywords('rba') := null;
g_keywords('read') := null;
g_keywords('reads') := null;
g_keywords('real') := null;
g_keywords('rebalance') := null;
g_keywords('rebuild') := null;
g_keywords('records_per_block') := null;
g_keywords('recover') := null;
g_keywords('recoverable') := null;
g_keywords('recovery') := null;
g_keywords('recycle') := null;
g_keywords('reduced') := null;
g_keywords('ref') := null;
g_keywords('references') := null;
g_keywords('referencing') := null;
g_keywords('refresh') := null;
g_keywords('register') := null;
g_keywords('reject') := null;
g_keywords('relational') := null;
g_keywords('rely') := null;
g_keywords('rename') := null;
g_keywords('repair') := null;
g_keywords('replace') := null;
g_keywords('reset') := null;
g_keywords('resetlogs') := null;
g_keywords('resize') := null;
g_keywords('resolve') := null;
g_keywords('resolver') := null;
g_keywords('resource') := null;
g_keywords('restrict') := null;
g_keywords('restricted') := null;
g_keywords('resumable') := null;
g_keywords('resume') := null;
g_keywords('retention') := null;
g_keywords('return') := null;
g_keywords('returning') := null;
g_keywords('reuse') := null;
g_keywords('reverse') := null;
g_keywords('revoke') := null;
g_keywords('rewrite') := null;
g_keywords('right') := null;
g_keywords('role') := null;
g_keywords('roles') := null;
g_keywords('rollback') := null;
g_keywords('rollup') := null;
g_keywords('row') := null;
--g_keywords('rowid') := null;
--g_keywords('rownum') := null;
g_keywords('rows') := null;
g_keywords('rule') := null;
g_keywords('sample') := null;
g_keywords('savepoint') := null;
g_keywords('sb4') := null;
g_keywords('scan') := null;
g_keywords('scan_instances') := null;
g_keywords('schema') := null;
g_keywords('scn') := null;
g_keywords('scope') := null;
g_keywords('sd_all') := null;
g_keywords('sd_inhibit') := null;
g_keywords('sd_show') := null;
g_keywords('second') := null;
g_keywords('security') := null;
g_keywords('segment') := null;
g_keywords('seg_block') := null;
g_keywords('seg_file') := null;
g_keywords('select') := null;
g_keywords('selectivity') := null;
g_keywords('sequence') := null;
g_keywords('sequenced') := null;
g_keywords('serializable') := null;
g_keywords('servererror') := null;
g_keywords('session') := null;
g_keywords('session_cached_cursors') := null;
g_keywords('sessions_per_user') := null;
g_keywords('sessiontimezone') := null;
g_keywords('sessiontzname') := null;
g_keywords('set') := null;
g_keywords('sets') := null;
g_keywords('settings') := null;
g_keywords('share') := null;
g_keywords('shared') := null;
g_keywords('shared_pool') := null;
g_keywords('shrink') := null;
g_keywords('shutdown') := null;
g_keywords('siblings') := null;
--g_keywords('sid') := null;
g_keywords('single') := null;
g_keywords('singletask') := null;
g_keywords('simple') := null;
g_keywords('size') := null;
g_keywords('skip') := null;
g_keywords('skip_unusable_indexes') := null;
g_keywords('smallint') := null;
g_keywords('snapshot') := null;
g_keywords('some') := null;
g_keywords('sort') := null;
g_keywords('source') := null;
g_keywords('space') := null;
g_keywords('specification') := null;
g_keywords('spfile') := null;
g_keywords('split') := null;
g_keywords('sql_trace') := null;
g_keywords('standby') := null;
g_keywords('start') := null;
g_keywords('startup') := null;
g_keywords('statement_id') := null;
g_keywords('statistics') := null;
g_keywords('static') := null;
g_keywords('stop') := null;
g_keywords('storage') := null;
g_keywords('store') := null;
g_keywords('stripe') := null;
g_keywords('strict') := null;
g_keywords('structure') := null;
g_keywords('subpartition') := null;
g_keywords('subpartitions') := null;
g_keywords('subpartition_rel') := null;
g_keywords('substitutable') := null;
g_keywords('successful') := null;
g_keywords('summary') := null;
g_keywords('suspend') := null;
g_keywords('supplemental') := null;
g_keywords('switch') := null;
g_keywords('switchover') := null;
g_keywords('sys_op_bitvec') := null;
g_keywords('sys_op_col_present') := null;
g_keywords('sys_op_cast') := null;
g_keywords('sys_op_enforce_not_null$') := null;
g_keywords('sys_op_mine_value') := null;
g_keywords('sys_op_noexpand') := null;
g_keywords('sys_op_ntcimg$') := null;
g_keywords('synonym') := null;
--g_keywords('sysdate') := null;
g_keywords('sysdba') := null;
g_keywords('sysoper') := null;
g_keywords('system') := null;
--g_keywords('systimestamp') := null;
g_keywords('table') := null;
g_keywords('tables') := null;
g_keywords('tablespace') := null;
g_keywords('tablespace_no') := null;
g_keywords('tabno') := null;
g_keywords('tempfile') := null;
g_keywords('template') := null;
g_keywords('temporary') := null;
--g_keywords('test') := null;
g_keywords('than') := null;
g_keywords('the') := null;
g_keywords('then') := null;
g_keywords('thread') := null;
g_keywords('through') := null;
g_keywords('timestamp') := null;
g_keywords('time') := null;
g_keywords('timeout') := null;
g_keywords('timezone_abbr') := null;
g_keywords('timezone_hour') := null;
g_keywords('timezone_minute') := null;
g_keywords('timezone_region') := null;
g_keywords('time_zone') := null;
g_keywords('to') := null;
g_keywords('toplevel') := null;
g_keywords('trace') := null;
g_keywords('tracing') := null;
g_keywords('trailing') := null;
g_keywords('transaction') := null;
g_keywords('transitional') := null;
g_keywords('treat') := null;
g_keywords('trigger') := null;
g_keywords('triggers') := null;
g_keywords('true') := null;
g_keywords('truncate') := null;
g_keywords('tx') := null;
g_keywords('type') := null;
g_keywords('types') := null;
g_keywords('tz_offset') := null;
g_keywords('ub2') := null;
g_keywords('uba') := null;
--g_keywords('uid') := null;
g_keywords('unarchived') := null;
g_keywords('unbound') := null;
g_keywords('unbounded') := null;
g_keywords('under') := null;
g_keywords('undo') := null;
g_keywords('undrop') := null;
g_keywords('uniform') := null;
g_keywords('union') := null;
g_keywords('unique') := null;
g_keywords('unlimited') := null;
g_keywords('unlock') := null;
g_keywords('unpacked') := null;
g_keywords('unprotected') := null;
g_keywords('unquiesce') := null;
g_keywords('unrecoverable') := null;
g_keywords('until') := null;
g_keywords('unusable') := null;
g_keywords('unused') := null;
g_keywords('upd_indexes') := null;
g_keywords('upd_joinindex') := null;
g_keywords('updatable') := null;
g_keywords('update') := null;
g_keywords('upgrade') := null;
g_keywords('urowid') := null;
g_keywords('usage') := null;
g_keywords('use') := null;
g_keywords('use_private_outlines') := null;
g_keywords('use_stored_outlines') := null;
g_keywords('user') := null;
g_keywords('user_defined') := null;
g_keywords('using') := null;
g_keywords('validate') := null;
g_keywords('validation') := null;
g_keywords('value') := null;
g_keywords('values') := null;
g_keywords('varchar') := null;
g_keywords('varchar2') := null;
g_keywords('varray') := null;
g_keywords('varying') := null;
g_keywords('version') := null;
g_keywords('view') := null;
g_keywords('wait') := null;
g_keywords('when') := null;
g_keywords('whenever') := null;
g_keywords('where') := null;
g_keywords('with') := null;
g_keywords('within') := null;
g_keywords('without') := null;
g_keywords('work') := null;
g_keywords('write') := null;
g_keywords('xmlattributes') := null;
g_keywords('xmlcolattval') := null;
g_keywords('xmlelement') := null;
g_keywords('xmlforest') := null;
g_keywords('xmltype') := null;
g_keywords('xmlschema') := null;
g_keywords('xid') := null;
g_keywords('year') := null;
g_keywords('zone') := null;
end populate_g_keywords;
----------------------------------------------------------
-- returns the least of the non-zero arguments
-- (or zero if they are all equal to zero)
function least_non_zero (
p1 int,
p2 int default 0,
p3 int default 0,
p4 int default 0,
p5 int default 0
)
return int
is
l_ret int default greatest (p1,p2,p3,p4);
begin
if p1 <> 0 and p1 < l_ret then
l_ret := p1;
end if;
if p2 <> 0 and p2 < l_ret then
l_ret := p2;
end if;
if p3 <> 0 and p3 < l_ret then
l_ret := p3;
end if;
if p4 <> 0 and p4 < l_ret then
l_ret := p4;
end if;
if p5 <> 0 and p5 < l_ret then
l_ret := p5;
end if;
return l_ret;
end;
----------------------------------------------------------
-- get the closing position of a comment,hint,quoted-ident
-- or string literal section.
-- nb the closing pos is "one after the end":
-- aaa 'pippo' xxx
-- ^ closing pos
function get_closing_pos (
p_stmt_stripped varchar2,
p_opening_pos int,
p_opening_token varchar2
)
return int
is
l_closing_token varchar2(2);
l_closing_pos int;
l_quote_delimiter varchar2(1);
l_close_delimiter varchar2(1);
begin
if p_opening_token = '/*' then
l_closing_token := '*/';
elsif p_opening_token = '--' then
l_closing_token := chr(10);
elsif p_opening_token = '"' then
l_closing_token := '"';
elsif p_opening_token = '''' then
l_closing_token := '''';
elsif p_opening_token = 'q''' then
-- get quote_delimiter
l_quote_delimiter := substr (p_stmt_stripped, p_opening_pos+2, 1);
-- l_quote_delimiter = ' ' is possible only when the stmt is truncated,
-- since ' ' is not a valid quote delimiter
if l_quote_delimiter = ' ' then
l_closing_token := ' ';
else
l_close_delimiter := case l_quote_delimiter
when '[' then ']'
when '{' then '}'
when '<' then '>'
when '(' then ')'
else l_close_delimiter
end;
l_closing_token := l_close_delimiter || '''';
end if;
end if;
l_closing_pos := instr (p_stmt_stripped,
l_closing_token,
p_opening_pos + length(p_opening_token));
-- close the section at the end of the statement if no closing position
-- was found (possible if eg statement is truncated at 1000 chars)
if l_closing_pos = 0 then
return length (p_stmt_stripped) + 1;
end if;
-- handle double-quotes in string eg 'dell''era'
-- by searching again after the current closing position
if p_opening_token = ''''
and substr (p_stmt_stripped, l_closing_pos+1, 1) = ''''
then
return get_closing_pos (p_stmt_stripped, l_closing_pos+1, p_opening_token);
end if;
-- return the "one after the end" position
return l_closing_pos + length (l_closing_token);
end get_closing_pos;
----------------------------------------------------------
-- copies the token in p_tokens and replace it with