Questions
Questions
PL/SQL Demystified
The best way of learning something is by asking questions. That's why I've organized this
hub in a question-answer format.
The questions range from Basic to Advanced. I gave a concise answer too, only for quick
reference and revision. For detailed answer to each question, refer to any Oracle PL/SQL
online documentation.
Some of these questions were actually asked in my Job Interviews in the US.
I have added some others which I found interesting. Very useful to know.
- Name or handle to a private SQL area where Oracle parses and fetches query results.
-Oracle recognizes similar statements. The SQL area is used many times for similar
statements.
What is the difference between anonymous blocks and stored procedures ? ( Basic)
- Stored procedure is compiled and stored in database with the dependency information as
well.
- Former is PL/SQL code directly called from an application. Latter is stored in database.
- Performance better coz all SQL stmts are sent in one go from the application to the
database
- Prior to Oracle 9i, we have only bytecode and a virtual machine in the database runs it.
Later versions have faster native code execution.
- PL/SQL engine is the main component that executes procedural stmt and passes the SQL
to the SQL statement executor.
- It has all the advantages of dynamic sql .. like runtime construction of sql, DDL statements
can be executed.
What is a package spec and package body ? Why the separation ? ( Basic)
- Spec declares public constructs. Body defines public constructs, additionally declares and
defines Private constructs
- Dependency is simplified. You can modify body without invalidating dependent objects.
- Dependency simplified
- SQL%BULK_EXCEPTIONS(i).ERROR_CODE,
SQL%BULK_EXCEPTIONS(i).ERROR_INDEX
SQL%BULK_EXCEPTIONS.COUNT
- Use FORALL instead of FOR, and use BULK COLLECT to avoid looping many times
- Use NOCOPY for OUT and IN OUT if the original value need not be retained. Overhead of
keeping a copy of OUT is avoided.
- Minimize datatype conversions => Assign data to exact same type variables
- Do not use subtypes like POSITIVE, NATURAL, INTEGER as they have additional checks
- ALL_PLSQL_OBJECT_SETTINGS
- Conditional compilation
- Quoting mechanism . Instead of quoting single quotes twice everytime, give your own
delimiter to go on using single quotes.
- Improved Overloading