The CREATE_RULE procedure creates a custom rewrite rule.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only the MySQL mode.
Syntax
PROCEDURE CREATE_RULE (
rule_name IN VARCHAR,
pattern IN CLOB,
replacement IN CLOB,
enabled IN VARCHAR := 'YES'
);
Parameters
| Parameter | Description |
|---|---|
| rule_name | The name of the rule. |
| rule_owner_name | The database name, which is required only in MySQL mode. |
| pattern | The template of a statement that matches the rule. |
| replacement) | The template that specifies how to rewrite a statement that matches pattern. |
| enabled | Specifies whether the rule is enabled. |
Considerations
The limits on the rewrite and binding rules are as follows:
- Supported SQL statement types are
SELECT,INSERT,REPLACE,UPDATE,DELETE,MERGE, andSET. - The two parameter markers "?" and ":{name}" cannot coexist in a rule template.
- If ":{name}" is used as a parameter marker in a
patterndefinition,namemust be unique. patternandreplacementcannot be empty.patternandreplacementdo not support multi-queries.rule_namemust be unique within a tenant.- In a rule template,
patternandreplacementmust have the same number of parameter markers. - In a rule template,
patternandreplacementmust use the same parameter marker, which can be "?" or ":{name}".
Examples
obclient> CALL DBMS_UDR.CREATE_RULE('rule1', 'select ? from dual','select ? + 1 from dual');
Query OK, 0 rows affected
obclient> SELECT 1 FROM DUAL;
+-----+
| ?+1 |
+-----+
| 2 |
+-----+
1 row in set