从上面例可以看出,静态的增,删,改语句与交互方式没有太大的差别,对于查询语句就没有
那么简单,查询语句在下一章中介绍.
现用几个例题程序加以说明.
例题程序 1 (建立一表并向表中插入数据)
/
*=====================================================================
=========
This is a sample program which include SQL sentence about
CREATE ,INSERT a table.
======================================================================
========*/
EXEC SQL BEGIN DECLARE SECTION ;
CHAR sno[10],sname[10],city[10];
INT status;
EXEC SQL END DECLARE SECTION ;
EXEC SQL INCLUDE USERCA;
main()
{
int i;
EXEC SQL CONNECT "cobase:cobase" ;
EXEC SQL CREATE TABLE S_TEST /* Create a table named S_TEST */
(SNO CHAR (9),
SNAME CHAR (20),
STATUS INT ,CITY CHAR(10));
printf(" create table success,insert?");
printf(" 0 ---- no ");
printf(" 1 ---- yes ");
printf(" choice:");
scanf("%d",&i);
while(i)
{
printf("input sno:");
scanf("%s",sno);
printf("input sname:");
scanf("%s",sname);
printf("input status:");
scanf("%d",&status);
printf("input city:");
scanf("%s",city);
EXEC SQL INSERT INTO S_TEST(SNO,SNAME,STATUS,CITY)
VALUES ((:sno,:sname,:status,:city));
printf("continue?");
printf(" 0 ----terminate ");