How to get the dimension of a DECLAREd variable in SPs?

…衆ロ難τιáo~ 提交于 2019-12-11 06:31:30

问题


Suppose I declared some variables in SPs.

DECLARE _R1 VARCHAR(25);
DECLARE _R2 DECIMAL(4,0);
DECLARE _R3 DECIMAL(3,0);
DECLARE _R4 DECIMAL(2,0);

How do I get their dimensions like 25, 4, 3, 2?


回答1:


One option is to create a really long value.

Than put in the variable, and run the length() function on it. As it will keep only as much value as the definition says it returns the correct length.

Now remains to find out how to do this without affecting the current value.

SET _R1=LPAD('',1000,1); 
RETURN(LENGTH(_R1));


来源:https://stackoverflow.com/questions/4213973/how-to-get-the-dimension-of-a-declared-variable-in-sps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!