SAGE Computing Services Customised Oracle Training Workshops and Consulting 11g New Features … of the SQL & PL/SQL Variety Scott Wesley Systems Consultant.

Slides:



Advertisements
Similar presentations
Password Management for Oracle8 Ari Kaplan Independent Consultant.
Advertisements

AN INTRODUCTION TO PL/SQL Mehdi Azarmi 1. Introduction PL/SQL is Oracle's procedural language extension to SQL, the non-procedural relational database.
PL/SQL. Introduction to PL/SQL PL/SQL is the procedure extension to Oracle SQL. It is used to access an Oracle database from various environments (e.g.
Murali Mani Persistent Stored Modules (Stored Procedures) : PSM.
Triggers The different types of integrity constraints discussed so far provide a declarative mechanism to associate “simple” conditions with a table such.
Chapter 4B: More Advanced PL/SQL Programming
Creating Triggers.
Oracle PL/SQL TRIGGERS
System Administration Accounts privileges, users and roles
Oracle8 - The Complete Reference. Koch a& Loney1 By What Authority? Presented by Victor Matos.
Introduction to Structured Query Language (SQL)
Triggers in SQL’99 CS561.
2 Copyright © 2004, Oracle. All rights reserved. Creating Stored Functions.
PL / SQL P rocedural L anguage / S tructured Q uery L anguage Chapter 7 in Lab Reference.
11g New Features for PL/SQL Developers Tim Hall Oracle ACE Director Oracle ACE of the Year 2006 OCP DBA (7, 8, 8i, 9i, 10g,
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 David M. Kroenke’s Chapter Seven: SQL for Database Construction and.
SAGE Computing Services Customised Oracle Training Workshops and Consulting Are you making the most of PL/SQL? Hints and tricks and things you may have.
CHAPTER 6 Users and Basic Security. Progression of Steps for Creating a Database Environment 1. Install Oracle database binaries (Chapter 1) 2. Create.
Lecture 4 PL/SQL language. PL/SQL – procedural SQL Allows combining procedural and SQL code PL/SQL code is compiled, including SQL commands PL/SQL code.
Overview · What is PL/SQL · Advantages of PL/SQL · Basic Structure of a PL/SQL Block · Procedure · Function · Anonymous Block · Types of Block · Declaring.
In Oracle.  A PL/SQL block stored in the database and fired in response to a specified event ◦ DML statements : insert, update, delete ◦ DDL statements.
Oracle 11g DATABASE DEVELOPMENT LAB1. Introduction  Oracle 11g Database:-  Oracle 11g database is designed for some features, which helps to the organizations.
PRACTICE OVERVIEW PL/SQL Part Examine this package specification and body: Which statement about the V_TOTAL_BUDGET variable is true? A. It must.
Managing users and security Akhtar Ali. Aims Understand and manage profiles Understand and manage users Understand and manage privileges Understand and.
Chapter 2 Views. Objectives ◦ Create simple and complex views ◦ Creating a view with a check constraint ◦ Retrieve data from views ◦ Data manipulation.
1 ISYS Triggers. 2 Agenda Triggers Review Correlation identifiers (pseudo records) Restrictions on triggers Trigger usage Mutating tables Enabling.
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Database Application Development using PL/SQL Programming.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Advanced SQL: Triggers & Assertions
1 © 2010 Julian Dyke Edition-Based Redefinition Julian Dyke Independent Consultant juliandyke.com Web Version.
Objectives Database triggers and syntax
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 9 Database Triggers.
Controlling User Access. 2 home back first prev next last What Will I Learn? Compare the difference between object privileges and system privileges Construct.
Database Security. Multi-user database systems like Oracle include security to control how the database is accessed and used for example security Mechanisms:
PL/SQLPL/SQL Oracle11g: PL/SQL Programming Chapter 9 Database Triggers.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 9 Database Triggers.
Retrieving Data in PL/SQL. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Recognize the SQL statements that can.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Function, Trigger used in PosgreSQL.
A procedure is a module performing one or more actions; it does not need to return any values. The syntax for creating a procedure is as follows: CREATE.
A database trigger is a stored PL/SQL program unit associated with a specific database table. ORACLE executes (fires) a database trigger automatically.
Program with PL/SQL Lesson 3. Interacting with the Oracle Server.
Chapter 8 Advanced SQL Pearson Education © Chapter 8 - Objectives How to use the SQL programming language How to use SQL cursors How to create stored.
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
1 11g NEW FEATURES ByVIJAY. 2 AGENDA  RESULT CACHE  INVISIBLE INDEXES  READ ONLY TABLES  DDL WAIT OPTION  ADDING COLUMN TO A TABLE WITH DEFAULT VALUE.
 CONACT UC:  Magnific training   
5 Copyright © 2007, Oracle. All rights reserved. Implementing the Performance Improvements.
CS422 Principles of Database Systems Stored Procedures and Triggers Chengyu Sun California State University, Los Angeles.
What is the Flashback Database? Improves a database’s availability Useful alternative to traditional restoration methods Contains Flashback logs Archived.
1 Procedural Extension to SQL using Triggers - Lecture 2 Dr Akhtar AlI.
C Copyright © 2004, Oracle. All rights reserved. Studies for Implementing Triggers.
ISYS Triggers.
Controlling User Access
Creating Database Triggers
SQL Stored Triggers Presented by: Dr. Samir Tartir
Introduction to Triggers
Agenda Triggers Review Correlation identifiers (pseudo records)
ISYS Triggers.
What Is a View? EMPNO ENAME JOB EMP Table EMPVU10 View
Advanced SQL: Views & Triggers
Chapter 2 Views.
Instructor: Mohamed Eltabakh
Chapter 2 Views.
Introduction to Triggers
Oracle9i Developer: PL/SQL Programming Chapter 8 Database Triggers.
Prof. Arfaoui. COM390 Chapter 9
Triggers in SQL’99 CS561.
IST 318 Database Administration
TRIGGERS.
Presentation transcript:

SAGE Computing Services Customised Oracle Training Workshops and Consulting 11g New Features … of the SQL & PL/SQL Variety Scott Wesley Systems Consultant

Documentation Passwords Sequences Triggers SQL PL/SQL Recursion Read only tables Virtual columns 11g

Documentation is your friend

Readme’s are still around Features Not Available or Restricted in This Release –Edition-based redefinition is not available in Oracle Database 11g Release 1 (11.1). You cannot create an edition, an editioning view, or a crossedition trigger; nor can you use the ENABLE EDITIONS clause in the CREATE USER and ALTER USER commands. As a consequence, other related functionality (for example, the ALTER SESSION SET EDITION statement or the new overload of DBMS_Sql.Parse() that lets you specify an edition or a crossedition trigger) becomes uninteresting and attempting to use it will cause a semantic error.

Can you log in?

conn scott/tiger ERROR: ORA-01017: invalid username/password; logon denied Warning: You are no longer connected to ORACLE.

conn scott/Tiger Connected.

ALTER SYSTEM SET SEC_CASE_SENSITIVE_LOGON = false; System altered.

conn scott/tiger Connected.

select username, password_versions from dba_users where username = 'SCOTT'; USERNAME PASSWORD SCOTT 10G 11G 1 row selected.

Password Complexity

@$ORACLE_HOME/RDBMS/ADMIN/utlpwdmg.sql ALTER PROFILE DEFAULT LIMIT PASSWORD_VERIFY_FUNCTION verify_function_11g; Profile altered.

password Changing password for SCOTT Old password: New password: Retype new password: sagesage ERROR: ORA-28003: password verification for the specified password failed ORA-20006: Password too simple Password unchanged

ALTER PROFILE DEFAULT LIMIT PASSWORD_VERIFY_FUNCTION NULL; Profile altered.

Quick win: SQL*Plus supports BLOBs

SQL*Plus Free Available at every site Supported by Oracle Thin Fast Can do pie charts

Let’s get our hands dirty...

Allow Sequence in PL/SQL expressions

create table T ( id number, value number ); Table created. create sequence id_seq; Sequence created. create or replace 2 trigger populate_id 3 before insert on T 4 for each row 5 begin 6 -- dbms_db_version.ver_le_ select id_seq.nextval into from dual; dbms_db_version.ver_le_11 10 :new.id := id_seq.nextval; 11 end; 12 / Trigger created.

This feature brings improved usability for the PL/SQL programmer and improved runtime performance and scalability.

declare 2 n pls_integer; 3 begin 4 for i in loop 5 select id_seq.nextval into n from dual; 6 end loop; 7 end; 8 / PL/SQL procedure successfully completed. Elapsed: 00:00:06.18

declare 2 n pls_integer; 3 begin 4 for i in loop 5 n := id_seq.nextval; 6 end loop; 7 end; 8 / PL/SQL procedure successfully completed. Elapsed: 00:00:06.68

alter session set sql_trace=true; variable n number begin for i in loop :n := scott.id_seq.nextval; end loop; end; / alter session set sql_trace=false;

Select ID_SEQ.NEXTVAL from dual call count cpu elapsed disk query current rows Parse Execute Fetch total

Same Same. But Different

insert into T test2 2 select rownum, rownum from dual connect by level < 50000; rows created. Elapsed: 00:00:04.01

drop trigger populate_id; Trigger dropped. insert into T test2 2 select id_seq.nextval, rownum from dual connect by level < 50000; rows created. Elapsed: 00:00:00.71

Triggers are still an overhead (in this case) Seth Godin -->

As Connor McDonald likes to say: What we really need is...

create table typical_table ( id_col number default id_seq.nextval,...

But we do have trigger improvements

create or replace trigger populate_id before insert on T for each row disable begin :new.id := id_seq.nextval; end; /

Compound triggers

CREATE OR REPLACE TRIGGER compound_trigger FOR UPDATE OF salary ON employees COMPOUND TRIGGER -- Declarative part (optional) -- Variables declared here have firing-statement duration. threshold CONSTANT SIMPLE_INTEGER := 200; BEFORE STATEMENT IS BEGIN NULL; END BEFORE STATEMENT; BEFORE EACH ROW IS BEGIN NULL; END BEFORE EACH ROW; AFTER EACH ROW IS BEGIN NULL; END AFTER EACH ROW; AFTER STATEMENT IS BEGIN NULL; END AFTER STATEMENT; END compound_trigger; / Trigger created.

To avoid the mutating-table error eg: A business rule states that an employee's salary increase must not exceed 10% of the average salary for the employee's department.

To accumulate rows destined for a second table so that you can periodically bulk-insert them

create table audit_emp (employee_id number(20),old_salary number(10),new_salary number(10),ts timestamp);

create or replace trigger old_way after update of salary on emp_large for each row begin insert into audit_emp values (:new.employee_id,:old.salary,:new.salary,systimestamp); end old_way; /

update emp_large set salary = salary -1; rows updated. Elapsed: 00:00:08.75 select count(*) from audit_emp; COUNT(*) row selected. alter trigger old_way disable;

create or replace trigger new_way for update of salary on emp_large compound trigger threshhold constant simple_integer := 100; type audit_t is table of audit_emp%rowtype index by simple_integer; t_audit audit_t; ln_index simple_integer := 0;

after each row is begin ln_index := ln_index + 1; t_audit(ln_index).employee_id := :new.employee_id; t_audit(ln_index).old_salary := :old.salary; t_audit(ln_index).new_salary := :new.salary; t_audit(ln_index).ts := systimestamp; if ln_index >= threshhold then -- index >= 100 flush_array; end if; end after each row; procedure flush_array is n constant SIMPLE_INTEGER := t_audit.count(); begin forall j in 1..n insert into audit_emp values t_audit(j); t_audit.delete(); ln_index := 0; end flush_array;

procedure flush_array is n constant SIMPLE_INTEGER := t_audit.count(); begin forall j in 1..n insert into audit_emp values t_audit(j); t_audit.delete(); ln_index := 0; end flush_array; after statement is begin flush_array; end after statement;

update emp_large set salary = salary -1; rows updated. Elapsed: 00:00:04.01 select count(*) from audit_emp; COUNT(*) row selected.

Triggers are still ok (in this case)

create or replace trigger package_trigger after update of salary on employees for each row begin dbms_output.put_line('package_trigger'); end old_way; / create or replace trigger custom_stuff after update of salary on employees for each row follows package_trigger begin dbms_output.put_line('custom_stuff'); end old_way; /

update employees set salary=1 where employee_id = 99; package_trigger custom_stuff 1 row updated.

What about “PRECEDES”?

Named Parameters in SQL

create or replace function f(p1 in integer,p2 in integer := 2,p3 in integer := null) return number is begin return nvl(p1,0) +nvl(p2,0) +nvl(p3,0); end; /

select f(1,2,3) from dual; F(1,2,3) row selected.

select f from dual; select f from dual * ERROR at line 1: ORA-06553: PLS-306: wrong number or types of arguments in call to 'F'

select f(1,null) from dual; F(1,NULL) row selected.

select f(1,p3=>3) from dual; F(1,P3=>3) row selected.

CONTINUE-WHEN

declare x number := 0; begin > loop -- after continue statement, control resumes here dbms_output.put_line ('Inside loop: x = ' || to_char(x)); x := x + 1; continue my_loop when x < 3; dbms_output.put_line ('Inside loop, after CONTINUE: x = ' || to_char(x)); exit when x = 5; end loop my_loop; dbms_output.put_line ('After loop: x = ' || to_char(x)); end; / Inside loop: x = 0 Inside loop: x = 1 Inside loop: x = 2 Inside loop, after CONTINUE: x = 3 Inside loop: x = 3 Inside loop, after CONTINUE: x = 4 Inside loop: x = 4 Inside loop, after CONTINUE: x = 5 After loop: x = 5 PL/SQL procedure successfully completed.

Native PL/SQL Compilation

create or replace function factorial_interpreted(p_n number) return number is begin if (p_n = 1) then return 1; else return factorial_interpreted(p_n-1)*p_n; end if; end; /

create or replace function factorial_native(p_n number) return number is begin if (p_n = 1) then return 1; else return factorial_native(p_n-1)*p_n; end if; end; /

ALTER PROCEDURE factorial_native COMPILE PLSQL_CODE_TYPE=NATIVE REUSE SETTINGS;

declare l_n number; begin for i in loop l_n := factorial_interpreted(50); end loop; end; / Elapsed: 00:00:14.85

declare l_n number; begin for i in loop l_n := factorial_native(50); end loop; end; / Elapsed: 00:00:10.26

Read only tables

alter table logons read only;

update logons set user_id = upper(user_id); * ERROR at line 1: ORA-12081: update operation not allowed on table "HR"."LOGONS"

conn sage/sage select privilege from user_tab_privs where table_name = 'LOGONS'; PRIVILEGE UPDATE 1 row selected.

update hr.logons set user_id = upper(user_id) * ERROR at line 1: ORA-12081: update operation not allowed on table "HR"."LOGONS"

Very Versatile Virtual Verticals

Virtual Columns Formula/computed columns – on the database Further constraints – on the database New category for partitioning – on the database Creative referential integrity – on the database Without Triggers - expensive Views – sometimes forgotten Re-design – too much hard work!

And there’s more! Query result cache PL/SQL Result Cache Pivot / Unpivot Invisible indexes PL/SQL Inlining Optimisation SQL Plan Management SQL Performance Analyser DBA Stuff

SAGE Computing Services Customised Oracle Training Workshops and Consulting Questions and Answers? Presentations are available from our website: