oracle游标多线程,多线程能使用这样定义的游标么?会不会出问题?

/*

*  Fetch from the EMP table, using a cursor variable.

*  The cursor is opened in the stored PL/SQL procedure

*  open_cur, in the EMP_DEMO_PKG package.

*

*  This package is available on-line in the file

*  cv_demo.sql, in the demo directory.

*

*/

#include

#include

#include

/* Error handling function. */

void sql_error(void)

{

EXEC SQL WHENEVER SQLERROR continue;

printf("%.70s\n", sqlca.sqlerrm.sqlerrmc);

exit(1);

}

void main()

{

char temp[32];

EXEC SQL BEGIN DECLARE SECTION;

char * uid = "scott/tiger";

SQL_CURSOR emp_cursor;

int dept_num;

struct

{

int   emp_num;

char  emp_name[11];

char  job[10];

int   manager;

char  hire_date[10];

float salary;

float commission;

int   dept_num;

} emp_info;

struct

{

short emp_num_ind;

short emp_name_ind;

short job_ind;

short manager_ind;

short hire_date_ind;

short salary_ind;

short commission_ind;

short dept_num_ind;

} emp_info_ind;

EXEC SQL END DECLARE SECTION;

EXEC SQL WHENEVER SQLERROR do sql_error();

/* Connect to Oracle. */

EXEC SQL CONNECT :uid;

/* Allocate the cursor variable. */

EXEC SQL ALLOCATE :emp_cursor;

/* Exit the inner for (;;) loop when NO DATA FOUND. */

EXEC SQL WHENEVER NOTFOUND DO break;

for (;;)

{

printf("\nEnter department number  (0 to exit): ");

gets(temp);

dept_num = atoi(temp);

if (dept_num <= 0)

break;

EXEC SQL EXECUTE

begin

emp_demo_pkg.open_cur(:emp_cursor, :dept_num);

end;

END-EXEC;

printf("\nFor department %d--\n", dept_num);

printf("ENAME\t             SAL\t            COMM\n");

printf("-----\t             ---\t            ----\n");

/* Fetch each row in the EMP table into the data struct.

Note the use of a parallel indicator struct. */

for (;;)

{

EXEC SQL FETCH :emp_cursor

INTO :emp_info INDICATOR :emp_info_ind;

printf("%s\t", emp_info.emp_name);

printf("%8.2f\t\t", emp_info.salary);

if (emp_info_ind.commission_ind != 0)

printf("    NULL\n");

else

printf("%8.2f\n", emp_info.commission);

}

}

/* Close the cursor. */

EXEC SQL WHENEVER SQLERROR CONTINUE;

EXEC SQL CLOSE :emp_cursor;

exit(0);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值