2

为什么在 select 语句中使用别名时会被视为外星人?

我无法想象这种情况总是如此,但我不得不更改此代码:

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()) { . . .

...对此:

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()) { . . .

...让它在运行时返回 vals(我在第一个版本中得到“IndexOutOfRangeException”)

4

1 回答 1

4

您需要引用别名。

E.DEWDROPNAME 'FOGGY' ...
于 2012-07-10T22:24:20.723 回答