0% found this document useful (0 votes)
4 views

Oracle-2

This document provides detailed instructions on managing tables and data in Oracle, including how to create, insert, alter, and update tables. It explains SQL commands such as CREATE TABLE, INSERT INTO, and ALTER TABLE, along with examples and constraints like primary key, foreign key, unique key, not null, and check constraints. Additionally, it includes a series of one-word question and answer sections for quick reference on key concepts.

Uploaded by

hirenheckar55
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Oracle-2

This document provides detailed instructions on managing tables and data in Oracle, including how to create, insert, alter, and update tables. It explains SQL commands such as CREATE TABLE, INSERT INTO, and ALTER TABLE, along with examples and constraints like primary key, foreign key, unique key, not null, and check constraints. Additionally, it includes a series of one-word question and answer sections for quick reference on key concepts.

Uploaded by

hirenheckar55
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 37

CHAPTER -2(MANAGING TABLES AND DATA)

Q- HOW TO CREATE TABLE? EXPLAIN WITH EXAMPLE.

USE CREATE TABLE COMMAND TO


CREATE NEW TABLE IN ORALCE

CREATE TABLE:
The CREATE TABLE statement allows you to create and define a table.

Syntax:
CREATE TABLE table_name
(
Column 1 data type(size),
column 2 data type(size),
...
Column data type (size)
);

Each column must have a data type.


Column name must not contain space or any special
character. It can contain underscore (_).
The column should either be defined as "null" or "not null" and if this value is
left blank, the database assumes "null" as the default.

Example:
Create table student
(
studno number(2),
studnm varchar2(20),
sem number(1),
course varchar2(6),
join_dt date
);

ONE WORD QUESTION ANSWER

SR.NO QUESTION ANSWER


1. WHICH COMMAND CAN USE CREATE TABLE
TO CREATE NEW TABLE? COMMAND

2 COLUMN NAME MEANS FIELD NAME

3 HOW MANY DATY TYPES ARE BOTH


USE
4 IT IS CASE SENSITIVE? NO
5 ‘ ‘ IT MEANS WHEN USET ENTER
TEXT & DATE AT
THAT
TIME ‘ ‘ IS USE.
HOW TO INSERT DATA INTO TABLE? EXPLAIN WITH EXAMPLE.

USE INSERT INTO COMMAND WE CAN INSERT DATA INTO


TABLE.

INSERT INTO STATEMENT:


The INSERT INTO statement allows you to insert a single record or
multiple records into a table.

Syntax 1: Inserting value in all the fields of table

INSERT INTO table-name


VALUES (value-1, value-2, ... value-n);

Example:

Insert into student values (11,’Palak’,1,’PGDCA’,’01-Jun-2008’);

Syntax 2: Inserting values in all the fields of table using variable.

INSERT INTO table-name


VALUES (&variable1, &variable2, …, &variableN);

Example:
INSERT INTO student VALUES
(&student_no,’&student_nm’,&semester,’&course’,’&Joining_date’);

Here, student_no, student_nm, semester and course and


joining_date are variables.

Rules:
1. Variable name can be same as column name of the
table or it can be different.
2. Space is not allowed in variable name.
3. Variable that represents Varchar2, Char and Date type
of columns, must be written in single bracket (‘ ‘).

Syntax 3: Inserting values in selected


fields.

INSERT INTO table-name (column name1, column name2, column


name3)
VALUES (value1, value2,
value3);

Exam
ple:
INSERT INTO student (studno,studnm,course)
VALUES (10,’Ravi’,’PGDCA’);

Syntax 4: Inserting values in selected fields using variable.

INSERT INTO table-name (column name1, column name2, column name3)


VALUES (&variable1, &variable2,
&variable3);

Example:
INSERT INTO student (studno,studnm,course)
VALUES (&student_no,;&student_name’,’&course’);
ONE WORD QUESTION ANSWER

SR.NO QUESTION ANSWER


1. USE OF INSERT COMMAND INSERT RECORD IN
TABLE
2 CAN MULTIPLE RECORD ARE YES
INSERT INTO TABLE?
3 HOW MANY TYPES OF BOTH
METHODS ARE AVAILBLE TO
INSERT INTO TABLE
4 MAXIMUX LIMIT OF RECORD NO LIMIT.
ARE

HOW TO ALTER TABLE? EXPLAIN WITH EXAMPLE.

ALTER MEANS CHANGE THE STRUCTURE OF TABLE


WE CAN ADD OR MODIFY THE TABLE STRUCTURE.
ALTERING OR MODIFYING STRUCTURE OF TABLE
Syntax 1: Adding new column in the table.

ALTER TABLE table-name


ADD (newcolumnname datatype(size), newcolumnname datatype(size), …);

Example:

ALTER TABLE student


ADD (result varchar2 (20));

Syntax 2: Modifying existing column

ALTER TABLE table-name


MODIFY (columnname newdatatype(newsize));

Example:

ALTER TABLE student


MODIFY (course varchar2 (7));

Restriction on ALTER TABLE:

1. One cannot change the name of the table.


2. Once cannot change the name of the column.
3. One cannot drop (remove) the column.

Note: Dropping a column is possible in Oracle 8i onwards versions of oracle.

Syntax is ALTER TABLE table-name DROP COLUMN column name.

4. One cannot decrease the size of a column if table data exists.


5. One cannot change the data type of a column if table data exists.

ONE WORD QUESTION ANSWER

SR.NO QUESTION ANSWER


1. ALTER MEANS ADD OR MODIFY
STRUCTRE
2 ADD MEANS ADD NEW COLUMN

3 MODIFY MEANS CHAGE THE COLUMN


4 CAN WE CHANGE TABLE NO
NAME?
5 CAN WE DROP COLUMN? NO
6 CAN WE CHANGE THE NO
COLUMN NAME?
7 CAN WE DECRESE THE SIZE OF NO
COLUMN IF DATA IS IN
TABLE?

WHAT ARE CONSTRAINTS? EXPLAIN IT.


ANS:

CONSTRAINT MEANS RULES. ONE TYPE OF CONDITION.


DETAILING:-
Rules which are enforced on data being entered
and prevent the user from entering invalid data into
tables are called Constraints.
The data passes this check, can stored in the table otherwise the data is
rejected.
If a single column of the record being entered into the table fails a
constraint, the entire record is rejected and not stored in the table.
Constraints can be connected to a column or a table by CREATE TABLE or
ALTER TABLE command.
Thus, oracle allows defining constraint at
Column Level
Table Level

Column Level constraint


o When data constraints are defined along with the column
definition while creating or altering table, they are known
as column level constraints.
Table Level constraint

o When data constraints are defined


after defining all the columns of table while
creating or altering table, they are known
as table level constraints.

TYPES OF DATA CONSTRAINTS


There are two types of
data constraints
1.I/O Constraints
2.Business Rule Constraints
1. I/O Constraints:

The Input/output (I/O) constraints are further divided into two


different constraints
a. Primary Key constraint
b. Foreign Key Constraint
Oracle also has NOT NULL & UNIQUE
constraints.

2. Business Rule Constraints:


Business rule can be implemented in
Oracle using CHECK constraint. Business
Managers determine business rules.
ONE WORD QUESTION ANSWER

SR.NO QUESTION ANSWER


1. CONSTRAINT CAN DEFINE CREATE TABLE AND
IN TABLE SO WE CAN USE ALTER TABLE
WHICH COMMAND COMMAND
2 HOW MANY TYPES OF 2
CONSTRAINT ARE AVAILABLE
3 LIST THE NAME OF I/O AND BUSINESS
CONSTRAINTS
4 IS CONSTRAINTS SPECIFY YES
WHOLE COLUMN?
5 IF CONSTRAINTS IS FAIL THEN NO NOT INSERT
RECORD IS INSERT OR NOT?

EXPLAIN PRIMARY KEY WITH


EXAMPLE. DETAILING:-

A primary key is one or more column in a table used to identify each row
uniquely in table.
Once the column has defined Primary Key constraint, it gets NOT NULL and
UNIQUE constraints.
A single column primary key is called a Simple Key and Multicolumn primary
key is called Composite Primary Key.

PRIMARY KEY constraint at column level:

Syntax:
Column name data type (size) PRIMARY KEY,

Example:
CREATE TABLE
emp (
empno varchar2(4) PRIMARY KEY,
empnm varchar2(15),
address1 varchar2 (20),
address2 varchar2 (20),
City varchar2 (15)
);

e Now, after creating table, empno column must not be NULL and value
entered in empno column must be UNIQUE means one cannot repeat
the value of empno column.

PRIMARY KEY constraint at table level:

Syntax: PRIMARY KEY (<column name> [, <column name> , … ])

Example:
CREATE TABLE empdept
(
empno varchar2(4),
empnm varchar2(15),
deptno varchar2(3),
Salary number (10, 2),
PRIMARY KEY (empno, deptno)
);
Now, after creating table, empno & deptno must not be NULL and value
entered in empno & deptno column must be UNIQUE.

Suppose the user is entering following record after creating table

INSERT INTO empdept values (‘e101’, ‘Kishan’, ‘d1’, 7000);


Record added successfully. Now user is entering another record

INSERT INTO empdept values(‘e101’ , ‘K1’ , ‘d11’ , 3000);

This record will not get added and error has been generated.
When composite primary key is defined, table will not accept the value if
the data of the entire composite column gets repeated.
It accepts the value if any one of the composite key column value gets
repeated.

ONE WORD QUESTION ANSWER

SR.NO QUESTION ANSWER


