Showing posts with label DBA Interview questions. Show all posts
Showing posts with label DBA Interview questions. Show all posts

Monday, May 29, 2017

Oracle Interview Questions and Answers - SQL Queries and Database

1. What is oracle database ?
Oracle Database is a relational database management system (RDBMS) which is used to store and retrieve the large amounts of data. Oracle Database had physical and logical structures. Logical structures and physical structures are separated from each other
2. Explain oracle grid architecture?
Grid computing is a information technology architecture that provides lower cost enterprise information systems. Using grid computing, independent hardware, and software components can be connected and rejoined on demand to meet the changing needs of businesses. It also enables the use of smaller individual hardware components.
3. What is the difference between large dedicated server and oracle grid?
Large dedicated server:
  • It has expensive costly components.
  • High incremental costs.
  • It has single point of failure.
  • Enterprise service at higher cost.
Oracle Grid:
  • It has low cost modular components.
  • Low incremental costs.
  • It has no single point of failure.
  • Enterprise service at low cost.
4. What are the computing components of oracle grid?
The computing componenets of oracle grid are:
  • Oracle Enterprise Manager and Grid Control
  • Oracle 10g Database and Real Application Clusters.
  • ASM Storage Grid.
5. What is server virtualization?
Oracle Real Application Clusters 10g (RAC) enables a single database to run across multiple clustered nodes in a grid, pooling the processing resources of several standard machines.

6. What is storage virtualization?
The Oracle Automatic Storage Management (ASM) is a feature of Oracle Database 10g which provides a virtual layer between the database and storage so that group of disks can be treated as a single disk group and disks can be dynamically added or removed while keeping databases online.
Also Read Basic to Advanced Oracle SQL Query Interview Question and Answers
7. What is Grid Management feature?
The Grid Management feature of Oracle Enterprise Manager 10g provides a single console to manage multiple systems together as a logical group.
8. When oracle allocates an SGA?
When Oracle starts, it reads the initialization parameter file to determine the values of initialization parameters. After this, it allocates an SGA and creates background processes.
9. What is an oracle instance?
When you start, the database instance comes into picture into system memory. Combination of the SGA and the Oracle processes is called an Oracle instance.
10. What are the several tools for interacting with the oracle database using sql?
There are several tools for interfacing with the database using SQL:
  • Oracle SQL*Plus and iSQL*Plus 
  • Oracle Forms, Reports, and Discoverer
  • Oracle Enterprise Manager 
  • Third-party tools
11. How oracle works?
  • An instance has started on the database server.
  • A client established a connection to the server, using the proper Oracle Net Services driver.
  • The server creates a dedicated server process on behalf of the user process.
  • The user executes SQL statement and commits the transaction.
  • The server process receives the statement and checks for any shared SQL area that contains a similar SQL.
  • The server process retrieves data from datafile (table) or SGA.
  • The server process modifies data in the SGA area. The DBWn process writes modified blocks permanently to disk. The LGWR process records the transaction in the redo log file.
  • The server process sends a message to the application.

12. What contains oracle physical database structure?
It contains
  • Datafiles
  • Control Files
  • Redo Log Files
  • Archive Log Files
  • Parameter Files
  • Alert and Trace Log Files
  • Backup Files
