2

Why would aliases be treated like aliens when used in a select statement?

I can't imagine this is always the case, but I had to change this code:

const string query = 
    @"SELECT C.PLATYPUSCLIENTID, E.DEWDROPNAME FOGGY
    FROM DUCKBILLACCOUNT B,
        PLATYPUSCLIENT C,
        ENTITY E
    WHERE B.DUCKBILLNUMBER = :PLATYPUSACCOUNTID
        AND B.DUCKBILLACCOUNTABCID = C.DUCKBILLACCOUNTABCID
        AND C.PLATYPUSCLIENTABCID = E.ABCID
    ORDER BY FOGGY, PLATYPUSCLIENTID";
    try {
        oc.Open();
        using (OracleCommand ocmd = new OracleCommand(query, oc)) {
            ocmd.Parameters.Add("PLATYPUSACCOUNTID", PLATYPUSACCOUNTID);
            using (OracleDataReader odr = ocmd.ExecuteReader()) {
                while (odr.Read()) { . . .

...to this:

const string query = 
    @"SELECT C.PLATYPUSCLIENTID, E.DEWDROPNAME 
    FROM DUCKBILLACCOUNT B,
        PLATYPUSCLIENT C,
        ENTITY E
    WHERE B.DUCKBILLNUMBER = :PLATYPUSACCOUNTID
        AND B.DUCKBILLACCOUNTABCID = C.DUCKBILLACCOUNTABCID
        AND C.PLATYPUSCLIENTABCID = E.ABCID
    ORDER BY DEWDROPNAME, PLATYPUSCLIENTID";
    try {
        oc.Open();
        using (OracleCommand ocmd = new OracleCommand(query, oc)) {
            ocmd.Parameters.Add("PLATYPUSACCOUNTID", PLATYPUSACCOUNTID);
            using (OracleDataReader odr = ocmd.ExecuteReader()) {
                while (odr.Read()) { . . .

...to get it to return vals at runtime (I was getting "IndexOutOfRangeException" with the first version)

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • Does your query run as desired against the DB from within SQL Developer? I remember needing to use the `AS` keyword before, but I don't remember if the Oracle SQL engine expects it or not. – Jesse Webb Jul 10 '12 at 22:09
  • @Jesse: I don't know what SQL Developer is, but it runs fine in TOAD – B. Clay Shannon-B. Crow Raven Jul 10 '12 at 22:26
  • SQL Developer is Oracle's GUI tool for DB management. It is similar to Microsoft's SSMS for SQL Server. http://www.oracle.com/technetwork/developer-tools/sql-developer/overview/index.html – Jesse Webb Jul 11 '12 at 14:29

1 Answers1

4

You need to quote the alias name.

E.DEWDROPNAME 'FOGGY' ...
Shawn
  • 3,583
  • 8
  • 46
  • 63