错误ORA-00907:调用command.ExecuteReader()

时间:2019-06-03 09:47:09

标签: c# sql oracle

调用方法时,会发生错误。括号的数量与打开括号和关闭括号相同。我不明白错误是什么。

var commandText = "select uwi, well_name, cid_rab, cid, plast, top, base, H_ef, porosity_alt, KH, nas, sat_tek from " +
                                  "(select ws.uwi, h.well_name, h.crstatus, h.class, h.well_type, " +
                                  "(select udmurtneft_n.dg_sdes(hs.ora1) || decode(hs.ora2, null, null, ': ' || udmurtneft_n.dg_sdes(hs.ora2)) " +
                                  "|| decode(hs.ora3, null, null, ', ' || udmurtneft_n.dg_sdes(hs.ora3)) from udmurtneft_n.well_stock_hist_ext hs " +
                                  "|| decode(hs.ora3, null, null, ', ' || udmurtneft_n.dg_sdes(hs.ora3)) from udmurtneft_n.well_stock_hist_ext hs " +
                                  "where decode(instr(ws.uwi,'B'), 0, ws.uwi, substr(ws.uwi, 1, length(ws.uwi)-2)) = hs.uwi and hs.status_date in '01.04.2019') as cid_rab, " +
                                  "udmurtneft_n.dg_sdes(ws.reservoir) as cid, udmurtneft_n.dg_des(ws.layer_id) as plast, ws.top, ws.base, ws.top_dsrd, ws.base_dsrd, " +
                                  "abs(round(ws.top_dsrd,5)-round(ws.base_dsrd,5)) as H_ef, round(ws.permeability_alt,5), ws.porosity_alt, " +
                                  "abs(round(ws.top_dsrd,5)-round(ws.base_dsrd,5))*round(ws.permeability,5) as KH, ws.saturation, udmurtneft_n.dg_des(ws.saturation) as nas, " +
                                  "(select udmurtneft_n.str_sum(distinct ps.top) from unofm.perflayers2 ps " +
                                  "where Uwi = ws.Uwi and ((top>=ws.top and top<ws.base) or (botm>ws.top and botm<=ws.base) or (ws.top>=top and ws.top<botm) or (ws.base>top and ws.base<=botm)) " +
                                  "and ps.dat_perf is not null and Interpreter in (1,3)) top_ps, (select udmurtneft_n.str_sum(distinct ps.botm) from unofm.perflayers2 ps " +
                                  "where Uwi = ws.Uwi and ((top>=ws.top and top<ws.base) or (botm>ws.top and botm<=ws.base) or (ws.top>=top and ws.top<botm) or (ws.base>top and ws.base<=botm)) " +
                                  "and ps.dat_perf is not null and Interpreter in (1,3)) botm_ps, (select udmurtneft_n.str_sum(distinct tt.sat_cat) " +
                                  "from udmurtneft_n.geophys_st st, udmurtneft_n.geophys_st_interpr i, udmurtneft_n.dict_sat tt where st.id=i.id and st.uwi=ws.uwi and trim(tt.sat_rem) = trim(i.saturation) " +
                                  "and((i.top>=ws.top and i.top<ws.base) or (i.bottom>ws.top and i.bottom<=ws.base) or (ws.top>=i.top and ws.top<i.bottom) or (ws.base>i.top and ws.base<=i.bottom))) " +
                                  "as sat_tek from udmurtneft_n.well_log_result_sublayers ws, udmurtneft_n.well_hdr h " +
                                  "where ws.uwi = h.uwi and ws.interpreter in (1,3) and ws.uwi not like '%_F%' and h.field = 510399) " +
                                  "where top_ps is null and H_ef >= 1 and KH > 100 and porosity_alt >= 0.16 " +
                                  "and class = 26690 and crstatus not in (85790, 85850) and well_type is null and uwi not like '%B%' " +
                                  "and saturation in (217463,217443,217483,217603,217683,217783,273943,274003,1083681,1126381) " +
                                  "and(sat_tek is null or (sat_tek not like '%водонасыщенный%' and sat_tek not like '%газонасыщенный%' and sat_tek not like '%газоводонасыщенный%%')) " +
                                  "order by uwi, top";

var command = new OracleCommand();
command.Connection = connection;
command.CommandText = commandText;

using (DbDataReader reader = command.ExecuteReader()) // ERROR
{
    using (OracleDataAdapter dataAdapter = new OracleDataAdapter())
    {
         dataAdapter.SelectCommand = command;
         dataAdapter.Fill(dataSet);
    }
}

1 个答案:

答案 0 :(得分:1)

多么丑陋的代码!难怪您找不到错误。

我删除了双引号和+符号。然后,格式化程序将显示以下内容:

<snip>
                       || DECODE (hs.ora3,
                                  NULL, NULL,
                                  ', ' || udmurtneft_n.dg_sdes (hs.ora3))
