当前位置:首页 » 编程语言 » sql位数不足补0

sql位数不足补0

发布时间: 2022-11-27 12:33:00

sql怎样在固定值后面补0

具体什么数据库

以sqlserver,mysql,oracle各自为例:

sqlserver:

createtabletest
(点名varchar(20));

insertintotestvalues('HS901');
insertintotestvalues('HS9010');
insertintotestvalues('HS9010');

执行:

selectLEFT(点名+'00000000',8)fromtest

结果:

② sql server 保留2位小数,如果整数 后面补0

1、创建测试表,

create table test_num(id number, value number);

③ sql位数不足补0

假设结果值用变量a表示,补位用b表示,需求结果用c表示
if len(a)=1 then
b="000"
elseif len(a)=2 then
b="00"
elseif len(a)=3 then
b="0"
else
b=""
end if

c=b&a

④ sql中不足六位的补零该怎么写

假设#a 表有字段 a char(10)

该代码即可实现该功能:

if exists(select a from #a where len(a)<=6)
begin
update #a set a=rtrim(cast(a as char(8)))+'000'
end
else if exists(select a from #a where len(a)<0)
begin
rollback transaction
end
else
begin
print '该数据已经有六位'
end

⑤ sql 不够七位数 在左侧自动补零,怎么实现

sqlserver:
select right(cast('0000000000'+rtrim(字段) as varchar(20)),7)

oralce:
select lpad(字段, 7 , '0') from al

⑥ sql数据补位

用lapd函数,左补零

用法
select LPAD(100,5,0) from al

100为字段名,5为补完后的长度,0为补充的字符

⑦ SQL不够10位 补0 补到10位写何写


咱们来看:

cast('000000000'+convert(int,code)asvarchar(20))

首先:

convert(int,code) :你把code 转为 int

然后

'000000000'+convert(int,code)我估计sqlserver肯定把表达式作为数字相加了,那么0000...的相加就没有作用了。

最后

就不是你要的结果了。


大致应该这样:

SELECT
right(cast('000000000'+rtrim(code)asvarchar(20)),10),code,
id,pydate,isnull(lzdate,'9999-12-31'),0
FROMzlemployee



⑧ 在SQL数据库中怎样让编号从6位数开始,而且不足6位就在前面补0

SQL本身难以处理,应该在应用程序写入/读取的时候进行格式化

insert 或者 select 的时候对编号字段格式化format(编号,"000000")

⑨ sql中如何在插入数时不足位数前加0

你好!
不足位数前加0,位数是几位啊,我就认为是5位了哦,插入的数据为number
select
right('00000'+convert(varchar,number),5)
希望对你有所帮助,望采纳。

⑩ sql server怎么把inFileIndex列通过update更新成4位,不足前面补零。 例如:0049 0115 0113 0001 ......

首先保证inFileIndex要为字符类型,不能是数字类型,否则更新不进去。

update表名setinFileIndex=right('000'+inFileIndex,4)


更新前可以先查询看看结果是否正确

selectright('000'+inFileIndex,4)from表名
热点内容
我配置很高了ae为什么卡 发布:2025-05-17 14:54:50 浏览:167
python数据分析实战pdf 发布:2025-05-17 14:49:42 浏览:950
海澜之家广告脚本 发布:2025-05-17 13:56:06 浏览:30
手文件夹恢复 发布:2025-05-17 13:53:32 浏览:993
linux怎么看进程 发布:2025-05-17 13:53:30 浏览:303
thinkphp字段缓存 发布:2025-05-17 13:52:01 浏览:575
山灵app安卓版如何设置 发布:2025-05-17 13:51:49 浏览:388
帆布压缩袋 发布:2025-05-17 13:26:27 浏览:460
c语言16进制表示方法 发布:2025-05-17 13:11:25 浏览:482
ftp单位 发布:2025-05-17 13:10:03 浏览:144