040908 Q SQL statement In SqlServer & Oracle --SELECT TOP 0 * FROM & ROWNUM = 0

时间:2022-05-30 03:09:17

1.string strSQL = "SELECT TOP 0 * FROM " + strTblName ;

OracleDataAdapter oraAdapter = new OracleDataAdapter();

     oraAdapter.SelectCommand = GetOraCommand(strSQL) ; // new OracleCommand

     DataTable dt = new DataTable();

     oraAdapter.FillSchema(dt, System.Data.SchemaType.Mapped);

     // Error :ORA-00923: FROMキーワードが指定の位置にありません。/n

    使用SqlClient时正常,Oracle 时出上面错。为什么?

   A:Oracle 使用 WHERE ROWNUM = 0

2.Oracle 里使用OracleParameter的SQL 语句

   DataTable dt = new DataTable();
   string ConnectString = "server=ibm2d; uid=ibm2d;pwd=ibm2d; Data Source=ibm2d";
   string strSQL = "SELECT * FROM JS_KOJIN_TBL WHERE KJNNO  = :KJNNO";//SqlServer里用KJNNO = @KJNNO
   OracleConnection conn = new OracleConnection(ConnectString);
   conn.Open();

   OracleCommand cmd = new OracleCommand(strSQL, conn);
   cmd.CommandType = CommandType.Text;
   OracleDataAdapter oraAdapter = new OracleDataAdapter();
   oraAdapter.SelectCommand = cmd;
   oraAdapter.SelectCommand.Parameters.Add (":KJNNO",OracleType.VarChar,4,"KJNNO");
   oraAdapter.SelectCommand.Parameters[":KJNNO"].Value = "1099";
   
   oraAdapter.Fill(dt);