1. PRIMARY MEANS UNIQUE
2 HOW MANY WAY TO DEFINE 2
PRAMAY KEY
3 PRIMARY KEY USE FOR YES
RELATION?
4 HOW MANY WAY TO DEFINE 2LIKE COLUMN LEVEL
PRAMAY KEY AND TABLE
LEVEL.

EXPLAIN FOREING KEY WITH


EXAMPLE. DETAILING:-
FOREIGN KEY constraint

Foreign key represent relationships between tables.

A foreign key is a column or group of columns whose values are derived


from the primary key of some other table.
The table in which foreign key is defined is called a foreign key table or
detail table.
The table that defines the primary key and is referenced by the foreign
key is called primary table or master table.

Principles of foreign key constraint:

 e Rejects an INSERT or UPDATE of a value, if a corresponding


value does not exist in the master key table.
 If the ON DELETE CASCADE option is set, a DELETE operation in
the master table will DELETE corresponding records in the detail
table also.
 Rejects a DELETE for the master table if corresponding
records in the detail table exist.
 Must reference a PRIMARY KEY or UNIQUE column in primary table.
 Will automatically reference the PRIMARY KEY of the master table if no
column or group of columns is specified when creating the foreign
key.
 Foreign key column and primary key column must have same
data type and size.
 Foreign key column name and primary key column
name may be different.
 One column can be primary key column and foreign key column too.

FOREIGN KEY at column level:

Syntax:
Column name data type (size) REFERENCES table name [(column name)] [ON DELETE
CASCADE]

Example:
CREATE TABLE empdetail
(
empno varchar2(4) REFERENCES
emp, Salary number (10, 2),
Design varchar2 (4)
);

FOREIGN KEY at table level:


Syntax:
FOREIGN KEY (column name [, column name , …]) REFERENCES table
name [(column name) [, column name , … ] ]

Example:
CREATE TABLE empdetail
(
empno varchar2(4),
Salary number (10, 2),
Design varchar2 (4),
FOREIGN KEY empno REFERENCES emp(empno)
);

ONE WORD QUESTION AND ANSWER


SR.NO QUESTION ANSWER
1. FOREIGN KEY DEFINE RELATIONSHIP
2 FOREIGN KEY CALL DETAIL TABLE
3 FOREIGN KEY CAN RELATION PRIMARY KEY.
WITH WHICH KEY?
4 HOW MANY WAY TO DEFINE 2LIKE COLUMN LEVEL
FOREIGN KEY AND TABLE
LEVEL.
EXPLAIN UNIQUE KEY WITH
EXAMPLE. DETAILING:-

e The purpose of UNIQUE constraint is to ensure that the data in


the column is unique and it must not be repeated across the
column.
e A table can have more than one UNIQUE key column.

UNIQUE constraint at column level:

Syntax:
Column name data type (size) UNIQUE,

Example:
CREATE TABLE
emp (
empno varchar2(4) UNIQUE,
empnm varchar2(15)
address1 varchar2 (20)
address2 varchar2 (20),
);

UNIQUE constraint at table level:

Syntax:
UNIQUE (columnname [, columnname , … ])

Example:
CREATE TABLE
emp (
empno varchar2(4),
empnm varchar2(15),
address1 varchar2 (20),
address2 varchar2 (20),
city varchar2(15),
UNIQUE (empno)
);

ONE WORD QUESTION AND ANSWER

SR.NO QUESTION ANSWER


1. UNIQUE MEANS NOT REPEAT
2 HOW MANY WAY TO DEFINE 2
UNIQUE KEY
3 UNIQUE KEY USE FOR NO
RELATION?
4 HOW MANY WAY TO DEFINE 2LIKE COLUMN LEVEL
UNIQUE KEY AND TABLE
LEVEL.
EXPLAIN NOT NULL AND CHECK CONSTRAINTS WITH EXAMPLE.

DETAILING:-
NOT NULL constraints:
 A NULL value is different from space or zero.
 A NULL value can be inserted into the column of any data type.
 NOT NULL constraint at Column Level:
When a column is defined as not null, it becomes mandatory column.
It means that a value must be entered into the column.

Syntax:
Columnname datatype(size) NOT NULL,

Example:
CREATE TABLE
emp (
empno varchar2 (4) NOT NULL,
empnm varchar2 (15) NOT NULL,
address1 varchar2 (20),
city varchar2(15) NOT NULL
);

Note: NOT NULL constraint cannot be applied at table level; it can only be
applied at column level.

CHECK constraint

Business Rule validations can be applied to a column using CHECK constraint.


CHECK constraint must be specified as logical expression that evaluates either
to TRUE or FALSE.

CHECK constraint at column level:

Syntax:
Column name data type (size) CHECK (logical expression)

Create a table with following check constraints

empno must start with ‘E’


