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

Oracle-3

The document provides an overview of various Oracle database objects including views, sequences, synonyms, database links, indexes, and commands like GRANT and REVOKE. It details how to create, manipulate, and manage these objects, along with their syntax and examples. Additionally, it explains transaction management concepts such as COMMIT, ROLLBACK, and SAVEPOINT.

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-3

The document provides an overview of various Oracle database objects including views, sequences, synonyms, database links, indexes, and commands like GRANT and REVOKE. It details how to create, manipulate, and manage these objects, along with their syntax and examples. Additionally, it explains transaction management concepts such as COMMIT, ROLLBACK, and SAVEPOINT.

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/ 19

H-3 :- OTHER ORACLE DATA BASE OBJECT

Q-1. EXPLAIN VIEW WITH EXAMPLE.


ANS:
VIEWS:

 After a table is created and populated with data, it


may become necessary to prevent all users from
accessing all columns of a table, for data security
reasons.
 View use for hide particular column of table.
 View is dependent object.
 With out table we can not create view.
 View connect with other object.
 In view we can also insert ,update and delete data.
 If we can create view for any table so if we insert
record into table so it already insert to view and if
we update record in view it will automatic update in
table.
 When data security is required At a time view
is create.
Creating views
Syntax:
Create view viewname as
Select column1, column2 from table name
Example:
Create view v1 as select no,name from emp;

Selecting a data set from a view:

 Once a view has been created, it can be queried


exactly like a base table.

Syntax:
Select ColumnName1, Column Name2 from ViewName;

Example:
Select * from v1;
Updateable Views:

 Views can also be used for data manipulation (The user


can perform the Insert, Update and Delete operations).
 Views on which data manipulation can be done are
called updatable views.
 When updatable view names is given in an insert
update or delete sql statement, modification to data in
the view will be immediately passed to the underlying
table and also modification in table will affect the view.

Inserting data in views:


Example:
Insert into v1 values (500,’Harit’);
Updating data in views
Example
Update v1 set name=’vishal’ where name=’amar’;

Deleting data from views

Example
Delete from v1 where no=500;
Destroying a view

The drop view command is used to remove a view from the


database.

Syntax:
Drop view <View Name>>
Example
Drop view v1;
EXPLAIN SEQUENCE IN DETAIL.
SEQUENCES

Oracle provides an object called a Sequence that can generate


numeric values.
 The value generated can have a maximum of 38 digits.
 A sequence can be defined to:

1. Generate numbers in ascending or descending order


2. Provide intervals between numbers
3. Caching of sequence numbers in memory to speed up
their availability

 A sequence is an independent object and can be used


with any table that requires its output.

Syntax:
Create sequence Sequence Name
[Increment By <Integer Value>
Start With <Integer Value>
Maxvalue <Integer Value> / NonMaxvalue
Minvalue <Integer Value> / Nonminvalue
Cycle/NoCycle
Cache <Integer Value> / No Cache
Order / Noorder]

Keywords and Parameters:


Increment By:
Specifies the interval between sequence
numbers. It can be any positive or negative value
but not zero.
If this clause is omitted, the default value is 1.
MinValue:
Specifies the sequence minimum value.
Nominvalue:
Specifies a minimum value of 1 for an ascending
sequence and –(10)^26 for a descending
sequence.
Maxvalue:
Specifies the maximum value that a sequence can
generate
Nomaxvalue:
Specifies a maximum of 10^27 for an ascending
sequence or -1 for a descending sequence. This is
the default clause.
Startwith:
Specifies the first sequence number ot be
generated.
The default for an ascending sequence is the
sequence minimum value (1) and for a
descending sequence, it is the maximum value (-
1).
Cycle:
Specifies that the sequence continues
to generate repeat values after reaching
eitherits maximum value.
Nocycle:
Specifies that a sequence cannot generate more
values after reaching the maximum value.
Cache:
Specifies how many values of a sequence Oracle
pre-allocates and keeps in memory for faster
access.
The minimum value for this parameter is tow.
No Cache:
Specifies that values of a sequence are not pre-
allocated.

Note: If the cache/NoCache clause is omitted


Oracle caches 20 sequence numbers by default.

Example:
Create sequence s1 start with 5 increment by 1 maxvalue 50;
To reference next value of sequence
Syntax:
Select Sequence Name.Nextval from dual;
· This will display the next value held in the cache.
· Every time nextval references a sequence its output
is automatically incremented from the old value to
the new value ready for user.
Example:
Select s1.nextval from dual;

To reference current value of sequence


Syntax:
Select <Sequence Name>.Currval From Dual;

Example
Select stest1.currval from dual;

