You are on page 1of 4

Difference between decode and case.

in which case we are using case and in which case we are using decode? with an example.

SELECT ENAME,SAL,DECODE(DEPTNO,10,'ACCOUNTING',20,'RESEARCH',30,'SALES',40,'OPERATI ONS','OTHERS') "DEPARTMENTS" FROM EMP Select case snum when snum > 10 then 'High' when snum>5 then 'Low' end from sales Using CASE expression we can use all comparative operators (<,>,==, etc), where as using DECODE we should always use = condition.

Question : How can i hide a particular table name of our schema.

you can hide the table name by creating synonyms. e.g) you can create a synonym y for table x create synonym y for x;
How to delete same id in rows? For example empid=5 repeated for times in rows. How to delete which sql query is used?

delete from emp_dup where rowid not in (select min(rowid) from emp_dup group by empno); delete duplicate rows delete from emp_dup2 where rowid not in (select min(rowid) from emp_dup2 group by empno,ename,job,mgr,hiredate,sal,comm,deptno)

Question : Which system tables contain information on privileges granted and privileges obtained? Answers:

USER_TAB_PRIVS_MADE, USER_TAB_PRIVS_RECD.
Question : What is normalization and different kinds of normalization?

Normalization is a process of decomposing a complex table into simplest form.The main idea is to reduce the redundancy.Usually,it divides the database into 2 0r more tables and define a relationship between them.The main objective is to isolate the data,so that if any modifications or updation is needed for a field,then it can be done just in one table

and can be propagated to other tables in the dbase via the defined relationships. There are many types of normal form,1NF,2nd NF,3rd NF,4thNF etc. 2. Joins are used to identify the relationships between the tables. Inner join,outer join(left outer join,right outer join),self join,cross join
Question

select name from v$database


: How to find out the database name from SQL*PLUS command prompt?

Select * from global_name select name from v$database


Question : What the difference between UNION and UNIONALL?

union wont allow the duplicates,where as unionall allows the duplicates. while we use union the result will be sorted in the asc order of the first col of the select statement by default.where as no sorting in unionall by default.

Question : Which function is used to find the largest integer less than or equal to a specific value?

No answer
Question : What is the use of the DROP option in the ALTER TABLE command?

It is used to delete The Constraints on the table or delete column in the table
Question : Cursor Syntax brief histor

To process multiple records in pl/sql. Type: Explicit - Declare by user and used by user Implicit - Delare by Oracle and used by user and Oracle. Life Cycle of Explicit Cursor: Declare: Used to declare explicit cursor. Cursor <Cursorname> is Select stmt; Open:

Execution is done here. Open <Cursorname>; Fetch: Retrieval of data into variable is done through this section. Fetch <Cursorname> into <Var>; Close: Explicitly closes the Cursor. Close <Cursorname>;
Question : TRUNCATE TABLE EMP; DELETE FROM EMP; Will the outputs of the above two commands differ?

A delete statement deletes all records in the table, but it does not free any space. A Truncate statement frees the space as well. However, a truncate can not be rolled back but delete can be rolled back. TRUNCATE is more fastre than DELETE. Truncate requires special privileges to be granted on the table
How can I change my default date format?

We can change it by using this SQL commnd ALTER SESSION set nls_date_format='desired format';
There is a eno & gender in a table. Eno has primary key and gender has a check constraints for the values 'M' and 'F'. While inserting the data into the table M was misspelled as F and F as M. What is the update statement to replace F with M and M with F?

update empsex set sex=decode(sex,'M','F','F','M')


What is the advantage of specifying WITH GRANT OPTION in the GRANT command?

The privilege receiver can further grant the privileges he/she has obtained from the owner to any other user.

What is the difference between Truncate and Delete interms of Referential Integrity?

DELETE removes one or more records in a table, checking referential Constraints (to see if there are dependent child records) and firing any DELETE triggers. In the order you are

deleting (child first then parent) There will be no problems. TRUNCATE removes ALL records in a table. It does not execute any triggers. Also, it only checks for the existence (and status) of another foreign key Pointing to the table. If one exists and is enabled, then you will get The following error. This is true even if you do the child tables first. ORA-02266: unique/primary keys in table referenced by enabled foreign keys You should disable the foreign key constraints in the child tables before issuing the TRUNCATE command, then re-enable them afterwards.

You might also like