Oracle Practical 16 CREATION OF SEQUENCES AND SYNONYMS Sequences Use Sequences to assign unique values, like an AutoNumber in MS Access. The syntax is as follows… CREATE SEQUENCE seqname INCREMENT BY integer START WITH integer MAXVALUE integer MINVALUE integer CYCLE CACHE integer ORDER / -- or NOCYCLE -- or NOCACHE -- or NOORDER SEQUENCE – the name you give the sequence generator INCREMENT BY – this refers to the interval between sequence numbers (does the number increment by 2 or 5 for example. The default is 1.) START WITH – what number does the sequence start at (default is 1) MAXVALUE – the maximum value that the sequence can generate MINVALUE – the minimum value that the sequence can generate CYCLE – this refers to whether the numbers in the sequence are re-cycled when the maximum value is reached. CACHE - specifies how many values the Oracle Server will pre-allocate and keep in memory. ORDER – the order in which the numbers are allocated To use a sequence, you use the following syntax… SELECT FROM seq_tdb_log.nextval dual; Seq_tdb_log – this is the name of the sequence being called. Nextval is a pseudocolumn. See USER_SEQUENCES for data dictionary information on sequences. Page 1 of 2 Oracle Practical 16 Synonyms “A word having the same or nearly the same meaning as another word or other words in a language.” So we can query SCOTT.EMP, if we have been granted select on that table… SELECT FROM * scott.emp; Typing SCOTT every time we query one of his tables is annoying; we should create a synonym for the table. CREATE SYNONYM emp FOR scott.emp / Now we can omit ‘SCOTT.’. To help others we may want t make this synonym available to everyone, by making it public. CREATE PUBLIC SYNONYM emp FOR scott.emp / Now every user account within this database can refer to that table without specifying the user. See USER_SYNONYMS for data dictionary information. Recommended Books for those interested in pursuing Oracle in their Careers, Not required: “Oracle: The complete reference”. (Latest edition, Oracle Press). “Oracle: PL/SQL Programming”. (Latest edition, Oracle Press). Page 2 of 2