background image
<< Correlating Queries for Tables with Constraints | To enable the script to run >>
<< Correlating Queries for Tables with Constraints | To enable the script to run >>

the next available number

Database Vuser Scripts · Correlating Database Statements
Creating Vuser Scripts
Chapter 10, page 183
the next available number, or
count + 1
. In the example below, the query returned
a count of 4 records and therefore assigned the new employee an ID of 5, or
newemp=5
. The table's columns are
Name
,
ID
,
DOB
,
Dept
, and
DeptNo
.
lrd_stmt(Csr2, "select count(*) from employees", -1, 1 /*Deferred*/,
2 /*Ora V7*/, 0);
lrd_bind_col(Csr2, 1, &COUNT_D1, 0, 0);
lrd_exec(Csr2, 0, 0, 0, 0, 0);
lrd_fetch(Csr2, 1, 1, 0, PrintRow2, 0);
lrd_stmt(Csr2, "\t\tdeclare\n \tPROCEDURE new_emp (empno in integer, "
"newemp out integer) is\n\t\tbegin\n\t\t\tnewemp:=empno+1;\n\t\tend "
"new_emp;\n\t begin\n\t\t\tnew_emp(:empno,:newemp);\n\t\tend;", -
1, -1
/*Deferred*/, 2 /*Ora V7*/, 0);
lrd_assign_bind(Csr2, "empno", "4", &empno_D2, 0, 0, 0);
lrd_assign_bind(Csr2, "newemp", "0", &newemp_D3, 0, 0, 0);
lrd_exec(Csr2, 0, 0, 0, 0, 0);
lrd_stmt(Csr2, "insert into employees values ('TOM JONES',5,"
"'1-JAN-97','R&D',22)", -1, 0 /*Non deferred*/, 2 /*Ora V7*/, 0);
lrd_assign_bind(Csr2, "newemp", "5", &newemp_D4, 0, 0, 0);
lrd_exec(Csr2, 0, 0, 0, 0, 0);