私はを使用しています.Net Managed Data Access Clientは.netです。パラメータからタイムスタンプ(形式:MM/dd/yyyy hh:mi:ss:ff AM)を渡す必要があります。また、TIME_STAMP()関数を使用してoracle固有のタイムスタンプに変換する必要があります。私が値を直接注入すると、それは機能します。しかし、私はパラメータを通過すると、私はエラーが発生します。私は、それがvarchar/stringではなくオブジェクトとしてパラメータを取ると信じています。odp.netパラメータ値として渡された日付を解析する方法は?
したがって、値をOracleParameterとして渡して、oracle固有のtimeStampに変換するにはどうすればよいですか。
しかし、これはありません。これにより、日付のデータは表示されますが、指定されたタイムスタンプが正しく表示されません(秒数分を比較する必要もあります)。値について
string SELECTGROUPSESSIONS = @"SELECT * FROM (
SELECT Recent.sent_date, Recent.thread_id, Recent.body_string, Recent.body_text,
Recent.message_string, Recent.message_text, Recent.body_len, Recent.from_jid ,
Recent.to_jid, Recent.history_flag
FROM JM Recent Left Join
(Select * from JM where sent_date > TO_TIMESTAMP(:FromHistory,'MM/dd/yyyy hh:mi:ss:ff AM')) Old
on (Recent.body_string=Old.body_string and
Recent.body_len=Old.body_len and Recent.from_jid=Old.from_jid and
REGEXP_REPLACE(Recent.to_jid , '([/])\w+', '') = REGEXP_REPLACE(Old.to_jid , '([/])\w+', '')
and Recent.history_flag=Old.history_flag and Old.sent_date < Recent.sent_date)
where Recent.msg_type ='g'
and Recent.body_len>0 and Recent.sent_date > TO_TIMESTAMP(:FromDate,'MM/dd/yyyy hh:mi:ss:ff AM')
and Recent.sent_date < TO_TIMESTAMP(:ToDate,'MM/dd/yyyy hh:mi:ss:ff AM')
and Old.sent_date is null
order by Recent.sent_date asc
)
WHERE rownum <= {0}";
:
私のクエリは次のようになります。
SELECT * FROM (
SELECT Recent.sent_date, Recent.thread_id, Recent.body_string,
Recent.body_text, Recent.message_string, Recent.message_text, Recent.body_len,
Recent.from_jid , Recent.to_jid, Recent.history_flag FROM JM Recent Left Join
(Select * from JM where sent_date >
TO_TIMESTAMP('02/19/2017 10:43:00:8357400 AM','MM/dd/yyyy hh:mi:ss:ff AM')) Old on
(Recent.body_string=Old.body_string and Recent.body_len=Old.body_len and
Recent.from_jid=Old.from_jid and
REGEXP_REPLACE(Recent.to_jid , '([/])\w+', '') = REGEXP_REPLACE(Old.to_jid , '([/])\w+', '')
and Recent.history_flag=Old.history_flag and Old.sent_date < Recent.sent_date)
where Recent.msg_type ='g' and Recent.body_len>0 and Recent.sent_date >
TO_TIMESTAMP('03/21/2017 10:43:00:8357400 AM','MM/dd/yyyy hh:mi:ss:ff AM') and
Recent.sent_date < TO_TIMESTAMP('03/22/2017 09:02:28:3049506 AM','MM/dd/yyyy hh:mi:ss:ff AM')
and Old.sent_date is null order by Recent.sent_date asc ) WHERE rownum <= 500
C#のコード:
selectCommand = _factory.GetDbCommand(queryStatement, SqlConnection);
selectCommand.Parameters.Clear();
using (selectCommand)
{
if (parameters != null)
{
foreach (var param in parameters)
{
selectCommand.Parameters.Add(_factory.CreateParameter(param.Key, param.Value));
}
}
try
{
using (
var reader = selectCommand.ExecuteReader())
{
processReader(reader);
}
結果: それは日付フォーマットの不一致が原因だろうか?
を試してみてください正しいタイプ。 –
これらの{0}プレースホルダは何ですか?これらは有効なOracleパラメータ識別子ではありません。クエリは 'WHERE rownum <= {0}'ではなく 'WHERE rownum <=:num 'で終わる必要があります。文字列操作を使用してクエリを生成していますか?それはあなたにSQLインジェクション攻撃や変換エラーにさらされることを保証しています。 –
@PanagiotisKanavosごめんなさい。ただ説明するだけでした。それはうまくいくだろう。しかし、oracleパラメータと同じ値を渡すと、それはしません。私はデータを取得しますが、それらは指定されたタイムスタンプに正確にはありません。タイムスタンプの形式は、02/09/2017 10:47:01:273161000 AMです。 –