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
+23-23Lines changed: 23 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,34 +7,34 @@ Method4 is a PL/SQL application to run dynamic SQL in SQL.
7
7
8
8
The simplest way to call Method4 is to pass in a literal query to evaluate:
9
9
10
-
select * from table(method4.query('select * from dual'));
11
-
12
-
D
13
-
-
14
-
X
10
+
select * from table(method4.query('select * from dual'));
11
+
12
+
D
13
+
-
14
+
X
15
15
16
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
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
-
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
-
]'
29
-
));
30
-
31
-
TABLE_NAME A
32
-
------------------------- ----------
33
-
TEST 19765
34
-
TEST1 1
35
-
TEST2 1
36
-
TEST3 1
37
-
...
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
+
]'
29
+
));
30
+
31
+
TABLE_NAME A
32
+
------------------------- ----------
33
+
TEST 19765
34
+
TEST1 1
35
+
TEST2 1
36
+
TEST3 1
37
+
...
38
38
39
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).
0 commit comments