2013-07-12 50 views
1

我使用VS2010和Oracle作爲我的數據庫在x64機器中,但是我的.NET代碼出現問題。它是:ORA-00923:FROM關鍵字找不到預期的地方,但它適用於Oracle Toad

這只是一個從DataGrid選擇功能的Web服務調用的函數。

Public Shared Function get_lista(ByVal i_filtros As CBoletaGarantiaListafiltro, ByVal i_usuario As CUsuario, ByVal i_con As OracleConnection, ByVal i_tran As OracleTransaction, ByRef o_error As CError) As List(Of CBoletaGarantiaLista) 
     Dim sql As String 
     sql = " select " 
     sql = sql & " a.id_proyecto " 
     sql = sql & " ,a.id_solicitud " 
     sql = sql & " ,a.fecha_ingreso " 
     sql = sql & " ,a.usuario_ingreso " 
     sql = sql & " ,a.estado " 
     sql = sql & " ,a.cod_motivo " 
     sql = sql & " ,a.beneficiario " 
     sql = sql & " ,a.tipo_obra_bol " 
     sql = sql & " ,a.tipo_plazo " 
     sql = sql & " ,a.vigencia " 
     sql = sql & " ,a.monto " 
     sql = sql & " ,a.codigo_moneda " 
     sql = sql & " ,a.flex " 
     sql = sql & " ,a.fecha_esperada " 
     sql = sql & " ,a.tomador " 
     sql = sql & " ,b.sdesc tipo_obra_desc " 
     sql = sql & " ,c.sdesc tipo_plazo_desc " 
     sql = sql & " ,d.sdesc tomador_desc " 
     sql = sql & " ,e.sdesc beneficiario_desc " 
     sql = sql & " ,f.sdesc codigo_moneda_desc" 
     sql = sql & " ,g.nombre nombre_proyecto" 
     sql = sql & " ,a.etapa " 
     sql = sql & " ,h.sdesc estado_desc " 
     sql = sql & " ,a.glosa " 
     sql = sql & " ,i.nro_boleta " 
     sql = sql & " from abd_bol_garantia a " 
     sql = sql & " , abd_codigos b " 
     sql = sql & " , abd_codigos c " 
     sql = sql & " , abd_codigos d " 
     sql = sql & " , abd_codigos e " 
     sql = sql & " , abd_monedas f " 
     sql = sql & " , abd_proyectos g " 
     sql = sql & " , abd_codigos h " 
     sql = sql & " , abd_bol_garantia_obtencion i " 
     sql = sql & " where " 
     sql = sql & " b.tipo=65 " 
     sql = sql & " and b.codigo=a.tipo_obra_bol " 
     sql = sql & " and c.tipo=66 " 
     sql = sql & " and c.codigo=a.tipo_plazo " 
     sql = sql & " and d.tipo=67 " 
     sql = sql & " and d.codigo=a.tomador " 
     sql = sql & " and e.tipo=68 " 
     sql = sql & " and e.codigo=a.beneficiario " 
     sql = sql & " and f.ID_MONEDA=a.codigo_moneda " 
     sql = sql & " and g.ID_proyecto=a.id_proyecto " 
     sql = sql & " and h.tipo=71 " 
     sql = sql & " and h.codigo=a.estado " 
     sql = sql & " and a.id_solicitud=i.id_solicitud(+)" 


     If Not i_filtros.estado Is Nothing Then 
      sql = sql & " and a.estado=:estado " 
     End If 

     sql = sql & " and a.vigencia>=:vigencia_ini " 
     sql = sql & " and a.vigencia<:vigencia_fin " 

     If Not i_filtros.id_proyecto Is Nothing Then 
      sql = sql & " and a.id_proyecto=:id_proyecto " 
     End If 

     If Not i_filtros.id_solicitud Is Nothing Then 
      sql = sql & " and a.id_solicitud=:id_solicitud " 
     End If 

     sql = sql & " order by a.id_solicitud " 

     Dim comando As New OracleCommand(sql, i_con, i_tran) 


     comando.Parameters.Add("vigencia_ini", OracleType.DateTime).Value = i_filtros.fecha_vigencia_ini.Date 
     comando.Parameters.Add("vigencia_fin", OracleType.DateTime).Value = i_filtros.fecha_vigencia_fin.Date.AddDays(1) 


     If Not i_filtros.estado Is Nothing Then 
      comando.Parameters.Add("estado", OracleType.Int32).Value = i_filtros.estado 
     End If 


     If Not i_filtros.id_proyecto Is Nothing Then 
      comando.Parameters.Add("id_proyecto", OracleType.Int32).Value = i_filtros.id_proyecto 
     End If 

     If Not i_filtros.id_solicitud Is Nothing Then 
      comando.Parameters.Add("id_solicitud", OracleType.Int32).Value = i_filtros.id_solicitud 
     End If 


     Dim leer As OracleDataReader 


     leer = comando.ExecuteReader 


     Dim x_lista As New List(Of CBoletaGarantiaLista) 
     While leer.Read 
      Dim a As New CBoletaGarantiaLista 

      If Not leer.IsDBNull(0) Then 
       a.id_proyecto = leer.GetInt32(0) 
      End If 

      If Not leer.IsDBNull(1) Then 
       a.id_solicitud = leer.GetInt32(1) 
      End If 

      If Not leer.IsDBNull(2) Then 
       a.fecha_ingreso = leer.GetDateTime(2) 
      End If 

      If Not leer.IsDBNull(3) Then 
       a.usuario_ingreso = leer.GetString(3) 
      End If 

      If Not leer.IsDBNull(4) Then 
       a.estado = leer.GetInt32(4) 
      End If 

      If Not leer.IsDBNull(5) Then 
       a.cod_motivo = leer.GetInt32(5) 
      End If 

      If Not leer.IsDBNull(6) Then 
       a.beneficiario = leer.GetInt32(6) 
      End If 

      If Not leer.IsDBNull(7) Then 
       a.tipo_obra_bol = leer.GetInt32(7) 
      End If 

      If Not leer.IsDBNull(8) Then 
       a.tipo_plazo = leer.GetInt32(8) 
      End If 

      If Not leer.IsDBNull(9) Then 
       a.vigencia = leer.GetDateTime(9) 
      End If 

      If Not leer.IsDBNull(10) Then 
       a.monto = leer.GetDouble(10) 
      End If 

      If Not leer.IsDBNull(11) Then 
       a.codigo_moneda = leer.GetInt32(11) 
      End If 

      If Not leer.IsDBNull(12) Then 
       a.flex = leer.GetInt32(12) 
      End If 

      If Not leer.IsDBNull(13) Then 
       a.fecha_esperada = leer.GetDateTime(13) 
      End If 

      If Not leer.IsDBNull(14) Then 
       a.tomador = leer.GetInt32(14) 
      End If 

      If Not leer.IsDBNull(15) Then 
       a.tipo_obra_desc = leer.GetString(15) 
      End If 

      If Not leer.IsDBNull(16) Then 
       a.tipo_plazo_desc = leer.GetString(16) 
      End If 

      If Not leer.IsDBNull(17) Then 
       a.tomador_desc = leer.GetString(17) 
      End If 

      If Not leer.IsDBNull(18) Then 
       a.beneficiario_desc = leer.GetString(18) 
      End If 

      If Not leer.IsDBNull(19) Then 
       a.codigo_moneda_desc = leer.GetString(19) 
      End If 

      If Not leer.IsDBNull(20) Then 
       a.nombre_proyecto = leer.GetString(20) 
      End If 

      If Not leer.IsDBNull(21) Then 
       a.etapa = leer.GetInt32(21) 

       If a.etapa = 1 Then 
        a.etapa_desc = "Aprobacion de Solicitud" 
       ElseIf a.etapa = 2 Then 
        a.etapa_desc = "Entrega de Boleta" 
       ElseIf a.etapa = 3 Then 
        a.etapa_desc = "Retiro de Boleta" 
       ElseIf a.etapa = 4 Then 
        a.etapa_desc = "Devolucion a Tesoreria" 
       End If 
      End If 

      If Not leer.IsDBNull(22) Then 
       a.estado_desc = leer.GetString(22) 
      End If 

      If Not leer.IsDBNull(23) Then 
       a.glosa = leer.GetString(23) 
      End If 

      If Not leer.IsDBNull(24) Then 
       a.nro_boleta = leer.GetString(24) 
      End If 

      x_lista.Add(a) 
     End While 

     leer.Close() 
     Return x_lista 
    End Function 