13. What is a Tablespace?
Oracle use Tablespace for logical data Storage. Physically, data will get stored in Datafiles. Datafiles will be connected to tablespace. A tablespace can have multiple datafiles. A tablespace can have objects from different schema's and a schema can have multiple tablespace's. Database creates "SYSTEM tablespace" by default during database creation. It contains read only data dictionary tables which contains the information about the database. 
14. What is a Control File ?
Control file is a binary file which stores Database name, associated data files, redo files, DB creation time and current log sequence number. Without control file database cannot be started and can hamper data recovery.
15. What are data blocks?
Oracle stores data in data blocks also called as logical blocks, Oracle blocks or pages. A data block represents specific number of bytes of space on disk.
16. What is an extent?
An extent is a specific number of consecutive data blocks allocated for storing a specific type of information.
17. What is a segment?
A segment is a group of extents, each of which has been allocated for a specific data structure and all of which are stored in the same table-space.
18. What is Rollback Segment ? 
Database contain one or more Rollback Segments to roll back transactions and data recovery.
19. What are the different type of Segments ? 
Data Segment(for storing User Data), Index Segment (for storing index), Rollback Segment and Temporary Segment.
20. What is an oracle schema?
A user account and its associated data including tables, views, indexes, clusters, sequences,procedures, functions, triggers,packages and database links is known as Oracle schema. System, SCOTT etc are default schema's. We can create a new Schema/User. But we can't drop default database schema's.
21. When and how oracle database creates a schema?
Oracle Database automatically creates a schema when you create a user.
22. What is a view?
A view is a tailored presentation of the data contained in one or more tables or other views. A view is output of a query and treats it as a table. Therefore, a view can be thought of as a stored query or a virtual table. A view is not assigned any storage space, nor does a view actually contain data.
23. How views are used?
  • It provides security by restricting access to a predetermined set of rows or columns of a table. It hides data complexity. It simplifies statements for the user.
  • An example would be the views, which allow users to select data from multiple tables without actually knowing how to perform a join.
  • It presents the data in a different perspective from that of the base table. It isolate applications from changes in definitions of base tables. It saves complex queries.
24. What are materialized views?
These are schema objects that are used to summarize, compute, replicate, and distribute data. They can be used in various environments for computation such as data warehousing, decision support, and distributed or mobile computing and it also provides local access to data rather than accessing from remote sites. In data warehouses, MVs are used to compute and store aggregated data.

New Oracle Interview questions - Multinationals Oracle Questions Dump

Oracle is a secured database that is widely used in multinational companies. The frequently asked questions from oracle database are given below.

1) What are the components of physical database structure of Oracle database?

Components of physical database structure are given below.
  • One or more data files.
  • Two or more redo log files.
  • One or more control files.

2) What are the components of logical database structure in Oracle database?

Components of logical database structure.
  • Tablespaces
  • Database's schema objects

3) What is a tablespace?

A database contains Logical Storage Unit called tablespaces. A tablespace is a set of related logical structures. Actually a tablespace groups related logical structures together.

4) What is a SYSTEM tablespace and when it is created?

When the database is created in Oracle database system, it automatically generate a SYSTEM named SYSTEM tablespace. The SYSTEM tablespace contains data dictionary tables for the entire database.

5) What is an Oracle table?

A table is basic unit of data storage in Oracle database. A table contains all the accessible information of a user in rows and columns.

6) In the Oracle version 9.3.0.5.0, what does each number shows?

Oracle version number refers:
  • 9 - Major database release number
  • 3 - Database maintenance release number
  • 0 - Application server release number
  • 5 - Component Specific release number
  • 0 - Platform Specific release number

7) What is bulk copy or BCP in Oracle?

Bulk copy or BCP in Oracle, is used to import or export data from tables and views but it does not copy structure of same data.
The main advantage of BCP is fast mechanism for coping data and you can also take the backup of data easily.

8) What is the relationship among database, tablespace and data file?

An Oracle database contains one or more logical storage units called tablespaces. These tablespaces collectively store whole data of databases and each tablespace in Oracle database consists of one or more files called datafiles. These datafiles are physical structure that confirm with the operating system in which Oracle is running.

9) What is a snapshot in Oracle database?

A snapshot is a replica of a target master table from a single point-in-time. In simple words you can say, snapshot is a copy of a table on a remote database.

10) What is the difference between hot backup and cold backup in Oracle? Tell about their benefits also.

Hot backup (Online Backup): A hot backup is also known as online backup because it is done while the database is active. Some sites can not shut down their database while making a backup copy, they are used for 24 hour a day, 7 days a week.
Cold backup (Offline Backup): A cold backup is also known as offline backup because it is done while the database has been shutdown using the SHUTDOWN normal command. If the database is suddenly shutdown with a uncertain condition it should be restarted with RESTRICT mode and then shutdown with NORMAL option.
For a complete cold backup the following files must be backed up.
All datafiles, All control files, All online redo log files(optional) and the init.ora file (you can recreate it manually).

