Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 如何将oracle数字类型转换为字符串格式?_String_Oracle_Numbers_Format_Converter - Fatal编程技术网

String 如何将oracle数字类型转换为字符串格式?

String 如何将oracle数字类型转换为字符串格式?,string,oracle,numbers,format,converter,String,Oracle,Numbers,Format,Converter,我想将数字类型转换为字符串,格式为: number -> string 1 -> 001 2 -> 002 12 -> 012 340 -> 340 您可以使用(在这种情况下更可取)函数或函数来实现所需的结果: SQL> with t1(col) as( 2 select 1 from dual union all 3 select 2 from dual u

我想将数字类型转换为字符串,格式为:

number -> string

    1      -> 001
    2      -> 002
    12     -> 012
    340    -> 340  
您可以使用(在这种情况下更可取)函数或函数来实现所需的结果:

SQL> with t1(col) as(
  2    select 1   from dual union all
  3    select 2   from dual union all
  4    select 12  from dual union all
  5    select 340 from dual
  6  )
  7  select to_char(col, '000')        as num_1
  8       , lpad(to_char(col), 3, '0') as num_2
  9    from t1
 10  ;

NUM_1 NUM_2
----- ------------
 001  001
 002  002
 012  012
 340  340
您可以使用(在这种情况下更可取)函数或函数来实现所需的结果:

SQL> with t1(col) as(
  2    select 1   from dual union all
  3    select 2   from dual union all
  4    select 12  from dual union all
  5    select 340 from dual
  6  )
  7  select to_char(col, '000')        as num_1
  8       , lpad(to_char(col), 3, '0') as num_2
  9    from t1
 10  ;

NUM_1 NUM_2
----- ------------
 001  001
 002  002
 012  012
 340  340