當我嘗試調試它,我一直在具有的錯誤消息:在預期的位置

從關鍵字沒有找到,但我試圖在甲骨文蟾蜍和SQLPLUS,它運行時沒有任何錯誤。

我是一個新手,但我不應該有任何問題,這個查詢...它不是那麼複雜,不是嗎?

在此先感謝

+0

您很可能有格式錯誤。您是否嘗試在調試器中打印出sql字符串,將其粘貼到蟾蜍中並運行它? – OldProgrammer

+0

是的,我試過並且完美地工作問題是當我在VS2010上調試/運行它 –

+1

您使用的是什麼版本的Oracle?你應該做的第一件事是放棄這種語法,這是Oracle本身不推薦的。一個標準的'內連接... ...','左連接...','右連接...',而不是'加',如'a.id_solicitud = i.id_solicitud(+)' ,至於vb.net編碼去,這是災難,你應該停止這一點:'sql = sql&「a.id_proyecto」'並且這樣做:'sql =「a.id_proyecto」&_' –

回答

0

這是你的代碼的第一部分應該是什麼樣子。請注意,我可能沒有得到確切的正確的命令對象超載,但重點是稍後分配命令文本。

Dim static as String = "Select" & _ 
" a.id_proyecto" & _ 
", a.id_solicitud" & _ 
", a.fecha_ingreso" & _ 
", a.usuario_ingreso" & _ 
", a.estado" & _ 
", a.cod_motivo" & _ 
", a.beneficiario" & _ 
", a.tipo_obra_bol" & _ 
", a.tipo_plazo" & _ 
", a.vigencia" & _ 
", a.monto" & _ 
", a.codigo_moneda" & _ 
", a.flex" & _ 
", a.fecha_esperada" & _ 
", a.tomador" & _ 
", b.sdesc tipo_obra_desc" & _ 
", c.sdesc tipo_plazo_desc" & _ 
", d.sdesc tomador_desc" & _ 
", e.sdesc beneficiario_desc" & _ 
", f.sdesc codigo_moneda_desc" & _ 
", g.nombre nombre_proyecto" & _ 
", a.etapa" & _ 
", h.sdesc estado_desc" & _ 
", a.glosa " & _ 
", i.nro_boleta" & _ 
" From " & _ 
"abd_bol_garantia a inner join " & _ 
"abd_codigos b on b.codigo = a.tipo_obra_bol inner join " & _ 
"abd_codigos c on c.codigo = a.tipo_plazo inner join " & _ 
"abd_codigos d on d.codigo = a.tomador inner join " & _ 
"abd_codigos e on e.codigo = a.beneficiario inner join " & _ 
"abd_monedas f on f.ID_MONEDA = a.codigo_moneda inner join " & _ 
"abd_proyectos g on g.ID_proyecto = a.id_proyecto inner join " & _ 
"abd_codigos h on h.codigo = a.estado left join " & _ 
"abd_bol_garantia_obtencion i on a.id_solicitud = i.id_solicitud " & _ 
"Where " & _ 
"b.tipo = 65 and " & _ 
"c.tipo = 66 and " & _ 
"d.tipo = 67 and " & _ 
"e.tipo = 68 and " & _ 
"h.tipo = 71" 

