insert1.c

来自「本源代码是通过oci连接oracle数据库的代码。适合初步接触Oracle的开发」· C语言 代码 · 共 93 行

C
93
字号
/* Copyright (c) 2004, 2005, Oracle. All rights reserved.  *//*   NAME     insert1.c - <one-line expansion of the name>   DESCRIPTION     <short description of facility this file declares/defines>   EXPORT FUNCTION(S)     <external functions defined for use outside package - one-line descriptions>   INTERNAL FUNCTION(S)     <other external functions defined - one-line descriptions>   STATIC FUNCTION(S)     <static functions defined - one-line descriptions>   NOTES     <other useful comments, qualifications, etc.>   MODIFIED   (MM/DD/YY)   ardesai     03/04/05 - Include windows.h for windows platform.   subanerj    06/06/04 - subanerj_odbc_env_setup   ardesai     06/02/04 - Creation*/#ifdef WIN32COMMON#include <windows.h>#endif#include <stdio.h>#include <sql.h>#include <sqlext.h>#define  STR_LEN 30int main(){  HENV        henv;                            /* environment handle */  HDBC        hdbc;                            /* connection handle */  HSTMT       hstmt;                           /* statement handle */  SDWORD      retcode;                         /* return code */  SQLCHAR     *stmt ="insert into myemp(empno, sal) values (953,8989)";  SQLCHAR     ename[40]="Rama";  SQLUINTEGER empno=111, sal=2222;  SQLINTEGER  enameInd, salInd, enoInd;  SQLCHAR     SqlState[6], Msg[SQL_MAX_MESSAGE_LENGTH];  SQLINTEGER  NativeError;  SQLSMALLINT MsgLen;  retcode = SQLAllocEnv(&henv);  retcode = SQLAllocConnect(henv, &hdbc);  retcode = SQLConnect(hdbc, "TestDBDSN", SQL_NTS, "scott", SQL_NTS, "tiger",                       SQL_NTS);  retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);        if ((retcode =  SQLPrepare(hstmt, stmt, SQL_NTS)) != SQL_SUCCESS)    goto EXIT;  if ((retcode = SQLExecute(hstmt)) != SQL_SUCCESS)    goto EXIT;  SQLEndTran(SQL_HANDLE_ENV, henv, SQL_COMMIT);EXIT:  if (retcode != SQL_SUCCESS)  {   if((retcode = SQLGetDiagRec(                               SQL_HANDLE_DBC, hdbc, 1,                                SqlState, &NativeError, Msg, sizeof(Msg),                               &MsgLen                              )      ) != SQL_NO_DATA     )     printf("SqlState = %s\n Message = %s\n", SqlState, Msg);  }    SQLFreeStmt(hstmt, SQL_CLOSE);  SQLDisconnect(hdbc);  SQLFreeConnect(hdbc);  SQLFreeEnv(henv);  return 1;}/* end of file insert1.c */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?