Altering a Sequence
Syntax:
Alter sequence <<Sequence Name>>
Incremented by interger value
Maxvalue Integer Value/ Nomaxvalue

Example:

Alter sequence s1 increment by 2;

Dropping a Sequence:
Syntax:
Drop Sequence <<Sequence Name>>;

Example:
Drop Sequence stest1;

Explain synonyms with example.


DETAILING:
A synonym is an alternative name for objects such as
tables, views, sequences, stored procedures, and other
database objects.
Synonyms is dependent object.

Syntax:
Create Synonym Synonym.Name for Table Name

Example:
Create synonym employees for emp;

· Now, users of other schemas can reference the table


emp, which is now called as employees without having
to prefix the table name with the schema named
Scoot.
Example:
Select * from Employee;

Dropping

Synonyms Syntax:
Drop Synonym Synonym.Name;

Example
Drop Synonym employees;

ONE WORD QUESTION AND ANSWER


SR.NO QUESTION ANSWER
1. SYNONYMS ALTERNATE
MEANS_ NAME OF
OBJECT
2 IT IS NO
INDEPENDEN
T OBJECT?

3 WE CAN INSERT YES


,UPDATE AND DELETE
ROCORD INTO
SYNONYMS?
4 WHICH STATEMENT SELECT
USE TO DISPLAY
RECORD OF
SYNONYMS?

Explain Database Link with example.


· If our data base is very big in size and at that time we
can share to other user.
· In Oracle, remote data accesses such as queries and
updates are enabled through the use of database links.
· You will also find information about direct connections
to remote database, such as those used in client-server
applications.
· Data base link is used to connect database with other
user.
· It is network concept.
· Dabase link use in client server model.
Data base---------data base link--------user.
Database links tell oracle how to get from one database to
another.
If you will frequently use the same connection to a remote
database then a database link is appropriate.

Database links specify the following connection information:

1) The communications protocol (such as TCP/ IP) to use


during the connection.
2) The host on which the remote database resides.
3) The name of the database on the remote host.
4) The name of a valid account in the remote database.

ONE WORD QUESTION AND ANSWER

SR.NO QUESTION ANSWER


1. DBL MEANS? DATA BASE LINK
2 DBL USE FOR? LINK BETWEEN
DATA BASE AND
SERVER
3 IT IS YES
NETWROK
TOOL?

EXPLAIN INDEX IN DETAIL.


DETAILING:
· Indexes are data structures that have to improve
speed in obtaining specific row from table.
· Indexing a table is an access strategy that is a way
to short and search records in the table.
· An index is an order list of the content of column.
· Index should be created on a column that is
queried frequently.

Usually to major types of indexes are used:


1) B-TREE index
2) BITMAP index
B-TREE index:
Oracle allows the creation of two types of indexes:
1) Duplicate index
2) Unique index

Duplicate index:
Index that allows duplicate value for the
indexed column.
Unique index:
Index that only unique value for the indexed
column.

Indexes are further divided into two group based


on the number of columns
1) Simple index
2) Composite index

Duplicate index:
1) Simple duplicate index
An index created on a single column of a table
is called simple index.

Syntax:
Create index <index name> on <table name> (<column
name>);

Example:
Create index i1 on emp (empno);

2) Composite duplicate index


An index created on a multiple column of a
table is called composite index.
Syntax:
Create index <index name> on <table name> (<column
name1>, <column name2>...);
Example:
Create index i1 on emp
(empno, ename);

Unique index:
1) Unique simple index:
Syntax:
Create unique index <index name> on <table

Exampl
e:
Create unique index i1 on emp (empno);

2) Unique Composite index:

Syntax:
Create unique index <index name> on <table name> (<column name1>, <column name2>);
Example:
Create unique index i1 on emp (empno, ename)

ONE WORD QUESTION AND ANSWER


SR.NO QUESTION ANSWER
1. INDEX IS DATA
STRUCTURE.
2 HOWMANY TYPES OF 2
INDEX ARE
AVAILABLE?
3 IT IS NO
INDEPENDEN
T OBJECT?
4 INDEX CAN APPLY YES
ONE COLUMN OF
TABLE?
5 INDEX CAN APPLY YES
MULTIPLE COLUMN?
EXPLAIN GRANT AND REVOKE COMMAND WITH EXAMPLE.
Grant

· The Grant statement provides various types of access to


database objects such as tables, views and sequences and
so on.
Syntax:
GRANT <Object Privileges> ON <Object Name> TO <User Name> [WITH GRANT OPTION];

Object Privileges:
A user can grant all the privileges or grant only specific
object privileges.

The list of object privileges is as follows:

ALTER Allows the grantee to change the table