11) How many memory layers are in the Oracle shared pool?

Oracle shared pools contains two layers:
  1. library cache
  2. data dictionary cache

12) What is save point in Oracle database?

Save points are used to divide a transaction into smaller parts. It allows rolling back of a transaction. Maximum five save points are allowed. It is used to save our data, whenever you encounter an error you can roll back from the point where you save your SAVEPOINT.

13) What is hash cluster in Oracle?

Hash cluster is a technique to store a data in hash table and improve the performance of data retrieval. Hash function is applied on table row's cluster key value and store in hash cluster.

14) What are the various Oracle database objects?

Tables: This is a set of elements organized in vertical and horizontal fashion.
Tablespaces: This is a logical storage unit in Oracle.
Views: It is virtual table derived from one or more tables.
Indexes: This is a performance tuning method to process the records.
Synonyms: This is a name for tables.

15) What is the difference between pre-select and pre-query?

A pre-query trigger fire before the query executes and fire once while you try to query. With the help of this trigger you can modify the where clause part dynamically.
Pre-select query fires during the execute query and count query processing after Oracle forms construct the select statement to be issued, but before the statement is actually issued.
Pre-query trigger fires before Pre-select trigger.

16) What are the different types of modules in Oracle forms?

Following are the different modules in Oracle forms:
  • Form module
  • Menu module
  • Pl/SQL Library module
  • Object Library module

17) What is the usage of ANALYZE command in Oracle?

ANALYZE command is used to perform various functions on index, table, or cluster. The following list specifies the usage of ANALYZE command in Oracle:
  • It is used to identify migrated and chained rows of the table or cluster.
  • It is used to validate the structure of the object.
  • It helps in collecting the statistics about object used by the optimizer. They are then stored in the data dictionary.
  • It helps in deleting statistics used by object from the data dictionary.

18) Can you create a synonym without having a table?

Yes. We can create a synonym without having a base table.

19) What types of joins are used in writing SUBQUERIES?

  • Self join
  • Outer Join
  • Equi-join

20) What is the usage of control file in Oracle?

In Oracle, control file is used for database recovery. The control file is also used to identify the database and redo log files that must be opened for database operation to go ahead, whenever an instance of an ORACLE database begins.

21) What is a synonym?

A synonym is also known as alias for a table, view, sequence or program unit.

22) What are the different types of synonyms?

There are two types of synonyms or alias:
Private: It can only accessed by the owner.
Public: It can be accessed by any database user.

23) What is the usage of synonyms?

  • Synonym can be used to hide the real name and owner of an object.
  • It provides public access to an object.
  • It also provides location transparency for tables, views or program units of a remote database.
  • It simplifies the SQL statements for database users.

24) How do you store pictures in a database?

Yes, you can store pictures in a database using Long Raw Data type. This data type is used to store binary data for 2 gigabytes of length. However, the table can have only one Long Raw data type.

25) What is BLOB data type in Oracle?

BLOB data type is a data type with varying length binary string. It is used to store two gigabytes memory. For BLOB data type, the length needs to be specified in bytes.

26) What is the difference between TRANSLATE and REPLACE in Oracle?

Translate is used to substitute a character by character while Replace is used to substitute a single character with a word.

27) What are the different types of database objects?

A list of different types of database objects:
  • Tables: This is a set of elements organized in vertical and horizontal fashion.
  • Tablespaces: This is a logical storage unit in Oracle.
  • Views: It is virtual table derived from one or more tables.
  • Indexes: This is a performance tuning method to process the records.
  • Synonyms: This is a name for tables.

28) What is the usage of Save Points in Oracle database?

Save Points are used to divide a transaction into smaller phases. It enables rolling back part of a transaction. There are maximum 5 save points allowed in Oracle Database. Whenever an error is encountered, it is possible to rollback from the point where the SAVEPOINT has been saved.

