Saturday, 30 July 2016

Sequence & Synonym

Sequence In Oracle


**Its a Numeric Value Generator
**Its Mostly used in Primary Key Columns
**Its One of the Schema Object
**Its a Sharable Object

NEXTVAL::


The Oracle NEXTVAL function is used to retrieve the next value in a sequence. The Oracle NEXTVAL function must be called before calling the CURRVAL function, or an error will be thrown.

Example::

SQL> create sequence Seq_1;

Sequence created.

SQL> select Seq_1.Nextval from dual;

NEXTVAL
----------
1

SQL> select Seq_1.Nextval from dual;

NEXTVAL
----------
2

SQL> select Seq_1.Nextval from dual;

NEXTVAL
----------
3

SQL> create sequence Seq_2
2  START WITH 10
3  INCREMENT BY 3
4  MAXVALUE 10000
5  CYCLE
6  CACHE 5;

Sequence created.

SQL> select Seq_2.nextval from dual;

NEXTVAL
----------
10

SQL> select Seq_2.nextval from dual;

NEXTVAL
----------
13

SQL> select Seq_2.nextval from dual;

NEXTVAL
----------
16

SQL> select Seq_2.nextval from dual;

NEXTVAL
----------
19


CURRVAL::


**It Returns the current value of a sequence.
**If the Currval Once executed the Nextval Should be the Next Value of the Currval.

Example::

SQL> select Seq_2.Nextval from dual;

NEXTVAL
----------
19
SQL> select Seq_2.CURRVAL from dual;

CURRVAL
----------
19

SQL> select Seq_2.Nextval from dual;

NEXTVAL
----------
22


SYNONYM::

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

Example::

SQL> CREATE SYNONYM Emp For Employees;

SYNONYM CREATED.

SQL> select * From Emp;

Advantages of synonyms


Synonyms are often used for security and convenience.

for Example, they can do the following things.

  • Mask the name and owner of an object.
  • Provide location transparency for remote objects of a distributed database.
  • Simplify SQL statements for database users

Private & Public Synonyms::

  • A normal synonym is called private synonym whereas a public synonym is created by a keyword public.
  • A private synonym is accessible within your schema and a public synonym is accessible to any schema in the database.

----------END----------

Related Posts:

  • Func Part..1 FUNCTIONS FUNCTIONS:: 1.Single Row Functions 2.Multi Row Functions 1.Single Row Functions:: If we input 'n' number of input and it produce 'n' number of Output.(n->n) Types in Single Row Function:: 1.Case Functi… Read More
  • Func Part..3 FUNCTIONS CONTINUES.. GENERAL FUNCTIONS:: The General functions are mainly used for Process the "NULL" Values. There are following four types of General functions are there:: 1.NVL()   --It's having two argume… Read More
  • SUB QUERY                SUB QUERY *The Query with in another is query is known as "SUB QUERY". *In Sub query the inner part is execute first and the Outer query will execute second. *Can … Read More
  • Func Part..2 FUNCTION CONTINUES NUMBER FUNCTIONS:: 1.ROUND() 2.TRUNC() 3.MOD() 4.POWER() 1.ROUND():: The ROUND() Function mainly used for Round of the Decimal Values Or Round of the Values based on the Position Which is Passed i… Read More
  • JOINS Joins In Oracle        JOIN is used for selecting the data's from one or more tables. TYPES OF JOINS:: 1.EQUI JOIN 2.OUTER JOIN    i)LEFT OUTER JOIN   ii)RIGHT OUTER JOIN … Read More

0 comments:

Post a Comment