- COBOL程序
$ cat SELECTORA.pco
* * DATABASE TABLE DEFINITION
* * CREATE TABLE TESTTAB(A CHAR(4) PRIMARY KEY)
* * INSERT INTO TESTTAB VALUES('AAAA')
IDENTIFICATION DIVISION.
PROGRAM-ID. MULTISELECT.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 DBUSER PIC X(005) VALUE "scott".
01 DBPASS PIC X(005) VALUE "tiger".
01 DBSTRING PIC X(010) VALUE "orcl01".
01 DBNAME PIC X(010) VALUE "db1".
01 DBUSER2 PIC X(005) VALUE "scott".
01 DBPASS2 PIC X(005) VALUE "tiger".
01 DBSTRING2 PIC X(010) VALUE "orcl02".
01 DBNAME2 PIC X(010) VALUE "db2".
01 H-VALUE-A PIC X(4).
EXEC SQL END DECLARE SECTION END-EXEC.
EXEC SQL INCLUDE SQLCA END-EXEC.
PROCEDURE DIVISION.
BEGIN-PGM.
* * CONNECT TO DB1
EXEC SQL
CONNECT :DBUSER IDENTIFIED BY :DBPASS
AT :DBNAME USING :DBSTRING
END-EXEC.
IF SQLCODE = 0
DISPLAY "RETURN OK"
DISPLAY "RETURN ROWS: " SQLERRD(3)
ELSE IF SQLCODE = 100
DISPLAY "NO DATA ROW IS FOUND"
DISPLAY "RETURN ROWS: " SQLERRD(3)
ELSE IF SQLCODE = -2112
DISPLAY "RETURN TOO MANY ROWS"
DISPLAY "RETURN ROWS: " SQLERRD(3)
ELSE
DISPLAY "ORACLE ERROR DETECTED:"
DISPLAY "SQLCODE = " SQLCODE
DISPLAY "SQLERRM = " SQLERRMC
END-IF.
* * CONNECT TO DB2
EXEC SQL
CONNECT :DBUSER2 IDENTIFIED BY :DBPASS2
AT :DBNAME2 USING :DBSTRING2
END-EXEC.
IF SQLCODE = 0
DISPLAY "RETURN OK"
DISPLAY "RETURN ROWS: " SQLERRD(3)
ELSE IF SQLCODE = 100
DISPLAY "NO DATA ROW IS FOUND"
DISPLAY "RETURN ROWS: " SQLERRD(3)
ELSE IF SQLCODE = -2112
DISPLAY "RETURN TOO MANY ROWS"
DISPLAY "RETURN ROWS: " SQLERRD(3)
ELSE
DISPLAY "ORACLE ERROR DETECTED:"
DISPLAY "SQLCODE = " SQLCODE
DISPLAY "SQLERRM = " SQLERRMC
END-IF.
* * SELECT FROM DB1
EXEC SQL
AT :DBNAME
SELECT A
INTO :H-VALUE-A
FROM TESTTAB
END-EXEC.
IF SQLCODE = 0
DISPLAY "RETURN OK"
DISPLAY "RETURN ROWS: " SQLERRD(3)
PERFORM DISPLAY-INFOS
ELSE IF SQLCODE = 100
DISPLAY "NO DATA ROW IS FOUND"
DISPLAY "RETURN ROWS: " SQLERRD(3)
ELSE IF SQLCODE = -2112
DISPLAY "RETURN TOO MANY ROWS"
DISPLAY "RETURN ROWS: " SQLERRD(3)
ELSE
DISPLAY "ORACLE ERROR DETECTED:"
DISPLAY "SQLCODE = " SQLCODE
DISPLAY "SQLERRM = " SQLERRMC
END-IF.
* * SELECT FROM DB2
EXEC SQL
AT :DBNAME2
SELECT A
INTO :H-VALUE-A
FROM TESTTAB
END-EXEC.
IF SQLCODE = 0
DISPLAY "RETURN OK"
DISPLAY "RETURN ROWS: " SQLERRD(3)
PERFORM DISPLAY-INFOS
ELSE IF SQLCODE = 100
DISPLAY "NO DATA ROW IS FOUND"
DISPLAY "RETURN ROWS: " SQLERRD(3)
ELSE IF SQLCODE = -2112
DISPLAY "RETURN TOO MANY ROWS"
DISPLAY "RETURN ROWS: " SQLERRD(3)
ELSE
DISPLAY "ORACLE ERROR DETECTED:"
DISPLAY "SQLCODE = " SQLCODE
DISPLAY "SQLERRM = " SQLERRMC
END-IF.
* * STOP RUN.
GOBACK.
DISPLAY-INFOS.
DISPLAY "RETURN A=" H-VALUE-A.
- makefile
$ cat makefile
ORACLE_HOME=/home/oracle/app/oracle/product/19c/db_1
PGMS = SELECTORA
all: $(PGMS)
.SUFFIXES: .pco .cbl
.PRECIOUS: %.cbl
.pco.cbl:
procob $(PCCINCLUDE) iname='$*.pco' lname='$*.lis' oname='$*.cbl' release_cursor=no hold_cursor=no mode=oracle sqlcheck=syntax common_parser=yes declare_section=no picx=char
SELECTORA: SELECTORA.cbl
cob -x -o $@ $< -L${ORACLE_HOME}/lib ${ORACLE_HOME}/precomp/lib/cobsqlintf.o -lclntsh
clean:
-rm -rf *.o *.cbl *.lis *.int *.idy $(PGMS)
- 编译运行
$ make
$ ./SELECTORA
网友评论