--> error          FROM udmurtneft_n.well_stock_hist_ext hs || decode(hs.ora3, null, null, ', ' || 

您正在将表别名(hs)与另一个DECODE串联-无法使用。

如果我们完全删除该FROM子句,则代码将被格式化:

  SELECT uwi,
         well_name,
         cid_rab,
         cid,
         plast,
         top,
         base,
         H_ef,
         porosity_alt,
         KH,
         nas,
         sat_tek
    FROM (SELECT ws.uwi,
                 h.well_name,
                 h.crstatus,
                 h.class,
                 h.well_type,
                 (SELECT    udmurtneft_n.dg_sdes (hs.ora1)
                         || DECODE (hs.ora2,
                                    NULL, NULL,
                                    ': ' || udmurtneft_n.dg_sdes (hs.ora2))
                         || DECODE (hs.ora3,
                                    NULL, NULL,
                                    ', ' || udmurtneft_n.dg_sdes (hs.ora3))
-- FROM udmurtneft_n.well_stock_hist_ext hs  --> FROM removed, here
                         || DECODE (hs.ora3,
                                    NULL, NULL,
                                    ', ' || udmurtneft_n.dg_sdes (hs.ora3))
                    FROM udmurtneft_n.well_stock_hist_ext hs
                   WHERE     DECODE (INSTR (ws.uwi, 'B'),
                                     0, ws.uwi,
                                     SUBSTR (ws.uwi, 1, LENGTH (ws.uwi) - 2)) =
                                hs.uwi
                         AND hs.status_date IN '01.04.2019')
                    AS cid_rab,
                 udmurtneft_n.dg_sdes (ws.reservoir) AS cid,
                 udmurtneft_n.dg_des (ws.layer_id) AS plast,
                 ws.top,
                 ws.base,
                 ws.top_dsrd,
                 ws.base_dsrd,
                 ABS (ROUND (ws.top_dsrd, 5) - ROUND (ws.base_dsrd, 5)) AS H_ef,
                 ROUND (ws.permeability_alt, 5),
                 ws.porosity_alt,
                   ABS (ROUND (ws.top_dsrd, 5) - ROUND (ws.base_dsrd, 5))
                 * ROUND (ws.permeability, 5)
                    AS KH,
                 ws.saturation,
                 udmurtneft_n.dg_des (ws.saturation) AS nas,
                 (SELECT udmurtneft_n.str_sum (DISTINCT ps.top)
                    FROM unofm.perflayers2 ps
                   WHERE     Uwi = ws.Uwi
                         AND (   (    top >= ws.top
                                  AND top < ws.base)
                              OR (    botm > ws.top
                                  AND botm <= ws.base)
                              OR (    ws.top >= top
                                  AND ws.top < botm)
                              OR (    ws.base > top
                                  AND ws.base <= botm))
                         AND ps.dat_perf IS NOT NULL
                         AND Interpreter IN (1, 3))
                    top_ps,
                 (SELECT udmurtneft_n.str_sum (DISTINCT ps.botm)
                    FROM unofm.perflayers2 ps
                   WHERE     Uwi = ws.Uwi
                         AND (   (    top >= ws.top
                                  AND top < ws.base)
                              OR (    botm > ws.top
                                  AND botm <= ws.base)
                              OR (    ws.top >= top
                                  AND ws.top < botm)
                              OR (    ws.base > top
                                  AND ws.base <= botm))
                         AND ps.dat_perf IS NOT NULL
                         AND Interpreter IN (1, 3))
                    botm_ps,
                 (SELECT udmurtneft_n.str_sum (DISTINCT tt.sat_cat)
                    FROM udmurtneft_n.geophys_st st,
                         udmurtneft_n.geophys_st_interpr i,
                         udmurtneft_n.dict_sat tt
                   WHERE     st.id = i.id
                         AND st.uwi = ws.uwi
                         AND TRIM (tt.sat_rem) = TRIM (i.saturation)
                         AND (   (    i.top >= ws.top
                                  AND i.top < ws.base)
                              OR (    i.bottom > ws.top
                                  AND i.bottom <= ws.base)
                              OR (    ws.top >= i.top
                                  AND ws.top < i.bottom)
                              OR (    ws.base > i.top
                                  AND ws.base <= i.bottom)))
                    AS sat_tek
            FROM udmurtneft_n.well_log_result_sublayers ws,
                 udmurtneft_n.well_hdr h
           WHERE     ws.uwi = h.uwi
                 AND ws.interpreter IN (1, 3)
                 AND ws.uwi NOT LIKE '%_F%'
                 AND h.field = 510399)
   WHERE     top_ps IS NULL
         AND H_ef >= 1
         AND KH > 100
         AND porosity_alt >= 0.16
         AND class = 26690
         AND crstatus NOT IN (85790, 85850)
         AND well_type IS NULL
         AND uwi NOT LIKE '%B%'
         AND saturation IN (217463,
                            217443,
                            217483,
                            217603,
                            217683,
                            217783,
                            273943,
                            274003,
                            1083681,
                            1126381)
         AND (   sat_tek IS NULL
              OR (    sat_tek NOT LIKE '%водонасыщенный%'
                  AND sat_tek NOT LIKE '%газонасыщенный%'
                  AND sat_tek NOT LIKE
                         '%газоводонасыщенный%%'))
ORDER BY uwi, top;

看看是否有帮助。