data entered in empnm column must be upper
case.
Only allow “Bombay”, “Delhi”, “Rajkot” and “Pune”
as city name.
Example:
CREATE TABLE
emp (
empno varchar2(4) CHECK(empno like ‘E%’),
empnm varchar2(15) CHECK(empnm=upper(empnm)),
address1 varchar2 (20) NOT NULL,
address2 varchar2 (20),
city varchar2(15) CHECK(city IN (‘bombay’,’delhi’,’rajkot’,’pune’))
);
CHECK constraint at table level:

Syntax:
CHECK (logical expression)

Example:
CREATE TABLE
emp (
empno varchar2(4),
empnm varchar2(15),
city varchar2(15),
CHECK(empno like ‘E%’),
CHECK(empnm=upper(empnm)),
CHECK(city IN (‘bombay’,’delhi’,’rajkot’,’pune’))
);

Restrictions on CHECK constraints:


a. The condition must be a Boolean expression.
b. The condition cannot contain sub query or sequence.
The condition cannot include the SYSDATE, UID, USER or USERRENV
functions.

ONE WORD QUESTION AND ANSWER

SR.NO QUESTION ANSWER


1. NOT NULL MEANS MANDATORY ENTRY
2 HOW MANY WAY TO DEFINE 1
NOT NULL KEY
3 CHECK CONSTRAITS USE BUSINESS RULES.
FOR
4 HOW MANY WAY TO DEFINE 2LIKE COLUMN LEVEL
CHECK CONSTRAINTS AND TABLE
LEVEL.

HOW TO UPDATE RECODRS IN TABLE? EXPLAIN

IT. DETAILING:-

UPDATE statement
The UPDATE command is used to change or modify data values in a table.
UPDATE statement can update all the rows from a table or selected rows
from the table.

Syntax 1: Update all rows from table.


UPDATE table-name
SET column name=expression, column name=expression,..;
xample:
UPDATE student
SET sem=2;

Syntax 2: Update selected rows from table.


UPDATE table-name
SET <column name>=expression, <column name>=expression, …
WHERE <column name>=expression;

Example:
UPDATE student
SET studnm=’Meeta’
WHERE studnm=’Mita’;

ONE WORD QUESTION AND ANSWER

SR.NO QUESTION ANSWER


1. UPDATE MEANS MODIFY RECORED
2 WHICH KEY WORD USE WITH SET AND WHERE
UPDATE
3 CAN WE UPDATE ALL YES
RECORED AT A TIME IN
UPDATE COMMAND?
4 CAN WE UPDATE SPECIFY YES
RECORD IN USE OF
UPDATE
COMMAND?

HOW TO DELETE RECORDS OF TABLE? EXPLAIN IT.


DELETE Statement

Delete Statement is used to remove all rows from a table or selected


rows from a table.
Syntax 1: Remove all rows
DELETE FROM table-name;

Example:
DELETE FROM student;

Syntax 2: Remove selected rows


DELETE FROM table name
WHERE column name=expression;

Example:
DELETE FROM student
WHERE studno>60;

TRUNCATE statement

TRUNCATE TABLE removes all rows from a table.


TRUNCATE TABLE is functionally identical to DELETE statement with no
WHERE clause but TRUNCATE TABLE is faster and uses fewer system and
transaction log resources than DELETE.

Syntax:
TRUNCATE TABLE table-name;

Example:
TRUNCATE TABLE student;

ONE WORD QUESTION AND ANSWER

SR.NO QUESTION ANSWER


1. DELETE MEANS TO REMOVE RECORDS
2 TRUNCATE CAN REMOVE NO
SPECIFY RECORD?
3 DELETE CAN REMOVE ALL YES
THE RECORDS OF TABLE AT
A
TIME?
4 DELETE CAN REMOVE YES
SPECIFY RECORD INTO
TABLE?
EXPLAIN SELECT STATEMENT WITH
EXAMPLE. DETAILING:-
The SELECT statement allows you to retrieve records from one or more tables.

Syntax 1: Selected column and all rows


SELECT columnname1, columnname2 … column name n FROM <table name>;

Example: SELECT empno, empnm, address1, city FROM EMP;

Syntax 2: All rows and all columns


SELECT * FROM <table name>;

Example: SELECT * FROM

Selected rows and all columns:


· To retrieve selected rows from the table, Oracle provides ‘where’ clause in
an SQL statement.
· When ‘where’ clause is added to the SQL statement, the Oracle Server
compares each record from the table with the condition specified in
the ‘where’ clause and display only those records that satisfy the
specified condition.

Syntax:
SELECT * FROM <table name> WHERE <column name>=expression;

Example: SELECT * FROM EMP WHERE city = ‘rajkot’;

Logical Operator “AND”: ;


The Oracle engine will display only those rows of a table which satisfies all
the condition specified in ‘where’ clause using AND operator.

Example: SELECT * FROM student WHERE course = ‘PGDCA’ and SEM=’2’;

Above example will retrieve all the row of student table whose course is
PGDCA and semester is 2.

Logical Operator “OR”:


