insert into 表名(字段1,字段2)values('1',to_char(12,'000000000000'))为何存进数据库时" 000000000012"会前面多个空格啊,谁能告诉我下

解决方案 »

  1.   

    回楼上 会报ORA-00904: "TO_VARCHAR"; invalid identifier错误
      

  2.   

    to_char 是什么函数?没见过
      

  3.   

    这样看看
    insert into 表名(字段1,字段2)values('1',to_char(12,'FM000000000000'))
      

  4.   

    我也不太清楚,这样用过。感觉是oracle的to_char函数格式化的一个参数,搂主可以去oralce网站上查查
      

  5.   

    一般都剪掉空格保险  在MSSQL中也ltrim这样去掉左边的空格
      

  6.   

    格式符0的含义是:在对应位置返回对应的字符,如果没有则以'0'填充.
    to_char(12,'000000000000') 按格式符的含义结果应该是:000000000012
    但是为什么多一个空格?想问下lz数据库中字段2的类型是什么,varchar?char?
      

  7.   

    FMFill mode. Oracle uses blank characters to fill format elements to a constant width equal to the largest element for the relevant format model in the current session language. For example, when NLS_LANGUAGE is AMERICAN, the largest element for MONTH is SEPTEMBER, so all values of the MONTH format element are padded to 9 display characters. This modifier suppresses blank padding in the return value of the TO_CHAR function:In a datetime format element of a TO_CHAR function, this modifier suppresses blanks in subsequent character elements (such as MONTH) and suppresses leading zeroes for subsequent number elements (such as MI) in a date format model. Without FM, the result of a character element is always right padded with blanks to a fixed length, and leading zeroes are always returned for a number element. With FM, which suppresses blank padding, the length of the return value may vary.In a number format element of a TO_CHAR function, this modifier suppresses blanks added to the left of the number, so that the result is left-justified in the output buffer. Without FM, the result is always right-justified in the buffer, resulting in blank-padding to the left of the number.