Some Playful, Complex & Amazing Queries

1. Query to get Financial or Yearly Calendar from desired date.
2. Query to print string in X formation.
3. Query to form diamond.
5. Query to form reverse diamond.
6. Query to generate mathematical tables using cartesian product / cross join.

Advanced SQL & PL/SQL

Q1. How to rebuild the index of a table? Answer. ALTER INDEX index_name REBUILD; Q2. What is a Dead Lock? Answer. When two or more users are waiting for access to data that has been locked by each other, it is known as deadlock. When a deadlock occurs, the transactions fail to go ahead –Continue reading “Advanced SQL & PL/SQL”

Subquery Factoring or Common Table Expression (CTE)

Q1. What is Subquery Factoring? Answer. Subquery factoring is implemented with the usage of with clause. The WITH clause may be processed as an inline view or resolved as a temporary table. The advantage is that repeated references to the subquery may be more efficient as the data is easily retrieved from the temporary table,Continue reading “Subquery Factoring or Common Table Expression (CTE)”

Triggers

Q1. Explain two virtual tables available at the time of database trigger execution. Answer. :OLD and :NEW are the 2 virtual tables available at the time of database trigger execution. The table columns are referred as :OLD.column_name and :NEW.column_name. Trigger Event Availability of values in :NEW.column_name :OLD.column_name Insert Available Not Available Update Available Available DeleteContinue reading “Triggers”

Functions, Procedures & Packages

Q1. What are the various types of parameter modes in a procedure / function? Answer. IN, OUT AND INOUT. Q2. What is a transaction? Answer. A transaction is a set of SQL statements between any two COMMIT and ROLLBACK statements. Q3. What is Sysdate? A function or A pseudo column or A system defined variable?Continue reading “Functions, Procedures & Packages”

Cursors

Q1. What is a cursor? Why Cursor is required? Answer. Cursor is a named private SQL area from where information can be accessed. Cursors are required to process rows individually for queries returning multiple rows. Cursors are unidirectional only. Q2. What are cursor attributes? Explain them. Answer. Following are the cursor attributes:• %Found – toContinue reading “Cursors”

Indexes

Q1. What is the difference between foreign key and reference key? Answer. A Foreign key is the key which refers to another table’s primary key.A Reference key is the primary key of table referred by another table. Q2. Differentiate between Primary key and Unique Key Answer. Primary key and Unique key both enforces uniqueness ofContinue reading “Indexes”

Views & Materialized Views

Q1. Why are views created? Answer. Views are created for:• Storing complicated queries in the database so that they are not to be re-written every time they are required.• Hide the complicated logics on joins from the users.• Hide the sensitive data from the users by limiting their view to limited fields mentioned in views.•Continue reading “Views & Materialized Views”