DB Flashcards

1
Q

What are Oracle packages?

A

Oracle packages are database objects that group related procedures, functions, variables, and other elements as a single unit for easier management and organization.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the purpose of using packages in Oracle databases?

A

Packages provide a way to encapsulate and modularize database logic, offering better organization, reusability, and security.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What components can be included in an Oracle package?

A

An Oracle package can contain procedures, functions, variables, constants, cursors, and exception declarations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How are Oracle packages created and stored?

A

Packages are created using SQL or PL/SQL scripts and stored within the Oracle database schema as named database objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the benefits of using Oracle packages?

A

Using packages improves code reusability, enhances code maintenance, reduces namespace pollution, and offers better security by controlling access to encapsulated elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How are packages invoked or used within Oracle databases?

A

Procedures and functions within packages can be invoked or called from other PL/SQL blocks or SQL statements within the database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a cursor in Oracle PL/SQL?

A

A cursor in Oracle PL/SQL is a pointer or handle to the result set of a SELECT query, allowing sequential processing of retrieved data rows.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the types of cursors in Oracle?

A

Oracle supports both Implicit and Explicit cursors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does an Implicit cursor work?

A

Implicit cursors are automatically created by Oracle when executing a SQL statement, typically used for single-row queries.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the process of using an Explicit cursor?

A

Explicit cursors are user-defined and require declaration, opening, fetching data, and closing, offering more control over result set traversal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the steps involved in using an Explicit cursor?

A

Declaration: Define the cursor and its query.
Opening: Open the cursor to execute the query and make the result set available.
Fetching: Retrieve rows one by one or in a loop using FETCH statement.
Closing: Close the cursor to release associated resources after data retrieval.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How is data fetched using a cursor?

A

Cursors fetch data sequentially using FETCH statements, which retrieve rows from the result set into variables defined in PL/SQL code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the role of cursors in database operations?

A

Cursors facilitate row-level manipulation and processing of query results, enabling better control over retrieved data in PL/SQL programs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How are cursors helpful in PL/SQL programming?

A

Cursors allow handling and processing of query results row by row, enabling operations like data manipulation, aggregation, and business logic implementation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does the NVL function do in Oracle?

A

NVL is a function used to replace NULL values with a specified alternate value.
The syntax is: NVL(expression, replacement_value). If the expression is NULL, the replacement_value is returned; otherwise, the expression itself is returned.
If the expression is not NULL, the original value of the expression is returned by the NVL function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the purpose of the DECODE function in Oracle SQL?

A

The DECODE function is used to perform conditional comparisons in SQL queries within Oracle. It compares an expression against a list of conditions and returns a result when a match is found.

17
Q

How does the DECODE function work in Oracle?

A

The DECODE function evaluates an expression against a set of conditions. When the expression matches a condition, it returns the corresponding result. If no match is found, it returns a default value or NULL if not specified.

18
Q

What is the syntax of the DECODE function in Oracle?

A

The syntax is: DECODE(expression, search1, result1, search2, result2, …, default). It compares the expression with search values and returns the corresponding result when a match is found. If there’s no match, it returns the default value.

19
Q

Can you provide an example of using the DECODE function in Oracle?

A

SELECT DECODE(score, 1, ‘Low’, 2, ‘Medium’, 3, ‘High’, ‘Unknown’) FROM students. This query compares the “score” column and returns ‘Low’ for 1, ‘Medium’ for 2, ‘High’ for 3, and ‘Unknown’ if no match is found.

20
Q

What is Set programming in SQL?

A

Set Programming: Performing operations on entire sets of data using SQL queries without explicitly iterating through each record.

21
Q

What are the characteristics of Set programming in SQL?

A

Declarative Nature: Focused on describing the desired result without specifying the step-by-step process.
Efficiency: Optimized for performance by allowing the database to handle operations in the most efficient manner.
Use of Aggregate Functions: Utilizes aggregate functions like SUM, COUNT, AVG, etc., to process data across sets.

22
Q

What is Procedural programming in SQL?

A

Procedural Programming: Writing SQL code that involves explicit iteration, conditional statements, and procedural logic to perform operations step by step.

23
Q

What are the characteristics of Procedural programming in SQL?

A

Imperative Nature: Requires explicit instructions and control flow statements.
Cursor Usage: Involves using cursors to iterate through individual rows of a result set.
Increased Control: Offers more granular control over the sequence of operations executed.

24
Q

What are the key differences between Set and Procedural programming in SQL?

A

Set vs. Procedural:
Set: Focuses on operations across entire sets of data.
Procedural: Involves explicit iteration and step-by-step execution of operations.

25
Q

How does Set programming improve performance in SQL?

A

Performance Improvement: Set programming optimizes query execution by allowing the database engine to process operations in bulk across entire sets of data, reducing the need for explicit iteration and improving efficiency.

26
Q

What are the limitations of Set programming in SQL?

A

Limited Control: Set programming might lack the granular control needed for intricate or complex procedural operations.
Difficulty in Some Scenarios: Some complex business logic or conditional operations might be challenging to express using pure set-based operations.

27
Q

How does Procedural programming enable complex data transformations in SQL?

A

Complex Operations: Procedural programming allows developers to implement complex business logic, conditional operations, and intricate data transformations by explicitly defining each step.

28
Q

What are the common scenarios where Procedural programming is preferred over Set programming in SQL?

A

Custom Data Transformations: When operations require intricate conditional logic or custom data manipulations not easily achieved using set-based operations.
Iterative Processing: Cases where explicit iteration over individual records or complex control flow is necessary.

29
Q

Can Set and Procedural programming be combined in SQL?

A

Hybrid Approaches: Some database systems support hybrid approaches where developers can leverage both set-based and procedural methods within the same SQL code to achieve complex operations while maintaining performance benefits.