Lädt...


🔧 Materialized view in PLSQL


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

Here’s a simple example of creating a materialized view with sample data.

Step 1: Create a sample table and insert data

CREATE TABLE orders (
order_id NUMBER,
customer_id NUMBER,
order_date DATE,
order_total NUMBER
);

INSERT INTO orders VALUES (1, 101, DATE '2024-09-01', 150);
INSERT INTO orders VALUES (2, 102, DATE '2024-09-02', 200);
INSERT INTO orders VALUES (3, 101, DATE '2024-09-03', 100);
INSERT INTO orders VALUES (4, 103, DATE '2024-09-03', 250);
INSERT INTO orders VALUES (5, 102, DATE '2024-09-04', 300);

COMMIT;

Step 2: Create the materialized view

CREATE MATERIALIZED VIEW customer_sales_mv
BUILD IMMEDIATE
REFRESH COMPLETE
ON DEMAND
AS
SELECT customer_id, SUM(order_total) AS total_sales
FROM orders
GROUP BY customer_id;

Explanation:

BUILD IMMEDIATE: The view is populated immediately.

REFRESH COMPLETE: The view will be fully refreshed each time you refresh it.

ON DEMAND: The view will only be refreshed when you explicitly refresh it.

Step 3: Query the materialized view

SELECT * FROM customer_sales_mv;

Output:

This materialized view shows the total sales for each customer, based on the orders table.

Step 4: Refresh the materialized view (if new data is inserted)

If new data is added to the orders table, the materialized view will not be updated until you manually refresh it.

To refresh:

EXEC DBMS_MVIEW.REFRESH('customer_sales_mv');

Now the materialized view will include the new data after the refresh.

Step 5: Add new data and refresh

INSERT INTO orders VALUES (6, 101, DATE '2024-09-05', 50);
COMMIT;

EXEC DBMS_MVIEW.REFRESH('customer_sales_mv');

Query again:

SELECT * FROM customer_sales_mv;

Updated Output:

The materialized view now reflects the updated data after the refresh.

...

🔧 Materialized view in PLSQL


📈 52.35 Punkte
🔧 Programmierung

🔧 Difference Between Materialized View and View in SQL


📈 39.6 Punkte
🔧 Programmierung

🔧 View vs Materialized View in Oracle SQL


📈 39.6 Punkte
🔧 Programmierung

🔧 Virtual tables in SQL - Views, Materialized View, Global Temporary Table and Inline View


📈 39.6 Punkte
🔧 Programmierung

🔧 Materialized View in SQL


📈 31.47 Punkte
🔧 Programmierung

🔧 Materialized View in SQL


📈 31.47 Punkte
🔧 Programmierung

🔧 Views and Materialized View in SQL


📈 31.47 Punkte
🔧 Programmierung

🔧 Build a Real-Time Materialized View From Postgres Changes


📈 31.47 Punkte
🔧 Programmierung

🎥 Wiko View / View XL und View Prime mit Dual-Frontkamera im ersten Test – Hands-on | IFA


📈 24.4 Punkte
🎥 Videos

📰 Wiko View, View XL & View Prime: Wiko stellt neue Smartphones vor


📈 24.4 Punkte
📰 IT Security Nachrichten

📰 Wiko View, View XL und View Prime im Hands-On: Edle Optik in der Mittelklasse


📈 24.4 Punkte
📰 IT Nachrichten

🔧 How To Use Materialized Views


📈 23.34 Punkte
🔧 Programmierung

🔧 On-Demand Refresh | Materialized Views (Mviews) in ORACLE SQL


📈 23.34 Punkte
🔧 Programmierung

🔧 Materialized Views in SQL | Best Explanation


📈 23.34 Punkte
🔧 Programmierung

🔧 Optimizing PostgreSQL Queries with Materialized Views


📈 23.34 Punkte
🔧 Programmierung

🔧 PostgreSQL Semi Join, Unique-ify RHS, Materialized CTEs, and Rows Estimation


📈 23.34 Punkte
🔧 Programmierung

🔧 A Comprehensive Guide to Materialized Views in MySQL


📈 23.34 Punkte
🔧 Programmierung

🔧 Views vs. Materialized Views: What’s the Difference?


📈 23.34 Punkte
🔧 Programmierung

🔧 How to avoid N+1 query using SQL views (materialized) in Rails application


📈 23.34 Punkte
🔧 Programmierung

🔧 How materialized views saved our bacon


📈 23.34 Punkte
🔧 Programmierung

🔧 Demystifying Materialized Views in PostgreSQL


📈 23.34 Punkte
🔧 Programmierung

🐧 Configuring for Materialized Views


📈 23.34 Punkte
🐧 Linux Tipps

📰 Preview: Materialized Views für die Azure Cosmos DB API für Cassandra


📈 23.34 Punkte
📰 IT Nachrichten

🎥 Flutter web support updates, BigQuery materialized views, Cloud Spanner emulator, & more!


📈 23.34 Punkte
🎥 Videos

📰 Meltdown and Spectre, one year on: Feared CPU slowdown never really materialized


📈 23.34 Punkte
📰 IT Security Nachrichten

🔧 Named Calling Notations in PLSQL


📈 20.88 Punkte
🔧 Programmierung

🔧 PRAGMA EXCEPTION_INIT | keyword in PLSQL | Exceptional Handling


📈 20.88 Punkte
🔧 Programmierung

🔧 PLSQL - Day 1


📈 20.88 Punkte
🔧 Programmierung

🔧 Stored procedure in PLSQL


📈 20.88 Punkte
🔧 Programmierung

🔧 Deterministic Functions in PLSQL


📈 20.88 Punkte
🔧 Programmierung

🔧 PACKAGES in PLSQL in detail


📈 20.88 Punkte
🔧 Programmierung

🔧 Context Switching in PLSQL


📈 20.88 Punkte
🔧 Programmierung

🔧 CURSOR in PLSQL | Best Explanation


📈 20.88 Punkte
🔧 Programmierung

🔧 Exception Handling in PLSQL


📈 20.88 Punkte
🔧 Programmierung

matomo