📄 07-prcmp.pc
字号:
/* 07-PRCMP.PC */
/* This file contains the Pro*C examples used in Chapter 7
of "Oracle PL/SQL Programming". These examples are Pro*C
program fragments only - they are not complete programs. */
/* This is version 1.0 of this file, updated 2/18/96.
Comments and questions should go to Scott Urman at
surman@us.oracle.com. */
/* *** Chapter 7: Embedding a block *** */
EXEC SQL BEGIN DECLARE SECTION;
/* Declare C variables. */
VARCHAR v_Department[4]; /* The VARCHAR pseudo-type is
available only in Pro*C, and is
converted into a record type with
two fields - .arr and .len */
int v_Course; /* v_Course is an integer. */
int v_StudentID; /* So is v_StudentID. */
EXEC SQL END DECLARE SECTION;
/* Initialize the host variables. Here we are just assigning
to them, but they could be read from a file, accepted from
user input, etc. For the VARCHAR variables, the string is
copied into the .arr field, and the length of the string (3
in this case) is assigned to the .len field. */
strcpy(v_Department.arr, "ECN");
v_Department.len = 3;
v_Course = 101;
v_StudentID = 10006;
/* Begin the embedded PL/SQL block. Note the EXEC SQL EXECUTE
and END-EXEC; keywords, which delimit the block for the
precompiler. */
EXEC SQL EXECUTE
BEGIN
Register(:v_Department, :v_Course, :v_StudentID);
END;
END-EXEC;
/* *** Chapter 7: Using Indicator Variables *** */
EXEC SQL BEGIN DECLARE SECTION;
char v_Grade; /* v_Grade is a single character. */
short i_Grade; /* Note that the indicator is declared as a
short, which is a 2 byte integer. */
EXEC SQL END DECLARE SECTION;
EXEC SQL EXECUTE
BEGIN
SELECT grade
INTO :v_Grade INDICATOR :i_Grade
FROM registered_students
WHERE student_id = 10006
AND department = 'ECN'
AND course = 101;
END;
END-EXEC;
if (i_Grade != 0)
printf("No grade recorded for this student\n");
else
printf("The grade recorded is %c\n", v_Grade);
/* *** Chapter 7: Pro*C Error Handling *** */
EXEC SQL INCLUDE SQLCA; /* This statement includes the SQLCA
structure. This structure contains
fields used for error handling. */
EXEC SQL EXECUTE
BEGIN
RecordFullClasses;
END;
END-EXEC;
/* sqlca.sqlcode will be zero if the statement was successful,
and will contain the error code if the statement completed
with an error. If an error occurs, sqlca.sqlerrm.sqlerrmc
will contain the error message text, and sqlca.sqlerrm.sqlerrml
will contain the length of the message. */
if (sqlca.sqlcode != 0) {
printf("Error during execution of RecordFullClasses.\n");
printf("%.70s\n", sqlca.sqlerrm.sqlerrml, sqlca.sqlerrm.sqlerrmc);
}
else
printf("Execution successful.\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -