In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
Editor to share with you how to use the package DBMS_ADVANCED_REWRITE in Oracle10g to achieve the new query rewriting function. I hope you will get something after reading this article. Let's discuss it together.
Starting with Oracle10g version 1, a new package, DBMS _ ADVANCED_REWRITE, is provided to implement query rewriting. It allows you to intercept specific SQL statements and set the
It is redefined as another SQL statement. Here is a simple example:
1. Confirm that the test user has the necessary permissions to run
CONN sys/password AS SYSDBA
GRANT EXECUTE ON DBMS_ADVANCED_REWRITE TO test
GRANT CREATE MATERIALIZED VIEW TO test
[@ more@]
2. Create a test table
CONN test/test
DROP TABLE rewrite_test_tab
CREATE TABLE rewrite_test_tab (
Id NUMBER
Description VARCHAR2 (50)
CONSTRAINT rewrite_test_tab_pk PRIMARY KEY (id)
);
INSERT INTO rewrite_test_tab (id, description) VALUES (1, 'GLASGOW')
INSERT INTO rewrite_test_tab (id, description) VALUES (2, 'BIRMINGHAM')
INSERT INTO rewrite_test_tab (id, description) VALUES (3, 'LONDON')
COMMIT
EXEC DBMS_STATS.gather_table_stats (USER, 'rewrite_test_tab')
3. Query the test table
SELECT * FROM rewrite_test_tab
ID DESCRIPTION
1 GLASGOW
2 BIRMINGHAM
3 LONDON
3 rows selected.
SQL >
4. Create the view to be replaced by the SQL, and then redefine the above statement to query the view
CREATE OR REPLACE VIEW rewrite_test_tab_v AS
SELECT id
INITCAP (description) AS description
FROM rewrite_test_tab
ORDER BY description
BEGIN
SYS.DBMS_ADVANCED_REWRITE.declare_rewrite_equivalence (
Name = > 'test_rewrite'
Source_stmt = > 'SELECT * FROM rewrite_test_tab'
Destination_stmt = > 'SELECT * FROM rewrite_test_tab_v'
Validate = > FALSE
Rewrite_mode = > 'TEXT_MATCH')
END
/
Rewrite replaces only when they are consistent. And we want to realize that the output after replacement is different from the original output, so we need to modify the value of this parameter to
Only "TRUSTED" will do.
ALTER SESSION SET QUERY_REWRITE_INTEGRITY = TRUSTED
Session altered.
SELECT * FROM rewrite_test_tab
ID DESCRIPTION
2 Birmingham
1 Glasgow
3 London
3 rows selected.
SQL >
6. The view [USER | ALL | DBA] _ REWRITE_EQUIVALENCES contains information about these redefined queries.
SELECT * FROM user_rewrite_equivalences
OWNER NAME
SOURCE_STMT
DESTINATION_STMT REWRITE_MO
-
TEST TEST_REWRITE
SELECT * FROM rewrite_test_tab
SELECT * FROM rewrite_test_tab_v TEXT_MATCH
1 row selected.
SQL >
After reading this article, I believe you have a certain understanding of "how to use the package DBMS_ADVANCED_REWRITE to achieve the new query rewriting function in Oracle10g". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.