Declaring a cursor variable
EXEC SQL BEGIN DECLARE section;
Sql_cursor Emp_cursor;
Sql_cursor Dept_cursor;
EXEC SQL END DECLARE section;
After this definition, if you want to allocate resources before using allocate
EXEC SQL Allocate:emp_cursor;
EXEC SQL ALLOCATE:d ept_cursor;
When you're done, close
EXEC SQL Close:emp_cursor;
EXEC SQL CLOSE:d ept_cursor;
This close only corresponds to the cursor that open operation, where there is no release of resources, if you want to release resources
EXEC SQL Free:emp_cursor;
EXEC SQL free:d ept_cursor;
2. Record an error
When I was using PL/SQL to create a package, I added the Authid current_user to the package specification,
Then, when creating the package body, add Authid current_user,
And then kept reminding me that I had a warning about this authid, and then I put the bag in the body of the removal is OK.
3. Then I wrote the example of the book, also encountered a compilation problem, or the run of the problem can not be completed
2.pc #include <stdio.h> #include <stdlib.h> #include <sqlca.h>
void Sql_error (char *msg) {exit (1);}
int main (int argc, char *argv[]) {char temp[32];
EXEC SQL BEGIN DECLARE SECTION; char *uid = "Scott/xx"; 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 ( "Oracle error"); exec sql connect :uid; exec SQL ALLOCATE :emp_cursor; EXEC SQL WHENEVER NOT Found do break;
while (1) { printf ("\nenter department number (0 to quit): "); gets (temp); dept_num = atoi (temp); if (dept_num <= 0) break; EXEC SQL EXECUTE BEGIN emp_demo_pkg.open_cur (:emp_cursor, :d ept_num); end; end-exec;
printf ("\nfor department %d--\n", dept_num); printf ("ename sal comm\n"); printf ("----------------\ n"); while (1) { EXEC SQL fetch :emp_cursor INTO :emp_info INDICATOR :emp_info_ind; printf ("%s", emp_info.emp_name); printf ("%8.2f", emp_info.salary); if (emp_info_ind.commission_ind != 0) printf ("null\n"); else printf ("%8.2f\n", emp_info.commission); } }
EXEC SQL whenever SQLERROR CONTINUE; EXEC SQL Close:emp_cursor; EXEC SQL ROLLBACK work RELEASE;
return 0;}
I encountered this error when compiling with Proc.
1. EXEC SQL EXECUTE
................. 1
pcc-s-02345, Sqlcheck=semantics must is given when embedded PL/SQL blocks are used
This is when there is a PL/SQL block in the program to add a compile option
Sqlcheck=semantics or =full, that's not the difference I've been studying.
This later encountered another problem, in the program using the Scott user's package, but a compilation is not found, said to declare,
Then in the compilation options, add
Userid=scott/xx This is my Scott user's name and password, this I think he is compiled by the user first to find out the package
How else would it know if there was.
And then I used the full compilation command that was
Proc Parse=none code=kr_c line=yes iname=2.pc mode=oracle dbms=v8 unsafe_null=yes sqlcheck=full userid=scott/xx
2. So I'll compile the executable, the execution, or the one that can't be exited from the loop, has not been resolved,
Solved, and then came back to record the problem-solving method.
Oracle PRC C Learning II