问题
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