definition with the ALTER TABLE command
DELETE Allows the grantee to remove the records
from the table with the DELETE command.
INDEX Allows the grantee to create an index on the
table with the CREATE INDEX command.
INSERT Allows the grantee to add the records to the
table with the INSERT command.
Allows the grantee to query the table
definition with the SELECT command.
UPDATE Allows the grantee to modify the records in
the tables with the UPDATE command.

With Grant Option:


It allows the grantee to in turn grant object privileges to other
users.

EXAMPLE:
GRANT select, update ON emp TO
bca15;

Revoke
The REVOKE statement is used to deny the grant given
on
an object.
Syntax:
REVOKE <Object Privileges> ON <Object Name> FROM <User Name>;

EXAMPLE:
REVOKE delete ON emp FROM pgdca20;

ONE WORD QUESTION AND ANSWER


SR.NO QUESTION ANSWER
1. GRANT IS GIVE PERMISSION
.
2 REVOKE MEANS BACK PERMISSION
3 WHICH STATEMENT SQL STATEMENT.
USE IN GRANT AND
REVOKE

HOW TO CREATE USER EXPLAN IT


o The create user command is used to create
database user accounts.
When creating a user account with the create user
command one can:
· Define the user name
· Define the password associated with the
database user
· Define the default table space for the user
· Define the temporary table space for the user
· Allocate space quotas to various table spaces to
the user.
· Assign attributes to the user account
Syntax:
CREATE USER username
IDENTIFIED BY password
[DEFAULT TABLESPACE <table space name>]
[USER TABLESPACE <table space name>]
[TEMPORARY TABLESPACE <table space name>];

Example:
CREATE USER ABC IDENTIFIED BY aa1234;
Now, user is created but user cannot login into oracle.
DBA has to assign rights to user so that user can get connected
and can run sql statements.

GRANT CONNECT, RESOURCE TO username; ONE WORD

QUESTION AND ANSWER


SR.NO QUESTION ANSWER
1. CREATE USER USE CREATE OWN
FOR USER IN ORACLE.
2 IT IS NETWEOK YES
PRODUCT?
3 WHICH CONCEPT USER NAME AND
MUST USE? PWD

EXPLAIN COMMIT, ROLLBACK AND SAVEPOINT.


DETAILING:
Commit
· Oracle treats changes to table data as a two-step process.
1. The changes requested are done.
2. To make these changes permanent a COMMIT
statement has to be given at the SQL prompt.
· A COMMIT statement makes changes permanent.
These changes are done due to the execution of series of
SQL Statements.

· A COMMIT ends the current transaction and


makes permanent any changes made during the
transaction.

Syntax:
COMMIT

Rollback
· A ROLLBACK does exactly the opposite of COMMIT.
· It ends the transaction but undoes any changes made
during the transaction.
· All transactional locks acquired on tables are released.

Syntax:
ROLLBACK [WORK] [TO [SAVEPOINT] <Save Point Name>];
· WORK Is optional and is provided for ANSI compatibility.
· SAVEPOINT Is optional and used to rollback a
transaction partially, as far as the specified save point.
· SAVEPOINT NAME Is a name of save point
created during the current transaction.

A ROLLBACK operation performed without the SAVEPOINT


will work as under:

· Ends the transaction


· Undo all the changes in the current transaction
· Erases all save points in that transaction
· Releases the transactional locks

Save Point
· SAVEPOINT marks and saves the current point in
the processing of a transaction.
· When a SAVEPOINT is used with a ROLLBACK
statement, parts of a transaction can be undone.

Syntax:
SAVEPOINT <Save Point Name>;

A ROLLBACK operation performed with the TO


SAVEPOINT will work as under:
· A predetermined portion of the transaction is rolled
back
· Retains the save point rolled back to, but loses
those created after the named savepoint
· Releases all transactional locks that were acquired
since the savepoint was taken

Example with SAVEPOINT:


insert into emp values (151,’Disha’,’Manager’, 5000, 10);
savepoint s1;
Update emp set salary=salary+750 where deptno=20;
Update emp set salary=salary+1050 where deptno=30;
update emp set salary=salary+500 where deptno=10;

rollback to savepoint s1;

Above statement will rollback only the three update


statement and not rolled back insert into statement.

ONE WORD QUESTION AND ANSWER


SR.NO QUESTION ANSWER
1. COMMIT MEANS SAVE WORK

SAVE POINT SAVE WORK


MEANS_ POINT BY POINT
4 IT IS DCL STATEMENT? YES

Q- WHAT IS TRANSACTION ? EXPLAIN IN

- A SERIES OF ONE OR MORE SQL STATEMENT THAT ARE


