Chinaunix

标题: [b]pro*c 问题[/b] [打印本页]

作者: anrk0451    时间: 2003-03-13 20:37
标题: [b]pro*c 问题[/b]
:wink: 在pro*c中,声明sql变量时可不可以声明结构体类型的变量?如果可以,怎样把表中的字段存入结构体变量的域中?
作者: yikaikai    时间: 2003-03-13 20:59
标题: [b]pro*c 问题[/b]
仔细看看:



/*
*  sample1.pc
*
*  Prompts the user for an employee number,
*  then queries the emp table for the employee's
*  name, salary and commission.  Uses indicator
*  variables (in an indicator struct) to determine
*  if the commission is NULL.
*
*/

#include <stdio.h>;
#include <string.h>;
#include <stdlib.h>;
#include <sqlda.h>;
#include <sqlcpr.h>;

/* Define constants for VARCHAR lengths. */
#define     UNAME_LEN      20
#define     PWD_LEN        40

/* Declare variables.  No declare section is
   needed if MODE=ORACLE. */
VARCHAR     username[UNAME_LEN];  /* VARCHAR is an Oracle-supplied struct */
varchar     password[PWD_LEN];    /* varchar can be in lower case also. */

/* Define a host structure for the output values of
   a SELECT statement.  */
struct
{
    VARCHAR   emp_name[UNAME_LEN];
    float     salary;
    float     commission;
} emprec;

/* Define an indicator struct to correspond
   to the host output struct. */
struct
{
    short     emp_name_ind;
    short     sal_ind;
    short     comm_ind;
} emprec_ind;
。。。。。。。。。。。。。。。


如果你装了Oralce 客户端pro*C的话在你的硬盘里有
作者: anrk0451    时间: 2003-03-13 21:27
标题: [b]pro*c 问题[/b]
谢谢楼上的大哥,可是如何将数据库中的字段检索到结构体中,可以直接检索到结构体变量吗,还是检索到结构体的域中??多谢!




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2