Oracle SQL Synonyms

Posted on 2007-10-17
Last Modified: 2012-08-13
I'm working with SQL in Oracle. I want to write a select query using table and column synonyms. For example, how would I re-write the following select statement:

SELECT Saleno, Item, Amount
FROM Sales;

If the synonyms were:
Saleno =n
Item - i
amount = a
sales = s

Are there any other rules I should know?
Question by:kevin1478
    LVL 28

    Assisted Solution



    1) SELECT Saleno n, Item i, Amount q
    FROM Sales s;


    create synonym s for
    SELECT Saleno n, Item i, Amount q
    FROM Sales;

    select * from s;

    LVL 28

    Assisted Solution

    i have put q as aias for amount column .. that is a typing mistake..just change it to A

    LVL 142

    Accepted Solution

    like this, if I understand what you mean:

    SELECT s.Saleno n, s.Item i, s.Amount a
    FROM Sales s;
    LVL 9

    Assisted Solution

    select s.n, s.i, s.a
      from (select Saleno as n, Item as i, Amount as a
                  from Sales) s

    using synonyms is usefull in sql statements where tables are joined ...

    select s.Saleno, s.Item, s.Amount
      from Sales s, Items o
     where s.Saleno = i.ItemNo

    Author Comment

    Thank you for your fast reply.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
    Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
    This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
    This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now