Oracle資料庫Date型別字段讀寫經驗

2021-09-30 03:05:22 字數 1771 閱讀 3240

在oracle資料庫(簡體中文)中,date型別的資料字段在訪問時會比較麻煩,下面把在學習中的一些經驗記錄如下:

2、在asp.net應用程式中,如果要獲取使用者輸入的日期,必須將使用者輸入的日期轉換為上面的格式,如:insert into sample values(3422,'ssxxdd',23-4月-2003'),才能成功插入。如果採用函式now獲取當前時間,然後利用insert語句:「insert into mytable (indate) values(」 & now & 「)」則提示缺少,號??(不知為什麼?);若把now加上引號則提示格式不正確。只好用程式獲取當前時間,並合併成正確的格式,如:

dim rz as string = now.day.tostring + "-" + now.month.tostring + "月-" & now.year.tostring

dim sqlstr as string = "insert into sample values(3233,'xxddss','" & rz & "')"

但是若加上時間後就不行了,試了很多方式都不行,不知是什麼格式:(

如果是利用過程就沒有這麼多的麻煩啦!比如已經建立了下面的過程:

create or replace  procedure "gf"."sample_add" 

(in_no in   sample.no%type,

in_message in sample.message%type,

in_date in date)

asbegin

insert into gf.sample (no,message,indate) values(in_no,in_message,in_date);

end;

那麼在程式中只需直接給in_date引數用now函式賦值就行了:

dim cmd as new oraclecommand("sample_add", cn)

cmd.commandtype = commandtype.storedprocedure

cmd.parameters.add(new oracleparameter("in_date", oracletype.datetime))

cmd.parameters("in_date").value = now

資料表可以獲取完整的當前日期。

呵呵,oracle真是難搞啊。不過還得繼續琢磨。

又找到一種利用引數插入資料方法

dim sqlstr as string = "insert into sample values(:no,:message,:indate)"

dim cmd as new oraclecommand(sqlstr, cn)

cmd.parameters.add(new oracleparameter("no", oracletype.number, 5))

cmd.parameters("no").value = 3222

cmd.parameters.add(new oracleparameter("message", oracletype.varchar, 100))

cmd.parameters("message").value = "******xddddddddddd"

cmd.parameters.add(new oracleparameter("indate", oracletype.datetime))

cmd.parameters("indate").value = now

cmd.executenonquery()

注意:和sqlserver的區別在於:@no→:no

Oracle資料庫Date型別查詢問題

oracle資料庫date型別查詢問題 用過oracle資料庫的朋友應該知道,oracle資料庫在以date型別為查詢條件時存在乙個小小的bug,如 select from tablename where createdate to date 2007 01 01 yyyy mm dd and cr...

Oracle資料庫Date型別字段讀寫經驗

在oracle資料庫 簡體中文 中,date型別的資料字段在訪問時會比較麻煩,下面把在學習中的一些經驗記錄如下 2 在asp.net應用程式中,如果要獲取使用者輸入的日期,必須將使用者輸入的日期轉換為上面的格式,如 insert into sample values 3422,ssxxdd 23 4...

主流資料庫 DATE 型別適用指南

1,oracle public final static string oracle create table date type test date t date,timestamp t timestamp 3 interval t interval year to month public fi...