LOGICALLY RELATED.
- A SERIES OF OPERATION PERFORM ON ORACLE
DATA IS KNOWN AS TRANSACTION.
- THE TRANSACTION HAS TWO PARTS LIKE
1) BEGINNING OF TRANSACTION
2) ENDING AND CLOSING OF TRANSACTION

1) STARTING /BEGINNING OF TRANSACTION.

- TRANSACTION BEGIN IS FIRST EXECUTE


SQL STATEMENT.
- WHEN WE START ORACLE AND WORK IT IS
CALLED STARTING TRANSACTION.
- WHEN WE SAVE WORK AND THEN AGAIN START
WORK IS ALSO CALLED TRANSACTION.
2) CLOSING OR ENDING OF TRANSACTION:-

- WHEN WE CLOSE ORACLE IT IS CALLED CLOSING


OR ENDING TRANSACTION
- WHEN WE WRITE COMMIT COMMAND IT IS
ALSO CALLED TRANSACTION ENDING.

Q- EXPLAIN TRANSACTION CONTROL COMMAND.

DETAILING:
- THERE ARE THREE TYPES OF
TRANSACTION CONTROL COMMAND. LIKE
COMMIT
,ROLLBACK AND SAVEPOINT.

1) COMMIT:-
- COMMIT STATEMENT IS USED TO
SAVE WORK IN DATA BASE.
- COMMIT IS EXECUTE ALL THE
SQL STATEMENT.
- COMMIT ALSO USED TO END
OF TRANSACTION.

2) ROLLBCAK :-
- ROLLBACK STATEMENT IS USED TO
UNDO THE WORK .
- ROLLBACK CAN PERFORM
DISCARD CHAGES.
- THE SUCCESSFUL END OF TRANSACTION.
3) SAVE POINT:-
- IT IS USED TO IDENTIFY A POINT
IN TRANSACTION.
- SAVE POITN IS POINT BY POINT
DATA SAVING COMMAND.
- SAVE POINT IS LIKE MARKER TO DEVICE
THAT CONVERT LENGHTLY
TRANSACTION INTO SMALLER ONE.

Q- EXPLAIN LOCK IN DETAIL


- WHILE DESIGNING ANY DATA BASE
APPLICATION FOR MULTIPLE USER
ENVIRONMENT, PROGRAMMER MUST KEEP IN
MIND THE ISSUES OF CONCURRENT ACCESS OF
DATA BASE.
- THIS IS MAJOR ISSUES OF ANY
DATABASE APPLICATION.
- AND IT IS NOT MANAGE PROPERLY BY
DEVELOPER THEN THE WHOLE DATA
BASE IS FAIL.
- SO ORACLE PROVIDE LOCK TO HELP
THEN DEVELOPER TO SOLVE THIS
PROBLEM.
- DATA CONCURRENCY MEANS MANY USER
CAN ACCESS SAME DATA AT THE SAME
TIME.

- ORACLE PROVIDE VARIOUS TYPES OF LOCK


LETS EXLAIN ALL.
-
· TYPES OF LOCK :

- THERE ARE THREE TYPES OF LOCK


IN ORACLE.
- DDL LOCK,DML LOCK AND TABLE LOCK.

1) DDL LOCK:-
- DDL MEANS DATA DEFINITION LAMGUAGE.
- DDL LOCK DDL STATEMENT LIKE
CREATE,ALTER,GRANT AND
REVOKE.
2) DML LOCK:-
- DML MEANS DATA
MANIPULATION LANGUAGE.
- IT PROTECT DML STATEMENT.
- LIKE INSERT, UPDATE AND
DELETE STATEMENT LOCK .

3) TABLE LOCK OR INTERNAL LOCK:


- TABLE LOCK IS ALSO CALLED
INTERNAL LOCK.
- USING TABLE LOCK WE CAN
PROTECT TABLE’S ROW AND
COLUMN.
Q- EXPLAIN ORDER BY CLAUSE.

ANS:- ORACLE ALLOW DATA FROM A TABLE TO BE


VIEWD IN A SORTED FORM LIKE ASCENDING AND
DESCENDING.
- SYNTAX:
SELECT * FROM TABLE NAME ORDER BY
COLUMN NAME:

EX:-
SELECT * FROM BCA ORDER BY NAME;

EX.
SELECT * FROM BCA ORDER BY NAME
DESC;

Q- EXPLAIN DISTINCT CLAUSE.

ANS:- A TABLE CAN HAVE DUPLICATE ROWS.


- TO SEE ONLY UNIQUE ROWS, WE CAN
USED TO DISTINCT CLAUSE.
SYNTAX:- SELECT DISTINCT COLUMN NAME FROM
TABLE NAME;

EX: SELECT DISTINCT CITY FROM BCA;

You might also like