29) What is the difference between post-database commit and post-form commit?

The post-database commit trigger is executed after Oracle forms issue the commit to finalized transaction while, the post-form commit is fired during the post and commit transactions process, after the database commit occurs.

30) What is Logical backup in Oracle?

Logical backup is used to read a set of database records and writing them into a file. An Export utility is used to take the backup while an Import utility is used to recover from the backup.

31) What do you understand by Redo Log file mirroring?

Mirroring is a process of having a copy of Redo log files. It is done by creating group of log files together. This ensures that LGWR automatically writes them to all the members of the current on-line redo log group. If the group fails, the database automatically switches over to the next group. It diminishes the performance.

32) What is the meaning of recursive hints in Oracle?

The number of times a dictionary table is repeatedly called by various processes is known as recursive hint. Recursive hint is occurred because of the small size of data dictionary cache.

33) What are the limitations of CHECK constraint?

The main limitation of CHECK constraint is that the condition must be a Boolean expression evaluated using the values in the row being inserted or updated and can't contain sub queries.

34) What is the use of GRANT option in IMP command?

GRANT is used to import object grants.

35) What is the use of ROWS option in IMP command?

The ROWS option indicates whether the table rows should be imported.

36) What is the use of INDEXES option in IMP command?

The INDEXES option is used to determine whether indexes are imported.

37) What is the use of IGNORE option in IMP command?

The IGNORE option is used to specify how object creation errors should be handled.

38) What is the use of SHOW option in IMP command?

The SHOW option specifies when the value of show=y, the DDL within the export file is displayed.

39) What is the use of FILE param in IMP command?

FILE param is used to specify the name of the export file to import. Multiple files can be listed, separated by commas.

40) How to convert a date to char in Oracle? Give one example.

The to_char() function is used to convert date to character. You can also specify the format in which you want output.
  1. SELECT to_char ( to_date ('12-12-2012''DD-MM-YYYY') , 'YYYY-MM-DD'FROM dual;  
Or,
  1. SELECT to_char ( to_date ('12-12-2012''DD-MM-YYYY') , 'DD-MM-YYYY'FROM dual;  

41) What are actual and formal parameters?

Actual Parameters: Actual parameters are the variables or expressions referenced in the parameter list of a subprogram.
Let's see a procedure call which lists two actual parameters named empno and amt:
  1. raise_sal(empno, amt);  
Formal Parameters: Formal parameters are variables declared in a subprogram specification and referenced in the subprogram body.
Following procedure declares two formal parameters named empid and amt:
  1. PROCEDURE raise_sal(empid INTEGER, amt REALIS current_salary REAL;  

42) What are the extensions used by Oracle reports?

Oracle reports are use to make business enable with the facility to provide information of all level within or outside in a secure way. Oracle report uses REP files and RDF file extensions.

43) How to convert a string to a date in Oracle database?

Syntax: to_date (string , format)
Let us take an example :
  1. to_date ('2012-12-12''YYYY/MM/DD')  
It will return December 12, 2012.

44) How do you find current date and time in Oracle?

