Вы находитесь на странице: 1из 9

http://newtonapples.

com/oracle-pl-sql-tutorial/

1.What is the difference between VARCAHR and VARCHAR2 in Oracle? Ans) The difference between VARCHAR and VARCHAR2 is:-

Currently VARCHAR is used as VARCAHR2 it means the behavior of VARCHAR is same as VARCAHR2. In future VARCAHR is going to be replaced with VARCHAR2 in next releases of Oracle DataBase. Present versions of Oracle Database even if we define data type as VARCAHR it will be converted into VARCHAR2. VRACHAR can store upto 2000 bytes of data where as VARCAHR2 can store upto 4000 bytes of data. Earlier VARCHAR was fixed in length and right padded with null spaces, however Oracle resolved this issue with VARCHAR2, now only CHAR data type is fixed length data storage.

2. What is the difference between NULL in C and NULL in Oracle? Ans) NULL in C Language is considered as Zero Value where as NULL in Oracle is not considered as zero value or not even any valid value. NULL must be handled very carefully in Oracle. NULL value in C-Language can also be a VOID but in Oracle NULL in undetermined value and cannot be compared that means we cannot compare two NULL values in Oracle. 3.What is the difference between CAHR and VARCHAR2 in Oracle? Ans) The major difference between CHAR and VARCHAR2 is CHAR is fixed in length where as VARCAHR2 is variable length in size. For example assume that we declared CHAR(20) and VARCAHR2(20) and the data value is Newton. Here the size of Newton is 6 CHAR uses all the size and the size is 20 where as for VARCAHR2 the size is 6 the remaining space in CHAR is right padded with null spaces where as in VARCHAR2 it is not. 4. What is structure of Database? Ans) Click on the below link which will take us to the structure of the ORACLE with detail explanation. http://newtonapples.com/what-is-dbms-oracle/ 5. What is the difference between Primary Key and Unique Key Constraints? Ans) Unique key constraint is used if we want in a Column every row value must be different and not equals to each row value in the particular column. If the column is of type Unique Key constraint then we can pass one NULL value. Primary Key is used if we want to identify the values uniquely in a particular row and also to restrict to not to enter any NULL values, i.e, Primary Key is the combination of UNIQUE and NOT NULL constraint.

For example consider in a college students table we are using Hallticket_Number column as UNIQUE then we can pass marks value to a NULL hall ticket number, where as if we use PRIMARY KEY constraint for Hallticket_Number column value then we can restrict these kind of errors to not to happen. For a particular table we can give only one PRIMARY KEY constraint where as UNIQUE can be given to any number of columns which we wish. If we want to give PRIMARY KEY constraint value to more than one column value in a particular table then it leads to COMPOSITE PRIMARY KEY which we can give only at Table level not at Column level declaration of Constraints. 6. What is the purpose of Materialized Views? When they are used? Ans)

A materialized view is a database object that contains the results of a query. Materialized Views is a static view that holds data in it. Materialized views takes the snapshot of the data whenever it is created or refreshed. Materialized views does not support DML operations on it. Materialized views are used to maintain historic data.

7. What is a functional based Index Explain? Ans) Function based index is a index which is based on function instead of a column. We use Function based index to improve performance whenever we have functions used in the SELECT and WHERE clause. The example on Function based Index is as follows:-

SQL> CREATE INDEX na_fbi_job ON emp (UPPER (job));


8. What is Oracle table? Ans) To store data table is the most common form we use. Oracle table contains Rows and Columns as usually like other tables. The table in Oracle is called Database Object. The Object which gets stored in the database and maintained by the Data base is called Data Base objects. All the Database objects are logical because they cannot be seen from the end users. 9. What is Oracle index? Ans) Index is a tree structure that allows direct access to rows in a table.When there are thousands of records in a table, retrieving information will have performance issue. Therefore indexes are created on columns which are accessed frequently, so that the information can be retrieved quickly. INDEX is a pointer locates the physical address of data. Index is a schema object which will speed up the retrieval of rows in a table using pointer locators. The main purpose of using Index is to reduce the disck I/O. The different types of Indexes in Oracle are:-

Unique index Non-unique index

Composite index Function-based index

