当前位置:首页 » 编程语言 » 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表名
热点内容
随机启动脚本 发布:2025-07-05 16:10:30 浏览:515
微博数据库设计 发布:2025-07-05 15:30:55 浏览:19
linux485 发布:2025-07-05 14:38:28 浏览:299
php用的软件 发布:2025-07-05 14:06:22 浏览:750
没有权限访问计算机 发布:2025-07-05 13:29:11 浏览:425
javaweb开发教程视频教程 发布:2025-07-05 13:24:41 浏览:684
康师傅控流脚本破解 发布:2025-07-05 13:17:27 浏览:233
java的开发流程 发布:2025-07-05 12:45:11 浏览:678
怎么看内存卡配置 发布:2025-07-05 12:29:19 浏览:277
访问学者英文个人简历 发布:2025-07-05 12:29:17 浏览:828