-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.sql
9614 lines (8657 loc) · 310 KB
/
script.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
create type pljson_element force as object
(
obj_type number
)
not final;
/
create type pljson_value force as object (
/*
Copyright (c) 2010 Jonas Krogsboell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
* <p>Underlying type for all of <em>PL/JSON</em>. Each <code>pljson</code>
* or <code>pljson_list</code> object is composed of
* <code>pljson_value</code> objects.</p>
*
* <p>Generally, you should not need to directly use the constructors provided
* by this portion of the API. The methods on <code>pljson</code> and
* <code>pljson_list</code> should be used instead.</p>
*
* @headcom
*/
/**
* <p>Internal property that indicates the JSON type represented:<p>
* <ol>
* <li><code>object</code></li>
* <li><code>array</code></li>
* <li><code>string</code></li>
* <li><code>number</code></li>
* <li><code>bool</code></li>
* <li><code>null</code></li>
* </ol>
*/
typeval number(1), /* 1 = object, 2 = array, 3 = string, 4 = number, 5 = bool, 6 = null */
/** Private variable for internal processing. */
str varchar2(32767),
/** Private variable for internal processing. */
num number, /* store 1 as true, 0 as false */
/** Private variable for internal processing. */
num_double binary_double, -- both num and num_double are set, there is never exception (until Oracle 12c)
/** Private variable for internal processing. */
num_repr_number_p varchar2(1),
/** Private variable for internal processing. */
num_repr_double_p varchar2(1),
/** Private variable for internal processing. */
object_or_array pljson_element, /* object or array in here */
/** Private variable for internal processing. */
extended_str clob,
/* mapping */
/** Private variable for internal processing. */
mapname varchar2(4000),
/** Private variable for internal processing. */
mapindx number(32),
constructor function pljson_value(elem pljson_element) return self as result,
constructor function pljson_value(str varchar2, esc boolean default true) return self as result,
constructor function pljson_value(str clob, esc boolean default true) return self as result,
constructor function pljson_value(num number) return self as result,
/* E.I.Sarmas (github.com/dsnz) 2016-11-03 support for binary_double numbers */
constructor function pljson_value(num_double binary_double) return self as result,
constructor function pljson_value(b boolean) return self as result,
constructor function pljson_value return self as result,
member function get_element
return pljson_element,
/**
* <p>Create an empty <code>pljson_value</code>.</p>
*
* <pre>
* declare
* myval pljson_value := pljson_value.makenull();
* begin
* myval.parse_number('42');
* myval.print(); // => dbms_output.put_line('42');
* end;
* </pre>
*
* @return An instance of <code>pljson_value</code>.
*/
static function makenull
return pljson_value,
/**
* <p>Retrieve the name of the type represented by the <code>pljson_value</code>.</p>
* <p>Possible return values:</p>
* <ul>
* <li><code>object</code></li>
* <li><code>array</code></li>
* <li><code>string</code></li>
* <li><code>number</code></li>
* <li><code>bool</code></li>
* <li><code>null</code></li>
* </ul>
*
* @return The name of the type represented.
*/
member function get_type
return varchar2,
/**
* <p>Retrieve the value as a string (<code>varchar2</code>).</p>
*
* @param max_byte_size Retrieve the value up to a specific number of bytes, max = bytes for 5000 characters. Default: <code>null</code>.
* @param max_char_size Retrieve the value up to a specific number of characters, max = 5000. Default: <code>null</code>.
* @return An instance of <code>varchar2</code> or <code>null</code> if the value is not a string.
*/
member function get_string(max_byte_size number default null, max_char_size number default null)
return varchar2,
/**
* <p>Retrieve the value as a string represented by a <code>CLOB</code>.</p>
*
* @param buf The <code>CLOB</code> in which to store the string.
*/
member procedure get_string(self in pljson_value, buf in out nocopy clob),
/**
* <p>Retrieve the value as a string of clob type (<code>clob</code>).</p>
*
* @return the internal <code>clob</code> or <code>null</code> if the value is not a string.
*/
member function get_clob
return clob,
/**
* <p>Retrieve the value as a <code>number</code>.</p>
*
* @return An instance of <code>number</code> or <code>null</code> if the value is not a number.
*/
member function get_number
return number,
/* E.I.Sarmas (github.com/dsnz) 2016-11-03 support for binary_double numbers */
/**
* <p>Retrieve the value as a <code>binary_double</code>.</p>
*
* @return An instance of <code>binary_double</code> or <code>null</code> if the value is not a number.
*/
member function get_double
return binary_double,
/**
* <p>Retrieve the value as a <code>boolean</code>.</p>
*
* @return An instance of <code>boolean</code> or <code>null</code> if the value is not a boolean.
*/
member function get_bool
return boolean,
/**
* <p>Retrieve the value as a string <code>'null'<code>.</p>
*
* @return A <code>varchar2</code> with the value <code>'null'</code> or
* an actual <code>null</code> if the value isn't a JSON "null".
*/
member function get_null
return varchar2,
/**
* <p>Determine if the value represents an "object" type.</p>
*
* @return <code>true</code> if the value is an object, <code>false</code> otherwise.
*/
member function is_object
return boolean,
/**
* <p>Determine if the value represents an "array" type.</p>
*
* @return <code>true</code> if the value is an array, <code>false</code> otherwise.
*/
member function is_array
return boolean,
/**
* <p>Determine if the value represents a "string" type.</p>
*
* @return <code>true</code> if the value is a string, <code>false</code> otherwise.
*/
member function is_string
return boolean,
/**
* <p>Determine if the value represents a "number" type.</p>
*
* @return <code>true</code> if the value is a number, <code>false</code> otherwise.
*/
member function is_number
return boolean,
/**
* <p>Determine if the value represents a "boolean" type.</p>
*
* @return <code>true</code> if the value is a boolean, <code>false</code> otherwise.
*/
member function is_bool
return boolean,
/**
* <p>Determine if the value represents a "null" type.</p>
*
* @return <code>true</code> if the value is a null, <code>false</code> otherwise.
*/
member function is_null
return boolean,
/* E.I.Sarmas (github.com/dsnz) 2016-11-03 support for binary_double numbers, is_number is still true, extra info */
/* return true if 'number' is representable by Oracle number */
/** Private method for internal processing. */
member function is_number_repr_number
return boolean,
/* return true if 'number' is representable by Oracle binary_double */
/** Private method for internal processing. */
member function is_number_repr_double
return boolean,
/* E.I.Sarmas (github.com/dsnz) 2016-11-03 support for binary_double numbers */
-- set value for number from string representation; to replace to_number in pljson_parser
-- can automatically decide and use binary_double if needed
-- less confusing than new constructor with dummy argument for overloading
-- centralized parse_number to use everywhere else and replace code in pljson_parser
/**
* <p>Parses a string into a number. This method will automatically cast to
* a <code>binary_double</code> if it is necessary.</p>
*
* <pre>
* declare
* mynum pljson_value := pljson_value('42');
* begin
* dbms_output.put_line('mynum is a string: ' || mynum.is_string()); // 'true'
* mynum.parse_number('42');
* dbms_output.put_line('mynum is a number: ' || mynum.is_number()); // 'true'
* end;
* </pre>
*
* @param str A <code>varchar2</code> to parse into a number.
*/
-- this procedure is meant to be used internally only
-- procedure does not work correctly if called standalone in locales that
-- use a character other than "." for decimal point
member procedure parse_number(str varchar2),
/* E.I.Sarmas (github.com/dsnz) 2016-12-01 support for binary_double numbers */
/**
* <p>Return a <code>varchar2</code> representation of a <code>number</code>
* type. This is primarily intended to be used within PL/JSON internally.</p>
*
* @return A <code>varchar2</code> up to 4000 characters.
*/
-- this procedure is meant to be used internally only
member function number_toString
return varchar2,
/* Output methods */
member function to_char(spaces boolean default true, chars_per_line number default 0)
return varchar2,
member procedure to_clob(self in pljson_value, buf in out nocopy clob, spaces boolean default false,
chars_per_line number default 0, erase_clob boolean default true),
member procedure print(self in pljson_value, spaces boolean default true, chars_per_line number default 8192,
jsonp varchar2 default null), --32512 is maximum
member procedure htp(self in pljson_value, spaces boolean default false, chars_per_line number default 0,
jsonp varchar2 default null),
member function value_of(self in pljson_value, max_byte_size number default null, max_char_size number default null)
return varchar2
) not final;
/
create TYPE node as object (
x float,
y float,
nume varchar2(20),
nu number)
/
create type predecessor as object
(
parent int,
arrived int,
route int
)
/
create type intpair as object
(
id int,
dist int
)
/
create type PLJSON_VALUE_ARRAY as table of PLJSON_VALUE
/
create type PLJSON_VARRAY as table of VARCHAR2(32767)
/
create type PLJSON_NARRAY as table of NUMBER(0)
/
create type pljson_list force under pljson_element (
/*
Copyright (c) 2010 Jonas Krogsboell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
* <p>This package defines <em>PL/JSON</em>'s representation of the JSON
* array type, e.g. <code>[1, 2, "foo", "bar"]</code>.</p>
*
* <p>The primary method exported by this package is the <code>pljson_list</code>
* method.</p>
*
* <strong>Example:</strong>
*
* <pre>
* declare
* myarr pljson_list := pljson_list('[1, 2, "foo", "bar"]');
* begin
* myarr.get(1).print(); // => dbms_output.put_line(1)
* myarr.get(3).print(); // => dbms_output.put_line('foo')
* end;
* </pre>
*
* @headcom
*/
/** Private variable for internal processing. */
list_data pljson_value_array,
/* constructors */
/**
* <p>Create an empty list.</p>
*
* <pre>
* declare
* myarr pljson_list := pljson_list();
* begin
* dbms_output.put_line(myarr.count()); // => 0
* end;
*
* @return An instance of <code>pljson_list</code>.
*/
constructor function pljson_list return self as result,
/**
* <p>Create an instance from a given JSON array representation.</p>
*
* <pre>
* declare
* myarr pljson_list := pljson_list('[1, 2, "foo", "bar"]');
* begin
* myarr.get(1).print(); // => dbms_output.put_line(1)
* myarr.get(3).print(); // => dbms_output.put_line('foo')
* end;
* </pre>
*
* @param str The JSON array string to parse.
* @return An instance of <code>pljson_list</code>.
*/
constructor function pljson_list(str varchar2) return self as result,
/**
* <p>Create an instance from a given JSON array representation stored in
* a <code>CLOB</code>.</p>
*
* @param str The <code>CLOB</code> to parse.
* @return An instance of <code>pljson_list</code>.
*/
constructor function pljson_list(str clob) return self as result,
/**
* <p>Create an instance from a given JSON array representation stored in
* a <code>BLOB</code>.</p>
*
* @param str The <code>BLOB</code> to parse.
* @param charset The character set of the BLOB data (defaults to UTF-8).
* @return An instance of <code>pljson_list</code>.
*/
constructor function pljson_list(str blob, charset varchar2 default 'UTF8') return self as result,
/**
* <p>Create an instance instance from a given table of string values of type varchar2.</p>
*
* @param str_array The pljson_varray (table of varchar2) of string values.
* @return An instance of <code>pljson_list</code>.
*/
constructor function pljson_list(str_array pljson_varray) return self as result,
/**
* <p>Create an instance instance from a given table of string values of type varchar2.</p>
*
* @param str_array The pljson_varray (table of varchar2) of string values.
* @return An instance of <code>pljson_list</code>.
*/
constructor function pljson_list(num_array pljson_narray) return self as result,
/**
* <p>Create an instance from a given instance of <code>pljson_value</code>
* that represents an array.</p>
*
* @param elem The <code>pljson_value</code> to cast to a <code>pljson_list</code>.
* @return An instance of <code>pljson_list</code>.
*/
constructor function pljson_list(elem pljson_value) return self as result,
/* list management */
member procedure append(self in out nocopy pljson_list, elem pljson_value, position pls_integer default null),
member procedure append(self in out nocopy pljson_list, elem varchar2, position pls_integer default null),
member procedure append(self in out nocopy pljson_list, elem clob, position pls_integer default null),
member procedure append(self in out nocopy pljson_list, elem number, position pls_integer default null),
/* E.I.Sarmas (github.com/dsnz) 2016-12-01 support for binary_double numbers */
member procedure append(self in out nocopy pljson_list, elem binary_double, position pls_integer default null),
member procedure append(self in out nocopy pljson_list, elem boolean, position pls_integer default null),
member procedure append(self in out nocopy pljson_list, elem pljson_list, position pls_integer default null),
member procedure replace(self in out nocopy pljson_list, position pls_integer, elem pljson_value),
member procedure replace(self in out nocopy pljson_list, position pls_integer, elem varchar2),
member procedure replace(self in out nocopy pljson_list, position pls_integer, elem clob),
member procedure replace(self in out nocopy pljson_list, position pls_integer, elem number),
/* E.I.Sarmas (github.com/dsnz) 2016-12-01 support for binary_double numbers */
member procedure replace(self in out nocopy pljson_list, position pls_integer, elem binary_double),
member procedure replace(self in out nocopy pljson_list, position pls_integer, elem boolean),
member procedure replace(self in out nocopy pljson_list, position pls_integer, elem pljson_list),
member procedure remove(self in out nocopy pljson_list, position pls_integer),
member procedure remove_first(self in out nocopy pljson_list),
member procedure remove_last(self in out nocopy pljson_list),
member function count
return number,
member function get(position pls_integer)
return pljson_value,
member function get_string(position pls_integer)
return varchar2,
member function get_clob(position pls_integer)
return clob,
member function get_number(position pls_integer)
return number,
member function get_double(position pls_integer)
return binary_double,
member function get_bool(position pls_integer)
return boolean,
member function get_pljson_list(position pls_integer)
return pljson_list,
member function head
return pljson_value,
member function last
return pljson_value,
member function tail
return pljson_list,
member function to_json_value
return pljson_value,
/* output methods */
member function to_char(spaces boolean default true, chars_per_line number default 0)
return varchar2,
member procedure to_clob(self in pljson_list, buf in out nocopy clob, spaces boolean default false,
chars_per_line number default 0, erase_clob boolean default true),
member procedure print(self in pljson_list, spaces boolean default true, chars_per_line number default 8192,
jsonp varchar2 default null), --32512 is maximum
member procedure htp(self in pljson_list, spaces boolean default false, chars_per_line number default 0,
jsonp varchar2 default null),
/* json path */
member function path(json_path varchar2, base number default 1)
return pljson_value,
/* json path_put */
member procedure path_put(self in out nocopy pljson_list, json_path varchar2, elem pljson_value, base number default 1),
member procedure path_put(self in out nocopy pljson_list, json_path varchar2, elem varchar2, base number default 1),
member procedure path_put(self in out nocopy pljson_list, json_path varchar2, elem clob, base number default 1),
member procedure path_put(self in out nocopy pljson_list, json_path varchar2, elem number, base number default 1),
/* E.I.Sarmas (github.com/dsnz) 2016-12-01 support for binary_double numbers */
member procedure path_put(self in out nocopy pljson_list, json_path varchar2, elem binary_double,
base number default 1),
member procedure path_put(self in out nocopy pljson_list, json_path varchar2, elem boolean, base number default 1),
member procedure path_put(self in out nocopy pljson_list, json_path varchar2, elem pljson_list, base number default 1),
/* json path_remove */
member procedure path_remove(self in out nocopy pljson_list, json_path varchar2, base number default 1)
/* --backwards compatibility
member procedure add_elem(self in out nocopy json_list, elem json_value, position pls_integer default null),
member procedure add_elem(self in out nocopy json_list, elem varchar2, position pls_integer default null),
member procedure add_elem(self in out nocopy json_list, elem number, position pls_integer default null),
member procedure add_elem(self in out nocopy json_list, elem boolean, position pls_integer default null),
member procedure add_elem(self in out nocopy json_list, elem json_list, position pls_integer default null),
member procedure set_elem(self in out nocopy json_list, position pls_integer, elem json_value),
member procedure set_elem(self in out nocopy json_list, position pls_integer, elem varchar2),
member procedure set_elem(self in out nocopy json_list, position pls_integer, elem number),
member procedure set_elem(self in out nocopy json_list, position pls_integer, elem boolean),
member procedure set_elem(self in out nocopy json_list, position pls_integer, elem json_list),
member procedure remove_elem(self in out nocopy json_list, position pls_integer),
member function get_elem(position pls_integer) return json_value,
member function get_first return json_value,
member function get_last return json_value
--*/
) not final;
/
create type pljson force under pljson_element (
/*
Copyright (c) 2010 Jonas Krogsboell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
* <p>This package defines <em>PL/JSON</em>'s representation of the JSON
* object type, e.g.:</p>
*
* <pre>
* {
* "foo": "bar",
* "baz": 42
* }
* </pre>
*
* <p>The primary method exported by this package is the <code>pljson</code>
* method.</p>
*
* <strong>Example:</strong>
* <pre>
* declare
* myjson pljson := pljson('{ "foo": "foo", "bar": [0, 1, 2], "baz": { "foobar": "foobar" } }');
* begin
* myjson.get('foo').print(); // => dbms_output.put_line('foo')
* myjson.get('bar[1]').print(); // => dbms_output.put_line('0')
* myjson.get('baz.foobar').print(); // => dbms_output.put_line('foobar')
* end;
* </pre>
*
* @headcom
*/
/* Variables */
/** Private variable for internal processing. */
json_data pljson_value_array,
/** Private variable for internal processing. */
check_for_duplicate number,
/* constructors */
/**
* <p>Primary constructor that creates an empty object.</p>
*
* <p>Internally, a <code>pljson</code> "object" is an array of values.</p>
*
* <pre>
* decleare
* myjson pljson := pljson();
* begin
* myjson.put('foo', 'bar');
* dbms_output.put_line(myjson.get('foo')); // "bar"
* end;
* </pre>
*
* @return A <code>pljson</code> instance.
*/
constructor function pljson return self as result,
/**
* <p>Construct a <code>pljson</code> instance from a given string of JSON.</p>
*
* <pre>
* decleare
* myjson pljson := pljson('{"foo": "bar"}');
* begin
* dbms_output.put_line(myjson.get('foo')); // "bar"
* end;
* </pre>
*
* @param str The JSON to parse into a <code>pljson</code> object.
* @return A <code>pljson</code> instance.
*/
constructor function pljson(str varchar2) return self as result,
/**
* <p>Construct a <code>pljson</code> instance from a given CLOB of JSON.</p>
*
* @param str The CLOB to parse into a <code>pljson</code> object.
* @return A <code>pljson</code> instance.
*/
constructor function pljson(str in clob) return self as result,
/**
* <p>Construct a <code>pljson</code> instance from a given BLOB of JSON.</p>
*
* @param str The BLOB to parse into a <code>pljson</code> object.
* @param charset The character set of the BLOB data (defaults to UTF-8).
* @return A <code>pljson</code> instance.
*/
constructor function pljson(str in blob, charset varchar2 default 'UTF8') return self as result,
/**
* <p>Construct a <code>pljson</code> instance from
* a given table of key,value pairs of type varchar2.</p>
*
* @param str_array The pljson_varray (table of varchar2) to parse into a <code>pljson</code> object.
* @return A <code>pljson</code> instance.
*/
constructor function pljson(str_array pljson_varray) return self as result,
/**
* <p>Create a new <code>pljson</code> object from a current <code>pljson_value</code>.
*
* <pre>
* declare
* myjson pljson := pljson('{"foo": {"bar": "baz"}}');
* newjson pljson;
* begin
* newjson := pljson(myjson.get('foo').to_json_value)
* end;
* </pre>
*
* @param elem The <code>pljson_value</code> to cast to a <code>pljson</code> object.
* @return An instance of <code>pljson</code>.
*/
constructor function pljson(elem pljson_value) return self as result,
/**
* <p>Create a new <code>pljson</code> object from a current <code>pljson_list</code>.
*
* @param l The array to create a new object from.
* @return An instance of <code>pljson</code>.
*/
constructor function pljson(l in out nocopy pljson_list) return self as result,
/* member management */
/**
* <p>Remove a key and value from an object.</p>
*
* <pre>
* declare
* myjson pljson := pljson('{"foo": "foo", "bar": "bar"}')
* begin
* myjson.remove('bar'); // => '{"foo": "foo"}'
* end;
* </pre>
*
* @param pair_name The key name to remove.
*/
member procedure remove(pair_name varchar2),
/**
* <p>Add a <code>pljson</code> instance into the current instance under a
* given key name.</p>
*
* @param pair_name Name of the key to add/update.
* @param pair_value The value to associate with the key.
*/
member procedure put(self in out nocopy pljson, pair_name varchar2, pair_value pljson_value,
position pls_integer default null),
/**
* <p>Add a <code>varchar2</code> instance into the current instance under a
* given key name.</p>
*
* @param pair_name Name of the key to add/update.
* @param pair_value The value to associate with the key.
*/
member procedure put(self in out nocopy pljson, pair_name varchar2, pair_value varchar2,
position pls_integer default null),
/**
* <p>Add a <code>clob</code> instance into the current instance under a
* given key name.</p>
*
* @param pair_name Name of the key to add/update.
* @param pair_value The value to associate with the key.
*/
member procedure put(self in out nocopy pljson, pair_name varchar2, pair_value clob, position pls_integer default null),
/**
* <p>Add a <code>number</code> instance into the current instance under a
* given key name.</p>
*
* @param pair_name Name of the key to add/update.
* @param pair_value The value to associate with the key.
*/
member procedure put(self in out nocopy pljson, pair_name varchar2, pair_value number,
position pls_integer default null),
/* E.I.Sarmas (github.com/dsnz) 2016-12-01 support for binary_double numbers */
/**
* <p>Add a <code>binary_double</code> instance into the current instance under a
* given key name.</p>
*
* @param pair_name Name of the key to add/update.
* @param pair_value The value to associate with the key.
*/
member procedure put(self in out nocopy pljson, pair_name varchar2, pair_value binary_double,
position pls_integer default null),
/**
* <p>Add a <code>boolean</code> instance into the current instance under a
* given key name.</p>
*
* @param pair_name Name of the key to add/update.
* @param pair_value The value to associate with the key.
*/
member procedure put(self in out nocopy pljson, pair_name varchar2, pair_value boolean,
position pls_integer default null),
/*
* had been marked as deprecated in favor of the overloaded method with pljson_value
* the reason is unknown even though it is useful in coding
* and removes the need for the user to do a conversion
* also path_put function has same overloaded parameter and is not marked as deprecated
*
* after tests by trying to add new overloaded procedures, a theory has emerged
* with all procedures there are cyclic type references and installation is not possible
* so some procedures had to be removed, and these were meant to be removed
*
* but by careful package ordering and removing only a few procedures from pljson_list package
* it is possible to compile the project without error and keep these procedures
*/
member procedure put(self in out nocopy pljson, pair_name varchar2, pair_value pljson,
position pls_integer default null),
/*
* had been marked as deprecated in favor of the overloaded method with pljson_value
* the reason is unknown even though it is useful in coding
* and removes the need for the user to do a conversion
* also path_put function has same overloaded parameter and is not marked as deprecated
*
* after tests by trying to add new overloaded procedures, a theory has emerged
* with all procedures there are cyclic type references and installation is not possible
* so some procedures had to be removed, and these were meant to be removed
*
* but by careful package ordering and removing only a few procedures from pljson_list package
* it is possible to compile the project without error and keep these procedures
*/
member procedure put(self in out nocopy pljson, pair_name varchar2, pair_value pljson_list,
position pls_integer default null),
/**
* <p>Return the number values in the object. Essentially, the number of keys
* in the object.</p>
*
* @return The number of values in the object.
*/
member function count
return number,
/**
* <p>Retrieve the value of a given key.</p>
*
* @param pair_name The name of the value to retrieve.
* @return An instance of <code>pljson_value</code>, or <code>null</code>
* if it could not be found.
*/
member function get(pair_name varchar2)
return pljson_value,
member function get_string(pair_name varchar2)
return varchar2,
member function get_clob(pair_name varchar2)
return clob,
member function get_number(pair_name varchar2)
return number,
member function get_double(pair_name varchar2)
return binary_double,
member function get_bool(pair_name varchar2)
return boolean,
member function get_pljson(pair_name varchar2)
return pljson,
member function get_pljson_list(pair_name varchar2)
return pljson_list,
/**
* <p>Retrieve a value based on its position in the internal storage array.
* It is recommended you use name based retrieval.</p>
*
* @param position Index of the value in the internal storage array.
* @return An instance of <code>pljson_value</code>, or <code>null</code>
* if it could not be found.
*/
member function get(position pls_integer)
return pljson_value,
/**
* <p>Determine the position of a given value within the internal storage
* array.</p>
*
* @param pair_name The name of the value to retrieve the index for.
* @return An index number, or <code>-1</code> if it could not be found.
*/
member function index_of(pair_name varchar2)
return number,
/**
* <p>Determine if a given value exists within the object.</p>
*
* @param pair_name The name of the value to check for.
* @return <code>true</code> if the value exists, <code>false</code> otherwise.
*/
member function exist(pair_name varchar2)
return boolean,
/**
* <p>Convert the object to a <code>pljson_value</code> for use in other methods
* of the PL/JSON API.</p>
*
* @returns An instance of <code>pljson_value</code>.
*/
member function to_json_value
return pljson_value,
member procedure check_duplicate(self in out nocopy pljson, v_set boolean),
member procedure remove_duplicates(self in out nocopy pljson),
/* output methods */
/**
* <p>Serialize the object to a JSON representation string.</p>
*
* @param spaces Enable pretty printing by formatting with spaces. Default: <code>true</code>.
* @param chars_per_line Wrap output to a specific number of characters per line. Default: <code>0<code> (infinite).
* @return A <code>varchar2</code> string.
*/
member function to_char(spaces boolean default true, chars_per_line number default 0)
return varchar2,
/**
* <p>Serialize the object to a JSON representation and store it in a CLOB.</p>
*
* @param buf The CLOB in which to store the results.
* @param spaces Enable pretty printing by formatting with spaces. Default: <code>false</code>.
* @param chars_per_line Wrap output to a specific number of characters per line. Default: <code>0<code> (infinite).
* @param erase_clob Whether or not to wipe the storage CLOB prior to serialization. Default: <code>true</code>.
* @return A <code>varchar2</code> string.
*/
member procedure to_clob(self in pljson, buf in out nocopy clob, spaces boolean default false,
chars_per_line number default 0, erase_clob boolean default true),
/**
* <p>Print a JSON representation of the object via <code>DBMS_OUTPUT</code>.</p>
*
* @param spaces Enable pretty printing by formatting with spaces. Default: <code>true</code>.
* @param chars_per_line Wrap output to a specific number of characters per line. Default: <code>8192<code> (<code>32512</code> is maximum).
* @param jsonp Name of a function for wrapping the output as JSONP. Default: <code>null</code>.
* @return A <code>varchar2</code> string.
*/
member procedure print(self in pljson, spaces boolean default true, chars_per_line number default 8192,
jsonp varchar2 default null), --32512 is maximum
/**
* <p>Print a JSON representation of the object via <code>HTP.PRN</code>.</p>
*
* @param spaces Enable pretty printing by formatting with spaces. Default: <code>true</code>.
* @param chars_per_line Wrap output to a specific number of characters per line. Default: <code>0<code> (infinite).
* @param jsonp Name of a function for wrapping the output as JSONP. Default: <code>null</code>.
* @return A <code>varchar2</code> string.
*/
member procedure htp(self in pljson, spaces boolean default false, chars_per_line number default 0,
jsonp varchar2 default null),
/* json path */
/**
* <p>Retrieve a value from the internal storage array based on a path string
* and a starting index.</p>
*
* @param json_path A string path, e.g. <code>'foo.bar[1]'</code>.
* @param base The index in the internal storage array to start from.
* This should only be necessary under special circumstances. Default: <code>1</code>.
* @return An instance of <code>pljson_value</code>.
*/
member function path(json_path varchar2, base number default 1)
return pljson_value,
/* json path_put */
member procedure path_put(self in out nocopy pljson, json_path varchar2, elem pljson_value, base number default 1),
member procedure path_put(self in out nocopy pljson, json_path varchar2, elem varchar2, base number default 1),
member procedure path_put(self in out nocopy pljson, json_path varchar2, elem clob, base number default 1),
member procedure path_put(self in out nocopy pljson, json_path varchar2, elem number, base number default 1),
/* E.I.Sarmas (github.com/dsnz) 2016-12-01 support for binary_double numbers */
member procedure path_put(self in out nocopy pljson, json_path varchar2, elem binary_double, base number default 1),
member procedure path_put(self in out nocopy pljson, json_path varchar2, elem boolean, base number default 1),
member procedure path_put(self in out nocopy pljson, json_path varchar2, elem pljson, base number default 1),
member procedure path_put(self in out nocopy pljson, json_path varchar2, elem pljson_list, base number default 1),
/* json path_remove */
member procedure path_remove(self in out nocopy pljson, json_path varchar2, base number default 1),
/* map functions */
/**
* <p>Retrieve all of the keys within the object as a <code>pljson_list</code>.</p>
*
* <pre>
* myjson := pljson('{"foo": "bar"}');
* myjson.get_keys(); // ['foo']
* </pre>
*
* @return An instance of <code>pljson_list</code>.
*/
member function get_keys
return pljson_list,
/**
* <p>Retrieve all of the values within the object as a <code>pljson_list</code>.</p>
*
* <pre>
* myjson := pljson('{"foo": "bar"}');
* myjson.get_values(); // ['bar']
* </pre>
*
* @return An instance of <code>pljson_list</code>.
*/
member function get_values
return pljson_list
) not final;
/
create type PLJSON_VTAB as table of PLJSON_VARRAY
/
create type pljson_table_impl as object (
/*
Copyright (c) 2016 E.I.Sarmas (github.com/dsnz)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/