10. Difference between View and Synonym? Ans) Synonym is an alias name to the Table. It means Synonym is another name to the table like SQL can also be called as SEQUEL. View is a SQL query which contains no data but it will retrieve the data from multiple tables according to the required business logic. View can be stored as a SELECT statement in database. Therefore View is a logical representation of data and Synonym is a database object which acts as alias name to the existing schema object. 11) What are the rules when dealing with Set operators? Ans) We have 4 types of Set Operators namely Union, Union All, Intersect, Minus.

UNION :- Union operator is used if we want the data without duplicates UNION ALL :- Union All is used if we want the data with duplicates. INTERSECT:- If we want to find out the common rows then we go for Intersect. MINUS:- If we want to find out the common values from the first end but not from the second end. 12) What are Constraints what are table level constraints and column level constraints? Ans) Constraint is a condition or a rule or a restriction which is imposed on table data. Constraints are used to enforce business rules on data. We use constraints, if we want to enforce rules whenever a row is inserted, updated or deleted from that table. i.e. For every operation on the table data to succeed, constraint must be satisfied first. Constraint can be added at Table level or Column Level. If we want a condition to be added for only one column value then we can give that constraint condition at that particular column and it is called as table level. If we want a constraint to be added to multiple columns then we define that constraint at Table level and table level constraints can be defined only at the end of finishing all the columns in a table. 13) Can we add NOT NULL constraint at Table level? Ans) No we cannot add NOT NULL constraint at Table level. NOT NULL constraint can be added only at column level. 14) How can you disable an INDEX? Ans) Index can be disabled using Alter command. For example see the below example which disables Index name called Emp_tab_index. Example to disable Index:-

SQL> ALTER INDEX

Emp_tab_index

DISABLE;

15) How can you find out View is updatable or not?

Ans) Seeing the definition of the view we can find out the view is up datable or not if the view is created based on a single table and it doesnt contain any aggregate functions (Group Functions) then that view is updateable If the View is created based on a join statement, or it contains any Aggregate functions then that view is not updateable. 16) What are the types of views? Ans) There are 4 types of views

Normal View Forced View Inline View Materialized View

17) What is Transaction in Oracle? Ans) A transaction is a set of SQL statements with a logical piece of work. A transaction starts whenever data is read or written and finally ends with COMMIT or ROLLBACK. 18) Is public synonym is a Schema Object? Ans) No public Synonym is not a schema object. 19) What is the use of Data Dictionary? Ans) Data Dictionary is the main source of information of every RDBMS. Data Dictionary is a collection of pre-defined set of tables called as dictionary tables (or) System Tables (or) Pre-defined tables. These Data Dictionary tables are created by executing some readymade scripts provided by Oracle. All these tables remain same in all Oracle Softwares. The data available in the Data Dictionary is called as Meta Data. 20) Can Check constraint be used for self referential integrity? Ans) It is possible to use Check Constraint as Referential Integrity. In CHECK condition we can refer to some other column of the same table. 21) Can we define multiple savepoints ? Ans) Yes we can define multiple savepoints. 22) Is it possible to Rollback to any savepoint location? Ans) Yes we can Rollback to any required savepoint location according to the need. 23) What is the maximum number of columns a table can have? Ans) We can create up to 1000 number of columns per table. 24) SYSDATE is a System Variable or System Function? Ans) SYSDATE is a System Function.

25) What is RDBMS (Relational Database Management System)? Ans) A Relational Database Management System (RDBMS) is a database management system (DBMS) that is based on the relational model introduced by E. F. Codd and most popular databases currently in use are based on the relational database model. To put in different words RDBMS is built on top of DBMS in which data is stored in tables and the relationships among the data are maintained. 26) Is it possible to Alter Synonym created on View? Ans) No it is not possible to Alter synonym which is created on View. 27) Can you create Index on View? Ans) No it is not possible to create Index on Views. 28) Difference between Foreign Key and References Key? Ans) The difference between Foreign key and References Key is that as we know we can define constraints at two levels table level and column level. If we are referencing another column of another table at column level then we use References Key. If we are referencing another table column at Table level then we use Foreign Key along with the References key. 29) What is Foreign Key Constraint used for? Ans) Foreign keys are used to refer the parent table primary key column which does not allow duplicates. For parent child relationships across tables, foreign key is always attached to the child table. We use foreign key if we want to ensure that for every child table record there is a reference in parent table. 30) Define various types of joins? Ans) We have two types of joins. Inner Join and Outer Join. Inner join is again divided into two types:-

