简体   繁体   中英

Oracle.DataAccess.Client.OracleException: ORA-00936: missing expression

I wrote a C# console program to try to query some data from Oracle, it is a very simple query but I don't know why it is always tell me "missing expression" while running it, see below my code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Oracle.DataAccess.Client;
using System.Configuration;

namespace ConnectToOracle
{
    class Program
    {
        static void Main(string[] args)
        {

            string strCon = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;

            using (OracleConnection oc = new OracleConnection(strCon))
            {
                OracleCommand cmd = new OracleCommand("select dname from dept where deptno = @deptno", oc);
                OracleParameter op = new OracleParameter();
                op.ParameterName = "@deptno";
                op.OracleDbType = OracleDbType.Int32;
                op.Direction = System.Data.ParameterDirection.Input;

                cmd.Parameters.Add(op);
                oc.Open();
                string dname = (string)cmd.ExecuteScalar();
           }
        }
    }
}

so, at the last line, the error "missing expression" will be thrown from cmd.ExecuteScalar() method, can any one tell me why? I was confused

thanks in advance!

Use : instead of @ .

 OracleCommand cmd = new OracleCommand("select dname from dept where deptno = :deptno", oc);
                OracleParameter op = new OracleParameter();
                op.ParameterName = "deptno";
                op.OracleDbType = OracleDbType.Int32;
                op.Direction = System.Data.ParameterDirection.Input;

Reference: OracleCommand.Parameters Property

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM