You are on page 1of 12

Default Constraint

What is default constraint? How we you apply it?


It specifies a default value for a new column or a new default for an existing column. Oracle
assigns this value to the column if a subsequent INSERT statement omits a value for the column.
A DEFAULT expression cannot contain references to other ...

Disable Restricted Session

How do you get back into SQLPlus to disable restricted session if you enabled.
"When database is in restricted mode only users who have restricted permissions can log on to
database"Â To disable itALTERÂ SYSTEM DISABLE RESTRICTED SESSION ...

How many ways you can delete the table records?

In how many ways can I delete all the contents of a table and the entire table. Explain with
syntax?
To delete the records in a table , there are 2 ways . 1.Using the delete statement 2.using the
truncate statement . To delete the entire table drop statement is used . Deleting a record from
a table :use the following statement. delete from table_name .

User defined exception waste

In which section of a PL/SQL block is a user defined exception waste?


Latest Answer: In exception block ...

List all customer (user id, name, and e-mail), number of charging

List all customer (user id, name, and e-mail), number of charging, total charging,number of
transaction and total number of transaction value?If u have these tables:1- 'Credit_card'columns:
credit_number,type,value,Customer_ID.2-'Coupon'columns:
Latest Answer: Hi, One of the solution is as follow: select
cust.customer_id,fname,mname,lname,e_mail,credit.tot_credit+coupan.tot_coup
no_of_recharge,credit.tot_credit_val+coupan.tot_coup_val
tot_recharging,tot_trans,credit.tot_credit_val+coupan.tot_coup_val-current_balance ...

What are the number datatypes allowed in a table?

Latest Answer: There is no restiction on number of datatypes allowed except for long and LOB.I
table can contain only one long column. ...

How is the data inserted in the Index table when a new row is inserted into the main table on
which

1
How is the data inserted in the Index table when a new row is inserted into the main table on
which the index is created ?

How can we use of select query to get the current date and time?

Latest Answer: select to_char(sysdate,'dd/mm/yy hh:mi:ss') from dual; ...

Explian the 18 character long ROWID? How it gets constructed? How we will identify each part of
ROWID?

Explian the 18 character long ROWID? How it gets constructed? How we will identify each part of
ROWID?
What is the fastest way of accessing a row in a table
A ROWID is created by Oracle for each new row in every table, it is a pseudo column that has a
value for every row in a table. The ROWID gives us the physical address of a row and is the
fastest way to access any row. The ROWID contains 3 bits of information, they are :-
The block within the database file.
Row # within the block.
Database file ID.
An example could be :-
000088C9.0191.0002

What is the basic difference between primary key and (unique key along with Not NULL).

Latest Answer: In addition to all this,unique key along with Not NULL constraint has got a name
i.e. "candidate key".So a table having a column which is unique as well as not null apart from
primar key is known as a candidate key.Thanks... ...

If you install SQL*PLUS in client, where does SQL engine run, at server side or client side?
Latest Answer: SQL plus doesn't have engine with that. So the SQL commands will be executed at
the database only. ...

To display the all employee name with end of ‘S’ without using like operator ?

Latest Answer: select employee_name from employees where substr(first_name,-1)='s' ...

How to grant all permission of one user to another user.

Latest Answer: SELECT 'GRANT ' ||privilege ||' ON '||table_schema||'.'||table_name ||' TO '||
USER ||' ;' FROM ALL_TAB_PRIVSWHERE grantee ='TILITS' -- user name that has already access ...

How do you insert image file, sound file using CLOB and BLOB.

