if oracle9i
then
there is new data type called timestamp
then
there is new data type called timestamp
解决方案 »
- date 类型
- 求 数据库设计文档 实例
- oracle 临时表
- oracle内部错误,什么原因呢?
- 大数据量查询,3种sql语句,为什么执行结果跟书上以及网上说的不一样呢?
- 怎么查看本机上有几个数据库啊
- 安装问题
- 装完WIN2000操作系统最新漏洞补丁(Windows2000-KB835732-x86-CHS.EXE后 ,oracleservice就再也启动不了了?
- 请问一下,在oracle中,select的用法.
- 在oracle存储过程中如何把R2,R3,R4,R5中用数组把R2 R3 R4 R5分离出来
- 如想更改oracle的字符集怎么办?
- oracle8.1.7(中文)中DATE类型的问题!急!
granular then the Oracle DATE type. This will work in 8.1.5 and up. It can
look like this:[email protected]> CREATE or replace JAVA SOURCE
2 NAMED "MyTimestamp"
3 AS
4 import java.lang.String;
5 import java.sql.Timestamp;
6
7 public class MyTimestamp
8 {
9 public static String getTimestamp()
10 {
11 return (new
12 Timestamp(System.currentTimeMillis())).toString();
13 }
14 };
15 /Java [email protected]> create or replace function my_timestamp return varchar2
2 AS LANGUAGE JAVA
3 NAME 'MyTimestamp.getTimestamp() return java.lang.String';
4 /Function created.
[email protected]> l
1* select my_timestamp, to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual
[email protected]> /MY_TIMESTAMP
---------------------------------------------------------------------------------
-------------------
TO_CHAR(SYSDATE,'YY
-------------------
2000-06-22 13:47:53.376
2000-06-22 13:47:53
[email protected]>
2) use an external procedure written in C. C has api's to the system that allow
for much more granular time components. This will work in 8.0 and up. For
example if you run something like:[email protected]> create or replace library timelib as
2 '/export/home/tkyte/src/t/extproc.so'
3 /
Library [email protected]> create or replace
2 procedure get_extended_time( p_timestring out varchar2 )
3 is external
4 name "get_extended_time"
5 library timelib
6 language C
7 with context
8 parameters ( CONTEXT,
9 p_timestring STRING,
10 p_timestring INDICATOR short,
11 p_timestring MAXLEN int,
12 p_timestring LENGTH int );
13
14 /Procedure created.
[email protected]> declare
2 l_timestring varchar2(30);
3 begin
4 get_extended_time( l_timestring );
5 dbms_output.put_line(
to_char( sysdate, 'mm/dd/yy hh24:mi:ss' ) );
6 dbms_output.put_line( l_timestring );
7 end;
8 /
06/22/00 13:26:28
06/22/00 13:26:28.103243PL/SQL procedure successfully completed.In sqlplus after compiling the following C code into a .so or .dll or .sl
(depending on platform) you can get the milliseconds.Here is the C code:#include <stdio.h>
#include <stdarg.h>
#include <time.h>#ifndef OCI_ORACLE
# include <oci.h>
#endif
#define raise_application_error return raise_application_error_xstatic long raise_application_error_x( OCIExtProcContext * ctx,
int errCode,
char * errMsg, ...)
{
char msg[8192];
va_list ap; va_start(ap,errMsg);
vsprintf( msg, errMsg, ap );
va_end(ap); OCIExtProcRaiseExcpWithMsg(ctx,errCode,msg,strlen(msg));
return -1;
}long
get_extended_time( OCIExtProcContext * ctx,
char * p_data,
short * p_data_i,
int * p_data_maxl,
int * p_data_l )
{
struct timeval tp; if ( *p_data_maxl < 25 )
raise_application_error( ctx, 20001,
"String must be 25 bytes or more" ); gettimeofday(&tp, NULL);
cftime( p_data, "%D %T", &tp.tv_sec );
sprintf( p_data+strlen(p_data), ".%d", tp.tv_usec ); *p_data_l = strlen(p_data);
*p_data_i = 0; return 0;
}