Equi Join Non-equi join

Outer join is again divided into 3 types:

Left Outer Join Full Outer Join Right Outer Join 31) If we delete the base table wether the synonym will there or not? If we use that synonym what type of error we will get? Ans) IF we delete the base table even though synonym will exist. If we use that synonym the following errors will come ORA-00980: synonym translation is no longer valid ORA-00903: invalid table name ORA-04043: object SCOTT.Table1 does not exist 32) How to create a view with out a table?

Ans) We can create view with out a table by using force command and it is called Force View. A force View is nothing but a view crating forcefully without any existing table in the database. For example see the following query which creates Force View:

SQL> CREATE FORCE VIEW xx_force_view_emp7 AS SELECT * FROM

EMP7;

Here EMP7 table not exit in the database. 33) What is Rollback, Savepoint and Commit? Ans) ROLLBACK: Used to cancel the all previous unsaved transactions. COMMIT: Used to save the data permanently. SAVEPOINT: If we want to save upto the particular transactions then we will divide the transactions with savepoints. 34) Can we change the datatype and size in a table when data is there and when data is not there? Ans) Yes we can change the data type and size when there is no data. When there is data we can change the only the size but we cannot change the data type. 35) What is the syntax for SEQUENCE? Ans) Sequences are used to generate unique sequential values. Sequence values are generally used for Primary Key columns to assign values automatically. The syntax of Sequence is as follows:-

CREATE SEQUENCE <sequence_name> INCREMENT BY <value> START WITH <value> MAXVALUE <value>/NOMAXVALUE MINVALUE <value>/NOMINVALUE CYCLE/NOCYCLE CACHE /NOCACHE ORDER / NOORDER;
36) What is sub query and correlated subquery and difference between these two? Ans) Subqeury is a type of query we will mention a query inside of another query where clause. Sub query is used for filtering data in select statement. The main query will execute based on the result of the sub query. Correlated subquery is also like a subquery .In the ordinary subquery the subquery will execute only once but in the correlated subquery sub query will executes the same number of times as how many times the main query executes. 37) What is the difference between IN & Exist? Ans) IN operator is used if we want to find out a value in a list of values. We will use EXIST operator when we want to find out a value from the Result of subquery. 38) Define GRANT and REVOKE syntaxes? Ans) Grant is part of Data Control Language (DCL) that allows us to grant privileges to other users. The syntax of Grant is as follows:

GRANT <privileges>ON Example:-

<object_name> TO <user_name>;

SQL> GRANT CONNECT, RESOURCE TO user2; SQL> GRANT SELECT, INSERT, UPDATE, DELETE ON emp TO user2; REVOKE command is used to revoke the privileges from the users to whom we have already granted the privileges. The syntax of Revoke is as follows:

REVOKE <privileges>ON Example:-

<object_name> TO <user_name>;

SQL> REVOKE SELECT, INSERT, UPDATE, DELETE ON emp TO user2; 39) What is the syntax of VIEW? Ans) The syntax of VIEW is as follows:

CREATE [OR REPLACE] [{FORCE / NOFORCE}] VIEW <view_name> [(Alias Name, ..)]

AS <Sub Query> [WITH {CHECK OPTION / READ ONLY}] [CONSTRAINT <constraint_name>];


40) How to create Synonym and what is the syntax of Synonym? Ans) The syntax of Synonym and example to create synonym is as follows:

Syntax:CREATE [PUBLIC] SYNONYM <synonym_name> FOR (schema_name).(object_name); Example on Synonym:SQL> CREATE SYNONYM na_emp FOR scott.emp;

