You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+17-15Lines changed: 17 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,28 +5,27 @@ Method4 is a PL/SQL application to run dynamic SQL in SQL.
5
5
6
6
## Example
7
7
8
-
The simplest way to call Method4 is to pass in a simple literal query to evaluate:
8
+
The simplest way to call Method4 is to pass in a literal query to evaluate:
9
9
10
-
select * from table(method4.run(q'[select * from dual]'));
10
+
select * from table(method4.query('select * from dual'));
11
11
12
12
D
13
13
-
14
14
X
15
15
16
-
At first that query seems pointless - why not just directly query `select * from dual`? Method4 allows custom code to control how the code is run and what is returned.
16
+
At first that query seems pointless - why not just directly query `select * from dual`? Method4 provides two benefits - it silently converts LONGs to CLOBs and it allows custom code to control exactly what query is run and returned.
17
17
18
-
As a simple and useful example, Method4 includes a mode that runs queries generated by queries. This can solve challenging problems such as "count the rows for every table".
18
+
Method4 includes a dynamic mode that runs queries generated by queries and concatenated with UNION ALLs. This can solve challenging problems such as "count the rows for every table", all within a single SQL statement.
19
19
20
-
To enable this re-evaluation mode, set the parameter `p_re_eval` to YES. In this mode, Method4 runs a query that returns a query string. Those queries are concatenated with UNION ALL and then run.
21
-
22
-
select * from table(method4.run(
23
-
p_stmt =>
24
-
q'[
25
-
select 'select '''||table_name||''' table_name, count(*) a from '||table_name sql
26
-
from user_tables
27
-
where table_name like 'TEST%'
28
-
]',
29
-
p_re_eval => 'YES'
20
+
select * from table(method4.dynamic_query(
21
+
q'[
22
+
select replace(
23
+
q'!
24
+
select '#TABLE_NAME#' table_name, count(*) a from #TABLE_NAME#
25
+
!', '#TABLE_NAME#', table_name) sql_statement
26
+
from user_tables
27
+
where table_name like 'TEST%'
28
+
]'
30
29
));
31
30
32
31
TABLE_NAME A
@@ -37,6 +36,9 @@ To enable this re-evaluation mode, set the parameter `p_re_eval` to YES. In thi
37
36
TEST3 1
38
37
...
39
38
39
+
These queries are powerful but they can also be confusing because of all the quotation marks required to build strings inside strings. Simplify your queries with the alternative quoting syntax (the "q" strings) and templating (use REPLACE instead of concatenating strings).
40
+
41
+
40
42
## Notes
41
43
42
44
Method4 is based on the Dictionary Long Application, (c) Adrian Billington www.oracle-developer.net. Much of this code contains advanced methods thoroughly discussed on his website, http://www.oracle-developer.net/display.php?id=422
@@ -53,7 +55,7 @@ Click the "Download ZIP" button, extract the files, CD to the directory with tho
0 commit comments