The CREATE_RULE procedure is used to create custom rewrite rules.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition does not support this feature.
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 name of the database. This parameter is required only in MySQL mode. |
| pattern | The template of the statement to be matched by the rule. |
| replacement | The template that indicates how to rewrite statements that match pattern. |
| enabled | Indicates whether the rule is enabled. |
Considerations
The rewrite binding rules are subject to the following restrictions:
- Supported SQL statement types:
SELECT,INSERT,REPLACE,UPDATE,DELETE,MERGE, andSET. - The question mark (?) and colon-name notation (:{name}) cannot be mixed in the rule templates.
- When using colon-name notation (:{name}) as the parameter marker in the
patterndefinition, thenamemust be unique. - The
patternandreplacementcannot be defined as empty. - The
patternandreplacementdo not support Multi Query. - The
rule_namemust be unique at the tenant level. - The number of parameter markers in the
patternandreplacementmust be the same. - The parameter markers in the
patternandreplacementmust be represented in the same way (either both using ? or both using :{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
