SQL Sequence Norm Function

The seq_norm()function takes a sequence argument of type double and calculates the normalized value of each element by dividing the element value by the square root of the sum of squares of all elements.

Following is an example script demonstrating the seq_norm() function:

 
    INSERT INTO SimpleSequence(testNumber,dVal1)
    VALUES(5,'{2.9,3.14,4.6}');
     
    SELECT dVal1, seq_norm(dVal1) AS "norm" FROM SimpleSequence WHERE testNumber = 5;
     
    dVal1{}
    norm{}
    --------------------------------------------------------------
    {2.900000, 3.140000, 4.600000}
    {0.461835, 0.500056, 0.732566}
     

So the result values for this dataset are obtained as follows:

1) Square the element values:

value square
2.90 8.41
3.14 9.86
4.60 21.16

2) The sum of the squared values = 39.4296

3) The square root of 39.4296 = 6.279299

4) Dividing each element by 6.279299 we get the following:

value / 6.279299 = norm

2.90 0.461835
3.14 0.500056
4.60 0.732566

Sample script

A sample script to demonstrate this select statement using xSQL can be run from the samples/xsql/scripts/financial directory with the following command:

     
    f 2