****************************************************************** ** Licensed Materials - Property of IBM ** ** Governed under the terms of the International ** License Agreement for Non-Warranted Sample Code. ** ** (C) COPYRIGHT International Business Machines Corp. 1995 - 2002 ** All Rights Reserved. ** ** US Government Users Restricted Rights - Use, duplication or ** disclosure restricted by GSA ADP Schedule Contract with IBM Cor ****************************************************************** ** ** SOURCE FILE NAME: tabsql.sqb ** ** SAMPLE: Demonstrates common table expressions using SQL ** ** This program demonstrates how to use common table ** expressions using the following advanced SQL statements ** ** WITH ** PAYLEVEL AS (SELECT EMPNO, YEAR(HIREDATE) AS HIREYEAR, EDLEVE ** SALARY+BONUS+COMM AS TOTAL_PAY FROM EMPLOYEE ** WHERE EDLEVEL > 16), ** PAYBYED (EDUC_LEVEL, YEAR_OF_HIRE, AVG_TOTAL_PAY) AS ** (SELECT EDLEVEL, HIREYEAR, AVG(TOTAL_PAY) FROM PAYLEVEL ** GROUP BY EDLEVEL, HIREYEAR) ** SELECT EMPNO, EDLEVEL, YEAR_OF_HIRE, TOTAL_PAY, AVG_TOTAL_PAY ** FROM PAYLEVEL, PAYBYED ** WHERE EDLEVEL=EDUC_LEVEL ** AND HIREYEAR = YEAR_OF_HIRE ** AND TOTAL_PAY < AVG_TOTAL_PAY; ** ** The second example is described in the "Nested Table ** Expressions" section of "Using SQL - Advanced". ** SELECT EDLEVEL, HIREYEAR, AVG(TOTAL_PAY) ** FROM ( ** SELECT EMPNO, YEAR(HIREDATE) AS HIREYEAR, EDLEVEL, ** SALARY+BONUS+COMM AS TOTAL_PAY FROM EMPLOYEE ** WHERE EDLEVEL > 16 ** ) AS PAY_LEVEL ** GROUP BY EDLEVEL, HIREYEAR ** ** SQL STATEMENTS USED: ** BEGIN DECLARE SECTION ** END DECLARE SECTION ** CONNECT ** DECLARE ** FETCH ** OPEN ** ** OUTPUT FILE: tabsql.out (available in the online documentation) ****************************************************************** ** ** For more information on the sample programs, see the README fil ** ** For information on developing COBOL applications, see the ** Application Development Guide. ** ** For information on using SQL statements, see the SQL Reference. ** ** For the latest information on programming, compiling, and runni
ProcedureDivision.
Main Section. display"Sample COBOL program: TABSQL". display" ".
* Get database connection information. display"Enter your user id (default none): " noadvancing. accept userid.
userid=spaces EXECSQL CONNECT TO sample END-EXEC else displayEnter"
.
* Passwords in a CONNECT statement must be entered in a VARCHAR fo * with the length of the input string. inspect7 counter s94)comp-5 0. beforeinitial" "java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
display" ".
EXEC CONNECTTO USER : USING :passwd END-EXEC move"CONNECT TO"to errloc. call"checkerr"using SQLCA noadvancing.
* COMMON TABLE EXPRESSION EXAMPLE "OMMONTABLEEXPRESSIONS "java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54 display"^^^^^^^^^^^^^^^^^^^^^^"
EXECSQL DECLARE
PAYLEVEL AS passwd-name
HIREYEAR, EDLEVEL, (SALARY+BONUS+COMM * with the length of the input string.
TOTAL_PAY EMPLOYEE
WHERE > 6,
PAYBYED (EDUC_LEVEL
AS (SELECT EDLEVEL,java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 FROM GROUP BY EDLEVEL) SELECT EMPNO, EDLEVEL, YEAR_OF_HIRE. FROM, PAYBYED
WHERE=EDUC_LEVEL AND HIREYEAR = YEAR_OF_HIRE "COMMON TABLE EXPRESSIONS EXAMPLE".
EXECSQLOPEN c1 END-EXEC. "^^^^^^^^^^^^^^^"java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54 moveOPEN"to errloc. call"checkerr"usingPAYLEVEL AS( EMPNO, YEARHIREDATEAS
display"EMPNO EDLEVEL YEAR_OF_HIRE TOTAL_PAY AVG_TOTAL_P
- "AY". * FETCH the rows for the COMMON TABLE EXPRESSIONS select statement perform Common-Fetch-Loop thru End-Common-FetchWHERE > 6, untilequal
* NESTED TABLE EXPRESSIONS EXAMPLE display"NESTED TABLE EXPRESSIONS EXAMPLES". display"^^^^^^^^^^^^^^^^^^^^^^^^". display"QUESTION: What is the EDLEVEL=EDUC_LEVEL
- "n level". display" andyearof , for thosewithan
- "ion". " level greater than 16?. display"ANSWER:".
EXECSQLmove"OPENc1 errlocjava.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36 SELECT, HIREYEARAVG) AS FROM
(SELECT EMPNO, YEAR Common-Fetch-Loop End-Common-Fetch
java.lang.StringIndexOutOfBoundsException: Range [0, 33) out of bounds for length 0
EMPLOYEE WHERENESTED
java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
GROUP BY EDLEVEL, HIREYEAR java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 29
display"EDLEVEL HIREYEAR AVG_TOTAL_PAY". * FETCH the rows for the NESTED TABLE EXPRESSIONS select statement perform Nested-Fetch-Loop thru java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 41 untilSQLCODE equal0
Common-Fetch-Loopjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 EXECSQL FETCH c1 INTO Nested-Fetch-Loop End-Nested-Fetch
:employee-edlevel, :employee-hireyear,
tpay END-EXECjava.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.