Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 在Oracle Pro*C中,如何插入一个双精度值作为类型为NUMBER(18,7)的Oracle列_Sql_C_Oracle_Embedded Sql - Fatal编程技术网

Sql 在Oracle Pro*C中,如何插入一个双精度值作为类型为NUMBER(18,7)的Oracle列

Sql 在Oracle Pro*C中,如何插入一个双精度值作为类型为NUMBER(18,7)的Oracle列,sql,c,oracle,embedded-sql,Sql,C,Oracle,Embedded Sql,我使用C代码中的Pro*C代码连接到Oracle DB,以便使用阵列进行批量插入/更新。 下面是一个将C双精度数据插入到列为数字(18,7)的表中的示例。 以下代码段有效吗?请建议,尤其是7(十进制)作为Oracle数据类型是否正确?下面给出的代码片段类似于 #包括 #包括 #包括 #包括 #定义尺寸5 /*连接字符串*/ char*username=“userid/passwd”; /*dbltbl表的列dblval作为编号(18,7)*/ char*sql\u stmt= “插入dbltbl

我使用C代码中的Pro*C代码连接到Oracle DB,以便使用阵列进行批量插入/更新。 下面是一个将C双精度数据插入到列为数字(18,7)的表中的示例。 以下代码段有效吗?请建议,尤其是7(十进制)作为Oracle数据类型是否正确?下面给出的代码片段类似于

#包括
#包括
#包括
#包括
#定义尺寸5
/*连接字符串*/
char*username=“userid/passwd”;
/*dbltbl表的列dblval作为编号(18,7)*/
char*sql\u stmt=
“插入dbltbl(dblval)值(:d)”;
int size=size;/*也必须有一个主机变量*/
SQLDA*binda;
双VAL[大小];
/*声明并初始化指示符变量。对于dblval列*/
短ind_dblval[SIZE]={0,0,0,0};
main()
{ 
每当SQLERROR转到SQL_错误时执行SQL;
/*连接*/
execsqlconnect:用户名;
printf(“已连接。\n”);
/*分配描述符并设置N组件。
这必须在描述之前完成。*/
binda=sqldaalloc(SQL\u SINGLE\u RCTX,1,0,0);
binda->N=1;
/*准备并描述SQL语句。*/
EXEC SQL PREPARE stmt FROM:SQL\u stmt;
EXEC SQL描述将stmt的变量绑定到binda中;
/*初始化描述符。*/
binda->V[0]=(字符*)VAL;
binda->L[0]=(长)尺寸(双);
binda->T[0]=7;/*十进制*/
binda->I[2]=工业部门;
/*初始化数据缓冲区。*/
VAL[0]=11.2;
VAL[1]=10.2;
VAL[2]=10.7;
VAL[3]=1.2;
VAL[4]=114.2;
/*做插入*/
printf(“添加…\n”);
EXEC SQL FOR:size
使用描述符binda执行stmt;
/*打印已处理的行数*/
printf(“%d行插入。\n\n”,sqlca.sqlerrd[2]);
execsql提交发布;
出口(0);
sql\u错误:
/*打印Oracle错误消息*/
printf(“\n%.70s”,sqlca.sqlerrm.sqlerrmc);
每当SQLERROR继续时执行SQL;
execsql回滚发布;
出口(1);
} 

是否有使用动态SQL的特定要求?与简单的EXEC SQL insert语句相比,这通常会增加开销。@jimmcnamara这是遗留代码的一部分,将尝试在其他地方使用EXEC SQL insert语句,但是,对于此特定查询,binda->T[0]=7;/*Decimal*/--当我们在Oracle端引用一个数字(M,N)类型,并且数据在应用程序端存储为C double时,可以吗?@jimmcnamara非常感谢
#include <stdio.h>
#include <sqlcpr.h>
#include <sqlda.h>
#include <sqlca.h>

#define SIZE    5

/* connect string */
char *username = "userid/passwd";

/* dbltbl table has column dblval as NUMBER(18,7) */
char *sql_stmt =
"INSERT INTO dbltbl(dblval) VALUES (:d)";
int  size = SIZE;  /* must have a host variable too */

SQLDA   *binda;

double vals[SIZE];

/* Declare and initialize indicator vars. for dblval columns */
short   ind_dblval[SIZE] = {0,0,0,0,0};

main() 
{ 
    EXEC SQL WHENEVER SQLERROR GOTO sql_error; 

/* Connect */ 
    EXEC SQL CONNECT :username; 
    printf("Connected.\n"); 

/* Allocate the descriptors and set the N component. 
   This must be done before the DESCRIBE. */ 
    binda = SQLSQLDAAlloc(SQL_SINGLE_RCTX, 1, 0, 0); 
    binda->N = 1; 

/* Prepare and describe the SQL statement. */ 
    EXEC SQL PREPARE stmt FROM :sql_stmt; 
    EXEC SQL DESCRIBE BIND VARIABLES FOR stmt INTO binda; 

/* Initialize the descriptors. */ 
    binda->V[0] = (char *) vals; 
    binda->L[0] = (long) sizeof (double); 
    binda->T[0] = 7;  /* Decimal */
    binda->I[2] = ind_dept; 

/* Initialize the data buffers. */ 
    vals[0] = 11.2; 
    vals[1] = 10.2; 
    vals[2] = 10.7; 
    vals[3] = 1.2; 
    vals[4] = 114.2; 

/* Do the INSERT. */
    printf("Adding ...\n");

    EXEC SQL FOR :size
    EXECUTE stmt USING DESCRIPTOR binda;

/*  Print rows-processed count. */
    printf("%d rows inserted.\n\n", sqlca.sqlerrd[2]);
    EXEC SQL COMMIT RELEASE;
    exit(0);

sql_error: 
/* Print Oracle error message. */
    printf("\n%.70s", sqlca.sqlerrm.sqlerrmc);
    EXEC SQL WHENEVER SQLERROR CONTINUE; 
    EXEC SQL ROLLBACK RELEASE; 
    exit(1); 
}