forked from doberkofler/PLSQL-JSON
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_sql.pks
More file actions
88 lines (74 loc) · 2.39 KB
/
Copy pathjson_sql.pks
File metadata and controls
88 lines (74 loc) · 2.39 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
CREATE OR REPLACE
PACKAGE json_sql
IS
------------
-- OVERVIEW
--
-- This package allows to dynamically generate a json representation of the rows in a select.
--
--
-----------
-- EXAMPLE
--
-- 1) Simple select
--
-- 1.1) from code
-- BEGIN
-- json_sql.htp('select * from user_tables order by table_name');
-- END;
--
-- 1.2) from browser
-- json_sql.htp?sqlCmd=select * from user_tables order by table_name
--
--
-- 2) Select with bind variables and format rows as objects
--
-- 2.1) from code
-- DECLARE
-- aBind json_object := json_object();
-- BEGIN
-- aBind.put('name', 'F');
-- json_sql.htp(sqlCmd=>'select * from user_tables where UPPER(table_name) > :name', sqlBind=>aBind, format=>json_sql.FORMAT_OBJ);
-- END;
--
-- 2.2) from browser
-- json_sql.htp?sqlCmd=select+*+from+user_tables+where+UPPER(table_name)+%3e+%3aname&sqlbind={"name":"F"}&format=obj
--
--
-------------
-- RESOURCES
--
--
----------------------------------------------------------
-- GLOBAL PUBLIC EXCEPTIONS
----------------------------------------------------------
----------------------------------------------------------
-- GLOBAL PUBLIC TYPES
----------------------------------------------------------
----------------------------------------------------------
-- GLOBAL PUBLIC CONSTANTS
----------------------------------------------------------
-- format
FORMAT_TAB CONSTANT VARCHAR2(3) := 'TAB';
FORMAT_OBJ CONSTANT VARCHAR2(3) := 'OBJ';
-- null binding
NULL_OBJECT CONSTANT json_object := json_object();
----------------------------------------------------------
-- GLOBAL PUBLIC ENUMERATIONS
----------------------------------------------------------
----------------------------------------------------------
-- GLOBAL PUBLIC VARIABLES
----------------------------------------------------------
----------------------------------------------------------
-- GLOBAL PUBLIC MODULES
----------------------------------------------------------
----------------------------------------------------------
-- Execute sql statement and return a josn object
--
FUNCTION get(theSqlStatement VARCHAR2, theBinding json_object DEFAULT NULL_OBJECT, format IN VARCHAR2 DEFAULT FORMAT_TAB) RETURN json_object;
----------------------------------------------------------
-- Execute sql statement and output a json structure
--
PROCEDURE htp(sqlCmd VARCHAR2, sqlBind IN VARCHAR2 DEFAULT NULL, format IN VARCHAR2 DEFAULT FORMAT_TAB);
END json_sql;
/