The SYSDATE() function is used in Oracle to find the current date and time of operating system on which the database is running.
  1. SELECT TO_CHAR (SYSDATE, 'MM-DD-YYYY HH24:MI:SS'"Current_Date" FROM DUAL;  

45) What will be the syntax to find current date and time in format "YYYY-MM-DD"?

  1. SELECT TO_CHAR (SYSDATE, 'YYYY-MM-DD HH24:MI:SS'"Current_Date" FROM DUAL;  

Sunday, November 29, 2015

Oracle SQL and PL/SQL Interview Questions Advanced

What is a cursor ? ( Basic)
- Name or handle to a private SQL area where Oracle parses and fetches query results.
How to control how many cursors are open ?(Intermediate)
- Set OPEN_CURSORS parameter in initialization parameters.
What is shared SQL ? (Intermediate)
-Oracle recognizes similar statements. The SQL area is used many times for similar statements.
What is Parsing ? (Intermediate)
- Syntax checking, privileges checking, allocating Private SQL Area.
What is the difference between anonymous blocks and stored procedures ? ( Basic)
- Anonymous block is compiled only when called.
- 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.
- Former has declare statement.Latter doesn't.
What are the advantages of procedures ? ( Basic)
- Loaded once and used many times
- Performance better coz all SQL stmts are sent in one go from the application to the database
- Security ( no object privileges are given directly )
- Invoker's rights possible
- Data integrity, productivity
What are standalone procedures ? (Basic)
- Those that are not part of package
How is a PL/SQL program stored in database ? (Advanced)
- Parsed code is stored. It's called P-code
How is a PL/SQL program executed ?(Advanced)
- 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.
What are the advantages and disadvantages of DBMS_SQL ? (Intermediate)
- It has all the advantages of dynamic sql .. like runtime construction of sql, DDL statements can be executed.
- Its advantage over EXECUTE IMMEDIATE is it can Describe objects
- It's kind of bulky and difficult compared to EXECUTE IMMEDIATE.
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
- Separation helps make development easier
- Dependency is simplified. You can modify body without invalidating dependent objects.
What are the advantages of Packages ? ( Basic)
- Encapsulation of code logic
- Privileges to objects can be controlled
- Loaded once into memory , used subsequently.
- Dependency simplified
- Public/private procs, functions, variables
How do you handle exceptions for bulk operations ? (Intermediate)
- Use the SAVE EXCEPTIONS clause ( FORALL index IN bound_clause SAVE EXCEPTIONS LOOP ... END LOOP )
- Use 'Exceptions When Others' to handle the exceptions
- SQL%BULK_EXCEPTIONS(i).ERROR_CODE,
SQL%BULK_EXCEPTIONS(i).ERROR_INDEX
SQL%BULK_EXCEPTIONS.COUNT
Tell some tips to avoid performance problems in PL/SQL. (Intermediate to Advanced)
- Use FORALL instead of FOR, and use BULK COLLECT to avoid looping many times
- Tune SQL statements to avoid CPU overhead
- Use NOCOPY for OUT and IN OUT if the original value need not be retained. Overhead of keeping a copy of OUT is avoided.
- Reorder conditional tests to put least expensive ones first
- Minimize datatype conversions => Assign data to exact same type variables
- Use PLS_INTEGER for computation intensive code. NUMBER, INTEGER maintain precision and scale but not optimized for performance as additional checks are made to maintain precision and scale.
- Do not use subtypes like POSITIVE, NATURAL, INTEGER as they have additional checks
- Use BINARY_FLOAT, BINARY_DOUBLE
- EXECUTE IMMEDIATE is faster than DBMS_SQL
How to know PL/SQL compile parameters ?(Advanced)
- SHOW PARAMETERS PLSQL
- ALL_PLSQL_OBJECT_SETTINGS
What is MERGE ?( Basic)
- Combination of INSERT and UPDATE
Tell some new features in PL/SQL in 10g (Intermediate to Advanced)
- Regular expression functions REGEXP_LIKE , REGEXP_INSTR, REGEXP_REPLACE, and REGEXP_SUBSTR
- Compile time warnings
- Conditional compilation
- Improvement to native compilation
- BINARY_INTEGER made similar to PLS_INTEGER
- INDICES OF , VALUES OF in FORALL lets you work on non-consecutive indices
- Quoting mechanism . Instead of quoting single quotes twice every time, give your own delimiter to go on using single quotes.
Ex: q'!I'm a string, you're a string.!'
- Flashback Query functions. SCN_TO_TIMESTAMP, TIMESTAMP_TO_SCN
- Implicit conversion between CLOB and NCLOB
- Improved Overloading
- New datatypes BINARY_FLOAT, BINARY_DOUBLE
- Global optimization enabled
- PLS_INTEGER range increased to 32bit
- DYNAMIC WRAP using DBMS_DDL
What is a sequence ? (Basic)
- A database object that offers high-speed access to an integer value
- Guaranteed to be unique (within that sequence).
-Used commonly to generate Primary key values