飞飞dafei.blog.chinaunix.net
wangfdxl
全部博文(45)
2012年(1)
2011年(4)
2010年(6)
2009年(3)
2008年(31)
xiaozhen
大鬼不动
cynthia
浪花小雨
alfred_g
dongdhc
_寒_CU
eatmysho
gumuzhiy
antipass
inzahgi
分类: IT职场
2008-08-25 20:29:53
#include <stdio.h> #include <sqlca.h> #include <stdlib.h> /* SQL COMMINICATION AREA */ EXEC SQL INCLUDE sqlca; //EXEC ORACLE OPTION (RELEASE_CURSOR = YES); EXEC SQL BEGIN DECLARE SECTION; VARCHAR username[20]; VARCHAR password[20]; EXEC SQL END DECLARE SECTION; /* c function */ void sqlerror(); main() { /* inner introduction section */ EXEC SQL BEGIN DECLARE SECTION; int emp_number; VARCHAR emp_name[15]; //float salary; //float commission; EXEC SQL END DECLARE SECTION; /* C variant */ int total_number; /* log on oracle */ strcpy(username.arr, "SCOTT"); username.len = strlen(username.arr); strcpy(password.arr, "TIGER"); password.len = strlen(password.arr); /* error deal declare */ //EXEC SQL WHENEVER SQLERROR DO sqlerror(); /* connect to oracle */ EXEC SQL CONNECT :username IDENTIFIED BY :password; printf("\n111connected to oracle as user:%s\n", username.arr); /* query info looply */ total_number = 0; /* get all data from table emp */ EXEC SQL DECLARE cur CURSOR FOR SELECT ENAME, EMPNO FROM EMP; //EXEC SQL WHENEVER NOT FOUND GOTO notfound; EXEC SQL OPEN cur; while (1) { emp_number = 0; strcpy(emp_name.arr, ""); //memset(emp_name, 0, sizeof(emp_name)); //EXEC SQL FETCH cur INTO :emp_name, :salary, :commission; EXEC SQL FETCH cur INTO :emp_name, :emp_number; if (sqlca.sqlcode == 1403) { printf("hello, 1403"); break; } /* output query result */ printf("\n\nEmployeeName\tEmployeeID\n"); printf("--------\t----\t--------\n"); emp_name.arr[emp_name.len] = '\0'; printf("%-8s\t%d\n", emp_name.arr, emp_number); total_number = total_number + 1; if (total_number > 50) break; continue; notfound: printf("\n not a valid employee number -- try again..\n"); } printf("\n\nTotal number querid was: %d\n", total_number); printf("\nHave a good day.\n"); /** deal end ,quit oracle **/ EXEC SQL COMMIT WORK RELEASE; exit(0); } /* error deal */ void sqlerror() { //EXEC SQL WHENEVER SQLERROR CONTINUE; printf("\noracle error detected(sqlerror):\n"); /* roll back */ EXEC SQL ROLLBACK RELEASE; exit(1); }
#egg.pc --> egg.c --> egg egg: egg.c gcc -o egg egg.c -lclntsh egg.c: egg.pc proc iname=egg.pc parse=none
#!/bin/bash make -f eggmake && ./egg
include=(/oracle/product/10.2.0/precomp/public) include=/oracle/product/10.2.0/precomp/hdrs include=/oracle/product/10.2.0/tpcc2x_2/src include=/oracle/product/10.2.0/precomp/precomp/include include=/oracle/product/10.2.0/precomp/oracore/include include=/oracle/product/10.2.0/precomp/oracore/public include=/oracle/product/10.2.0/precomp/rdbms/include include=/oracle/product/10.2.0/precomp/rdbms/public include=/oracle/product/10.2.0/precomp/rdbms/demo include=/oracle/product/10.2.0/precomp/nlsrtl/include include=/oracle/product/10.2.0/precomp/nlsrtl/public include=/oracle/product/10.2.0/precomp/network_src/include include=/oracle/product/10.2.0/precomp/network_src/public include=/oracle/product/10.2.0/precomp/network/include include=/oracle/product/10.2.0/precomp/network/public include=/oracle/product/10.2.0/precomp/plsql/public
上一篇:添加头注释的shell脚本
下一篇:这几句努力去做到
登录 注册