The Oracle engine will display only those rows of a table which satisfies at
least one condition specified in ‘where’ clause using OR operator.

Example: SELECT * FROM EMP WHERE city = ‘bombay’ or city = ‘pune’;

Above example will retrieve all the rows of EMP table whose city is either
Bombay or pune.

NOT Operator:
Operation will be TRUE when condition becomes FALSE.

Example: SELECT * FROM EMP WHERE NOT (city = ‘bombay’ or city =


‘pune’)

Above example will display all the rows of EMP table that are NOT in
Bombay or pune.

BETWEEN Operator:
To select the data within range, BETWEEN operators is used.

Example: SELECT * FROM empdet WHERE salary BETWEEN 2000 AND


7000;

The above statement will display all the records whose salary is between
2000 and 7000.

This will include both the limit value.

IN and NOT IN:


Operator = compares a single value to another single value.
If a value needs to compare with list of values IN is used.
By using IN, comparison becomes easy compare to doing with OR operator.

Example: SELECT * FROM EMP WHERE city IN (‘rajkot’, ’bombay’, ’pune’);

Above example will return all the rows of EMP table whose city is either
Rajkot or Bombay or pune.

Example: SELECT * FROM EMP WHERE city NOT IN (‘rajkot’, ’bombay’, ’pune’);

Above example will return all the rows of EMP table whose city is other than
Rajkot, Bombay and pune.

ONE WORD QUESTION AND ANSWER

SR.NO QUESTION ANSWER


1. SELECT MEANS RETIRVE RECORD INTO
DATA BASE
2 IN SELECT COMMAND CAN YES
WE USE OPERATOR?
3 IS SELECT COMAMND USE YES
FOR MULTI PURPOSE?
EXPLAIN GROUP BY AND HAVING CLAUSE WITH
EXAMPLE. DETAILING:-

GROUP BY:

· Group By clause is used to group rows based on distinct (unique) values


that exist for specified columns.
· GROUP BY is used in conjunction with aggregating functions to group
the results by the un-aggregated columns.

Syntax:
SELECT column1, column2, column, aggregate function (expression) FROM
table

EXAMPLE: Select deptno, sum (sal) from EMP group by deptno;

· In above example, the common rows in the deptno column are


grouped together and the total sum for each department is displayed
along with the deptno.

HAVING CLAUSE:
· A HAVING clause restricts the results of a GROUP BY clause.
· It can be used in conjunction with Group By clause.
· HAVING is used to give condition on group by clause column(s).
· The HAVING clause is applied to each group of the grouped data.

Syntax:
SELECT column1, column2 ... column, aggregate function (expression)
FROM table GROUP BY column1, column2, ... column HAVING groupbycolumn=expression;

EXAMPLE:
Select deptno, sum (sal) from EMP group by deptno having deptno=10 or

In above example, the common rows in the deptno column are grouped
together and the total salaries for only the deptno specified in HAVING
clause are displayed.
ONE WORD QUESTION AND ANSWER

SR.NO QUESTION ANSWER


1. GROUP BY USE WHICH AGGREGATE
FUNCTON?
2 WHEN WE CAN USE GROUP WE CAN SELECT
BY? GROUP WISE DATA
AT THAT
TIME WE CAN USE THIS.
3 HAVING MEANS?? IT IS PART OF GROUP
BY
4 IN HAVING CLAUSE WE CAN YES AGGREGATE
USE FUNCTION? FUNCTION.

EXPLAIN FOLLOWING OPERATOR WITH


EXAMPLE. DETAILING:-

LIKE:

· This operator is used for pattern matching.


· Pattern matching can be done using % and _ along with like operator.
· % is used to match any number of characters.
· It can be used in any position.
· When % is used, all characters after % are ignored by Oracle.
· For example ‘A%’ represents any name start with A followed by any no
of characters.

Example: Select * from EMP where name like

These examples give all the detail from employee table whose names are
started with C.

· _ is used to match any one character.


· When it is used Oracle will ignore the character only in the position
where underscore is put.
· For ex. ‘_ONY’ will display the word with 4 characters having first character
as any character and remaining 3 characters would be ‘ONY’.

Example: Select * from EMP where name like ‘_ca’;

This example will give the records from EMP table whose name has only 3
characters and last 2 characters are c and a respectively.
ONE WORD QUESTION AND ANSWER

SR.NO QUESTION ANSWER


1. LIKE OPERATOR USE FOR PATTARN MATCHING
2 HOW MANY WAY WE CAN 2
USE LIKE?

Explain join with


example. DETAILING:-

· Some times it is necessary to work with multiple tables as


though they were a single entity.
· Then a single SQL sentence can manipulate data from all the tables.
· To do this JOIN is used.
· Tables are joined on columns that have the same data type and
data width in the tables.
· There are three types of join.