2
Latest Answer: --This code will insert a image into database create or replace PROCEDURE
INSERT_BLOB(filE_namE IN VARCHAR2,dir_name varchar2)IStmp number;f_lob bfile;b_lob
blob;BEGINdbms_output.put_line('INSERT BLOB ...

What is theta join??

Latest Answer: Theta Joins Theta joins are joins that use any of the comparison operators:
Greater than, denoted by > Greater than or equal to, denoted by >= Less than, denoted by < Less
than or equal to, denoted by

How many types of data base triggers are there, what is cascading how many types of
queries are there

How many types of data base triggers are there, what is cascading how many types of queries
are there

How Multiple Transactions can be controlled ?

Latest Answer: use savepoint after each DML statement. If using procedure/function then do not
give commit in them. commit in proc/function will erase your savepoints. ...

How many types of joins are there in oracle and what are the difference between them

Latest Answer: There are four Type of joins in oracle1. Inner join2.cartision join3.self join4.
outer join ...

How can we order the column of day (mon to sun)such that monday comes first then tues
and so no.Suppose

select to_char(hiredate,'day') from emp order by to_char(hiredate-1,'d')

What is the difference between Commit and Go

Latest Answer: Commit to like making all the changes permanently in the Server...But in case of
GO statement which is available In SQL Server(TSQL), the set of steps before the GO statement
is complied at once and sent to server...I mean from the beginning of the script ...

HOw to get /select the nth row from the table ?how to select first n rows ,last n rows from a
table

SELECT SKU_CODE,SKU_NAME

FROM (SELECT SKU_CODE,SKU_NAME,ROWNUM A FROM VW_MASTER ORDER BY SKU_CODE) WHERE


A <= 500

Could anyone please explain about hash joins? Thanks.

3
Latest Answer: in cases where a very small table is being joind to large table ,the oracle hash
join will often dramatically speedup the querry hash join are for faster than nested loops join
same cashes.regards pratyush singh ...

How many autonumber columns are allowed?

255 autonumber columns till oracle 7.x.oracle 8 and higher are supporting upto 1000
autonumber columns . We can add upto 1040 column in the table

What is Ref cursor when we use ref cursor andadvantage of ref cursor

Latest Answer: The scope of cursor is limited to a block/ programme. here block/ programme
means upto a end of procedure/function and only one fixed query can be attached to that
cursor.where as the scope of ref cursor is global. Generally ref cursor is used with ...

Difference between a View and Materialized View

Latest Answer: materialized view is physical duplicate data in a table view is logical
representation of table...

Difference between view and table

View is a subset of data derived from table update of data in table we can see in in view but
update in view can not see in table. ...

View is nothing but a set a sql statements together which join single or multiple tables
and shows the data.. However views do not have the data themselves but point to the data.
View is a logical or virtual memory which is based on select query

Whereas Materialized view is a concept mainly used in Data warehousing.. These views contain
the data itself .Reason being it is easier/faster to access the data. The main purpose of
Materialized view is to do calculations and display data from multiple tables using joins. It works
faster than simple, Its works as snap shot and used for security purposes and we can make DML
command in materialize view

How to decrypt the password on oracle 8/8i in system/scott user?what is the query fired to
see the password?

DBMS_OBFUSCATION_TOOLKIT package provides the encryption of password. even DBA can not
come to know what is the password, ofcouse he can reset the new password

What values are stored internally for time (hour,minute ,second) if the date format is dd-
mon-yy??
4
Latest Answer: In sqlserver 2005 we can use as follows to retreive the date part of the given
date or sys dateselect datepart(dd,getdate()) ...

What is the condition to be follwed for the natural join syntax to be correct??

Latest Answer: It implicitly construct the join condition on the 2 tables taking all the column
with same name into consideration.Natural join is also called blind join.selectÂ
employee_id,last_name,department_name from employees natural join departments; ...

What is the difference between Inner and equi join?

Latest Answer: Inner jon Or equi join is The query that retrives the rows that exact match using
(=) sign in where clause ...

Inner joins are equi and non equi joins (<> , = conditions in the where clause ). An inner join is a
type of join where we use = and <> in the where condition joining the tables. In an equi join we
join tables with = operator only

What is the function of 'force' in view?


Latest Answer: "Force" option used to create a view without existance of Table in the
databaseSyntax: Create or replace FORCE VIEW as select * from

A table has following layout ; CITY, NAME , SEXHow do you write a query to get the count of
Male, count

How do you set AutoComit off for DDL commands in Oracle Server? Is this Possible..?

For DDL commands, We cannot do autocommit off. It is modify structure A of database object
such as table, view and these commands have automatically commit.Set autocommit on/off is
used for DML. ...

How to execute the following query without using tempselect * from temp;

SELECT * FROM (SELECT TABLE_NAME FROM USER_TABLES WHERE TABLE_NAME LIKE 'TEST');Above
query will give the result as TEST.If you dont want to use the table name directly in the query,
you can create synonym for that table and can use that synonym in your ...

What is ALTER TABLE? HOW WE USE IT TO ADD A NEW ROW?

5
by using alter table we can alter only column not the rows. by using alter command we write
query like this........alter table table_name add column_name datatype;for drop that column
;alter table table_name drop column_name datatype;it's ...

How to use command "COMMIT” and "ROLLBACK" in a transaction?

COMMIT: it is used to make the manipulations ENABLE permanently on the table where as
ROLLBACK is used to DISABLE the effect of the queries(which were typed a bit above it) on the
table. one ROLLBACK statement is sufficient ...

what is the process of connecting to Database manually in oracle Database

Latest Answer: The startup of database depends on the nature of Oracle server :Incase Of
Enterprise Server and Unix Environment :Go to Unix and type the following commands :sqldba
lmode=yconnect internalstartup This will start the Oracle Instance. Incase Of Workgroup ...
in 9i sqlplus /nolog
connect /as sysdba
startup

What is Snapshot in oracle 9i and what is different between view and Snapshot?

Latest Answer: In Oracle 9i instead of snapshot we can use meterialized views which can act as
snapshot.Diff between view & snapshot is view is not a table its a virtual table to join one or
more table or to prevent access from users on complete data on table. whenever ...

IS 'define' a valid SQL statement?

Latest Answer: if DEFINE is isqlplus command then how do u define ACCEPT command. what is
difference between them?i think define is a command in sql *plus which works same in isqlplus
with ACCEPT.pls do forward the argument. ...

Explain UNION, MINUS, UNION ALL and INTERSECT


UNION - the values of the first query are returned with the values of the second query
eliminating duplicates. MINUS - the values of the first query
Latest Answer: UNION: Take the common record once( No Duplicate)
UNION ALL : Takes Duplicates also
Minus: Result of first query - result of second queryexamleselect * from emp where rownum

Explain the different types of joins

Latest Answer: There are 5 types of joins available in sql server1) inner join2) outer join( left
outer join,Right outer join)3) Full Join4) Cross Join5) Self Join1) inner Join : Two tables having
the common column values go with inner join.Example:select * from emp ...

