procedure declaration, function declaration − RWP*Load Simulator declaration of procedures and functions
proceduredeclaration ::= [ private ] procedure identifier ( [ argumentlist ] ) [ statistics | nostatistics | statisticsonly ] [ is ] statementlist end [ procedure | identifier ] functiondeclaration ::= [ private ] function identifier ( [ argumentlist ] ) return simpledatatype [ is ] statementlist end [ function | identifier ] argumentlist ::= argument { , argument } argument ::= simpledatatype identifier simpledatatype ::= string [ ( expression ) ] | integer | double
Procedure and functions are a primary structure in rwloadsim, which like in many other programming language wrap a list of statements for execution. Both have a potentially empty list of arguments; if empty, the parentheses must still be there. The arguments and the return type for functions can be of type integer, double or string; a string without a specified length is 128 bytes by default. The actual value of the string length must be available during parsing. The is keyword is optional.
Procedures are often created such that they implement some type of simulated business logic and are as such called repeatedly using control loops to simulate some workload. They can therefore have statistics associated with them, which includes things like execution times, number of executions, etc. If the procedure contains any execution of SQL, such statistics are collected by default; using the nostatistics keyword turns this off. If the procedure does not contain any execution of SQL, you can provide the statistics keyword; doing so will enable statistics collection for the procedure and will additionally make rwloadsim treat the procedure as if it were doing SQL execution. This again implies the procedure will ensure a database connection exists (e.g. by getting on from a session pool). If the procedure does not contain any execution of SQL, you can alternatively provide the statisticsonly attribute. This implies statistics such as execution counts is being gathered, but the procedure will not ensure or require a database connection. See controlloop(1rwl) for an example of how this can be used.
Functions never have statistics collected, even if they contain SQL execution. Functions must have a return type and must have at least one return statement in their statement list. If you exit from a function other than via a return statement, the behavior is unspecified.
The terminating end can optionally be followed by the appropriate keyword or by the name of the procedure or function.
If either declaration has an initial private keyword, the procedure or function will only be available within the source file where it has been declared.
Declare a function that will add two doubles and return their sum rounded to integer.
function add(double a, double b) return integer is return round(a+b); end add;
Declare a procedure that simulates the business transaction "create order". Note that some variable declarations are omitted.
procedure create_order(integer linecount) integer custno, ordno, i, prodcode, amount; custno := uniform(1,maxcustomer); # Choose a random customer sql insert_order # Insert the order header returning orderno from sequence insert into order_header (orderno, custno) values (order_sequence.nextval, :custno) returning orderno into :ordno; bind ":custno" custno; bindout ":ordno", ordno; end insert_order; sql insert_line # Insert the order lines insert into orderlines ( ordno, linno, product, amount ) values ( :b1, :b2, :b3, :b4); bind 1 ordno, 2 i, 3 prodcode, 4 amount; array 10; end insert_line; insert_order; for i:=1 .. linecount loop prodcode := uniform(1,maxproducts); # A random product amount := 1 + round(erlang(10)); # At least one insert_line; end loop; commit; end create_order;
Copyright © 2023 Oracle Corporation
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl
statement(1rwl), cursorloop(1rwl), declaration(1rwl), randomproceduredeclaration(1rwl)