只是一个选择:
select SUBSTRING('1112223344',1,3)+'-'+
SUBSTRING('1112223344',4,3)+'-'+
SUBSTRING('1112223344',7,2)+'-'+
SUBSTRING('1112223344',9,2)
在你的情况下:
CREATE PROCEDURE SP_TELEPHONE_NUMBER
(@TELEPHONE_NUMBER VARCHAR(4000))
AS
BEGIN
INSERT INTO DOSYA_ARSIV(TELEPHONE_NUMBER)
VALUES
(
SUBSTRING(@TELEPHONE_NUMBER,1,3)+'-'+
SUBSTRING(@TELEPHONE_NUMBER,4,3)+'-'+
SUBSTRING(@TELEPHONE_NUMBER,7,2)+'-'+
SUBSTRING(@TELEPHONE_NUMBER,9,2)
)
END
正如 noobob 在他的评论中提到的那样,您可能将其作为 INT 类型(INT、BIGINT 或类似的东西)并处理它在前端的显示方式。例如,在 C# 中,您可以将其设置为:
TELEPHONE_NUMBER.ToString("###-###-##-##");
Another comment would be that defining the expected argument as VARCHAR(4000)
is way too much. Though it might not be very bad, it is a good point to define arguments or variables as close to expected input as you can. In your case i would say that something like VARCHAR(30)
would be enough.