6
What is difference between TRUNCATE & DELETE

TRUNCATE is a DDL command and cannot be rolled back. All of the memory space is released
back to the server. DELETE is a DML command and can be rolled
DELETE is a logged operation on a per row basis. This means that the deletion of each row gets
logged and physically deleted. You can DELETE any row that will not violate a constraint, while
leaving the foreign key or any other contraint in place. ...

Is it possible to access the current value in a session before accessing next value

Latest Answer: Nextval must be used to generate a sequence number in the current user's
session before currval can be referenced. ...

What is a transaction ?

Transaction is logical unit between two commits and commit and rollback.
Latest Answer: A Transaction is a logical unit of work that comprises one or more SQL
statements executed by a single user. ...

What is the maximum number of triggers, can apply to a single table

Latest Answer: there can be n number of trigger can have in a table . type of trigger may be
12 ...

How do I eliminate the duplicate rows

Latest Answer: With the help of Distinct function ...

Can a view be updated/inserted/deleted

Latest Answer: If a view is based upon a single table then DML operations can be performed on
it, while if a view is based upon more than two tables then it is a complex view and DML
operations can be performed using instead of triggers. ...

If a View on a single base table is manipulated will the changes be reflected on the base
table

What is meant by SORTING and GROUPING

Latest Answer: sorting mean puting the value in a particular order , could by alhphabatic

