时间:2021-07-01 10:21:17 帮助过:2人阅读
函数调用形式:
参数说明:
参数名 | 类型 | 说明 |
---|---|---|
sqlText | VARCHAR | 必选 |
dbType | VARCHAR | 可选。SQL方言,默认为mysql |
throwError | BOOLEAN | 可选。true时,遇到非法SQL抛出异常;false时,遇到非法SQL不抛出异常,返回null |
返回值:
类型 | 说明 |
---|---|
VARCHAR | sqlText的SQL语句中所有出现的函数名,用逗号分隔,列所属的表会进行关联推导,如果没有找到明确的表,则为UNKNOWN |
示例:
SELECT sql_export_functions(a.sql_text)
FROM (
SELECT ‘SELECT s_acctbal,
s_name,
n_name,
p_partkey,
p_mfgr,
s_address,
s_phone,
s_comment
FROM part,
supplier,
partsupp,
nation,
region
WHERE p_partkey = ps_partkey
AND s_suppkey = ps_suppkey
AND p_size = 35
AND p_type LIKE ‘‘%NICKEL‘‘
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ‘‘MIDDLE EAST‘‘
AND ps_supplycost IN
(
SELECT min(ps_supplycost)
FROM partsupp,
supplier,
nation,
region
WHERE s_suppkey = ps_suppkey
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ‘‘MIDDLE EAST‘‘ )
ORDER BY s_acctbal DESC,
n_name,
s_name,
p_partkey
LIMIT 100;‘ AS sql_text
) a;
+----------------------------------+
| sql_export_functions(a.sql_text) |
+----------------------------------+
| min |
+----------------------------------+
函数调用形式:
参数说明:
参数名 | 类型 | 说明 |
---|---|---|
sqlText | VARCHAR | 必选 |
dbType | VARCHAR | 可选。SQL方言,默认为mysql |
throwError | BOOLEAN | 可选。true时,遇到非法SQL抛出异常;false时,遇到非法SQL不抛出异常,返回null |
返回值:
类型 | 说明 |
---|---|
VARCHAR | sqlText的SQL语句中出现在谓词条件表达式中的列名,用逗号分隔,列所属的表会进行关联推导,如果没有找到明确的表,则为UNKNOWN |
示例:
SELECT sql_export_predicate_columns(a.sql_text)
FROM (
SELECT ‘SELECT s_acctbal,
s_name,
n_name,
p_partkey,
p_mfgr,
s_address,
s_phone,
s_comment
FROM part,
supplier,
partsupp,
nation,
region
WHERE p_partkey = ps_partkey
AND s_suppkey = ps_suppkey
AND p_size = 35
AND p_type LIKE ‘‘%NICKEL‘‘
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ‘‘MIDDLE EAST‘‘
AND ps_supplycost IN
(
SELECT min(ps_supplycost)
FROM partsupp,
supplier,
nation,
region
WHERE s_suppkey = ps_suppkey
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ‘‘MIDDLE EAST‘‘ )
ORDER BY s_acctbal DESC,
n_name,
s_name,
p_partkey
LIMIT 100;‘ AS sql_text
) a;
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| sql_export_predicate_columns(a.sql_text) |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| UNKNOWN.p_partkey,UNKNOWN.ps_partkey,UNKNOWN.s_suppkey,UNKNOWN.ps_suppkey,UNKNOWN.p_size,UNKNOWN.p_type,UNKNOWN.s_nationkey,UNKNOWN.n_nationkey,UNKNOWN.n_regionkey,UNKNOWN.r_regionkey,UNKNOWN.r_name,UNKNOWN.ps_supplycost |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
函数调用形式:
参数说明:
参数名 | 类型 | 说明 |
---|---|---|
sqlText | VARCHAR | 必选 |
dbType | VARCHAR | 可选。SQL方言,默认为mysql |
compactValues | BOOLEAN | 可选。true时,谓词条件中值以数组的形式出现在返回值中 |
throwError | BOOLEAN | 可选。true时,遇到非法SQL抛出异常;false时,遇到非法SQL不抛出异常,返回null |
返回值:
类型 | 说明 |
---|---|
VARCHAR | sqlText的SQL语句中所有出现的谓词条件表达式元素数组,用逗号分隔,列所属的表会进行关联推导,如果没有找到明确的表,则为UNKNOWN |
示例:
SELECT sql_export_predicates(a.sql_text, ‘mysql‘, true)
FROM (
SELECT ‘SELECT s_acctbal,
s_name,
n_name,
p_partkey,
p_mfgr,
s_address,
s_phone,
s_comment
FROM part,
supplier,
partsupp,
nation,
region
WHERE p_partkey = ps_partkey
AND s_suppkey = ps_suppkey
AND p_size = 35
AND p_type LIKE ‘‘%NICKEL‘‘
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ‘‘MIDDLE EAST‘‘
AND ps_supplycost IN
(
SELECT min(ps_supplycost)
FROM partsupp,
supplier,
nation,
region
WHERE s_suppkey = ps_suppkey
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ‘‘MIDDLE EAST‘‘ )
ORDER BY s_acctbal DESC,
n_name,
s_name,
p_partkey
LIMIT 100;‘ AS sql_text
) a;
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| sql_export_predicates(a.sql_text) |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| [["UNKNOWN","p_partkey","=",null],["UNKNOWN","ps_partkey","=",null],["UNKNOWN","s_suppkey","=",null],["UNKNOWN","ps_suppkey","=",null],["UNKNOWN","p_size","=",35],["UNKNOWN","p_type","LIKE","%NICKEL"],["UNKNOWN","s_nationkey","=",null],["UNKNOWN","n_nationkey","=",null],["UNKNOWN","n_regionkey","=",null],["UNKNOWN","r_regionkey","=",null],["UNKNOWN","r_name","=",["MIDDLE EAST","MIDDLE EAST"]],["UNKNOWN","ps_supplycost","IN",null]] |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
函数调用形式:
参数说明:
参数名 | 类型 | 说明 |
---|---|---|
sqlText | VARCHAR | 必选 |
dbType | VARCHAR | 可选。SQL方言,默认为mysql |
throwError | BOOLEAN | 可选。true时,遇到非法SQL抛出异常;false时,遇到非法SQL不抛出异常,返回null |
返回值:
类型 | 说明 |
---|---|
VARCHAR | sqlText的SQL语句中SELECT子句返回列中出现的列名列表(包括子查询),用逗号分隔,列所属的表会进行关联推导,如果没有找到明确的表,则为UNKNOWN |
示例:
SELECT sql_export_select_list_columns(a.sql_text)
FROM (
SELECT ‘SELECT s_acctbal,
s_name,
n_name,
p_partkey,
p_mfgr,
s_address,
s_phone,
s_comment
FROM part,
supplier,
partsupp,
nation,
region
WHERE p_partkey = ps_partkey
AND s_suppkey = ps_suppkey
AND p_size = 35
AND p_type LIKE ‘‘%NICKEL‘‘
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ‘‘MIDDLE EAST‘‘
AND ps_supplycost IN
(
SELECT min(ps_supplycost)
FROM partsupp,
supplier,
nation,
region
WHERE s_suppkey = ps_suppkey
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ‘‘MIDDLE EAST‘‘ )
ORDER BY s_acctbal DESC,
n_name,
s_name,
p_partkey
LIMIT 100;‘ AS sql_text
) a;
+------------------------------------------------------------------------------------------------------------------------------------------------------------+
| sql_export_select_list_columns(a.sql_text) |
+------------------------------------------------------------------------------------------------------------------------------------------------------------+
| UNKNOWN.s_acctbal,UNKNOWN.s_name,UNKNOWN.n_name,UNKNOWN.p_partkey,UNKNOWN.p_mfgr,UNKNOWN.s_address,UNKNOWN.s_phone,UNKNOWN.s_comment,UNKNOWN.ps_supplycost |
+------------------------------------------------------------------------------------------------------------------------------------------------------------+
函数调用形式:
参数说明:
参数名 | 类型 | 说明 |
---|---|---|
sqlText | VARCHAR | 必选 |
dbType | VARCHAR | 可选。SQL方言,默认为mysql |
throwError | BOOLEAN | 可选。true时,遇到非法SQL抛出异常;false时,遇到非法SQL不抛出异常,返回null |
返回值:
类型 | 说明 |
---|---|
VARCHAR | sqlText的SQL语句中所有出现的表名,用逗号分隔 |
示例:
SELECT sql_export_tables(a.sql_text)
FROM (
SELECT ‘SELECT s_acctbal,
s_name,
n_name,
p_partkey,
p_mfgr,
s_address,
s_phone,
s_comment
FROM part,
supplier,
partsupp,
nation,
region
WHERE p_partkey = ps_partkey
AND s_suppkey = ps_suppkey
AND p_size = 35
AND p_type LIKE ‘‘%NICKEL‘‘
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ‘‘MIDDLE EAST‘‘
AND ps_supplycost IN
(
SELECT min(ps_supplycost)
FROM partsupp,
supplier,
nation,
region
WHERE s_suppkey = ps_suppkey
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ‘‘MIDDLE EAST‘‘ )
ORDER BY s_acctbal DESC,
n_name,
s_name,
p_partkey
LIMIT 100;‘ AS sql_text
) a;
+--------------------------------------+
| sql_export_tables(a.sql_text) |
+--------------------------------------+
| part,supplier,partsupp,nation,region |
+--------------------------------------+
函数调用形式:
参数说明:
参数名 | 类型 | 说明 |
---|---|---|
sqlText | VARCHAR | 必选 |
dbType | VARCHAR | 可选。SQL方言,默认为mysql |
throwError | BOOLEAN | 可选。true时,遇到非法SQL抛出异常;false时,遇到非法SQL不抛出异常,返回null |
返回值:
类型 | 说明 |
---|---|
VARCHAR | 格式化sqlText的SQL语句 |
示例:
SELECT sql_format(a.sql_text)
FROM (
SELECT ‘SELECT s_acctbal,
s_name,
n_name,
p_partkey,
p_mfgr,
s_address,
s_phone,
s_comment
FROM part,
supplier,
partsupp,
nation,
region
WHERE p_partkey = ps_partkey
AND s_suppkey = ps_suppkey
AND p_size = 35
AND p_type LIKE ‘‘%NICKEL‘‘
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ‘‘MIDDLE EAST‘‘
AND ps_supplycost IN
(
SELECT min(ps_supplycost)
FROM partsupp,
supplier,
nation,
region
WHERE s_suppkey = ps_suppkey
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ‘‘MIDDLE EAST‘‘ )
ORDER BY s_acctbal DESC,
n_name,
s_name,
p_partkey
LIMIT 100;‘ AS sql_text
) a;
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| sql_format(a.sql_text) |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| SELECT s_acctbal, s_name, n_name, p_partkey, p_mfgr
, s_address, s_phone, s_comment
FROM part, supplier, partsupp, nation, region
WHERE p_partkey = ps_partkey
AND s_suppkey = ps_suppkey
AND p_size = 35
AND p_type LIKE ‘%NICKEL‘
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ‘MIDDLE EAST‘
AND ps_supplycost IN (
SELECT min(ps_supplycost)
FROM partsupp, supplier, nation, region
WHERE s_suppkey = ps_suppkey
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ‘MIDDLE EAST‘
)
ORDER BY s_acctbal DESC, n_name, s_name, p_partkey
LIMIT 100; |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
函数调用形式:
参数说明:
参数名 | 类型 | 说明 |
---|---|---|
sqlText | VARCHAR | 必选 |
dbType | VARCHAR | 可选。SQL方言,默认为mysql |
throwError | BOOLEAN | 可选。true时,遇到非法SQL抛出异常;false时,遇到非法SQL不抛出异常,返回null |
返回值:
类型 | 说明 |
---|---|
VARCHAR | 提取sqlText的SQL语句中的literal值 |
示例:
SELECT sql_params(a.sql_text)
FROM (
SELECT ‘SELECT s_acctbal,
s_name,
n_name,
p_partkey,
p_mfgr,
s_address,
s_phone,
s_comment
FROM part,
supplier,
partsupp,
nation,
region
WHERE p_partkey = ps_partkey
AND s_suppkey = ps_suppkey
AND p_size = 35
AND p_type LIKE ‘‘%NICKEL‘‘
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ‘‘MIDDLE EAST‘‘
AND ps_supplycost IN
(
SELECT min(ps_supplycost)
FROM partsupp,
supplier,
nation,
region
WHERE s_suppkey = ps_suppkey
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ‘‘MIDDLE EAST‘‘ )
ORDER BY s_acctbal DESC,
n_name,
s_name,
p_partkey
LIMIT 100;‘ AS sql_text
) a;
+------------------------------------------------+
| sql_params(a.sql_text) |
+------------------------------------------------+
| [35,"%NICKEL","MIDDLE EAST","MIDDLE EAST",100] |
+------------------------------------------------+
函数调用形式:
参数说明:
参数名 | 类型 | 说明 |
---|---|---|
sqlText | VARCHAR | 必选 |
dbType | VARCHAR | 可选。SQL方言,默认为mysql |
throwError | BOOLEAN | 可选。true时,遇到非法SQL抛出异常;false时,遇到非法SQL不抛出异常,返回null |
返回值:
类型 | 说明 |
---|---|
VARCHAR | 提取sqlText的SQL语句参数化后的SQL pattern, literal值换成? |
示例:
SELECT sql_pattern(a.sql_text)
FROM (
SELECT ‘SELECT s_acctbal,
s_name,
n_name,
p_partkey,
p_mfgr,
s_address,
s_phone,
s_comment
FROM part,
supplier,
partsupp,
nation,
region
WHERE p_partkey = ps_partkey
AND s_suppkey = ps_suppkey
AND p_size = 35
AND p_type LIKE ‘‘%NICKEL‘‘
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ‘‘MIDDLE EAST‘‘
AND ps_supplycost IN
(
SELECT min(ps_supplycost)
FROM partsupp,
supplier,
nation,
region
WHERE s_suppkey = ps_suppkey
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ‘‘MIDDLE EAST‘‘ )
ORDER BY s_acctbal DESC,
n_name,
s_name,
p_partkey
LIMIT 100;‘ AS sql_text
) a;
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| sql_pattern(a.sql_text) |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| SELECT s_acctbal, s_name, n_name, p_partkey, p_mfgr
, s_address, s_phone, s_comment
FROM part, supplier, partsupp, nation, region
WHERE p_partkey = ps_partkey
AND s_suppkey = ps_suppkey
AND p_size = ?
AND p_type LIKE ?
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ?
AND ps_supplycost IN (
SELECT min(ps_supplycost)
FROM partsupp, supplier, nation, region
WHERE s_suppkey = ps_suppkey
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ?
)
ORDER BY s_acctbal DESC, n_name, s_name, p_partkey
LIMIT ?; |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
函数调用形式:
参数说明:
参数名 | 类型 | 说明 |
---|---|---|
sqlText | VARCHAR | 必选 |
dbType | VARCHAR | 可选。SQL方言,默认为mysql |
throwError | BOOLEAN | 可选。true时,遇到非法SQL抛出异常;false时,遇到非法SQL不抛出异常,返回null |
返回值:
类型 | 说明 |
---|---|
VARCHAR | 提取sqlText的SQL语句参数化后的SQL pattern,并生成hash值 |
示例:
SELECT sql_pattern_hash(a.sql_text)
FROM (
SELECT ‘SELECT s_acctbal,
s_name,
n_name,
p_partkey,
p_mfgr,
s_address,
s_phone,
s_comment
FROM part,
supplier,
partsupp,
nation,
region
WHERE p_partkey = ps_partkey
AND s_suppkey = ps_suppkey
AND p_size = 35
AND p_type LIKE ‘‘%NICKEL‘‘
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ‘‘MIDDLE EAST‘‘
AND ps_supplycost IN
(
SELECT min(ps_supplycost)
FROM partsupp,
supplier,
nation,
region
WHERE s_suppkey = ps_suppkey
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ‘‘MIDDLE EAST‘‘ )
ORDER BY s_acctbal DESC,
n_name,
s_name,
p_partkey
LIMIT 100;‘ AS sql_text
) a;
+------------------------------+
| sql_pattern_hash(a.sql_text) |
+------------------------------+
| 925870115679910184 |
+------------------------------+
函数调用形式:
参数说明:
参数名 | 类型 | 说明 |
---|---|---|
sqlText | VARCHAR | 必选 |
dbType | VARCHAR | 可选。SQL方言,默认为mysql |
throwError | BOOLEAN | 可选。true时,遇到非法SQL抛出异常;false时,遇到非法SQL不抛出异常,返回null |
返回值:
类型 | 说明 |
---|---|
BOOLEAN | 对sqlText进行语法检查,1表示正确,0表示错误 |
示例:
SELECT sql_syntax_check(a.sql_text)
FROM (
SELECT ‘SELECT s_acctbal,
s_name,
n_name,
p_partkey,
p_mfgr,
s_address,
s_phone,
s_comment
FROM part,
supplier,
partsupp,
nation,
region
WHERE p_partkey = ps_partkey
AND s_suppkey = ps_suppkey
AND p_size = 35
AND p_type LIKE ‘‘%NICKEL‘‘
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ‘‘MIDDLE EAST‘‘
AND ps_supplycost IN
(
SELECT min(ps_supplycost)
FROM partsupp,
supplier,
nation,
region
WHERE s_suppkey = ps_suppkey
AND s_nationkey = n_nationkey
AND n_regionkey = r_regionkey
AND r_name = ‘‘MIDDLE EAST‘‘ )
ORDER BY s_acctbal DESC,
n_name,
s_name,
p_partkey
LIMIT 100;‘ AS sql_text
) a;
+------------------------------+
| sql_syntax_check(a.sql_text) |
+------------------------------+
| 1 |
+------------------------------+
本文作者:julian.zhou
原文链接
本文为云栖社区原创内容,未经允许不得转载。
DLA SQL分析函数:SQL语句审计与分析的利器
标签:aaaaa handle aic _for column har html 信息 pat