41) If you insert a row in a table2, then create another table say table3 and then say Rollback. In this case will the row which we inserted in a table2 is available or not? Ans) Yes the row inserted is available in table2 because Create table is a DDL which commits automatically as soon as it is executed. The DDL commits the transaction even if the create statement fails internally (eg table already exists error) and not syntactically. 42) What is schema? Ans) Schema is collection of database objects. All the objects that user owns are collectively called as schema. A schema, on its part, is always bound to exactly one user. Because there is obviously a 1 to 1 relationship between a user and a schema, these two terms are often used interchangeable. 43) What is Oracle table? Ans) A table in Oracle is a database schema object. Table is the basic unit of storage in Oracle database. Table data is stored in rows and columns. 44) Can we create a view based on another view? Ans) Yes we can create View based on another view. 45) What are the types of synonyms? Ans) There are two types of Synonyms in Oracle

Private Synonym Public Synonym

46) What is a private synonym? Ans) Private Synonym is a synonym that is available to a particular user only. To create a private synonym in our own schema, we must have the CREATE SYNONYM system privilege. Private synonym is specific to the user. 47) What is a Public synonym? Ans) Public Synonym is a synonym which can be accessed by the entire users in the database. These synonyms are generally created by Database administrators. To create public synonym, we should specify PUBLIC keyword in the syntax. Public synonyms can be referenced by all users in the database.

48) What is row chaining in Oracle? Ans) In circumstances, all of the data for a row in a table may not be able to fit in the same data block. When this occurs, the data for the row is stored in a chain of data block (one or more) reserved for that segment. 49) What is a database instance? Ans) A database instance (Server) is a set of memory structure and background processes that access a set of database files. The processes can be shared by all of the users. Database instance is the memory structure that is used to store the most queried data from database. This helps up to improve database performance by decreasing the amount of I/O performed against data file. 50) What is a deadlock? Ans) Two processes waiting to update the rows of a table, which are locked by other processes then deadlock arises. In a database environment this will often happen because of not issuing the proper row lock commands. Poor design of front-end application may cause this situation and the performance of server will reduce drastically. These locks will be released automatically when a commit/rollback operation performed or any one of this processes being killed externally. 51) What is the difference between Truncate and Delete? Ans) Truncate command will delete the entire data in the table but the table structure remains same. Truncate is a DDL command, as all the DDL commands are auto commit commands we cannot ROLLBACK the deleted data once we use Truncate. Delete statement is used to delete specific data rows in the table. It means DELETE command is used to delete only rows in the tables. If we want to delete specific rows then we must mention in the WHERE clause using some condition. Delete is a DML command and we can ROLLBACK the data. 52) Difference between SUBSTR and INSTR functions? Ans) SUBSTR function is used to extract the particular portion of the string. Click here to know more in detail about substr function in Oracle SQL. INSTR function returns integer value indicating the position of the string. Instring (INSTR) calculates the strings using characters as defined by the input character set. Click here to know more about INSTR function in detail. 53) What is ROWID? Ans) Rowid is the pseudo column in oracle. Pseudo column is nothing but which acts like a column but it will not store in any database table. Rowid is 18 characters length. 54) What is the fastest way of accessing a row in a table? Ans) Using ROWID we can access the row in a table very quickly. 55) What is an integrity constraint?

Ans) Integrity Constraint is a rule or condition that restricts values to a column in a table. Based on the Integrity Constraints rule constraints are divided into three types.

Domain Integrity Constraints. Entity Integrity Constraints. Referential Integrity Constraints.

56) What is ON DELETE CASCADE? Ans) ON DELETE CASCADE is an extension to Foreign key constraint. If a parent-child relationship (foreign key relationship) exists between the tables then we will not be able delete the parent record when child exists for it. By using ON DELETE CASCADE clause we can remove the parent record even it Childs exists. Because with ON DELETE CASCADE whenever you remove parent record system automatically removes all its dependent records from child table. 57) Name some data types that allowed in a Table? Ans)

CHAR VARCAHR/VARCHAR2 NUMBER DATE RAW LONG RAW LONG

58) How many LONG columns are allowed in a table? Ans) Only one LONG column is allowed per table. 59) Is it possible to use LONG columns in WHERE clause or ORDER BY? Ans) No it is not possible to use LONG clause in WHERE clause and ORDER BY clause. 60) Which data dictionary tables store Integrity Constraints information? Ans) There are three Data Dictionary tables that stores Constraints information.

User_Constraints All_Constraints Dbs_Constraints

Вам также может понравиться