1) INNER JOIN
2) OUTER JOIN
a. LEFT OUTER JOIN
b. RIGHT
OUTER
JOIN
c. FULL
OUTER
JOIN
3) CROSS JOIN
1) INNER JOIN
INNER JOIN is also known as Equi join.
It is known as Equi join because the where statement generally
compares two columns from two tables with the equivalence
operator (=).
It returns all rows from both tables where there is match.

Syntax (ANSI STYLE):


Select <column name1>, <column name N> from <table name1> inner join
<table name2>

EXAMPLE:
Select empno, bno from emp, branch on emp.bno = branch.bno

Syntax (THETA STYLE):


Select <column name1>, <column name N> from <table name1>, <table
name2> Where <Table name1>.<column name> = <table name2>.<column
name>
[And <condition> order by <column name1>, <column name N>]
EXAMPLE:
Select empno, bno from emp, branch where emp.bno =
branch.bno

2) OUTER JOIN
· Outer join is usually similar to inner join but
it gives a bit more flexibility.
· This type of join can be used in situations where it is
desired to select all rows from the table on the left
or right or both and other table has values in
common.
There are three types of outer join
1) left outer join
2) right outer join
3) full outer
join Left outer join:
· It gives all the data of and left hand side table
and only those of right hand side table which
are similar.

Syntax (THETA STYLE):


Select <column name1>, <column name N> from <table name1>,
<table name2> Where <Table name1>.<column name> = <table
name2>.<column name> (+) [And <condition> order by
<column name1>, <column name N>]

Syntax (ANSI STYLE):


Select <column name1>, <column name N> from <table name1> left join
<table n 2> On <table name1>.<column name> = <table
name2>.<column name> [where con n> order by <column name1>,
<column name n>]

ONE WORD QUESTION AND ANSWER

SR.NO QUESTION ANSWER

1. JOIN USE FOR COMBINE TWO TABLES


RECORDS
2 HOW MANY TYPES OF JOIN 3
ARE AVAILABLE?
3 LIST THE NAME OF JOIN INNER,OUTER,CROSS
JOIN
EXPLAIN STRING FUNCTION WITH
EXAMPLE. DETAILING:-
Following string functions are available in oracle.
Concat Initcap Lower Upper
Lpad Rpad Ltrim Rtrim
Replace Substr Length

1) Concat:
Purpose: it is used to combine the two strings and return combination of both
string.

Syntax: concat(string1, string2)

Example: select concat(‘hi ‘,’ hw are you’)

Output: hi hw are you

ONE WORD QUESTION AND ANSWER

SR.NO QUESTION ANSWER


1. CONCATE USE FOR MERGE STRING

2) Initcap:
Purpose: it returns the string with the first letter of each word in upper case and
all other letters in lower case.

Syntax: initcap(string)

Example: Select initcap(‘this is example’) from dual;

Output: This Is Example

ONE WORD QUESTION AND ANSWER

SR.NO QUESTION ANSWER


1. INITCAP USE FOR CAPITAL OF FIRST
LETTER

3) Lower:
Purpose: it returns the string with all letters in lower case.

Syntax: lower (string)


Example: Select lower(‘ABC’) from dual;

Output: abc

ONE WORD QUESTION AND ANSWER

SR.NO QUESTION ANSWER


1. LOWER USE FOR SMALL LETTER

4) Upper:

Purpose: it returns the string with all letters in upper case.

Syntax: Upper (string)

Example: Select upper (‘abc’) from dual;

Output: ABC

ONE WORD QUESTION AND ANSWER

SR.NO QUESTION ANSWER


1. UPPER USE FOR CONVERT INTO CAPITAL
LETTER

Lpad:
Purpose: it returns the Expr1 left padded to the length or n character with the
sequence of characters in Expr2.

Syntax:Lrpad (expr1, n, expr2)

Example: select lpad(‘hns’,10,’*’) from dual;

Output: * * * * * * * hns

ONE WORD QUESTION AND ANSWER

SR.NO QUESTION ANSWER


1. LPAD MEANS LEFT PADDING
5) Rpad:
Purpose: it returns expr1 right padded to length n character with sequence of
character in expr2.
This function is useful for formatting output of query.

Syntax: rpad(expr1,n,expr2)

Example:Select rpad(‘hns’,10,’*’) from dual;

Output: hns* * * * * * *

ONE WORD QUESTION AND ANSWER

SR.NO QUESTION ANSWER


1. RPAD USE FOR RIGHT PADING MEANS
WE CAN PUT DESIGN
RIGHT SIDE OF
CAHRACTER.

6) Ltrim:
Purpose: It removes from the left end of string all of the character contains in
set.
If set is not defined it will default as a blank.

Syntax: lrtrim(string,set)

Example: Select ltrim(‘xyXxyHNS’,’y’)

Output: XxyHNS

ONE WORD QUESTION AND ANSWER

SR.NO QUESTION ANSWER


