2016-09-08 39 views
0

我使用StringBuilderasp.net中使用多個查詢。但我得到錯誤的ORA-00936:使用stringbuilder時缺少表達式

ORA-00936:缺少表達

下面是我的查詢。

StringBuilder sb = new StringBuilder(); 
if (ddlProject.SelectedValue != "0" && ddlBuilding.SelectedValue != "0") 
{ 
    sb.Append("insert into xxacl_pN_LEASES_ALL_h select sysdate,* from xxacl_pN_LEASES_ALL"); 
    sb.Append(";"); 
    sb.Append("update xxacl_pN_LEASES_ALL set ASSIGNED_TO = '" + ddlSalesUser.SelectedValue + "'"); 
    sb.Append(";"); 
} 
if (ddlProject.SelectedValue != "0" && ddlBuilding.SelectedValue == "0") 
{ 
    sb.Append("insert into xxacl_pN_LEASES_ALL_h select sysdate,* from xxacl_pN_LEASES_ALL"); 
    sb.Append(";"); 
    sb.Append("update xxacl_pN_LEASES_ALL set ASSIGNED_TO = '" + ddlSalesUser.SelectedValue + "'"); 
    sb.Append(";"); 
} 

OracleConnection ObjPriCon = new OracleConnection(System.Configuration.ConfigurationManager.ConnectionStrings["OracleConn"].ToString()); 
OracleCommand cmd1 = new OracleCommand(); 
string allQueries = sb.ToString(); 
cmd1.CommandText = allQueries; 
cmd1.Connection = ObjPriCon; 
ObjPriCon.Open(); 
cmd1.ExecuteNonQuery(); // here is the error caused 
ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Record updated successfully');window.location ='FrmHoldingCoordinateUpdate.aspx?TranType=FM&PView=N&Mode=A&Redirect=oracle&Key=0&Redirect=" + Request.QueryString["Redirect"] + "&userid=" + Request.QueryString["userid"].ToString() + "';", true); 

此外,allQueries給出的結果

insert into xxacl_pN_LEASES_ALL_h select getdate(),* from xxacl_pN_LEASES_ALL;update xxacl_pN_LEASES_ALL set ASSIGNED_TO = '5681';

+0

Oracle是否支持 'GETDATE()'? –

+0

@ThomasSchremser:不,對不起我的錯誤,我會改變它。這是錯誤嗎? – BNN

+0

不應該在插入到xxacl_pN_LEASES_ALL_h後出現分號 –

回答

0

您需要使用別名表名* 例如前:

insert into xxacl_pN_LEASES_ALL_h select getdate(),t.* from xxacl_pN_LEASES_ALL t; 
+0

並且,爲了澄清這個(正確的)答案:select * from ... works,但如果添加其他列(如sysdate),則不起作用。在這種情況下,您必須在*之前使用表名(或別名)。 – mathguy

+0

@mathguy:我像這樣使用它'插入到xxacl_pN_LEASES_ALL_h選擇sysdate,t。*從xxacl_pN_LEASES_ALL t'但得到錯誤爲** ORA-00911:無效字符** – BNN

+0

@mathguy:由'Surename'發佈的答案不是爲我工作 – BNN