dim execSql as new StringBuilder(static) 
Dim comando As New OracleCommand(i_con, i_tran) 

execSql.Append(" and a.vigencia >= :vigencia_ini") 
execSql.Append(" and a.vigencia < :vigencia_fin") 
comando.Parameters.Add("vigencia_ini", OracleType.DateTime).Value = i_filtros.fecha_vigencia_ini.Date 
comando.Parameters.Add("vigencia_fin", OracleType.DateTime).Value = i_filtros.fecha_vigencia_fin.Date.AddDays(1)  


If Not i_filtros.estado Is Nothing Then 
    execSql.Append(" and a.estado = :estado") 
    comando.Parameters.Add("estado", OracleType.Int32).Value = i_filtros.estado 
End If 

If Not i_filtros.id_proyecto Is Nothing Then 
    execSql.Append(" and a.id_proyecto = :id_proyecto") 
comando.Parameters.Add("id_proyecto", OracleType.Int32).Value = i_filtros.id_proyecto 
End If 

If Not i_filtros.id_solicitud Is Nothing Then 
    execSql.Append(" and a.id_solicitud=:id_solicitud") 
    comando.Parameters.Add("id_solicitud", OracleType.Int32).Value = i_filtros.id_solicitud 
End If 

execSql.Append(" Order By a.id_solicitud") 


comando.CommandText = execSql.ToString() 
+0

我採取了一些答覆,並與我的代碼混合使其工作,謝謝TS ..但是,它只在重新啓動我的機器後,所以我認爲這是一個調試器問題。 :D –

+0

問題在於您的代碼正在填充內存堆。如果你使用我的,你會很好。另外,嚴格使用內部連接:o) –

相關問題