Re: Syntax error in Pro*C

From: Scott Urman <surman_at_dlsun338.us.oracle.com>
Date: 1996/08/01
Message-ID: <4tot68$42t_at_inet-nntp-gw-1.us.oracle.com>#1/1


In article <4tmc2k$e28_at_elan.cc.bellcore.com>, ilg_at_elan.cc.bellcore.com (guthrie,ian) writes:
|>
|> I am using Pro*C release 2.1.2.0.0, Oracle version 7.2.2 on Solaris 2.4.
|> I have the following code segment:
|>
|>
|> varchar rback[4];
|> char *p;
|>
|> if (p=getenv("RBACK")) {
|> strncpy((char *)rback.arr, p, 3);
|> rback.arr[4] = '\0';
|> rback.len = strlen((char *) rback.arr);
|>
|> EXEC SQL SET TRANSACTION USE ROLLBACK SEGMENT :rback;
|>
|> if (sqlca.sqlcode != 0) {
|> printf("cannot set rollback segment %s\n", rback.arr);
|> sql_error();
|> }
|>
|> }
|> else
|> printf("Environment variable RBACK, not defined.\n");
|>
|>
|> I get the following compile error:
|>
|> Syntax error at line 1417, column 49, file srf.pc:
|> EXEC SQL SET TRANSACTION USE ROLLBACK SEGMENT :rback;
|> ..............................................................1
|> (1) PCC-S-02201, Encountered the symbol ":" when expecting one
|> of the following:
|>
|> an identifier,
|>
|> It does not like the :rback. If I replace it with the actual value, (e.g.,
|> r01), it compiles. What's wrong with the syntax?
|>

Bind variables are allowed only in SELECT, INSERT, UPDATE, and DELETE statements. You can't use a host variable here. You can, however, use dynamic method 1:

varchar sql_stmt[100];

strcpy(sql_stmt.arr, "SET TRANSACTION USE ROLLBACK SEGMENT "); strcat(sql_stmt.arr, rback);
sql_stmt.len = strlen(sql_stmt.arr);

EXEC SQL EXECUTE IMMEDIATE :sql_stmt;

|> Thanks,
|>
|> Ian
|> --
|>
|>



Scott Urman Oracle Corporation surman_at_us.oracle.com

Author of _Oracle PL/SQL Programming_ ISBN 0-07-882176-2 Published by Oracle Press - http://www.osborne.com/oracle/index.htm

"The opinions expressed here are my own, and are not necessarily that of  Oracle Corporation"
Received on Thu Aug 01 1996 - 00:00:00 CEST

Original text of this message