1. LTRIM USE FOR TO REMOVE
CAHRACTER FORM
LEFT
SIDE.

7) Rtrim:
Purpose: It removes from the right end string all of the character contains in
set. If set is not defined it will default as blank.

Syntax: rtrim(string,set)

Example: Select rtrim(‘HNS*****’,’*’)

Output: HNS
ONE WORD QUESTION AND ANSWER

SR.NO QUESTION ANSWER


1. RTIRM MEANS TO REMOVE
CHARACTER FORM
RIGHT SIDE

8) Replace
Purpose:
It returns characters with every occurrence of search string replace with
replacement string.
If replacement string is omitted then all occurrence of search string are removed.

Syntax: replace (string,search_string, replacement_string);

Example: Select replace (‘BCA College’, ‘BCA’,’PGDCA’) from dual;

Output: PGDCA College.

ONE WORD QUESTION AND ANSWER

SR.NO QUESTION ANSWER


1. REPLACE USE FOR REPLACE PROPER
STRING

9) Substr
Purpose: This function returns a part of string beginning at character position
define by m to n character long.
If m is positive then start from beginning. If m is negative then start from ending.

Syntax: Substr (str,m,n)

Example: Select substr (‘hello’, 2, 5) from dual;

Output: ello

ONE WORD QUESTION AND ANSWER

SR.NO QUESTION ANSWER


1. SUBSTR USE FOR BREAK CHARACTER
10) length
Purpose: It returns the total length or size of the specified string.

Syntax: length (string)

Example: Select length (‘hello’) from dual;

Output: 5

ONE WORD QUESTION AND ANSWER

SR.NO QUESTION ANSWER


1. LENGTH USE FOR RETURN THE LENGTH
OF STRING

EXPLAIN DATE
FUNCTION. DETAILING:-
In oracle following functions are comes into date function
ADD_MONTHS LAST_DAY
MONTHS_BETWEEN NEXT_DAY SYSDATE

ADD_MONTHS:
Syntax: ADD_MONTHS (date,
Purpose:
· This function returns the date plus integer months.
· The date argument can be a date value or any values that can be
implicitly converted to DATE.
· The integer argument can be integer value or any values that can
be implicitly converted to integer.
· The return type of this function is date.

Example: select add_months(’07-JAN-2011’,1) from dual;

Output: 07-FEB-11
ONE WORD QUESTION AND ANSWER
SR.NO QUESTION ANSWER
1. ADD MONTHUSE FOR TO ADD MONTH
IN GIVEN DATE

LAST_DAY:
Syntax: LAST_DAY (d1)
Purpose:
· It returns the last date of specified month.
· The d1 argument can be any date value.

Example: select last_day(’07-JAN-2011’) from dual;

Output: 31-JAN-11

ONE WORD QUESTION AND ANSWER


SR .NO QUESTION ANSWER
1. LAST DAY USE FOR DISPLAY LAST DAY OF
MONTH

MONTHS_BETWEEN:

Syntax: MONTHS_BETWEEN (d1, d2)

Purpose:
· It returns the how many months fall between two dates.
· The return type of this function is number value.
· Here user has to give two dates as argument.

Example: select months_between(’07-FEB-2011’,’07-JAN-2011’) from dual;

Output: 1

ONE WORD QUESTION AND ANSWER


SR.NO QUESTION ANSWER
1. MONTH BETWEEN USE FOR DISPLAY DIGIT
BETWEEN TWO
MONTHS

SYSDATE:

Syntax: SYSDATE
Purpose:
· This function returns the current system date.
· The return type of this function is date.

Example: Select sysdate from dual;

Output: 06-MAR-11

ONE WORD QUESTION AND ANSWER


SR.NO QUESTION ANSWER
1. SYS DATE USE FOR GIVE THE LAST DATE OF
SYSTEM

EXPLAIN AGGREGATE FUNCTION.


ANS:
1) AVG:

Syntax: AVG ([<distinct>]

Purpose:
This function returns the average value of specified column.

Example: Select avg (sal) from EMP;

This statement returns the average value of sal from EMP table.

ONE WORD QUESTION AND ANSWER


SR.NO QUESTION ANSWER
1. AVG USE FOR DISPLAY AVERAGE OF
GIVEN COLUMN

2) MIN:

Syntax: MIN ([<distinct>] <expr>)


Purpose:
This function returns the minimum value of specified expression or column.

Example: Select min (1, 2, 3, 6) from EMP;

Output: 1

ONE WORD QUESTION AND ANSWER


SR.NO QUESTION ANSWER
1. MIN USE FOR RETURN MINIMUM
VALUE OF GIVEN
COLUMN

3) MAX:

Syntax: MAX ([<distinct>] <expr>)

Purpose:
This function returns the maximum value of specified expression or column.

Example: Select max (1, 2, 3, 4) from dual;

Output: 4

ONE WORD QUESTION AND ANSWER


