gpt4 book ai didi

c# - Oracle 日期格式 — 数据读取器无法识别 to_char 函数

转载 作者:行者123 更新时间:2023-12-03 03:48:21 28 4
gpt4 key购买 nike

基本上只是在 YYYYMMDD 中提取日期,我可以在查询分析器中很好地完成此操作,但是当我尝试在 C# 中运行此查询时,我不断收到未找到列的错误,似乎也很难进行串联(但这并不是什么大问题)所以有点不确定这里发生了什么..我真的只是希望我的 to_char 函数能够工作。有想法吗?谢谢!

  string oradb = "user id=x;password=x;data source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)"
+"(HOST=x)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=x)));";

OracleConnection conn = new OracleConnection(oradb);
conn.Open();

OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText =
"SELECT to_char(ProblemDate, 'yyyymmdd'), data1, data2,"
+"data4, data5, data6"
+" WHERE ( ProblemDate >='03-oct-2011' ) "
+"AND ( ProblemDate <= '08-oct-2011' ) AND "
+"( data1 in ( '3','5','6' ) )";
OracleDataReader dr = cmd.ExecuteReader();

string fileOut1 = Request.PhysicalApplicationPath;
string fileOut = fileOut1 + "Text5.txt";
// Creates the file
StreamWriter sw = new StreamWriter(fileOut);
if (dr.HasRows)
{
while (dr.Read())
{
string data1= (string)dr["data1"].ToString();
string data2 = (string)dr["data3"].ToString();
string data3 = (string)dr["data4"];
string data4 = (string)dr["data5"].ToString();
string data5 = (string)dr["data6"].ToString();
string ProblemDate = (string)dr["ProblemDate"].ToString();

//remove the comma
char[] MyChar = { ',' };

sw.WriteLine(data1.PadRight(10) + data2.PadRight(5) + data3.TrimEnd(MyChar) + "000" +
data4 + "000" + data5+ ProblemDate + " " + "N" );

Label1.Text = "File created successfully.<br />";
Label1.Text += fileOut1;
}
// Closes the connenction.
sw.Close();
conn.Close();
}
else
{
Label1.Text = "No data written.";
}

最佳答案

首先,您可以从 Java 内部打印查询并查看实际触发的查询吗?

这些是我看到的问题......

SELECT to_char(ProblemDate, 'yyyymmdd'), data1, data2,
data4, data5, data6
WHERE ( ProblemDate >='03-oct-2011' )
AND ( ProblemDate <= '08-oct-2011' )
AND data1 in ( '3','5','6' ) );
  1. 查询中没有 from 子句和 table_name。

  2. 这可能不是问题的原因,但想指出来。由于您正在执行 to_char,我假设 ProblemDate 是日期数据类型。始终建议在比较时使用显式强制转换,因此将条件更改为

    ProblemDate >=to_date('03-oct-2011','dd-mon-yyyy') 和ProblemDate <=to_date('08-oct-2011',,'dd-mon-yyyy')

关于c# - Oracle 日期格式 — 数据读取器无法识别 to_char 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8393210/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com