oracle-databasereportsqr

Align column values in SQR


I'm trying to align the column values, but they are of different lengths. I can't just use Print '123' (+1, 9) and then Print '123456' (+1, 9) because it'll look something like this:

123456790123456790123456790123456790123456790123456790 <- Ignore this line
       123
       123456

Notice how the right most numbers aren't aligned with each other. I want the output to be like this:

123456790123456790123456790123456790123456790123456790 <- Ignore this line
     123
  123456

So I would want to stop printing at a certain index. How would I achieve this using SQR?

I tried Print '123' (+1, 9) and Print '1234' (+1, 9) but it gives the wrong results.


Solution

  • I'm not familiar with SQR, but here's a suggestion: as SQR supports the LPAD function (see String functions):

    Pads the source_value on the left to a length of length_value using pad_value and returns the result.

    Syntax: dst_var = lpad(source_value, length_value, pad_value)

    you could apply it to strings you print. For example (once again: note that I don't know SQR, you might need to adjust it):

    Print lpad('123', 6, ' ') (+1, 9)
    

    which would make ...123 (each dot represents a space).

    Why LPAD to 6 characters in length? Well, because your other string ('123456') is 6 characters long. Change it, if necessary.