SR.NO QUESTION ANSWER
1. MAX USE FOR RETURN MAXIMUM
VALUE OF GIVEN
COLUMN

COUNT:

Syntax: COUNT ([<distinct>] <expr>)

Purpose:
This function returns the number of rows where expr is not null.

Example: Select count (sal) from EMP;


OUTPUT: 14
This function returns the total number of records into sal column.

ONE WORD QUESTION AND ANSWER


SR.NO QUESTION ANSWER
1. COUNT USE FOR RETURN NUMBER
VALUE OF GIVEN
COLUMN

4) SUM:

Syntax: SUM ([<distinct>] <n>)

Purpose:
This function returns the sum of the specified column or n.

Example: Select sum (1, 2, 3, 4) from dual;

OUTPUT: 10

ONE WORD QUESTION AND ANSWER


SR.NO QUESTION ANSWER

1. SUM USE FOR RETURN SUM OF


GIVEN COLUMN

EXPALIN NUMERIC
FUNCTION. DETAILING:-
1) ABS

Syntax: abs (n)

Purpose:
This function returns the absolute value of n.

Example: Select abs (-3) from

OUTPUT: 3

ONE WORD QUESTION AND ANSWER


SR.NO QUESTION ANSWER
1. ABS USE FOR ABSOLUTE VALUE
RETURN

2) POWER:
Syntax: Power (m,n)
Purpose:
This function returns the m raised to the nth power.
· N must be an integer, else an error is returned.

Example: Select power (2, 3) from dual;

OUTPUT: 8

ONE WORD QUESTION AND ANSWER


SR.NO QUESTION ANSWER
1. POWER USE FOR GIVEN POWER OF
VALUE

3) ROUND:

Syntax: round (n, [m])

Purpose:
· Returns n, rounded to m places to the right of a decimal point.
· If m is omitted, n is rounded to 0 places.
· M can be negative to round of digits to the left of the decimal point,
m must be an integer.

Example: Select round (15.19, 1) from dual;


OUTPUT: 15.2

ONE WORD QUESTION AND ANSWER


SR.NO QUESTION ANSWER
1. ROUND USE FOR RETURN ROUND VALUE

4) SQRT:

Syntax: SQRT (n)

Purpose: Returns square root of n. if n<0, null.


Example: Select sqrt (9) from dual;

OUTPUT: 3
ONE WORD QUESTION AND ANSWER
SR.NO QUESTION ANSWER
1. SQRT USE FOR RETURN
SQUARE VALUE
OF GIVEN
COLUMN

5) EXP:
Syntax: exp
Purpose:
Returns e raised to the nth power where e = 2.71828183

Example: Select exp (5) from dual;


OUTPUT: 148.413159
ONE WORD QUESTION AND ANSWER
SR.NO QUESTION ANSWER
1. EXP USE FOR RETURN EXP VALUE OF
GIVEN COLUMN

6) GREATEST:

Syntax: GREATEST (expr1, expr2 … expr)

Purpose:
Returns the greatest value in a list of expression.

Example: Select greatest (1, 2, 3, 6) from dual;

OUTPUT: 6

ONE WORD QUESTION AND ANSWER


SR.NO QUESTION ANSWER
1. GREATEST USE FOR RETURN MAX VALUE OF
GIVEN VALUES

7) LEAST

Syntax: LEAST (expr1, expr2 … expr)

Purpose:
Returns the smallest value in a list of expression.

Example: Select least (1, 2, 3, 6) from dual;

OUTPUT: 1

ONE WORD QUESTION AND ANSWER


SR.NO QUESTION ANSWER
1. LEAST USE FOR RETURN MINIMUM
VALUE OF GIVEN
NUMBERS
8) MOD
Syntax: MOD (m,n)
Purpose:
Returns the remainder of first number divided by second number passed
into the argument.
If the second number is zero, the result is the same as the first number.

Example: Select mod (6, 3) from dual;

OUTPUT: 0

ONE WORD QUESTION AND ANSWER


SR.NO QUESTION ANSWER
1. MOD USE FOR RETURN MODULAS
VALUE OF GIVEN
NUMBER

9) FLOOR
Syntax: FLOOR (n)
Purpose:
Returns the largest integer value that is equal to or less than a number.

Example: Select floor (24.8) from dual;

OUTPUT: 24
ONE WORD QUESTION AND ANSWER
SR.NO QUESTION ANSWER
1. FLOOR USE FOR RETURN FLOOR
VALUE OF GIVEN
NUMBER

10) CEIL
Syntax: CEIL (n)

Purpose: Returns the smallest integer value that is equal to or greater than a
number.

Example: Select ceil (24.8) from dual;

OUTPUT: 25
ONE WORD QUESTION AND ANSWER
SR.NO QUESTION ANSWER
1. CEIL USE FOR RETURN HIGEST
INTEGER VALUE
OF GIVEN
NUMBER

You might also like