lpad()函数和(row_number()over( order by )+ ...)

--LPAD自动在前面加数值,例子里面是0,凑足14位
select
'ZCZQ45' || LPAD((row_number() over(order by t1.C_PORT_CODE)+tmp_tbl.max_num), 14, '0') as abc
from  bbb
SQL : CREATE OR REPLACE PROCEDURE insert_display_order_part1( in_gondola_layout_version TEXT, in_system_date DATE, in_task_id TEXT, in_store_version TEXT ) LANGUAGE plpgsql AS $$ BEGIN INSERT INTO w_display_order_send( store_code, item_code, gondola_furniture_type, display_gondola, display_shelf, display_row, display_face, display_order_input_datetime, extraction_date, update_datetime, update_function_id, update_person_id, update_count ) SELECT tmp.store_code, tmp.item_code, CASE WHEN tmp.gondola_furniture_type IS NULL THEN NULL ELSE LPAD(TRIM(tmp.gondola_furniture_type), 3, '0') END, tmp.display_gondola, tmp.display_shelf, tmp.display_row, tmp.display_face, tmp.display_order_input_datetime, in_system_date, CURRENT_TIMESTAMP, in_task_id, in_task_id, 0 FROM ( SELECT te1.store_code, tn.item_code, gl1.gondola_furniture_type, tn.display_gondola, tn.display_shelf, tn.display_row, tn.display_face, tn.display_order_input_datetime, ROW_NUMBER() OVER ( PARTITION BY te1.store_code, tn.item_code, tn.label_code ORDER BY tn.display_order_input_datetime DESC ) AS registrationOrder FROM m_store_number te1 INNER JOIN m_display tn ON te1.original_store_code = tn.original_store_code LEFT JOIN m_gondola_layout gl1 ON gl1.version = in_gondola_layout_version AND tn.original_store_code = gl1.original_store_code AND tn.display_gondola = gl1.gondola_number WHERE te1.version = in_store_version AND in_system_date BETWEEN te1.apply_start_date AND te1.apply_end_date ) AS tmp WHERE tmp.registrationOrder <= 2 SQL : unterminated dollar-quoted string at or near "$$ BEGIN INSERT INTO w_display_order_send( store_code, item_code, gondola_furniture_type, display_gondola, display_shelf, display_row, display_face, display_order_input_datetime, extraction_date, update_datetime, update_function_id, update_person_id, update_count ) SELECT tmp.store_code, tmp.item_code, CASE WHEN tmp.gondola_furniture_type IS NULL THEN NULL ELSE LPAD(TRIM(tmp.gondola_furniture_type), 3, '0') END, tmp.display_gondola, tmp.display_shelf, tmp.display_row, tmp.display_face, tmp.display_order_input_datetime, in_system_date, CURRENT_TIMESTAMP, in_task_id, in_task_id, 0 FROM ( SELECT te1.store_code, tn.item_code, gl1.gondola_furniture_type, tn.display_gondola, tn.display_shelf, tn.display_row, tn.display_face, tn.display_order_input_datetime, ROW_NUMBER() OVER ( PARTITION BY te1.store_code, tn.item_code, tn.label_code ORDER BY tn.display_order_input_datetime DESC ) AS registrationOrder FROM m_store_number te1 INNER JOIN m_display tn ON te1.original_store_code = tn.original_store_code LEFT JOIN m_gondola_layout gl1 ON gl1.version = in_gondola_layout_version AND tn.original_store_code = gl1.original_store_code AND tn.display_gondola = gl1.gondola_number WHERE te1.version = in_store_version AND in_system_date BETWEEN te1.apply_start_date AND te1.apply_end_date ) AS tmp WHERE tmp.registrationOrder <= 2"
07-30
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值