使用 InstantSQL RMCobol 更新 Postgres

问题描述 投票:0回答:1

我需要使用同一个表中的字段和 cobol 字段更新 Postgres 中的列

    update mytable
    set col1 = (col2 * ?) + (col3 * ?) + (col4 * ?);

这里?是 cobol 字段。 col2、3、4 是整数,col1 是小数 (5,2)

我已经绑定了cobol参数如下:

      *bind parameters
        SQL BIND PARAMETER sql-QueryHandle
          1 sql-Numeric sql-Param-Input WS-fld1 OMITTED
          2 sql-Numeric sql-Param-Input WS-fld2 OMITTED
          3 sql-Numeric sql-Param-Input WS-fld3 OMITTED.

Cobol 字段值为

1. field 1 = 020.00
2. field 2 = 030.00
3. field 3 = 040.00

程序运行没有错误,但结果始终显示第 1 列为 0。

但是在同一个 SQL 中,如果我直接具有如下的 cobol 值,则 col1 具有正确的值:

    update mytable
    set col1 = (col2 * 020.00) + (col3 * 030.00) + (col4 * 040.00);

我尝试过与 sql-Numeric 和 sql-Decimal 绑定,但输出没有差异。

sql postgresql cobol
1个回答
0
投票

确保 Cobol 字段和 PostgreSQL 列在精度/小数位数和数据类型方面匹配。对于整数列,使用 sql-Integer,对于小数列,使用 sql-Decimal。 在执行 SQL 查询之前,检查 WS-fld1、WS-fld2 和 WS-fld3 的值是否有效。如果 col1 是小数,则使用 sql-Decimal 作为输出参数。 试试这个;

*bind parameters
SQL BIND PARAMETER sql-QueryHandle
  1 sql-Integer sql-Param-Input WS-fld1 OMITTED
  2 sql-Integer sql-Param-Input WS-fld2 OMITTED
  3 sql-Integer sql-Param-Input WS-fld3 OMITTED
  4 sql-Decimal sql-Param-Output WS-Col1 OMITTED.

希望有帮助:)

© www.soinside.com 2019 - 2024. All rights reserved.