Beruflich Dokumente
Kultur Dokumente
PL/SQL
12-1
Using Dynamic SQL
PLSQL S12L1 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 3
Using Dynamic SQL
Purpose
PLSQL S12L1 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 4
Using Dynamic SQL
Execution Flow of SQL
PLSQL S12L1 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 5
Using Dynamic SQL
Execution Flow of SQL in PL/SQL
Subprograms
PLSQL S12L1 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 6
Using Dynamic SQL
Execution Flow of SQL in PL/SQL
Subprograms
PLSQL S12L1 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 7
Using Dynamic SQL
Dynamic SQL
PLSQL S12L1 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 8
Using Dynamic SQL
Native Dynamic SQL
PLSQL S12L1 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 9
Using Dynamic SQL
Native Dynamic SQL
NDS:
– Is executed with Native Dynamic SQL statements (EXECUTE
IMMEDIATE) or the DBMS_SQL package.
– Provides the ability to execute SQL statements whose
structure is unknown until execution time.
– Can also use the OPEN-FOR, FETCH, and CLOSE PL/SQL
statements.
PLSQL S12L1 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 10
Using Dynamic SQL
Using the EXECUTE IMMEDIATE
Statement
PLSQL S12L1 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 11
Using Dynamic SQL
Using the EXECUTE IMMEDIATE
Statement
PLSQL S12L1 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 12
Using Dynamic SQL
Using the EXECUTE IMMEDIATE
Statement
PLSQL S12L1 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 13
Using Dynamic SQL
Example 1: Dynamic SQL with a DDL
Statement
PLSQL S12L1 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 14
Using Dynamic SQL
Example 2: Dynamic SQL with a DML
Statement
PLSQL S12L1 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 15
Using Dynamic SQL
Example 3: Dynamic SQL with a DML
Statement
BEGIN
add_row('EMPLOYEE_NAMES', 250, 'Chang');
END;
PLSQL S12L1 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 16
Using Dynamic SQL
Example 4: Using Native Dynamic SQL
to Recompile PL/SQL Code
PLSQL S12L1 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 17
Using Dynamic SQL
Example 4: Using Native Dynamic SQL
to Recompile PL/SQL Code
PLSQL S12L1 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 18
Using Dynamic SQL
Using the DBMS_SQL Package
PLSQL S12L1 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 19
Using Dynamic SQL
Using DBMS_SQL with a DML Statement
PLSQL S12L1 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 21
Using Dynamic SQL
Comparison of Native Dynamic SQL
and the DBMS_SQL Package
PLSQL S12L1 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 22
Using Dynamic SQL
Terminology
PLSQL S12L1 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 23
Using Dynamic SQL
Summary
PLSQL S12L1 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 24
Using Dynamic SQL