Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to get real data length of a VARCHAR2 column when using procob dynamic SQL SQLDA SELDSC

1046997Jul 20 2016 — edited Jul 20 2016

Hi export,

I am using procob dynamic SQL to retrieve column information and also data value.

Now the column information can be retrieved successfully, and also data value, however, there is one issue that I cannot get real data length for a varchar2 data column.

For example:

Suppose column is defined as "CCC VARCHAR(10)", and "inset into atab(CCC) values('ABCD')".

I can successfully get column name CCC as defined with VARCHAR2, and length is 10, and also get the column value ('ABCD');

However i cannot get the real data length, i.e,4 (that is length('ABCD'))

Can anybody help me.

WORKING-STORAGE SECTION.

       01  SELDSC.

           02  SQLDNUM             PIC S9(9) COMP-5 VALUE 20.

           02  SQLDFND             PIC S9(9) COMP-5.

           02  SELDVAR             OCCURS 20 TIMES.

               03 SELDV            PIC S9(18) COMP-5.

               03 SELDFMT          PIC S9(18) COMP-5.

               03 SELDVLN          PIC S9(9) COMP-5.

               03 SELDFMTL         PIC S9(4) COMP-5.

               03 SELDVTYP         PIC S9(4) COMP-5.

               03 SELDI            PIC S9(18) COMP-5.

               03 SELDH-VNAME      PIC S9(18) COMP-5.

               03 SELDH-MAX-VNAMEL PIC S9(4) COMP-5.

               03 SELDH-CUR-VNAMEL PIC S9(4) COMP-5.

               03 SELDFILL1        PIC S9(9) COMP-5.

               03 SELDI-VNAME      PIC S9(18) COMP-5.

               03 SELDI-MAX-VNAMEL PIC S9(4) COMP-5.

               03 SELDI-CUR-VNAMEL PIC S9(4) COMP-5.

               03 SELDFILL2        PIC S9(9) COMP-5.

               03 SELDFCLP         PIC S9(18) COMP-5.

               03 SELDFCRCP        PIC S9(18) COMP-5.

       01  XSELDI.

           03  SEL-DI                OCCURS 20 TIMES PIC S9(4) COMP-5.

       01  XSELDIVNAME.

           03  SEL-DI-VNAME          OCCURS 20 TIMES PIC X(80).

       01  XSELDV.

           03  SEL-DV                OCCURS 20 TIMES PIC X(80).

PROCEDURE DIVISION.

           CALL "SQLADR" USING

               SEL-DV(TABLE-INDEX)

               SELDV(TABLE-INDEX).

           MOVE "SELECT CCC FROM ATAB"

             TO DYN-STATEMENT.

           EXEC SQL PREPARE S1 FROM :DYN-STATEMENT  END-EXEC.

           EXEC SQL DECLARE C1 CURSOR FOR S1        END-EXEC.

           EXEC SQL OPEN C1 END-EXEC.

           EXEC SQL WHENEVER NOT FOUND GO TO NOTFOUND END-EXEC.

           EXEC SQL DESCRIBE SELECT LIST FOR S1 INTO SELDSC  END-EXEC.

           EXEC SQL FETCH C1 USING DESCRIPTOR SELDSC  END-EXEC.

          DISPLAY SELDVLN(TABLE-INDEX)":"

                 SEL-DV(TABLE-INDEX)(1:SELDVLN(TABLE-INDEX)),

                 " "

I could not find a way to get the real data length. in this case, 4 is expected.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 17 2016
Added on Jul 20 2016
10 comments
1,433 views