7
grouping mean making a group of same type of values and displaying a single row for that group
example select deptno, sum(sal) from emp group by deptno order by ;

What are the different types of OUTER JOINS

Latest Answer: LEFT OUTER JOIN, RIGHT OUTER JOIN, FULL OUTER JOIN ...

Subquery vs Join

subquery is faster when we have to retrieve data from large number of tables.Because it
becomes tedious to join more tables.
join is faster to retrieve data from database when we have less number of tables

What are the more common pseudo-columns

SELECT rownum, rowid FROM sometable


Besides these, the other pseudo columns are: user,uid ... Currval, Nextval

Implicit Cursor attributes

SQL%FOUND, SQL%NOT FOUND,SQL%ROW COUNT as implicit cursor attributes. sql% is not a valid
implicit cursor attribute, open is there but it will always return "false" for implicit cursor ...
Explicit & Implicit crusors have same attributes. ...

What are the different types of SQL

DQL(Data Query Language) select


DML(Data Manupulation Language) insert, update, delete, merge
DDL (Data Defination Language) Create, alter, drop, rename, truncate
TCL (Transaction Control Language) Commit, rollback, save point
DCL (Data control Language) grant, revoke

What is difference between CHAR and VARCHAR2


A varchar2 datatype, when stored in a database table, uses only the space
allocated to it.varchar2(50) and our entry ia of 30 bute then it will only occupy 30 bute and
other will b null.It can also store number as well as char.
CHAR only store character, always uses the maximum length

What are the different tablespaces in database

There are only three tablespaces as follows:-1.Permanent tablespace


2 .Undo tablespace 3.Temperory tablespace ...
8
A tablespace is a collection of one or more datafiles.all database objects are stored in
tablespaces.
diff types of tablespaces:-
1)system tablespace.2)temp tablespace.3)tools tablespace4)users tablespace.
5)rollback tablespace.6)data and index tablespace.

Display Odd/ Even number of records

We can use the below query to get the odd record of the table
select r from (SELECT rownum r FROM EMP)where mod(r,2) != 0
We can use the below query to get the even record of the table
select r from (SELECT rownum r FROM EMP)where mod(r,2) = 0

What is an integrity constraint

An integrity constraint is a rule that restricts the values in a database. There are six types: A
NOT NULL constraint prohibits a database value from being null. A unique constraint prohibits
multiple rows from having the same value in the ...

What is the output of SIGN function

SIGN (a): Returns 1 if a is positive ,-1 if a is less than 0 and 0 if a is 0 ...

What are the pre-requisites to modify datatype of a column and to add a column with NOT
NULL constraint

To modify the datatype of a column that should be empty, but if increasing the width then it can
be done even it holds the value.
To add not null column the table must be empty if not then add the column as nullable then
modify that column as not null.

The use of HAVING, WHERE and GROUPBY in one SQL

where condition we cann't use group function but having clause allows it, both r used 4 data
restriction only.group by is used 4 grouping similar items

If a view on a single base table is manipulated will the changes be reflected on the base
table

if a view based on one table or multiple table matter is it should contain all not null columns and
additionaly no calculated column then ant DML statement will cause changes in base table.

What is a database link


it is a way of connecting to remote database.
scott@8i> create database link ora8idev
2 connect to scott
3 identified by tiger

9
4 using 'ora8idev'
5 /
Database link created.
scott@8i> select * from dual@ora8idev;

Explain CONNECT BY PRIOR

it is used to get a tree type structure in data.


