SlideShare a Scribd company logo
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Useful Supplied
PL/SQL Packages
1
Maria Colgan
Master Product Manager
Oracle Database Server Technologies
June 2018
JEFF
@SQLMaria
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_SESSION.SLEEP()
2
Accessible sleep function within PL/SQL
SQL> set timing on;
SQL> DECLARE
v_start date;
v_end date;
BEGIN
v_start := SYSDATE;
-- Sleep for 10 seconds
dbms_lock.sleep(10);
v_end := SYSDATE;
END;
/
PL/SQL procedure successfully
completed.
Elapsed: 00:00:10.02
• DBMS_LOCK includes other, more
sensitive methods
• Therefore not granted to public
• Requires DBA intervention to get a
accessible sleep function in PL/SQL
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_SESSION.SLEEP()
3
Accessible sleep function within PL/SQL
SQL> set timing on;
SQL> DECLARE
v_start date;
v_end date;
BEGIN
v_start := SYSDATE;
-- Sleep for 10 seconds
DBMS_SESSION.SLEEP(10);
v_end := SYSDATE;
END;
/
PL/SQL procedure successfully
completed.
Elapsed: 00:00:10.02
• Doesn’t require GRANT anymore
– Before required explicit grant on
DBMS_LOCK
– DBMS_SESSION granted to public
• Compatible with DBMS_LOCK.SLEEP
– You can search/replace
• Introduced thanks to the Oracle
community
– https://community.oracle.com/ideas/4852
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_UTILITY.EXPAND_SQL_TEXT
4
SELECT view_name
FROM user_views
WHERE view_name LIKE 'SALE%';
VIEW_NAME
-------------------
SALES_REPORTING2_V
SALES_REPORTING_V
Determining if this really is the right view to use
12c
• Views can be a useful way to hide
complexity from developers
• But they can also cause problems
• It's easy to write apparently simple
statements, that result in extremely
complex SQL being sent to the database
• The DBMS_UTILITY.EXPAND_SQL_TEXT
procedure expands references to views,
turning them into subqueries in the
original statement
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_UTILITY.EXPAND_SQL_TEXT
set serveroutput on
DECLARE
l_clob CLOB;
BEGIN
dbms_utility.Expand_sql_text(
input_sql_text =>'SELECT * FROM SALES_REPORTING_V',
output_sql_text => l_clob);
dbms_output.Put_line(l_clob);
END;
/
5
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_UTILITY.EXPAND_SQL_TEXT
SELECT "A1"."order_id" "ORDER_ID",
"A1"."time_id" "TIME_ID",
"A1"."cust_id" "CUST_ID",
"A1"."prod_id" "PROD_ID"
FROM (SELECT "A3"."order_id" "ORDER_ID",
"A3"."time_id" "TIME_ID",
"A3"."cust_id" "CUST_ID",
"A3"."prod_id" "PROD_ID"
FROM "SH"."sales" "A3",
"SH"."products" "A2"
WHERE "A3"."prod_id" = "A2"."prod_id") "A1"
6
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_UTILITY.EXPAND_SQL_TEXT
set serveroutput on
DECLARE
l_clob CLOB;
BEGIN
dbms_utility.Expand_sql_text(
input_sql_text =>'SELECT * FROM SALES_REPORTING2_V',
output_sql_text => l_clob);
dbms_output.Put_line(l_clob);
END;
/
7
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_UTILITY.EXPAND_SQL_TEXT
SELECT "A1"."order_id" "ORDER_ID",
"A1"."time_id" "TIME_ID",
"A1"."cust_id" "CUST_ID",
"A1"."prod_id" "PROD_ID"
FROM (SELECT "A2"."order_id" "ORDER_ID",
"A2"."time_id" "TIME_ID",
"A2"."cust_id" "CUST_ID",
"A2"."prod_id" "PROD_ID"
FROM "SH"."sales" "A2”) "A1"
8
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_ADVANCED_REWRITE
9
Fixing the unfixable SQL statement
• You’ve been told you need to “fix” a
SQL statement that is no longer
returning results in the correct order
• But you can’t change the application
code directly as that would require
down time
• What do you do?
SQL> SELECT x, y, sum(z) FROM t
GROUP BY x, y;
X Y SUM(Z)
---------- ---------- ----------
1 4 110
2 3 84
10g
Something changes and now you get
SQL> SELECT x, y, sum(z) FROM t
GROUP BY x, y;
X Y SUM(Z)
---------- ---------- ----------
2 3 84
1 4 110
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_ADVANCED_REWRITE
10
Fixing the unfixable SQL statement
Step 1
• Check what changed with the
execution plan
ORIGINIAL PLAN
-----------------------------------
| Id | Operation | Name |
-----------------------------------
| 0 | SELECT STATEMENT | |
| 1 | HASH GROUP BY | |
| 2 | TABLE ACCESS FULL| T |
-----------------------------------
NEW PLAN
--------------------------------------
| Id | Operation | Name |
--------------------------------------
| 0 | SELECT STATEMENT | |
| 1 | SORT GROUP BY NOSORT| |
| 2 | INDEX FULL SCAN |T_IDX |
--------------------------------------
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_ADVANCED_REWRITE
11
Fixing the unfixable SQL statement
Step 2
• Check the order of the columns in the
index
SQL> SELECT column_position,
column_name
FROM user_ind_columns
WHERE index_name='T_IDX'
ORDER BY column_position;
COLUMN_POSITION COLUMN
--------------- ------
1 Y
2 X
3 Z
• New index returns the rows in a
different order because its sorted on
column Y rather than X
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_ADVANCED_REWRITE
12
Fixing the unfixable SQL statement
Step 3
• Create a view v that includes an order
by clause so the query results will
always be order based on the values
column x
SQL> CREATE OR REPLACE VIEW v
2 AS
3 SELECT x, y, sum(z) "SUM(Z)"
4 FROM t
5 GROUP BY x, y
6 ORDER BY x, y;
View created.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_ADVANCED_REWRITE
13
Fixing the unfixable SQL statement
Step 4
• Use the DBMS_ADVANCED_REWRITE procedure to map the original query
to a simple SELECT * FROM v;
SQL> BEGIN
2 sys.dbms_advanced_rewrite.declare_rewrite_equivalence(
3 name => 'DEMO_TIME',
4 source_stmt => 'SELECT x, y, sum(z) FROM t GROUP BY x, y',
5 destination_stmt => 'SELECT * FROM v',
6 validate => FALSE,
7 rewrite_mode => 'TEXT_MATCH');
8 END;
9 /
PL/SQL procedure successfully completed.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_ADVANCED_REWRITE
14
Fixing the unfixable SQL statement
• Each time our original SQL statement
is issued the
DBMS_ADVANCED_REWRITE
procedure rewrites it to be
SELECT * FROM v;
• Always get the query
output in an order list
SQL> SELECT x, y, sum(z) FROM t
GROUP BY x, y;
X Y SUM(Z)
---------- ---------- ----------
1 4 110
2 3 84
-----------------------------------
| Id | Operation | Name |
-----------------------------------
| 0 | SELECT STATEMENT | |
| 1 | VIEW | V |
| 2 | SORT GROUP BY | |
| 3 | INDEX FULL SCAN|T_IDX |
-----------------------------------
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_COMPARISON
• Trying to figure out why things behave
differently in production then they do in
test can be time consuming and painful
• The DBMS_COMPARISON package allows
you to compare objects, schemas or data
between databases or schemas
• For a table comparison you do need a
unique index on both tables
• Begin by creating the comparison
15
Figuring out why production is different to test
SQL> BEGIN
DBMS_COMPARISON.CREATE_COMPARISON
(
comparison_name => 'COMP_SALES',
schema_name => 'SH',
object_name => 'SALES',
dblink_name => 'orcl2_test'
);
END;
/
11g
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_COMPARISON
• Execute the
COMPARE function
to perform the
compare operation
• Returns a boolean to
say if there is or is not
consistency
• The scan_id allows
you to find out what
the differences are
16
SQL> DECLARE
scan_info DBMS_COMPARISON.COMPARISON_TYPE;
BEGIN
IF NOT DBMS_COMPARISON.COMPARE
( comparison_name => 'COMP_SALES'
, scan_info => scan_info
, perform_row_dif => TRUE
) THEN
DBMS_OUTPUT.PUT_LINE('Scan ID:'||
scan_info.scan_id);
END IF;
END;
/
Scan ID: 1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
DBMS_COMPARISON
17
SELECT c.COLUMN_NAME, r.INDEX_VALUE,
case when r.LOCAL_ROWID is null then ‘No’ else 'Yes’ end LOCAL,
Case when r.REMOTE_ROWID is null then 'No’ else 'Yes’ end REMOTE
FROM USER_COMPARISON_COLUMNS c, USER_COMPARISON_ROW_DIF r,
USER_COMPARISON_SCAN s
WHERE c.COMPARISON_NAME = 'COMP_SALES‘
AND c.INDEX_COLUMN = 'Y’
AND r.STATUS = 'DIF’
AND c.COMPARISON_NAME = r.COMPARISON_NAME
AND r.SCAN_ID = s.SCAN_ID
AND s.SCAN_ID = 1
ORDER BY r.INDEX_VALUE;
COLUMN_NAME INDEX_VALUE LOCAL REMOTE
----------- ----------- ----- ------
TAX_CODE 0.05 No Yes
Test environment has an different tax code
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Many More Powerful Supplied PL/SQL Packages
• Oracle Database 18c provides 300 PL/SQL packages
• Some of my favorites include:
– DBMS_STATS
– DBMS_SHARED_POOL
– DBMS_SPM
– DBMS_AUTO_TASK_ADMIN
– DBMS_SQLTUNE
• Check out more details in the PL/SQL Packages and Types Reference
18

More Related Content

What's hot

The Changing Role of a DBA in an Autonomous World
The Changing Role of a DBA in an Autonomous WorldThe Changing Role of a DBA in an Autonomous World
The Changing Role of a DBA in an Autonomous World
Maria Colgan
 
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle SQL Tuning for Day-to-Day Data Warehouse SupportOracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
nkarag
 
Oracle Data Redaction - UKOUG - TECH14
Oracle Data Redaction - UKOUG - TECH14Oracle Data Redaction - UKOUG - TECH14
Oracle Data Redaction - UKOUG - TECH14
Alex Zaballa
 
Sql parametrized queries
Sql parametrized queriesSql parametrized queries
Sql parametrized queries
Hadi Fadlallah
 
Creating Views - oracle database
Creating Views - oracle databaseCreating Views - oracle database
Creating Views - oracle database
Salman Memon
 
Top 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsTop 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tips
Nirav Shah
 
One Less Thing For DBAs to Worry About: Automatic Indexing
One Less Thing For DBAs to Worry About: Automatic IndexingOne Less Thing For DBAs to Worry About: Automatic Indexing
One Less Thing For DBAs to Worry About: Automatic Indexing
Jim Czuprynski
 
Data Redaction - OTN TOUR LA 2015
Data Redaction - OTN TOUR LA 2015 Data Redaction - OTN TOUR LA 2015
Data Redaction - OTN TOUR LA 2015
Alex Zaballa
 
Oracle Course
Oracle CourseOracle Course
Oracle Course
rspaike
 
Oracle Data Redaction
Oracle Data RedactionOracle Data Redaction
Oracle Data Redaction
Ivica Arsov
 
The Database Environment Chapter 8
The Database Environment Chapter 8The Database Environment Chapter 8
The Database Environment Chapter 8
Jeanie Arnoco
 
Oracle SQL, PL/SQL best practices
Oracle SQL, PL/SQL best practicesOracle SQL, PL/SQL best practices
Oracle SQL, PL/SQL best practices
Smitha Padmanabhan
 
Oracle Data Redaction
Oracle Data RedactionOracle Data Redaction
Oracle Data Redaction
Alex Zaballa
 
Oracle DB Performance Tuning Tips
Oracle DB Performance Tuning TipsOracle DB Performance Tuning Tips
Oracle DB Performance Tuning Tips
Asanka Dilruk
 
Database Objects
Database ObjectsDatabase Objects
Database Objects
Salman Memon
 
Oracle SQL Tuning
Oracle SQL TuningOracle SQL Tuning
Oracle SQL Tuning
Alex Zaballa
 
PL/SQL 3 DML
PL/SQL 3 DMLPL/SQL 3 DML
TSQL in SQL Server 2012
TSQL in SQL Server 2012TSQL in SQL Server 2012
TSQL in SQL Server 2012
Eduardo Castro
 
Aggregating Data Using Group Functions
Aggregating Data Using Group FunctionsAggregating Data Using Group Functions
Aggregating Data Using Group Functions
Salman Memon
 
Restricting and Sorting Data - Oracle Data Base
Restricting and Sorting Data - Oracle Data BaseRestricting and Sorting Data - Oracle Data Base
Restricting and Sorting Data - Oracle Data Base
Salman Memon
 

What's hot (20)

The Changing Role of a DBA in an Autonomous World
The Changing Role of a DBA in an Autonomous WorldThe Changing Role of a DBA in an Autonomous World
The Changing Role of a DBA in an Autonomous World
 
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle SQL Tuning for Day-to-Day Data Warehouse SupportOracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
 
Oracle Data Redaction - UKOUG - TECH14
Oracle Data Redaction - UKOUG - TECH14Oracle Data Redaction - UKOUG - TECH14
Oracle Data Redaction - UKOUG - TECH14
 
Sql parametrized queries
Sql parametrized queriesSql parametrized queries
Sql parametrized queries
 
Creating Views - oracle database
Creating Views - oracle databaseCreating Views - oracle database
Creating Views - oracle database
 
Top 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tipsTop 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tips
 
One Less Thing For DBAs to Worry About: Automatic Indexing
One Less Thing For DBAs to Worry About: Automatic IndexingOne Less Thing For DBAs to Worry About: Automatic Indexing
One Less Thing For DBAs to Worry About: Automatic Indexing
 
Data Redaction - OTN TOUR LA 2015
Data Redaction - OTN TOUR LA 2015 Data Redaction - OTN TOUR LA 2015
Data Redaction - OTN TOUR LA 2015
 
Oracle Course
Oracle CourseOracle Course
Oracle Course
 
Oracle Data Redaction
Oracle Data RedactionOracle Data Redaction
Oracle Data Redaction
 
The Database Environment Chapter 8
The Database Environment Chapter 8The Database Environment Chapter 8
The Database Environment Chapter 8
 
Oracle SQL, PL/SQL best practices
Oracle SQL, PL/SQL best practicesOracle SQL, PL/SQL best practices
Oracle SQL, PL/SQL best practices
 
Oracle Data Redaction
Oracle Data RedactionOracle Data Redaction
Oracle Data Redaction
 
Oracle DB Performance Tuning Tips
Oracle DB Performance Tuning TipsOracle DB Performance Tuning Tips
Oracle DB Performance Tuning Tips
 
Database Objects
Database ObjectsDatabase Objects
Database Objects
 
Oracle SQL Tuning
Oracle SQL TuningOracle SQL Tuning
Oracle SQL Tuning
 
PL/SQL 3 DML
PL/SQL 3 DMLPL/SQL 3 DML
PL/SQL 3 DML
 
TSQL in SQL Server 2012
TSQL in SQL Server 2012TSQL in SQL Server 2012
TSQL in SQL Server 2012
 
Aggregating Data Using Group Functions
Aggregating Data Using Group FunctionsAggregating Data Using Group Functions
Aggregating Data Using Group Functions
 
Restricting and Sorting Data - Oracle Data Base
Restricting and Sorting Data - Oracle Data BaseRestricting and Sorting Data - Oracle Data Base
Restricting and Sorting Data - Oracle Data Base
 

Similar to Useful PL/SQL Supplied Packages

07 Using Oracle-Supported Package in Application Development
07 Using Oracle-Supported Package in Application Development07 Using Oracle-Supported Package in Application Development
07 Using Oracle-Supported Package in Application Development
rehaniltifat
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
Alex Zaballa
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
Alex Zaballa
 
Les11.ppt
Les11.pptLes11.ppt
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Alex Zaballa
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Alex Zaballa
 
plsql les06
 plsql les06 plsql les06
plsql les06
sasa_eldoby
 
Sql views
Sql viewsSql views
Sql views
arshid045
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
Alex Zaballa
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
Alex Zaballa
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
Alex Zaballa
 
War of the Indices- SQL Server and Oracle
War of the Indices-  SQL Server and OracleWar of the Indices-  SQL Server and Oracle
War of the Indices- SQL Server and Oracle
Kellyn Pot'Vin-Gorman
 
Oracle SQL Tuning
Oracle SQL TuningOracle SQL Tuning
Oracle SQL Tuning
Alex Zaballa
 
DBA Commands and Concepts That Every Developer Should Know
DBA Commands and Concepts That Every Developer Should KnowDBA Commands and Concepts That Every Developer Should Know
DBA Commands and Concepts That Every Developer Should Know
Alex Zaballa
 
Msql
Msql Msql
Msql
ksujitha
 
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
Jürgen Ambrosi
 
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Alex Zaballa
 
Application_Performance_V1
Application_Performance_V1Application_Performance_V1
Application_Performance_V1
Mohan Reddy Timmapuram
 
War of the Indices- SQL vs. Oracle
War of the Indices-  SQL vs. OracleWar of the Indices-  SQL vs. Oracle
War of the Indices- SQL vs. Oracle
Kellyn Pot'Vin-Gorman
 
SSMS-waitstats
SSMS-waitstatsSSMS-waitstats
SSMS-waitstats
E Blake
 

Similar to Useful PL/SQL Supplied Packages (20)

07 Using Oracle-Supported Package in Application Development
07 Using Oracle-Supported Package in Application Development07 Using Oracle-Supported Package in Application Development
07 Using Oracle-Supported Package in Application Development
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAsOracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
Oracle Database 12c - New Features for Developers and DBAs
Oracle Database 12c  - New Features for Developers and DBAsOracle Database 12c  - New Features for Developers and DBAs
Oracle Database 12c - New Features for Developers and DBAs
 
Les11.ppt
Les11.pptLes11.ppt
Les11.ppt
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
plsql les06
 plsql les06 plsql les06
plsql les06
 
Sql views
Sql viewsSql views
Sql views
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
War of the Indices- SQL Server and Oracle
War of the Indices-  SQL Server and OracleWar of the Indices-  SQL Server and Oracle
War of the Indices- SQL Server and Oracle
 
Oracle SQL Tuning
Oracle SQL TuningOracle SQL Tuning
Oracle SQL Tuning
 
DBA Commands and Concepts That Every Developer Should Know
DBA Commands and Concepts That Every Developer Should KnowDBA Commands and Concepts That Every Developer Should Know
DBA Commands and Concepts That Every Developer Should Know
 
Msql
Msql Msql
Msql
 
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
 
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
Oracle Database 12c - The Best Oracle Database 12c Tuning Features for Develo...
 
Application_Performance_V1
Application_Performance_V1Application_Performance_V1
Application_Performance_V1
 
War of the Indices- SQL vs. Oracle
War of the Indices-  SQL vs. OracleWar of the Indices-  SQL vs. Oracle
War of the Indices- SQL vs. Oracle
 
SSMS-waitstats
SSMS-waitstatsSSMS-waitstats
SSMS-waitstats
 

More from Maria Colgan

Five_Things_You_Might_Not_Know_About_Oracle_Database_v2.pptx
Five_Things_You_Might_Not_Know_About_Oracle_Database_v2.pptxFive_Things_You_Might_Not_Know_About_Oracle_Database_v2.pptx
Five_Things_You_Might_Not_Know_About_Oracle_Database_v2.pptx
Maria Colgan
 
Part4 Influencing Execution Plans with Optimizer Hints
Part4 Influencing Execution Plans with Optimizer HintsPart4 Influencing Execution Plans with Optimizer Hints
Part4 Influencing Execution Plans with Optimizer Hints
Maria Colgan
 
Ground Breakers Romania: Oracle Autonomous Database
Ground Breakers Romania: Oracle Autonomous DatabaseGround Breakers Romania: Oracle Autonomous Database
Ground Breakers Romania: Oracle Autonomous Database
Maria Colgan
 
What to Expect From Oracle database 19c
What to Expect From Oracle database 19cWhat to Expect From Oracle database 19c
What to Expect From Oracle database 19c
Maria Colgan
 
Oracle Database in-Memory Overivew
Oracle Database in-Memory OverivewOracle Database in-Memory Overivew
Oracle Database in-Memory Overivew
Maria Colgan
 
JSON and the Oracle Database
JSON and the Oracle DatabaseJSON and the Oracle Database
JSON and the Oracle Database
Maria Colgan
 
Harnessing the Power of Optimizer Hints
Harnessing the Power of Optimizer HintsHarnessing the Power of Optimizer Hints
Harnessing the Power of Optimizer Hints
Maria Colgan
 
Oracle optimizer bootcamp
Oracle optimizer bootcampOracle optimizer bootcamp
Oracle optimizer bootcamp
Maria Colgan
 
What_to_expect_from_oracle_database_12c
What_to_expect_from_oracle_database_12cWhat_to_expect_from_oracle_database_12c
What_to_expect_from_oracle_database_12c
Maria Colgan
 
Oracle database 12c_and_DevOps
Oracle database 12c_and_DevOpsOracle database 12c_and_DevOps
Oracle database 12c_and_DevOps
Maria Colgan
 

More from Maria Colgan (10)

Five_Things_You_Might_Not_Know_About_Oracle_Database_v2.pptx
Five_Things_You_Might_Not_Know_About_Oracle_Database_v2.pptxFive_Things_You_Might_Not_Know_About_Oracle_Database_v2.pptx
Five_Things_You_Might_Not_Know_About_Oracle_Database_v2.pptx
 
Part4 Influencing Execution Plans with Optimizer Hints
Part4 Influencing Execution Plans with Optimizer HintsPart4 Influencing Execution Plans with Optimizer Hints
Part4 Influencing Execution Plans with Optimizer Hints
 
Ground Breakers Romania: Oracle Autonomous Database
Ground Breakers Romania: Oracle Autonomous DatabaseGround Breakers Romania: Oracle Autonomous Database
Ground Breakers Romania: Oracle Autonomous Database
 
What to Expect From Oracle database 19c
What to Expect From Oracle database 19cWhat to Expect From Oracle database 19c
What to Expect From Oracle database 19c
 
Oracle Database in-Memory Overivew
Oracle Database in-Memory OverivewOracle Database in-Memory Overivew
Oracle Database in-Memory Overivew
 
JSON and the Oracle Database
JSON and the Oracle DatabaseJSON and the Oracle Database
JSON and the Oracle Database
 
Harnessing the Power of Optimizer Hints
Harnessing the Power of Optimizer HintsHarnessing the Power of Optimizer Hints
Harnessing the Power of Optimizer Hints
 
Oracle optimizer bootcamp
Oracle optimizer bootcampOracle optimizer bootcamp
Oracle optimizer bootcamp
 
What_to_expect_from_oracle_database_12c
What_to_expect_from_oracle_database_12cWhat_to_expect_from_oracle_database_12c
What_to_expect_from_oracle_database_12c
 
Oracle database 12c_and_DevOps
Oracle database 12c_and_DevOpsOracle database 12c_and_DevOps
Oracle database 12c_and_DevOps
 

Recently uploaded

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 

Useful PL/SQL Supplied Packages

  • 1. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Useful Supplied PL/SQL Packages 1 Maria Colgan Master Product Manager Oracle Database Server Technologies June 2018 JEFF @SQLMaria
  • 2. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_SESSION.SLEEP() 2 Accessible sleep function within PL/SQL SQL> set timing on; SQL> DECLARE v_start date; v_end date; BEGIN v_start := SYSDATE; -- Sleep for 10 seconds dbms_lock.sleep(10); v_end := SYSDATE; END; / PL/SQL procedure successfully completed. Elapsed: 00:00:10.02 • DBMS_LOCK includes other, more sensitive methods • Therefore not granted to public • Requires DBA intervention to get a accessible sleep function in PL/SQL
  • 3. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_SESSION.SLEEP() 3 Accessible sleep function within PL/SQL SQL> set timing on; SQL> DECLARE v_start date; v_end date; BEGIN v_start := SYSDATE; -- Sleep for 10 seconds DBMS_SESSION.SLEEP(10); v_end := SYSDATE; END; / PL/SQL procedure successfully completed. Elapsed: 00:00:10.02 • Doesn’t require GRANT anymore – Before required explicit grant on DBMS_LOCK – DBMS_SESSION granted to public • Compatible with DBMS_LOCK.SLEEP – You can search/replace • Introduced thanks to the Oracle community – https://community.oracle.com/ideas/4852
  • 4. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_UTILITY.EXPAND_SQL_TEXT 4 SELECT view_name FROM user_views WHERE view_name LIKE 'SALE%'; VIEW_NAME ------------------- SALES_REPORTING2_V SALES_REPORTING_V Determining if this really is the right view to use 12c • Views can be a useful way to hide complexity from developers • But they can also cause problems • It's easy to write apparently simple statements, that result in extremely complex SQL being sent to the database • The DBMS_UTILITY.EXPAND_SQL_TEXT procedure expands references to views, turning them into subqueries in the original statement
  • 5. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_UTILITY.EXPAND_SQL_TEXT set serveroutput on DECLARE l_clob CLOB; BEGIN dbms_utility.Expand_sql_text( input_sql_text =>'SELECT * FROM SALES_REPORTING_V', output_sql_text => l_clob); dbms_output.Put_line(l_clob); END; / 5
  • 6. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_UTILITY.EXPAND_SQL_TEXT SELECT "A1"."order_id" "ORDER_ID", "A1"."time_id" "TIME_ID", "A1"."cust_id" "CUST_ID", "A1"."prod_id" "PROD_ID" FROM (SELECT "A3"."order_id" "ORDER_ID", "A3"."time_id" "TIME_ID", "A3"."cust_id" "CUST_ID", "A3"."prod_id" "PROD_ID" FROM "SH"."sales" "A3", "SH"."products" "A2" WHERE "A3"."prod_id" = "A2"."prod_id") "A1" 6
  • 7. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_UTILITY.EXPAND_SQL_TEXT set serveroutput on DECLARE l_clob CLOB; BEGIN dbms_utility.Expand_sql_text( input_sql_text =>'SELECT * FROM SALES_REPORTING2_V', output_sql_text => l_clob); dbms_output.Put_line(l_clob); END; / 7
  • 8. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_UTILITY.EXPAND_SQL_TEXT SELECT "A1"."order_id" "ORDER_ID", "A1"."time_id" "TIME_ID", "A1"."cust_id" "CUST_ID", "A1"."prod_id" "PROD_ID" FROM (SELECT "A2"."order_id" "ORDER_ID", "A2"."time_id" "TIME_ID", "A2"."cust_id" "CUST_ID", "A2"."prod_id" "PROD_ID" FROM "SH"."sales" "A2”) "A1" 8
  • 9. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_ADVANCED_REWRITE 9 Fixing the unfixable SQL statement • You’ve been told you need to “fix” a SQL statement that is no longer returning results in the correct order • But you can’t change the application code directly as that would require down time • What do you do? SQL> SELECT x, y, sum(z) FROM t GROUP BY x, y; X Y SUM(Z) ---------- ---------- ---------- 1 4 110 2 3 84 10g Something changes and now you get SQL> SELECT x, y, sum(z) FROM t GROUP BY x, y; X Y SUM(Z) ---------- ---------- ---------- 2 3 84 1 4 110
  • 10. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_ADVANCED_REWRITE 10 Fixing the unfixable SQL statement Step 1 • Check what changed with the execution plan ORIGINIAL PLAN ----------------------------------- | Id | Operation | Name | ----------------------------------- | 0 | SELECT STATEMENT | | | 1 | HASH GROUP BY | | | 2 | TABLE ACCESS FULL| T | ----------------------------------- NEW PLAN -------------------------------------- | Id | Operation | Name | -------------------------------------- | 0 | SELECT STATEMENT | | | 1 | SORT GROUP BY NOSORT| | | 2 | INDEX FULL SCAN |T_IDX | --------------------------------------
  • 11. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_ADVANCED_REWRITE 11 Fixing the unfixable SQL statement Step 2 • Check the order of the columns in the index SQL> SELECT column_position, column_name FROM user_ind_columns WHERE index_name='T_IDX' ORDER BY column_position; COLUMN_POSITION COLUMN --------------- ------ 1 Y 2 X 3 Z • New index returns the rows in a different order because its sorted on column Y rather than X
  • 12. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_ADVANCED_REWRITE 12 Fixing the unfixable SQL statement Step 3 • Create a view v that includes an order by clause so the query results will always be order based on the values column x SQL> CREATE OR REPLACE VIEW v 2 AS 3 SELECT x, y, sum(z) "SUM(Z)" 4 FROM t 5 GROUP BY x, y 6 ORDER BY x, y; View created.
  • 13. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_ADVANCED_REWRITE 13 Fixing the unfixable SQL statement Step 4 • Use the DBMS_ADVANCED_REWRITE procedure to map the original query to a simple SELECT * FROM v; SQL> BEGIN 2 sys.dbms_advanced_rewrite.declare_rewrite_equivalence( 3 name => 'DEMO_TIME', 4 source_stmt => 'SELECT x, y, sum(z) FROM t GROUP BY x, y', 5 destination_stmt => 'SELECT * FROM v', 6 validate => FALSE, 7 rewrite_mode => 'TEXT_MATCH'); 8 END; 9 / PL/SQL procedure successfully completed.
  • 14. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_ADVANCED_REWRITE 14 Fixing the unfixable SQL statement • Each time our original SQL statement is issued the DBMS_ADVANCED_REWRITE procedure rewrites it to be SELECT * FROM v; • Always get the query output in an order list SQL> SELECT x, y, sum(z) FROM t GROUP BY x, y; X Y SUM(Z) ---------- ---------- ---------- 1 4 110 2 3 84 ----------------------------------- | Id | Operation | Name | ----------------------------------- | 0 | SELECT STATEMENT | | | 1 | VIEW | V | | 2 | SORT GROUP BY | | | 3 | INDEX FULL SCAN|T_IDX | -----------------------------------
  • 15. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_COMPARISON • Trying to figure out why things behave differently in production then they do in test can be time consuming and painful • The DBMS_COMPARISON package allows you to compare objects, schemas or data between databases or schemas • For a table comparison you do need a unique index on both tables • Begin by creating the comparison 15 Figuring out why production is different to test SQL> BEGIN DBMS_COMPARISON.CREATE_COMPARISON ( comparison_name => 'COMP_SALES', schema_name => 'SH', object_name => 'SALES', dblink_name => 'orcl2_test' ); END; / 11g
  • 16. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_COMPARISON • Execute the COMPARE function to perform the compare operation • Returns a boolean to say if there is or is not consistency • The scan_id allows you to find out what the differences are 16 SQL> DECLARE scan_info DBMS_COMPARISON.COMPARISON_TYPE; BEGIN IF NOT DBMS_COMPARISON.COMPARE ( comparison_name => 'COMP_SALES' , scan_info => scan_info , perform_row_dif => TRUE ) THEN DBMS_OUTPUT.PUT_LINE('Scan ID:'|| scan_info.scan_id); END IF; END; / Scan ID: 1
  • 17. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | DBMS_COMPARISON 17 SELECT c.COLUMN_NAME, r.INDEX_VALUE, case when r.LOCAL_ROWID is null then ‘No’ else 'Yes’ end LOCAL, Case when r.REMOTE_ROWID is null then 'No’ else 'Yes’ end REMOTE FROM USER_COMPARISON_COLUMNS c, USER_COMPARISON_ROW_DIF r, USER_COMPARISON_SCAN s WHERE c.COMPARISON_NAME = 'COMP_SALES‘ AND c.INDEX_COLUMN = 'Y’ AND r.STATUS = 'DIF’ AND c.COMPARISON_NAME = r.COMPARISON_NAME AND r.SCAN_ID = s.SCAN_ID AND s.SCAN_ID = 1 ORDER BY r.INDEX_VALUE; COLUMN_NAME INDEX_VALUE LOCAL REMOTE ----------- ----------- ----- ------ TAX_CODE 0.05 No Yes Test environment has an different tax code
  • 18. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Many More Powerful Supplied PL/SQL Packages • Oracle Database 18c provides 300 PL/SQL packages • Some of my favorites include: – DBMS_STATS – DBMS_SHARED_POOL – DBMS_SPM – DBMS_AUTO_TASK_ADMIN – DBMS_SQLTUNE • Check out more details in the PL/SQL Packages and Types Reference 18

Editor's Notes

  1. Oracle Database 8i had only 60 pl/sql packages while 18c has 300!
  2. Oracle Database 8i only 60 PL/SQL packages