Oracle

게시글 보기
작성자 유건데이타 등록일 2015-05-21
제목 SAMPLE: DYNAMIC SQL METHOD2 SAMPLE(INSERT)
/**************************************************************
Dynamic SQL Method 2 : INSERT

This program uses dynamic SQL Method 2 to insert a row into
the EMP table.
**************************************************************/
#define USERNAME "SCOTT"
#define PASSWORD "TIGER"
#include
#include

EXEC SQL INCLUDE sqlca;

EXEC SQL BEGIN DECLARE SECTION;
char *username = USERNAME;
char *password = PASSWORD;
char sqlstmt[2][80];
int empno = 1234;
int deptno1 = 97;
char tmpi[160];
EXEC SQL END DECLARE SECTION;

main()
{
EXEC SQL WHENEVER SQLERROR GOTO sqlerror;

EXEC SQL CONNECT :username IDENTIFIED BY :password;
puts((char *) "\nConnected to ORACLE.\n");

sprintf(sqlstmt[1],
"INSERT INTO EMP (%s, %s)","empno","deptno");
sprintf(sqlstmt[2],"VALUES (:v%s, :v%s)","1","2");
strcpy(tmpi,sqlstmt[1]);
strcat(tmpi,sqlstmt[2]);
/* Display the SQL statement and its current input host
variables. */

printf(" v1 = %d, v2 = %d\n", empno, deptno1);

EXEC SQL PREPARE S FROM :tmpi;

EXEC SQL EXECUTE S USING :empno, :deptno1;

EXEC SQL COMMIT RELEASE;
puts((char *) "\nHave a good day!\n");
exit(0);

sqlerror:
printf("\n%.*s\n", sqlca.sqlerrm.sqlerrml,
sqlca.sqlerrm.sqlerrmc);
}
Comment
등록된 코멘트가 없습니다.