The start with .. connect by clause can be used to select data that has a hierarchical
relationship (usually some sort of parent->child (boss->employee or thing->parts).

select a.*, level from emp a


start with mgr is null
connect by mgr = prior empno;

How to drop the column in a table

Alter table <table name> drop column <column name>;


To make a column unused you could have following command:
SQL> Alter table <table name> set unused column <column name>;

if commission is null then the text “Not Applicable” want to display, instead of blank space.
How do I write the query
select ename,decode(nvl(comm,0),0,'Not Applicable',comm) from scott.emp;

SELECT NVL (To_Char(comm), 'Not Applicable') FROM table_name;


What are PL/SQL Cursor Exceptions

Latest Answer: Cursor_already_open, Invalid_cursor ...

How to access the current value and next value from a sequence

for current value the function is :- sequence_name.currval


and for the next value it is sequence_name.nextval
Difference between SUBSTR and INSTR

INSTR function finds the numeric starting position of a string within a string.

Select INSTR('Mississippi','i',3,3) test1,


INSTR('Mississippi','i',1,3) test2,
INSTR('Mississippi','i',-2,3) test3
from dual;

Test1 Test2 Test3


___________________________________________
11 8 2

SUBSTR function returns the section of thte specified string, specified by numeric character
positions.

Select SUBSTR('The Three Musketeers',1,3) from dual; -- will return 'The'.

10
What are the advantages of VIEW

The advantages of View are:

Security: only selected column from a table made available to view.

Complexity: write a complex query and assign this query to a view so next time no need to write
that complex query.

Faster: view refers to a query which is already parsed, so again it does not go to that stage

efficient: while writing trigger a condition may arise, trigger makes the table in mutating state,
so use of views in this scenario makes it easy.

How will you activate/deactivate integrity constraints

Alter table modify constraint < constraintname> disable/enableexamplealter table CONTACT_US


modify constraint CONTACT_US_UK disable;

How many LONG columns are allowed in a table

Only one column can have LONG data type. And that column cannot be used in WHERE clause or
in ORDER BY clause. Also we cannot add primary key constraint to that column only not to the
whole table, that means we will give primary key to any column in the

What is referential integrity constraint


Referential Integrity Constraint is used to specify interdependencies between relations. This
constraint specifies a column or list of columns as a foreign key of the referencing table.
A foreign key means the values in one table must also appear in another table. The foreign key
in the child table will generally reference a primary key in the parent table. The referencing
table is called the child table & referenced table is called the parent table.
Syntax: constraint <constraint name> references <primary table><primary key>

Referential Integrity Constraint is used to specify interdependencies between relations. This


constraint specifies a column or list of columns as a foreign key of the referencing table. A
foreign key means the values in one table must also appear in another

Is it possible to use LONG columns in WHERE clause or ORDER BY

NO, Long column can not used in where, order by clause


A table can have only one long column

How to drop the index

11
if index is create by primary key /unique key constraint thenby droping the constriant , the
index will be droped automaticallyelsedrop index

Other way to replace query result null value with a text

select empno, ename, mgr, nvl(to_char(mgr),'no manager') from emp;

Any three PL/SQL Exceptions

TOO_MANY_ROWS
NO_DATA_FOUND
INVALID_CURSORS
CURSOR_ALREADY_OPEN
DUP_VAL_ON_INDEX

What is correlated sub-query

In correlated subqueries, the information from the outer select statement participates as a condition
in the inner select statement.
Eg : Select deptno, ename, sal from emp a
where sal> (select avg(sal) from emp b where a.deptno =b.deptno)
order by deptno;

If unique key constraint on DATE column is created, will it validate the rows that are
inserted with sysdate

Yes. Becoz sysdate contains date and time.

What is ON DELETE CASCADE

ON DELETE CASCADE option permits deletions of referenced key values in the parent table and
automatically delete dependent rows in the child table to maintain referential integrity.

12

You might also like