关于获得毫秒问题 current_timestamp

tang2007c 2008-09-14 10:44:56

declare
i int;
str varchar(10);
begin
i:=to_number(to_char(current_timestamp(3),'FF'));--error
str:=to_char(current_timestamp(3),'FF');--error
dbms_output.put_line(length(str));
dbms_output.put_line(i);
end;

我的原意是想像sqlserver里的datepart('ms',getdate())一样获得3位的毫秒数
但是oracle里的to_char(sysdate,'')没有毫秒级的
上网找到了current_timestamp

用 select 语句
to_number(to_char(current_timestamp(3),'FF'))
str:=to_char(current_timestamp(3),'FF')

都可以,但是放入表达式赋值就不行了

pl/sql develop 提示错误:
Error: PLS-00306: wrong number or types of arguments in call to 'CURRENT_TIMESTAMP'

请大家帮下我,谢谢了。
...全文
466 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
oracledbalgtu 2008-09-14
  • 打赏
  • 举报
回复
去掉current_timestamp的精度参数就ok了。

DECLARE
I INT;
STR VARCHAR(10);
BEGIN
I := TO_NUMBER(TO_CHAR(CURRENT_TIMESTAMP(), 'FF')); --error
STR := TO_CHAR(CURRENT_TIMESTAMP( ), 'FF'); --error
DBMS_OUTPUT.PUT_LINE(LENGTH(STR));
DBMS_OUTPUT.PUT_LINE(I);
END;
/



[Quote=引用楼主 tang2007c 的帖子:]
SQL code
declare
i int;
str varchar(10);
begin
i:=to_number(to_char(current_timestamp(3),'FF'));--error
str:=to_char(current_timestamp(3),'FF');--error
dbms_output.put_line(length(str));
dbms_output.put_line(i);
end;



我的原意是想像sqlserver里的datepart('ms',getdate())一样获得3位的毫秒数
但是oracle里的to_char(sysdate,'')没有毫秒级的
上网找到了current_timestamp

[/Quote]
tang2007c 2008-09-14
  • 打赏
  • 举报
回复
T T
请大家帮帮我~~~~~~~~~
tang2007c 2008-09-14
  • 打赏
  • 举报
回复
str:=to_char(current_timestamp(3),'FF')
笔误
是to_char(current_timestamp(3),'FF')

sleepzzzzz 2008-09-14
  • 打赏
  • 举报
回复
弟弟不谢
tang2007c 2008-09-14
  • 打赏
  • 举报
回复
哈哈~~谢谢哥哥
又是你啊

您真内行哩~

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