blob: 1328e8695a572c4eb25176d71a75bd0db2d0a348 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 1.5.4">
<title>Stored Procedures in Java (SPJs) Guide</title>
<style>
/**
* @@@ START COPYRIGHT @@@
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
* @@@ END COPYRIGHT @@@
*/
/* Asciidoctor default stylesheet | MIT License | http://asciidoctor.org */
/* Remove the comments around the @import statement below when using this as a custom stylesheet */
/*@import "https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400";*/
article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block}
audio,canvas,video{display:inline-block}
audio:not([controls]){display:none;height:0}
[hidden],template{display:none}
script{display:none!important}
html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}
body{margin:0}
a{background:transparent}
a:focus{outline:thin dotted}
a:active,a:hover{outline:0}
h1{font-size:2em;margin:.67em 0}
abbr[title]{border-bottom:1px dotted}
b,strong{font-weight:bold}
dfn{font-style:italic}
hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0}
mark{background:#ff0;color:#000}
code,kbd,pre,samp{font-family:monospace;font-size:1em}
pre{white-space:pre-wrap}
q{quotes:"\201C" "\201D" "\2018" "\2019"}
small{font-size:80%}
sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}
sup{top:-.5em}
sub{bottom:-.25em}
img{border:0}
svg:not(:root){overflow:hidden}
figure{margin:0}
fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}
legend{border:0;padding:0}
button,input,select,textarea{font-family:inherit;font-size:100%;margin:0}
button,input{line-height:normal}
button,select{text-transform:none}
button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}
button[disabled],html input[disabled]{cursor:default}
input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}
input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box}
input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}
button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}
textarea{overflow:auto;vertical-align:top}
table{border-collapse:collapse;border-spacing:0}
*,*:before,*:after{-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box}
html,body{font-size:100%}
body{background:#fff;color:rgba(0,0,0,.8);padding:0;margin:0;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif,serif;font-weight:400;font-style:normal;line-height:1;position:relative;cursor:auto}
a:hover{cursor:pointer}
img,object,embed{max-width:100%;height:auto}
object,embed{height:100%}
img{-ms-interpolation-mode:bicubic}
#map_canvas img,#map_canvas embed,#map_canvas object,.map_canvas img,.map_canvas embed,.map_canvas object{max-width:none!important}
.left{float:left!important}
.right{float:right!important}
.text-left{text-align:left!important}
.text-right{text-align:right!important}
.text-center{text-align:center!important}
.text-justify{text-align:justify!important}
.hide{display:none}
.antialiased,body{-webkit-font-smoothing:antialiased}
img{display:inline-block;vertical-align:middle}
textarea{height:auto;min-height:50px}
select{width:100%}
p.lead,.paragraph.lead>p,#preamble>.sectionbody>.paragraph:first-of-type p{font-size:1.21875em;line-height:1.6}
.subheader,.admonitionblock td.content>.title,.audioblock>.title,.exampleblock>.title,.imageblock>.title,.listingblock>.title,.literalblock>.title,.stemblock>.title,.openblock>.title,.paragraph>.title,.quoteblock>.title,table.tableblock>.title,.verseblock>.title,.videoblock>.title,.dlist>.title,.olist>.title,.ulist>.title,.qlist>.title,.hdlist>.title{line-height:1.45;color:#3188ac;font-weight:400;margin-top:0;margin-bottom:.25em}
div,dl,dt,dd,ul,ol,li,h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6,pre,form,p,blockquote,th,td{margin:0;padding:0;direction:ltr}
a{color:#2156a5;text-decoration:underline;line-height:inherit}
a:hover,a:focus{color:#1d4b8f}
a img{border:none}
p{font-family:inherit;font-weight:400;font-size:1em;line-height:1.6;margin-bottom:1.25em;text-rendering:optimizeLegibility}
p aside{font-size:.875em;line-height:1.35;font-style:italic}
/* Defines headings */
h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-weight:bold;font-style:normal;color:#3188ac;text-rendering:optimizeLegibility;margin-top:1em;margin-bottom:.5em;line-height:1.0125em}
h1 small,h2 small,h3 small,#toctitle small,.sidebarblock>.content>.title small,h4 small,h5 small,h6 small{font-size:60%;color:#e99b8f;line-height:0}
h1{font-size:2.125em}
h2{font-size:1.6875em}
h3,#toctitle,.sidebarblock>.content>.title{font-size:1.375em}
h4,h5{font-size:1.125em}
h6{font-size:1em}
hr{border:solid #ddddd8;border-width:1px 0 0;clear:both;margin:1.25em 0 1.1875em;height:0}
em,i{font-style:italic;line-height:inherit}
strong,b{font-weight:bold;line-height:inherit}
small{font-size:60%;line-height:inherit}
/* Defines the `text` (passthru) format */
code{font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;font-weight:bold;color:#3188ac}
ul,ol,dl{font-size:1em;line-height:1.6;margin-bottom:1.25em;list-style-position:outside;font-family:inherit}
ul,ol,ul.no-bullet,ol.no-bullet{margin-left:1.5em}
ul li ul,ul li ol{margin-left:1.25em;margin-bottom:0;font-size:1em}
ul.square li ul,ul.circle li ul,ul.disc li ul{list-style:inherit}
ul.square{list-style-type:square}
ul.circle{list-style-type:circle}
ul.disc{list-style-type:disc}
ul.no-bullet{list-style:none}
ol li ul,ol li ol{margin-left:1.25em;margin-bottom:0}
dl dt{margin-bottom:.3125em;font-weight:bold}
dl dd{margin-bottom:1.25em}
abbr,acronym{text-transform:uppercase;font-size:90%;color:rgba(0,0,0,.8);border-bottom:1px dotted #ddd;cursor:help}
abbr{text-transform:none}
blockquote{margin:0 0 1.25em;padding:.5625em 1.25em 0 1.1875em;border-left:1px solid #ddd}
blockquote cite{display:block;font-size:.9375em;color:rgba(0,0,0,.6)}
blockquote cite:before{content:"\2014 \0020"}
blockquote cite a,blockquote cite a:visited{color:rgba(0,0,0,.6)}
blockquote,blockquote p{line-height:1.6;color:rgba(0,0,0,.85)}
@media only screen and (min-width:768px){h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{line-height:1.2}
h1{font-size:2.75em}
h2{font-size:2.3125em}
h3,#toctitle,.sidebarblock>.content>.title{font-size:1.6875em}
h4{font-size:1.4375em}}table{background:#fff;margin-bottom:1.25em;border:solid 1px #dedede}
table thead,table tfoot{background:#f7f8f7;font-weight:bold}
table thead tr th,table thead tr td,table tfoot tr th,table tfoot tr td{padding:.5em .625em .625em;font-size:inherit;color:rgba(0,0,0,.8);text-align:left}
table tr th,table tr td{padding:.5625em .625em;font-size:inherit;color:rgba(0,0,0,.8)}
table tr.even,table tr.alt,table tr:nth-of-type(even){background:#f8f8f7}
table thead tr th,table tfoot tr th,table tbody tr td,table tr td,table tfoot tr td{display:table-cell;line-height:1.6}
h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{line-height:1.2;word-spacing:-.05em}
h1 strong,h2 strong,h3 strong,#toctitle strong,.sidebarblock>.content>.title strong,h4 strong,h5 strong,h6 strong{font-weight:400}
.clearfix:before,.clearfix:after,.float-group:before,.float-group:after{content:" ";display:table}
.clearfix:after,.float-group:after{clear:both}
*:not(pre)>code{font-size:1.0em;font-style:normal!important;letter-spacing:0;padding:.1em .5ex;word-spacing:-.15em;-webkit-border-radius:4px;border-radius:4px;line-height:1.45;text-rendering:optimizeSpeed}
/**:not(pre)>code{font-size:.9375em;font-style:normal!important;letter-spacing:0;padding:.1em .5ex;word-spacing:-.15em;background-color:#f7f7f8;-webkit-border-radius:4px;border-radius:4px;line-height:1.45;text-rendering:optimizeSpeed}*/
pre,pre>code{line-height:1.45;color:rgba(0,0,0,.9);font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;font-weight:400;text-rendering:optimizeSpeed}
.keyseq{color:rgba(51,51,51,.8)}
kbd{display:inline-block;color:rgba(0,0,0,.8);font-size:.75em;line-height:1.4;background-color:#f7f7f7;border:1px solid #ccc;-webkit-border-radius:3px;border-radius:3px;-webkit-box-shadow:0 1px 0 rgba(0,0,0,.2),0 0 0 .1em white inset;box-shadow:0 1px 0 rgba(0,0,0,.2),0 0 0 .1em #fff inset;margin:-.15em .15em 0 .15em;padding:.2em .6em .2em .5em;vertical-align:middle;white-space:nowrap}
.keyseq kbd:first-child{margin-left:0}
.keyseq kbd:last-child{margin-right:0}
.menuseq,.menu{color:rgba(0,0,0,.8)}
b.button:before,b.button:after{position:relative;top:-1px;font-weight:400}
b.button:before{content:"[";padding:0 3px 0 2px}
b.button:after{content:"]";padding:0 2px 0 3px}
p a>code:hover{color:rgba(0,0,0,.9)}
#header,#content,#footnotes,#footer{width:100%;margin-left:auto;margin-right:auto;margin-top:0;margin-bottom:0;max-width:62.5em;*zoom:1;position:relative;padding-left:.9375em;padding-right:.9375em}
#header:before,#header:after,#content:before,#content:after,#footnotes:before,#footnotes:after,#footer:before,#footer:after{content:" ";display:table}
#header:after,#content:after,#footnotes:after,#footer:after{clear:both}
#content{margin-top:1.25em}
#content:before{content:none}
/* #header>h1:first-child{color:rgba(0,0,0,.85);margin-top:2.25rem;margin-bottom:0} */
#header>h1:first-child{color:#3188ac;margin-top:2.25rem;margin-bottom:0}
#header>h1:first-child+#toc{margin-top:8px;border-top:1px solid #ddddd8}
#header>h1:only-child,body.toc2 #header>h1:nth-last-child(2){border-bottom:1px solid #ddddd8;padding-bottom:8px}
#header .details{border-bottom:1px solid #ddddd8;line-height:1.45;padding-top:.25em;padding-bottom:.25em;padding-left:.25em;color:rgba(0,0,0,.6);display:-ms-flexbox;display:-webkit-flex;display:flex;-ms-flex-flow:row wrap;-webkit-flex-flow:row wrap;flex-flow:row wrap}
#header .details span:first-child{margin-left:-.125em}
#header .details span.email a{color:rgba(0,0,0,.85)}
#header .details br{display:none}
#header .details br+span:before{content:"\00a0\2013\00a0"}
#header .details br+span.author:before{content:"\00a0\22c5\00a0";color:rgba(0,0,0,.85)}
#header .details br+span#revremark:before{content:"\00a0|\00a0"}
#header #revnumber{text-transform:capitalize}
#header #revnumber:after{content:"\00a0"}
#content>h1:first-child:not([class]){color:rgba(0,0,0,.85);border-bottom:1px solid #ddddd8;padding-bottom:8px;margin-top:0;padding-top:1rem;margin-bottom:1.25rem}
#toc{border-bottom:1px solid #efefed;padding-bottom:.5em}
#toc>ul{margin-left:.125em}
#toc ul.sectlevel0>li>a{font-style:italic}
#toc ul.sectlevel0 ul.sectlevel1{margin:.5em 0}
#toc ul{font-family:"Open Sans","DejaVu Sans",sans-serif;list-style-type:none}
#toc a{text-decoration:none}
#toc a:active{text-decoration:underline}
#toctitle{color:#3188ac;font-size:1.2em}
@media only screen and (min-width:768px){#toctitle{font-size:1.375em}
body.toc2{padding-left:15em;padding-right:0}
#toc.toc2{margin-top:0!important;background-color:#f8f8f7;position:fixed;width:15em;left:0;top:0;border-right:1px solid #efefed;border-top-width:0!important;border-bottom-width:0!important;z-index:1000;padding:1.25em 1em;height:100%;overflow:auto}
#toc.toc2 #toctitle{margin-top:0;font-size:1.2em}
#toc.toc2>ul{font-size:.9em;margin-bottom:0}
#toc.toc2 ul ul{margin-left:0;padding-left:1em}
#toc.toc2 ul.sectlevel0 ul.sectlevel1{padding-left:0;margin-top:.5em;margin-bottom:.5em}
body.toc2.toc-right{padding-left:0;padding-right:15em}
body.toc2.toc-right #toc.toc2{border-right-width:0;border-left:1px solid #efefed;left:auto;right:0}}@media only screen and (min-width:1280px){body.toc2{padding-left:20em;padding-right:0}
/* Controls width of panel */
#toc.toc2{width:20em}
#toc.toc2 #toctitle{font-size:1.375em}
#toc.toc2>ul{font-size:.95em}
#toc.toc2 ul ul{padding-left:1.25em}
body.toc2.toc-right{padding-left:0;padding-right:20em}}#content #toc{border-style:solid;border-width:1px;border-color:#e0e0dc;margin-bottom:1.25em;padding:1.25em;background:#f8f8f7;-webkit-border-radius:4px;border-radius:4px}
#content #toc>:first-child{margin-top:0}
#content #toc>:last-child{margin-bottom:0}
#footer{max-width:100%;background-color:rgba(0,0,0,.8);padding:1.25em}
#footer-text,#footer_nav{color:rgba(255,255,255,.8);line-height:1.44}
#footer a{color: #990000}
.sect1{padding-bottom:.625em}
@media only screen and (min-width:768px){.sect1{padding-bottom:1.25em}}.sect1+.sect1{border-top:1px solid #efefed}
#content h1>a.anchor,h2>a.anchor,h3>a.anchor,#toctitle>a.anchor,.sidebarblock>.content>.title>a.anchor,h4>a.anchor,h5>a.anchor,h6>a.anchor{position:absolute;z-index:1001;width:1.5ex;margin-left:-1.5ex;display:block;text-decoration:none!important;visibility:hidden;text-align:center;font-weight:400}
#content h1>a.anchor:before,h2>a.anchor:before,h3>a.anchor:before,#toctitle>a.anchor:before,.sidebarblock>.content>.title>a.anchor:before,h4>a.anchor:before,h5>a.anchor:before,h6>a.anchor:before{content:"\00A7";font-size:.85em;display:block;padding-top:.1em}
#content h1:hover>a.anchor,#content h1>a.anchor:hover,h2:hover>a.anchor,h2>a.anchor:hover,h3:hover>a.anchor,#toctitle:hover>a.anchor,.sidebarblock>.content>.title:hover>a.anchor,h3>a.anchor:hover,#toctitle>a.anchor:hover,.sidebarblock>.content>.title>a.anchor:hover,h4:hover>a.anchor,h4>a.anchor:hover,h5:hover>a.anchor,h5>a.anchor:hover,h6:hover>a.anchor,h6>a.anchor:hover{visibility:visible}
#content h1>a.link,h2>a.link,h3>a.link,#toctitle>a.link,.sidebarblock>.content>.title>a.link,h4>a.link,h5>a.link,h6>a.link{color:#990000;text-decoration:none}
#content h1>a.link:hover,h2>a.link:hover,h3>a.link:hover,#toctitle>a.link:hover,.sidebarblock>.content>.title>a.link:hover,h4>a.link:hover,h5>a.link:hover,h6>a.link:hover{color:#a53221}
.audioblock,.imageblock,.literalblock,.listingblock,.stemblock,.videoblock{margin-bottom:1.25em}
.admonitionblock td.content>.title,.audioblock>.title,.exampleblock>.title,.imageblock>.title,.listingblock>.title,.literalblock>.title,.stemblock>.title,.openblock>.title,.paragraph>.title,.quoteblock>.title,table.tableblock>.title,.verseblock>.title,.videoblock>.title,.dlist>.title,.olist>.title,.ulist>.title,.qlist>.title,.hdlist>.title{text-rendering:optimizeLegibility;text-align:left;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif,serif;font-size:1rem;font-weight:bold}
/* Here */
table.tableblock>caption.title{white-space:nowrap;overflow:visible;max-width:0}
.paragraph.lead>p,#preamble>.sectionbody>.paragraph:first-of-type p{color:rgba(0,0,0,.85)}
table.tableblock #preamble>.sectionbody>.paragraph:first-of-type p{font-size:inherit}
.admonitionblock>table{border-collapse:separate;border:0;background:none;width:100%}
.admonitionblock>table td.icon{text-align:center;width:80px}
.admonitionblock>table td.icon img{max-width:none}
.admonitionblock>table td.icon .title{font-weight:bold;font-family:"Open Sans","DejaVu Sans",sans-serif;text-transform:uppercase}
.admonitionblock>table td.content{padding-left:1.125em;padding-right:1.25em;border-left:1px solid #ddddd8;color:rgba(0,0,0,.6)}
.admonitionblock>table td.content>:last-child>:last-child{margin-bottom:0}
.exampleblock>.content{border-style:solid;border-width:1px;border-color:#e6e6e6;margin-bottom:1.25em;padding:1.25em;background:#fff;-webkit-border-radius:4px;border-radius:4px}
.exampleblock>.content>:first-child{margin-top:0}
.exampleblock>.content>:last-child{margin-bottom:0}
.sidebarblock{border-style:solid;border-width:1px;border-color:#e0e0dc;margin-bottom:1.25em;padding:1.25em;background:#f8f8f7;-webkit-border-radius:4px;border-radius:4px}
.sidebarblock>:first-child{margin-top:0}
.sidebarblock>:last-child{margin-bottom:0}
.sidebarblock>.content>.title{color:#7a2518;margin-top:0;text-align:center}
.exampleblock>.content>:last-child>:last-child,.exampleblock>.content .olist>ol>li:last-child>:last-child,.exampleblock>.content .ulist>ul>li:last-child>:last-child,.exampleblock>.content .qlist>ol>li:last-child>:last-child,.sidebarblock>.content>:last-child>:last-child,.sidebarblock>.content .olist>ol>li:last-child>:last-child,.sidebarblock>.content .ulist>ul>li:last-child>:last-child,.sidebarblock>.content .qlist>ol>li:last-child>:last-child{margin-bottom:0}
.literalblock pre,.listingblock pre:not(.highlight),.listingblock pre[class="highlight"],.listingblock pre[class^="highlight "],.listingblock pre.CodeRay,.listingblock pre.prettyprint{background:#f7f7f8}
.sidebarblock .literalblock pre,.sidebarblock .listingblock pre:not(.highlight),.sidebarblock .listingblock pre[class="highlight"],.sidebarblock .listingblock pre[class^="highlight "],.sidebarblock .listingblock pre.CodeRay,.sidebarblock .listingblock pre.prettyprint{background:#f2f1f1}
.literalblock pre,.literalblock pre[class],.listingblock pre,.listingblock pre[class]{-webkit-border-radius:4px;border-radius:4px;word-wrap:break-word;padding:1em;font-size:.8125em}
.literalblock pre.nowrap,.literalblock pre[class].nowrap,.listingblock pre.nowrap,.listingblock pre[class].nowrap{overflow-x:auto;white-space:pre;word-wrap:normal}
@media only screen and (min-width:768px){.literalblock pre,.literalblock pre[class],.listingblock pre,.listingblock pre[class]{font-size:.90625em}}@media only screen and (min-width:1280px){.literalblock pre,.literalblock pre[class],.listingblock pre,.listingblock pre[class]{font-size:1em}}.literalblock.output pre{color:#f7f7f8;background-color:rgba(0,0,0,.9)}
.listingblock pre.highlightjs{padding:0}
.listingblock pre.highlightjs>code{padding:1em;-webkit-border-radius:4px;border-radius:4px}
.listingblock pre.prettyprint{border-width:0}
.listingblock>.content{position:relative}
.listingblock code[data-lang]:before{display:none;content:attr(data-lang);position:absolute;font-size:.75em;top:.425rem;right:.5rem;line-height:1;text-transform:uppercase;color:#999}
.listingblock:hover code[data-lang]:before{display:block}
.listingblock.terminal pre .command:before{content:attr(data-prompt);padding-right:.5em;color:#999}
.listingblock.terminal pre .command:not([data-prompt]):before{content:"$"}
table.pyhltable{border-collapse:separate;border:0;margin-bottom:0;background:none}
table.pyhltable td{vertical-align:top;padding-top:0;padding-bottom:0}
table.pyhltable td.code{padding-left:.75em;padding-right:0}
pre.pygments .lineno,table.pyhltable td:not(.code){color:#999;padding-left:0;padding-right:.5em;border-right:1px solid #ddddd8}
pre.pygments .lineno{display:inline-block;margin-right:.25em}
table.pyhltable .linenodiv{background:none!important;padding-right:0!important}
.quoteblock{margin:0 1em 1.25em 1.5em;display:table}
.quoteblock>.title{margin-left:-1.5em;margin-bottom:.75em}
.quoteblock blockquote,.quoteblock blockquote p{color:rgba(0,0,0,.85);font-size:1.15rem;line-height:1.75;word-spacing:.1em;letter-spacing:0;font-style:italic;text-align:justify}
.quoteblock blockquote{margin:0;padding:0;border:0}
.quoteblock blockquote:before{content:"\201c";float:left;font-size:2.75em;font-weight:bold;line-height:.6em;margin-left:-.6em;color:#7a2518;text-shadow:0 1px 2px rgba(0,0,0,.1)}
.quoteblock blockquote>.paragraph:last-child p{margin-bottom:0}
.quoteblock .attribution{margin-top:.5em;margin-right:.5ex;text-align:right}
.quoteblock .quoteblock{margin-left:0;margin-right:0;padding:.5em 0;border-left:3px solid rgba(0,0,0,.6)}
.quoteblock .quoteblock blockquote{padding:0 0 0 .75em}
.quoteblock .quoteblock blockquote:before{display:none}
.verseblock{margin:0 1em 1.25em 1em}
.verseblock pre{font-family:"Open Sans","DejaVu Sans",sans;font-size:1.15rem;color:rgba(0,0,0,.85);font-weight:300;text-rendering:optimizeLegibility}
.verseblock pre strong{font-weight:400}
.verseblock .attribution{margin-top:1.25rem;margin-left:.5ex}
.quoteblock .attribution,.verseblock .attribution{font-size:.9375em;line-height:1.45;font-style:italic}
.quoteblock .attribution br,.verseblock .attribution br{display:none}
.quoteblock .attribution cite,.verseblock .attribution cite{display:block;letter-spacing:-.05em;color:rgba(0,0,0,.6)}
.quoteblock.abstract{margin:0 0 1.25em 0;display:block}
.quoteblock.abstract blockquote,.quoteblock.abstract blockquote p{text-align:left;word-spacing:0}
.quoteblock.abstract blockquote:before,.quoteblock.abstract blockquote p:first-of-type:before{display:none}
table.tableblock{max-width:100%;border-collapse:separate}
table.tableblock td>.paragraph:last-child p>p:last-child,table.tableblock th>p:last-child,table.tableblock td>p:last-child{margin-bottom:0}
table.spread{width:100%}
table.tableblock,th.tableblock,td.tableblock{border:0 solid #dedede}
table.grid-all th.tableblock,table.grid-all td.tableblock{border-width:0 1px 1px 0}
table.grid-all tfoot>tr>th.tableblock,table.grid-all tfoot>tr>td.tableblock{border-width:1px 1px 0 0}
table.grid-cols th.tableblock,table.grid-cols td.tableblock{border-width:0 1px 0 0}
table.grid-all *>tr>.tableblock:last-child,table.grid-cols *>tr>.tableblock:last-child{border-right-width:0}
table.grid-rows th.tableblock,table.grid-rows td.tableblock{border-width:0 0 1px 0}
table.grid-all tbody>tr:last-child>th.tableblock,table.grid-all tbody>tr:last-child>td.tableblock,table.grid-all thead:last-child>tr>th.tableblock,table.grid-rows tbody>tr:last-child>th.tableblock,table.grid-rows tbody>tr:last-child>td.tableblock,table.grid-rows thead:last-child>tr>th.tableblock{border-bottom-width:0}
table.grid-rows tfoot>tr>th.tableblock,table.grid-rows tfoot>tr>td.tableblock{border-width:1px 0 0 0}
table.frame-all{border-width:1px}
table.frame-sides{border-width:0 1px}
table.frame-topbot{border-width:1px 0}
th.halign-left,td.halign-left{text-align:left}
th.halign-right,td.halign-right{text-align:right}
th.halign-center,td.halign-center{text-align:center}
th.valign-top,td.valign-top{vertical-align:top}
th.valign-bottom,td.valign-bottom{vertical-align:bottom}
th.valign-middle,td.valign-middle{vertical-align:middle}
table thead th,table tfoot th{font-weight:bold}
tbody tr th{display:table-cell;line-height:1.6;background:#f7f8f7}
tbody tr th,tbody tr th p,tfoot tr th,tfoot tr th p{color:rgba(0,0,0,.8);font-weight:bold}
p.tableblock>code:only-child{background:none;padding:0}
p.tableblock{font-size:1em}
td>div.verse{white-space:pre}
ol{margin-left:1.75em}
ul li ol{margin-left:1.5em}
dl dd{margin-left:1.125em}
dl dd:last-child,dl dd:last-child>:last-child{margin-bottom:0}
ol>li p,ul>li p,ul dd,ol dd,.olist .olist,.ulist .ulist,.ulist .olist,.olist .ulist{margin-bottom:.625em}
ul.unstyled,ol.unnumbered,ul.checklist,ul.none{list-style-type:none}
ul.unstyled,ol.unnumbered,ul.checklist{margin-left:.625em}
ul.checklist li>p:first-child>.fa-square-o:first-child,ul.checklist li>p:first-child>.fa-check-square-o:first-child{width:1em;font-size:.85em}
ul.checklist li>p:first-child>input[type="checkbox"]:first-child{width:1em;position:relative;top:1px}
ul.inline{margin:0 auto .625em auto;margin-left:-1.375em;margin-right:0;padding:0;list-style:none;overflow:hidden}
ul.inline>li{list-style:none;float:left;margin-left:1.375em;display:block}
ul.inline>li>*{display:block}
.unstyled dl dt{font-weight:400;font-style:normal}
ol.arabic{list-style-type:decimal}
ol.decimal{list-style-type:decimal-leading-zero}
ol.loweralpha{list-style-type:lower-alpha}
ol.upperalpha{list-style-type:upper-alpha}
ol.lowerroman{list-style-type:lower-roman}
ol.upperroman{list-style-type:upper-roman}
ol.lowergreek{list-style-type:lower-greek}
.hdlist>table,.colist>table{border:0;background:none}
.hdlist>table>tbody>tr,.colist>table>tbody>tr{background:none}
td.hdlist1{padding-right:.75em;font-weight:bold}
td.hdlist1,td.hdlist2{vertical-align:top}
.literalblock+.colist,.listingblock+.colist{margin-top:-.5em}
.colist>table tr>td:first-of-type{padding:0 .75em;line-height:1}
.colist>table tr>td:last-of-type{padding:.25em 0}
.thumb,.th{line-height:0;display:inline-block;border:solid 4px #fff;-webkit-box-shadow:0 0 0 1px #ddd;box-shadow:0 0 0 1px #ddd}
.imageblock.left,.imageblock[style*="float: left"]{margin:.25em .625em 1.25em 0}
.imageblock.right,.imageblock[style*="float: right"]{margin:.25em 0 1.25em .625em}
.imageblock>.title{margin-bottom:0}
.imageblock.thumb,.imageblock.th{border-width:6px}
.imageblock.thumb>.title,.imageblock.th>.title{padding:0 .125em}
.image.left,.image.right{margin-top:.25em;margin-bottom:.25em;display:inline-block;line-height:0}
.image.left{margin-right:.625em}
.image.right{margin-left:.625em}
a.image{text-decoration:none}
span.footnote,span.footnoteref{vertical-align:super;font-size:.875em}
span.footnote a,span.footnoteref a{text-decoration:none}
span.footnote a:active,span.footnoteref a:active{text-decoration:underline}
#footnotes{padding-top:.75em;padding-bottom:.75em;margin-bottom:.625em}
#footnotes hr{width:20%;min-width:6.25em;margin:-.25em 0 .75em 0;border-width:1px 0 0 0}
#footnotes .footnote{padding:0 .375em;line-height:1.3;font-size:.875em;margin-left:1.2em;text-indent:-1.2em;margin-bottom:.2em}
#footnotes .footnote a:first-of-type{font-weight:bold;text-decoration:none}
#footnotes .footnote:last-of-type{margin-bottom:0}
#content #footnotes{margin-top:-.625em;margin-bottom:0;padding:.75em 0}
.gist .file-data>table{border:0;background:#fff;width:100%;margin-bottom:0}
.gist .file-data>table td.line-data{width:99%}
div.unbreakable{page-break-inside:avoid}
.big{font-size:larger}
.small{font-size:smaller}
.underline{text-decoration:underline}
.overline{text-decoration:overline}
.line-through{text-decoration:line-through}
.aqua{color:#00bfbf}
.aqua-background{background-color:#00fafa}
.black{color:#000}
.black-background{background-color:#000}
.blue{color:#0000bf}
.blue-background{background-color:#0000fa}
.fuchsia{color:#bf00bf}
.fuchsia-background{background-color:#fa00fa}
.gray{color:#606060}
.gray-background{background-color:#7d7d7d}
.green{color:#006000}
.green-background{background-color:#007d00}
.lime{color:#00bf00}
.lime-background{background-color:#00fa00}
.maroon{color:#600000}
.maroon-background{background-color:#7d0000}
.navy{color:#000060}
.navy-background{background-color:#00007d}
.olive{color:#606000}
.olive-background{background-color:#7d7d00}
.purple{color:#600060}
.purple-background{background-color:#7d007d}
.red{color:#bf0000}
.red-background{background-color:#fa0000}
.silver{color:#909090}
.silver-background{background-color:#bcbcbc}
.teal{color:#006060}
.teal-background{background-color:#007d7d}
.white{color:#bfbfbf}
.white-background{background-color:#fafafa}
.yellow{color:#bfbf00}
.yellow-background{background-color:#fafa00}
span.icon>.fa{cursor:default}
.admonitionblock td.icon [class^="fa icon-"]{font-size:2.5em;text-shadow:1px 1px 2px rgba(0,0,0,.5);cursor:default}
.admonitionblock td.icon .icon-note:before{content:"\f05a";color:#19407c}
.admonitionblock td.icon .icon-tip:before{content:"\f0eb";text-shadow:1px 1px 2px rgba(155,155,0,.8);color:#111}
.admonitionblock td.icon .icon-warning:before{content:"\f071";color:#bf6900}
.admonitionblock td.icon .icon-caution:before{content:"\f06d";color:#bf3400}
.admonitionblock td.icon .icon-important:before{content:"\f06a";color:#bf0000}
.conum[data-value]{display:inline-block;color:#fff!important;background-color:rgba(0,0,0,.8);-webkit-border-radius:100px;border-radius:100px;text-align:center;font-size:.75em;width:1.67em;height:1.67em;line-height:1.67em;font-family:"Open Sans","DejaVu Sans",sans-serif;font-style:normal;font-weight:bold}
.conum[data-value] *{color:#fff!important}
.conum[data-value]+b{display:none}
.conum[data-value]:after{content:attr(data-value)}
pre .conum[data-value]{position:relative;top:-.125em}
b.conum *{color:inherit!important}
.conum:not([data-value]):empty{display:none}
h1,h2{letter-spacing:-.01em}
dt,th.tableblock,td.content{text-rendering:optimizeLegibility}
p,td.content{letter-spacing:-.01em}
p strong,td.content strong{letter-spacing:-.005em}
p,blockquote,dt,td.content{font-size:1.0625rem}
p{margin-bottom:1.25rem}
.sidebarblock p,.sidebarblock dt,.sidebarblock td.content,p.tableblock{font-size:1em}
.exampleblock>.content{background-color:#fffef7;border-color:#e0e0dc;-webkit-box-shadow:0 1px 4px #e0e0dc;box-shadow:0 1px 4px #e0e0dc}
.print-only{display:none!important}
@media print{@page{margin:1.25cm .75cm}
*{-webkit-box-shadow:none!important;box-shadow:none!important;text-shadow:none!important}
a{color:inherit!important;text-decoration:underline!important}
a.bare,a[href^="#"],a[href^="mailto:"]{text-decoration:none!important}
a[href^="http:"]:not(.bare):after,a[href^="https:"]:not(.bare):after{content:"(" attr(href) ")";display:inline-block;font-size:.875em;padding-left:.25em}
abbr[title]:after{content:" (" attr(title) ")"}
pre,blockquote,tr,img{page-break-inside:avoid}
thead{display:table-header-group}
img{max-width:100%!important}
p,blockquote,dt,td.content{font-size:1em;orphans:3;widows:3}
h2,h3,#toctitle,.sidebarblock>.content>.title{page-break-after:avoid}
#toc,.sidebarblock,.exampleblock>.content{background:none!important}
#toc{border-bottom:1px solid #ddddd8!important;padding-bottom:0!important}
.sect1{padding-bottom:0!important}
.sect1+.sect1{border:0!important}
#header>h1:first-child{margin-top:1.25rem}
body.book #header{text-align:center}
body.book #header>h1:first-child{border:0!important;margin:2.5em 0 1em 0}
body.book #header .details{border:0!important;display:block;padding:0!important}
body.book #header .details span:first-child{margin-left:0!important}
body.book #header .details br{display:block}
body.book #header .details br+span:before{content:none!important}
body.book #toc{border:0!important;text-align:left!important;padding:0!important;margin:0!important}
body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-break-before:always}
.listingblock code[data-lang]:before{display:block}
#footer{background:none!important;padding:0 .9375em}
#footer-text{color:rgba(0,0,0,.6)!important;font-size:.9em}
.hide-on-print{display:none!important}
.print-only{display:block!important}
.hide-for-print{display:none!important}
.show-for-print{display:inherit!important}}
div.paragraph.indented p {padding-left: 3em;}
div.paragraph.indented2 p {padding-left: 6em;}
div.paragraph.indented3 p {padding-left: 9em;}
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
<style>
/* Stylesheet for CodeRay to match GitHub theme | MIT License | http://foundation.zurb.com */
/*pre.CodeRay {background-color:#f7f7f8;}*/
.CodeRay .line-numbers{border-right:1px solid #d8d8d8;padding:0 0.5em 0 .25em}
.CodeRay span.line-numbers{display:inline-block;margin-right:.5em;color:rgba(0,0,0,.3)}
.CodeRay .line-numbers strong{color:rgba(0,0,0,.4)}
table.CodeRay{border-collapse:separate;border-spacing:0;margin-bottom:0;border:0;background:none}
table.CodeRay td{vertical-align: top;line-height:1.45}
table.CodeRay td.line-numbers{text-align:right}
table.CodeRay td.line-numbers>pre{padding:0;color:rgba(0,0,0,.3)}
table.CodeRay td.code{padding:0 0 0 .5em}
table.CodeRay td.code>pre{padding:0}
.CodeRay .debug{color:#fff !important;background:#000080 !important}
.CodeRay .annotation{color:#007}
.CodeRay .attribute-name{color:#000080}
.CodeRay .attribute-value{color:#700}
.CodeRay .binary{color:#509}
.CodeRay .comment{color:#998;font-style:italic}
.CodeRay .char{color:#04d}
.CodeRay .char .content{color:#04d}
.CodeRay .char .delimiter{color:#039}
.CodeRay .class{color:#458;font-weight:bold}
.CodeRay .complex{color:#a08}
.CodeRay .constant,.CodeRay .predefined-constant{color:#008080}
.CodeRay .color{color:#099}
.CodeRay .class-variable{color:#369}
.CodeRay .decorator{color:#b0b}
.CodeRay .definition{color:#099}
.CodeRay .delimiter{color:#000}
.CodeRay .doc{color:#970}
.CodeRay .doctype{color:#34b}
.CodeRay .doc-string{color:#d42}
.CodeRay .escape{color:#666}
.CodeRay .entity{color:#800}
.CodeRay .error{color:#808}
.CodeRay .exception{color:inherit}
.CodeRay .filename{color:#099}
.CodeRay .function{color:#900;font-weight:bold}
.CodeRay .global-variable{color:#008080}
.CodeRay .hex{color:#058}
.CodeRay .integer,.CodeRay .float{color:#099}
.CodeRay .include{color:#555}
.CodeRay .inline{color:#000}
.CodeRay .inline .inline{background:#ccc}
.CodeRay .inline .inline .inline{background:#bbb}
.CodeRay .inline .inline-delimiter{color:#d14}
.CodeRay .inline-delimiter{color:#d14}
.CodeRay .important{color:#555;font-weight:bold}
.CodeRay .interpreted{color:#b2b}
.CodeRay .instance-variable{color:#008080}
.CodeRay .label{color:#970}
.CodeRay .local-variable{color:#963}
.CodeRay .octal{color:#40e}
.CodeRay .predefined{color:#369}
.CodeRay .preprocessor{color:#579}
.CodeRay .pseudo-class{color:#555}
.CodeRay .directive{font-weight:bold}
.CodeRay .type{font-weight:bold}
.CodeRay .predefined-type{color:inherit}
.CodeRay .reserved,.CodeRay .keyword {color:#000;font-weight:bold}
.CodeRay .key{color:#808}
.CodeRay .key .delimiter{color:#606}
.CodeRay .key .char{color:#80f}
.CodeRay .value{color:#088}
.CodeRay .regexp .delimiter{color:#808}
.CodeRay .regexp .content{color:#808}
.CodeRay .regexp .modifier{color:#808}
.CodeRay .regexp .char{color:#d14}
.CodeRay .regexp .function{color:#404;font-weight:bold}
.CodeRay .string{color:#d20}
.CodeRay .string .string .string{background:#ffd0d0}
.CodeRay .string .content{color:#d14}
.CodeRay .string .char{color:#d14}
.CodeRay .string .delimiter{color:#d14}
.CodeRay .shell{color:#d14}
.CodeRay .shell .delimiter{color:#d14}
.CodeRay .symbol{color:#990073}
.CodeRay .symbol .content{color:#a60}
.CodeRay .symbol .delimiter{color:#630}
.CodeRay .tag{color:#008080}
.CodeRay .tag-special{color:#d70}
.CodeRay .variable{color:#036}
.CodeRay .insert{background:#afa}
.CodeRay .delete{background:#faa}
.CodeRay .change{color:#aaf;background:#007}
.CodeRay .head{color:#f8f;background:#505}
.CodeRay .insert .insert{color:#080}
.CodeRay .delete .delete{color:#800}
.CodeRay .change .change{color:#66f}
.CodeRay .head .head{color:#f4f}
</style>
</head>
<body class="book toc2 toc-left">
<div id="header">
<h1>Stored Procedures in Java (SPJs) Guide</h1>
<div class="details">
<span id="revnumber">version 2.4.0</span>
</div>
<div id="toc" class="toc2">
<div id="toctitle">Table of Contents</div>
<ul class="sectlevel1">
<li><a href="#_about_this_document">1. About This Document</a>
<ul class="sectlevel2">
<li><a href="#_intended_audience">1.1. Intended Audience</a></li>
<li><a href="#_document_organization">1.2. Document Organization</a></li>
<li><a href="#_new_and_changed_information">1.3. New and Changed Information</a></li>
<li><a href="#_notation_conventions">1.4. Notation Conventions</a></li>
<li><a href="#_comments_encouraged">1.5. Comments Encouraged</a></li>
</ul>
</li>
<li><a href="#introduction">2. Introduction</a>
<ul class="sectlevel2">
<li><a href="#what-is-an-spj">2.1. What Is an SPJ?</a></li>
<li><a href="#benefits-of-spjs">2.2. Benefits of SPJs</a>
<ul class="sectlevel3">
<li><a href="#java-methods-callable-from-sql">2.2.1. Java Methods Callable From SQL</a></li>
<li><a href="#common-packaging-technique">2.2.2. Common Packaging Technique</a></li>
<li><a href="#security">2.2.3. Security</a></li>
<li><a href="#increased-productivity">2.2.4. Increased Productivity</a></li>
<li><a href="#portability">2.2.5. Portability</a></li>
</ul>
</li>
<li><a href="#use-spjs">2.3. Use SPJs</a></li>
</ul>
</li>
<li><a href="#get-started">3. Get Started</a>
<ul class="sectlevel2">
<li><a href="#required-client-software">3.1. Required Client Software</a>
<ul class="sectlevel3">
<li><a href="#java-development-kit">3.1.1. Java Development Kit</a></li>
</ul>
</li>
<li><a href="#recommended-client-software">3.2. Recommended Client Software</a>
<ul class="sectlevel3">
<li><a href="#trafodion-command-interface-trafci">3.2.1. Trafodion Command Interface (trafci)</a></li>
<li><a href="#hp-jdbc-type-4-driver">3.2.2. Trafodion JDBC Type 4 Driver</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#develop-spj-methods">4. Develop SPJ Methods</a>
<ul class="sectlevel2">
<li><a href="#guidelines-for-writing-spj-methods">4.1. Guidelines for Writing SPJ Methods</a>
<ul class="sectlevel3">
<li><a href="#signature-of-the-java-method">4.1.1. Signature of the Java Method</a></li>
<li><a href="#returning-output-values-from-the-java-method">4.1.2. Returning Output Values From the Java Method</a></li>
<li><a href="#returning-stored-procedure-result-sets">4.1.3. Returning Stored Procedure Result Sets</a></li>
<li><a href="#using-the-main-method">4.1.4. Using the main() Method</a></li>
<li><a href="#null-input-and-output">4.1.5. Null Input and Output</a></li>
<li><a href="#static-java-variables">4.1.6. Static Java Variables</a></li>
<li><a href="#nested-java-method-invocations">4.1.7. Nested Java Method Invocations</a></li>
</ul>
</li>
<li><a href="#accessing-a-trafodion-database">4.2. Accessing Trafodion</a>
<ul class="sectlevel3">
<li><a href="#use-of-java.sql.connection-objects">4.2.1. Use of java.sql.Connection Objects</a></li>
<li><a href="#using-jdbc-method-calls">4.2.2. Using JDBC Method Calls</a></li>
<li><a href="#referring-to-database-objects-in-an-spj-method">4.2.3. Referring to Database Objects in an SPJ Method</a></li>
<li><a href="#using-the-session_user-or-current_user-function-in-an-spj-method">4.2.4. Using the SESSION_USER or CURRENT_USER Function in an SPJ Method</a></li>
<li><a href="#exception-handling">4.2.5. Exception Handling</a></li>
</ul>
</li>
<li><a href="#handling-java-exceptions">4.3. Handling Java Exceptions</a>
<ul class="sectlevel3">
<li><a href="#user-defined-exceptions">4.3.1. User-Defined Exceptions</a></li>
</ul>
</li>
<li><a href="#compiling-and-packaging-java-classes">4.4. Compiling and Packaging Java Classes</a></li>
</ul>
</li>
<li><a href="#deploy-spj-jar-files">5. Deploy SPJ JAR Files</a>
<ul class="sectlevel2">
<li><a href="#create-a-library">5.1. Create a Library</a></li>
<li><a href="#drop-a-library">5.2. Drop a Library</a></li>
<li><a href="#display-libraries">5.3. Display Libraries</a></li>
</ul>
</li>
<li><a href="#create-spjs">6. Create SPJs</a>
<ul class="sectlevel2">
<li><a href="#create-a-procedure">6.1. Create a Procedure</a>
<ul class="sectlevel3">
<li><a href="#create-procedure-settings">6.1.1. Create Procedure Settings</a></li>
</ul>
</li>
<li><a href="#understand-external-security">6.2. Understand External Security</a></li>
<li><a href="#drop-a-procedure">6.3. Drop a Procedure</a></li>
<li><a href="#display-procedures-and-their-properties">6.4. Display Procedures and Their Properties</a></li>
</ul>
</li>
<li><a href="#grant-privileges">7. Grant Privileges</a>
<ul class="sectlevel2">
<li><a href="#granting-execute-privileges-on-an-spj">7.1. Granting Execute Privileges on an SPJ</a></li>
<li><a href="#granting-privileges-on-referenced-database-objects">7.2. Granting Privileges on Referenced Database Objects</a></li>
<li><a href="#revoking-execute-privileges-on-an-spj">7.3. Revoking Execute Privileges on an SPJ</a></li>
<li><a href="#_using_script_files_to_grant_and_revoke_privileges">7.4. Using Script Files to Grant and Revoke Privileges</a>
<ul class="sectlevel3">
<li><a href="#_script_file_for_granting_privileges">7.4.1. Script File for Granting Privileges</a></li>
<li><a href="#_script_file_for_revoking_privileges">7.4.2. Script File for Revoking Privileges</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#execute-spjs">8. Execute SPJs</a>
<ul class="sectlevel2">
<li><a href="#required-privileges-for-calling-an-spj">8.1. Required Privileges for Calling an SPJ</a></li>
<li><a href="#transaction-behavior">8.2. Transaction Behavior</a>
<ul class="sectlevel3">
<li><a href="#transaction-required">8.2.1. Transaction Required</a></li>
<li><a href="#no-transaction-required">8.2.2. No Transaction Required</a></li>
</ul>
</li>
<li><a href="#multithreading">8.3. Multithreading</a></li>
<li><a href="#using-the-call-statement">8.4. Using the CALL Statement</a>
<ul class="sectlevel3">
<li><a href="#specifying-the-name-of-the-spj">8.4.1. Specifying the Name of the SPJ</a></li>
<li><a href="#listing-the-parameter-arguments-of-the-spj">8.4.2. Listing the Parameter Arguments of the SPJ</a></li>
</ul>
</li>
<li><a href="#calling-spjs-in-trafci">8.5. Calling SPJs in trafci</a>
<ul class="sectlevel3">
<li><a href="#using-named-parameters">8.5.1. Using Named Parameters</a></li>
<li><a href="#using-unnamed-parameters">8.5.2. Using Unnamed Parameters</a></li>
<li><a href="#returning-result-sets-in-trafci">8.5.3. Returning Result Sets in trafci</a></li>
</ul>
</li>
<li><a href="#calling-spjs-from-an-odbc-client-application">8.6. Calling SPJs From an ODBC Client Application</a>
<ul class="sectlevel3">
<li><a href="#returning-result-sets-in-an-odbc-client-application">8.6.1. Returning Result Sets in an ODBC Client Application</a></li>
</ul>
</li>
<li><a href="#calling-spjs-from-a-jdbc-client-application">8.7. Calling SPJs From a JDBC Client Application</a>
<ul class="sectlevel3">
<li><a href="#returning-result-sets-in-a-jdbc-client-application">8.7.1. Returning Result Sets in a JDBC Client Application</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#performance-and-troubleshooting">9. Performance and Troubleshooting</a>
<ul class="sectlevel2">
<li><a href="#troubleshooting-common-problems">9.1. Troubleshooting Common Problems</a></li>
<li><a href="#performance-tip">9.2. Performance Tip</a></li>
<li><a href="#displaying-an-execution-plan-of-a-call-statement">9.3. Displaying an Execution Plan of a CALL Statement</a>
<ul class="sectlevel3">
<li><a href="#using-the-explain-statement">9.3.1. Using the EXPLAIN Statement</a></li>
<li><a href="#using-the-explain-function">9.3.2. Using the EXPLAIN Function</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#a-sample-spjs">10. A Sample SPJs</a>
<ul class="sectlevel2">
<li><a href="#procedures-in-the-sales-schema">10.1. Procedures in the SALES Schema</a>
<ul class="sectlevel3">
<li><a href="#lowerprice-procedure">10.1.1. LOWERPRICE Procedure</a></li>
<li><a href="#dailyorders-procedure">10.1.2. DAILYORDERS Procedure</a></li>
<li><a href="#monthlyorders-procedure">10.1.3. MONTHLYORDERS Procedure</a></li>
<li><a href="#totalprice-procedure">10.1.4. TOTALPRICE Procedure</a></li>
<li><a href="#partdata-procedure">10.1.5. PARTDATA Procedure</a></li>
<li><a href="#ordersummary-procedure">10.1.6. ORDERSUMMARY Procedure</a></li>
</ul>
</li>
<li><a href="#procedures-in-the-persnl-schema">10.2. Procedures in the PERSNL Schema</a>
<ul class="sectlevel3">
<li><a href="#adjustsalary-procedure">10.2.1. ADJUSTSALARY Procedure</a></li>
<li><a href="#employeejob-procedure">10.2.2. EMPLOYEEJOB Procedure</a></li>
<li><a href="#projectteam-procedure">10.2.3. PROJECTTEAM Procedure</a></li>
<li><a href="#topsalesreps-procedure">10.2.4. TOPSALESREPS Procedure</a></li>
</ul>
</li>
<li><a href="#procedures-in-the-invent-schema">10.3. Procedures in the INVENT Schema</a>
<ul class="sectlevel3">
<li><a href="#supplierinfo-procedure">10.3.1. SUPPLIERINFO Procedure</a></li>
<li><a href="#supplyquantities-procedure">10.3.2. SUPPLYQUANTITIES Procedure</a></li>
<li><a href="#partlocations-procedure">10.3.3. PARTLOCATIONS Procedure</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#b-sample-database">11. B Sample Database</a>
<ul class="sectlevel2">
<li><a href="#persnl-schema">11.1. PERSNL Schema</a>
<ul class="sectlevel3">
<li><a href="#job-table">11.1.1. JOB Table</a></li>
<li><a href="#employee-table">11.1.2. EMPLOYEE Table</a></li>
<li><a href="#dept-table">11.1.3. DEPT Table</a></li>
<li><a href="#project-table">11.1.4. PROJECT Table</a></li>
</ul>
</li>
<li><a href="#sales-schema">11.2. SALES Schema</a>
<ul class="sectlevel3">
<li><a href="#customer-table">11.2.1. CUSTOMER Table</a></li>
<li><a href="#orders-table">11.2.2. ORDERS Table</a></li>
<li><a href="#odetail-table">11.2.3. ODETAIL Table</a></li>
<li><a href="#parts-table">11.2.4. PARTS Table</a></li>
<li><a href="#invent-schema">11.2.5. INVENT Schema</a></li>
<li><a href="#supplier-table">11.2.6. SUPPLIER Table</a></li>
<li><a href="#partsupp-table">11.2.7. PARTSUPP Table</a></li>
<li><a href="#partloc-table">11.2.8. PARTLOC Table</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p><strong>License Statement</strong></p>
</div>
<div class="paragraph">
<p>Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at <a href="http://www.apache.org/licenses/LICENSE-2.0" class="bare">http://www.apache.org/licenses/LICENSE-2.0</a></p>
</div>
<div class="paragraph">
<p>Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.</p>
</div>
<div style="page-break-after: always;"></div>
<div class="paragraph">
<p><strong>Acknowledgements</strong></p>
</div>
<div class="paragraph">
<p>Microsoft®, Windows®, Windows NT®, Windows® XP, and Windows Vista® are
U.S. registered trademarks of Microsoft Corporation. Intel® and Intel®
Itanium® are trademarks of Intel Corporation in the U.S. and other
countries. Java® is a registered trademark of Oracle and/or its
affiliates. Motif, OSF/1, UNIX®, X/Open®, and the X device is a
trademark of X/Open Company Ltd. in the UK and other countries.</p>
</div>
<div class="paragraph">
<p>OSF, OSF/1, OSF/Motif, Motif, and Open Software Foundation are trademarks of
the Open Software Foundation in the U.S. and other countries.
© 1990, 1991, 1992, 1993 Open Software Foundation, Inc.</p>
</div>
<div class="paragraph">
<p>The OSF documentation and the OSF software to which it relates are derived in
part from materials supplied by the following: © 1987, 1988, 1989
Carnegie-Mellon University. © 1989, 1990, 1991 Digital Equipment
Corporation. © 1985, 1988, 1989, 1990 Encore Computer Corporation. © 1988 Free
Software Foundation, Inc. © 1987, 1988, 1989, 1990, 1991 Hewlett-Packard
Company. © 1985, 1987, 1988, 1989, 1990, 1991, 1992 International
Business Machines Corporation. © 1988, 1989 Massachusetts Institute of
Technology. © 1988, 1989, 1990 Mentat Inc. © 1988 Microsoft Corporation.
© 1987, 1988, 1989, 1990, 1991,
1992 SecureWare, Inc. © 1990, 1991 Siemens Nixdorf Informations systeme
AG. © 1986, 1989, 1996, 1997 Sun Microsystems, Inc. © 1989, 1990, 1991
Transarc Corporation.</p>
</div>
<div class="paragraph">
<p>OSF software and documentation are based in part
on the Fourth Berkeley Software Distribution under license from The
Regents of the University of California. OSF acknowledges the following
individuals and institutions for their role in its development: Kenneth
C.R.C. Arnold, Gregory S. Couch, Conrad C. Huang, Ed James, Symmetric
Computer Systems, Robert Elz. © 1980, 1981, 1982, 1983, 1985, 1986,
1987, 1988, 1989 Regents of the University of California. OSF MAKES NO
WARRANTY OF ANY KIND WITH REGARD TO THE OSF MATERIAL PROVIDED HEREIN,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE. OSF shall not be liable for errors
contained herein or for incidental consequential damages in connection
with the furnishing, performance, or use of this material.</p>
</div>
<div style="page-break-after: always;"></div>
<div class="paragraph">
<p><strong>Revision History</strong></p>
</div>
<table class="tableblock frame-all grid-all spread">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Version</th>
<th class="tableblock halign-left valign-top">Date</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.2.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">TBD</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.1.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">May 1, 2017</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.0.1</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">July 7, 2016</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">2.0.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">June 6, 2016</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">1.3.0</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">January, 2016</p></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="sect1">
<h2 id="_about_this_document">1. About This Document</h2>
<div class="sectionbody">
<div class="paragraph">
<p>This guide describes how to develop, deploy, and manage Stored Procedures in Java (SPJs) on Trafodion.</p>
</div>
<div class="sect2">
<h3 id="_intended_audience">1.1. Intended Audience</h3>
<div class="paragraph">
<p>This manual is intended for application programmers who are writing and compiling Java code for stored procedures
and for database administrators who are deploying and managing Stored Procedures in Java (SPJs) on Trafodion.
The reader should know:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The Java programming language.</p>
</li>
<li>
<p>JDBC and the Trafodion JDBC Type-4 Driver.</p>
</li>
<li>
<p>Structured Query Language (SQL) and database terms and concepts.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Although not required, it helps to be familiar with the part of the ANSI SQL/Foundation standard called
SQL/JRT (Java Routines and Types) on which this implementation of stored procedures is based.</p>
</div>
</div>
<div class="sect2">
<h3 id="_document_organization">1.2. Document Organization</h3>
<div class="paragraph">
<p>This document is organized as follows:</p>
</div>
<table class="tableblock frame-all grid-all spread">
<colgroup>
<col style="width: 30%;">
<col style="width: 70%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Chapter</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><a href="#introduction">Introduction</a></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Defines what an SPJ is, describes the benefits of using SPJs on the database,
and lists steps for developing and deploying SPJs on Trafodion.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><a href="#get-started">Get Started</a></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Describes the software requirements for using SPJs on Trafodion.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><a href="#develop-spj-methods">Develop SPJ Methods</a></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Provides guidelines for writing and compiling a Java method to be used as the
body of a stored procedure.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><a href="#deploy-spj-jar-files">Deploy SPJ JAR Files</a></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Explains how to deploy SPJ JAR files on Trafodion.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><a href="#create-spjs">Create SPJs</a></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Explains how to create, drop, and alter an SPJ on Trafodion.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><a href="#grant-privileges">Grant Privileges</a></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Explains how to grant and revoke privileges for executing SPJs on the
Trafodion database.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><a href="#execute-spjs">Execute SPJs</a></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Explains how to execute an SPJ on Trafodion by using the CALL statement.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><a href="#performance-and-troubleshooting">Performance and Troubleshooting</a></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Describes how to improve and monitor the performance of SPJs and provides guidelines for troubleshooting common problems.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><a href="#sample-spjs">Appendix A: Sample SPJs</a></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Provides examples of SPJ methods that demonstrate business logic on Trafodion.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><a href="#sample-database">Appendix B: Sample Database</a></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Describes the sample database on which the Sample SPJs operate.</p></td>
</tr>
</tbody>
</table>
</div>
<div class="sect2">
<h3 id="_new_and_changed_information">1.3. New and Changed Information</h3>
<div class="paragraph">
<p>This is a new manual.</p>
</div>
</div>
<div class="sect2">
<h3 id="_notation_conventions">1.4. Notation Conventions</h3>
<div class="paragraph">
<p>This list summarizes the notation conventions for syntax presentation in this manual.</p>
</div>
<div class="ulist">
<ul>
<li>
<p>UPPERCASE LETTERS</p>
<div class="paragraph">
<p>Uppercase letters indicate keywords and reserved words. Type these items exactly as shown. Items not enclosed in brackets are required.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">SELECT</code></pre>
</div>
</div>
</li>
<li>
<p>lowercase letters</p>
<div class="paragraph">
<p>Lowercase letters, regardless of font, indicate variable items that you supply. Items not enclosed in brackets are required.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">file-name</code></pre>
</div>
</div>
</li>
<li>
<p>&#91; &#93; Brackets</p>
<div class="paragraph">
<p>Brackets enclose optional syntax items.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">DATETIME [start-field TO] end-field</code></pre>
</div>
</div>
<div class="paragraph">
<p>A group of items enclosed in brackets is a list from which you can choose one item or none.</p>
</div>
<div class="paragraph">
<p>The items in the list can be arranged either vertically, with aligned brackets on each side of the list, or horizontally, enclosed in a pair of brackets and separated by vertical lines.</p>
</div>
<div class="paragraph">
<p>For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">DROP SCHEMA schema [CASCADE]
DROP SCHEMA schema [ CASCADE | RESTRICT ]</code></pre>
</div>
</div>
</li>
<li>
<p>{ } Braces</p>
<div class="paragraph">
<p>Braces enclose required syntax items.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">FROM { grantee [, grantee ] ... }</code></pre>
</div>
</div>
<div class="paragraph">
<p>A group of items enclosed in braces is a list from which you are required to choose one item.</p>
</div>
<div class="paragraph">
<p>The items in the list can be arranged either vertically, with aligned braces on each side of the list, or horizontally, enclosed in a pair of braces and separated by vertical lines.</p>
</div>
<div class="paragraph">
<p>For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">INTERVAL { start-field TO end-field }
{ single-field }
INTERVAL { start-field TO end-field | single-field }</code></pre>
</div>
</div>
</li>
<li>
<p>| Vertical Line</p>
<div class="paragraph">
<p>A vertical line separates alternatives in a horizontal list that is enclosed in brackets or braces.</p>
</div>
</li>
</ul>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">{expression | NULL}</code></pre>
</div>
</div>
<div class="ulist">
<ul>
<li>
<p>&#8230; Ellipsis</p>
<div class="paragraph">
<p>An ellipsis immediately following a pair of brackets or braces indicates that you can repeat the enclosed sequence of syntax items any number of times.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">ATTRIBUTE[S] attribute [, attribute] ...
{, sql-expression } ...</code></pre>
</div>
</div>
<div class="paragraph">
<p>An ellipsis immediately following a single syntax item indicates that you can repeat that syntax item any number of times.</p>
</div>
<div class="paragraph">
<p>For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">expression-n ...</code></pre>
</div>
</div>
</li>
</ul>
</div>
<div style="page-break-after: always;"></div>
<div class="ulist">
<ul>
<li>
<p>Punctuation</p>
<div class="paragraph">
<p>Parentheses, commas, semicolons, and other symbols not previously described must be typed as shown.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">DAY (datetime-expression)
@script-file</code></pre>
</div>
</div>
<div class="paragraph">
<p>Quotation marks around a symbol such as a bracket or brace indicate the symbol is a required character that you must type as shown.</p>
</div>
<div class="paragraph">
<p>For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">&quot;{&quot; module-name [, module-name] ... &quot;}&quot;</code></pre>
</div>
</div>
</li>
<li>
<p>Item Spacing</p>
<div class="paragraph">
<p>Spaces shown between items are required unless one of the items is a punctuation symbol such as a parenthesis or a comma.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">DAY (datetime-expression) DAY(datetime-expression)</code></pre>
</div>
</div>
<div class="paragraph">
<p>If there is no space between two items, spaces are not permitted. In this example, no spaces are permitted between the period and any other items:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">myfile.sh</code></pre>
</div>
</div>
</li>
<li>
<p>Line Spacing</p>
<div class="paragraph">
<p>If the syntax of a command is too long to fit on a single line, each continuation line is indented three spaces and is separated from the preceding line by a blank line.</p>
</div>
<div class="paragraph">
<p>This spacing distinguishes items in a continuation line from items in a vertical list of selections.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">match-value [NOT] LIKE _pattern
[ESCAPE esc-char-expression]</code></pre>
</div>
</div>
</li>
</ul>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect2">
<h3 id="_comments_encouraged">1.5. Comments Encouraged</h3>
<div class="paragraph">
<p>We encourage your comments concerning this document. We are committed to providing documentation that meets your
needs. Send any errors found, suggestions for improvement, or compliments to <a href="mailto:user@trafodion.apache.org">user@trafodion.apache.org</a>.</p>
</div>
<div class="paragraph">
<p>Include the document title and any comment, error found, or suggestion for improvement you have concerning this document.</p>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="introduction">2. Introduction</h2>
<div class="sectionbody">
<div class="paragraph">
<p>This chapter introduces stored procedures in Java (SPJs) in Trafodion
and covers these topics:</p>
</div>
<div class="sect2">
<h3 id="what-is-an-spj">2.1. What Is an SPJ?</h3>
<div class="paragraph">
<p>A stored procedure is a type of user-defined routine (UDR) that operates
within a database server and typically performs SQL operations on a
database. The database server contains information about the stored
procedure and controls its execution. A client application executes a
stored procedure by issuing an SQL CALL statement. Unlike a user-defined
function, which returns a value directly to the calling application, a
stored procedure returns each output value to a dynamic parameter in its
parameter list or returns a set of values to a result set array.</p>
</div>
<div class="paragraph">
<p>Trafodion supports stored procedures written in the Java
programming language. The Trafodion implementation of stored procedures
complies mostly, unless otherwise specified, with SQL/JRT (Java Routines
and Types), which extends the ANSI SQL/Foundation standard. A stored
procedure in Java (SPJ) is a Java method contained in a Java archive
(JAR) file on Trafodion, registered in the database, and
executed by the database engine when a client application issues a CALL
statement.</p>
</div>
<div class="paragraph">
<p>The body of a stored procedure consists of a public, static Java method
that returns void. These Java methods, called <em>SPJ methods</em>, are
contained in classes within JAR files on the cluster hosting Trafodion.</p>
</div>
<div class="paragraph">
<p>An SPJ method must be registered as a stored procedure in the database before a
client application can execute it with a CALL statement. You upload the SPJ to
the cluster where Trafodion is running
and then you register the SPJ as a library object using the
<a href="http://trafodion.apache.org/docs/sql_reference/index.html#create_library_statement">CREATE LIBRARY</a>
statement. Next, you register the library object using the
<a href="http://trafodion.apache.org/docs/sql_reference/index.html#create_procedure_statement">CREATE PROCEDURE</a>
statement.</p>
</div>
</div>
<div class="sect2">
<h3 id="benefits-of-spjs">2.2. Benefits of SPJs</h3>
<div class="paragraph">
<p>SPJs provide an efficient and secure way to implement business logic in
the database. SPJs offer these advantages:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="#java-methods-callable-from-sql">Java Methods Callable From SQL</a></p>
</li>
<li>
<p><a href="#common-packaging-technique">Common Packaging Technique</a></p>
</li>
<li>
<p><a href="#security">Security</a></p>
</li>
<li>
<p><a href="#increased-productivity">Increased Productivity</a></p>
</li>
<li>
<p><a href="#portability">Portability</a></p>
</li>
</ul>
</div>
<div class="sect3">
<h4 id="java-methods-callable-from-sql">2.2.1. Java Methods Callable From SQL</h4>
<div class="paragraph">
<p>With support for SPJs, Java methods are callable from any client
application that connects to Trafodion. For example, you can
invoke the same SPJ method from JDBC client applications and ODBC client
applications. By using the database engine to invoke Java methods, you
can extend the functionality of the database and share business logic
among different applications.</p>
</div>
<div class="paragraph">
<p>For more information, see <a href="#execute-spjs">Execute SPJs</a>.</p>
</div>
</div>
<div class="sect3">
<h4 id="common-packaging-technique">2.2.2. Common Packaging Technique</h4>
<div class="paragraph">
<p>Different applications can invoke the same SPJ to perform a common
business function. By encapsulating business logic in an SPJ, you can
maintain consistent database operations and avoid duplicating code in
applications.</p>
</div>
<div class="paragraph">
<p>Applications that call SPJs are not required to know the structure of
the database tables that the SPJ methods access. The application does
not need to use any table or column names; it needs only the name of the
stored procedure in the CALL statement. If the table structure changes,
you might need to change the SPJ methods but not necessarily the CALL
statements within each application.</p>
</div>
</div>
<div class="sect3">
<h4 id="security">2.2.3. Security</h4>
<div class="paragraph">
<p>By using SPJs, you can conceal sensitive business logic inside SPJ
methods instead of exposing it in client applications. You can also
grant privileges to execute an SPJ to specific users and restrict the
privileges of other users. For more information, see
<a href="#grant-privileges">Grant Privileges</a></p>
</div>
</div>
<div class="sect3">
<h4 id="increased-productivity">2.2.4. Increased Productivity</h4>
<div class="paragraph">
<p>Use SPJs to reduce the time and cost of developing and maintaining
client applications. By having several applications call the same SPJ,
you need only change the SPJ method once when business rules or table
structures change instead of changing every application that calls the
SPJ.</p>
</div>
<div class="paragraph">
<p>Using the Java language to implement stored procedures increases
productivity. Given the popularity of the Java language, you can
leverage the existing skill set of Java programmers to develop SPJs.</p>
</div>
<div class="paragraph">
<p>The portability of the Java language enables you to write and compile
Java class files for SPJs once and deploy them anywhere.</p>
</div>
</div>
<div class="sect3">
<h4 id="portability">2.2.5. Portability</h4>
<div class="paragraph">
<p>Because SPJ methods are written in Java, and SPJs conform to the ANSI
SQL standard, SPJs are portable across different database servers. With
minimal changes to SPJ methods, you can port existing SPJ JAR files from
another database server to Trafodion and register the methods
as stored procedures in a Trafodion database. You can also port client
applications that call SPJs in other databases to Trafodion SQL with
minimal changes to the CALL statements in the application.</p>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
<div class="sect2">
<h3 id="use-spjs">2.3. Use SPJs</h3>
<div class="paragraph">
<p>To use SPJs in Trafodion:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Verify that you have the required software installed on the client
workstation. See <a href="#get-started">Get Started</a>.</p>
</li>
<li>
<p>Develop a Java method to be used as an SPJ:</p>
<div class="olist loweralpha">
<ol class="loweralpha" type="a">
<li>
<p>Write a static Java method:</p>
<div class="paragraph">
<p>Create a file named <code>Payroll.java</code> with the following content:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="keyword">import</span> <span class="include">java.sql</span>.* ;
<span class="keyword">import</span> <span class="include">java.math</span>.* ;
<span class="directive">public</span> <span class="type">class</span> <span class="class">Payroll</span>
{
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> adjustSalary( <span class="predefined-type">BigDecimal</span> empNum
, <span class="type">double</span> percent, <span class="predefined-type">BigDecimal</span><span class="type">[]</span> newSalary
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> setSalary =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">UPDATE trafodion.persnl.employee </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">SET salary = salary * (1 + (? / 100)) </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE empnum = ?</span><span class="delimiter">&quot;</span></span>
) ;
<span class="predefined-type">PreparedStatement</span> getSalary =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT salary </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.persnl.employee </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE empnum = ?</span><span class="delimiter">&quot;</span></span>
) ;
setSalary.setDouble( <span class="integer">1</span>, percent ) ;
setSalary.setBigDecimal( <span class="integer">2</span>, empNum ) ;
setSalary.executeUpdate() ;
getSalary.setBigDecimal( <span class="integer">1</span>, empNum ) ;
<span class="predefined-type">ResultSet</span> rs = getSalary.executeQuery() ;
rs.next() ;
newSalary[<span class="integer">0</span>] = rs.getBigDecimal( <span class="integer">1</span> ) ;
rs.close() ;
conn.close() ;
}
}</code></pre>
</div>
</div>
</li>
<li>
<p>Compile the Java source file to produce a class file:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">$ javac Payroll.java
$</code></pre>
</div>
</div>
</li>
<li>
<p>Package the SPJ class file in a JAR file:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">jar cvf Payroll.jar Payroll.class</code></pre>
</div>
</div>
<div class="paragraph">
<p>If the SPJ class refers to other classes, package the other classes in
the same JAR file as the SPJ class:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">$ jar cvf Payroll.jar Payroll.class other.class
added manifest
adding: Payroll.class(in = 1213) (out= 711)(deflated 41%)
$</code></pre>
</div>
</div>
<div class="paragraph">
<p>For details, see <a href="#develop-spj-methods">Develop SPJ Methods</a>.</p>
</div>
</li>
</ol>
</div>
</li>
<li>
<p>Deploy the SPJ JAR file on Trafodion by creating a
library object for the JAR file in one of the database schemas. For
details, see <a href="#Deploy-spj-jar-files">Deploy SPJ JAR Files</a>.</p>
</li>
<li>
<p>As the schema owner, create the SPJ in the database. For details,
see <a href="#create-spjs">Create SPJs</a>.</p>
</li>
<li>
<p>Grant privileges to database users for executing the SPJ and for
operating on the referenced database objects. For example, you can issue
GRANT statements in an trafci session, as shown below:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">GRANT</span> EXECUTE
<span class="keyword">ON</span> <span class="type">PROCEDURE</span> trafodion.persnl.adjustsalary
<span class="keyword">TO</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">payrolldir1</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">payrolldir2</span><span class="delimiter">&quot;</span></span>
WITH <span class="class">GRANT</span> OPTION ;
<span class="class">GRANT</span> <span class="class">SELECT</span>, <span class="class">UPDATE</span> (salary)
<span class="keyword">ON</span> <span class="type">TABLE</span> trafodion.persnl.employee
<span class="keyword">TO</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">payrolldir1</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">payrolldir2</span><span class="delimiter">&quot;</span></span>
WITH <span class="class">GRANT</span> OPTION ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>For details, see <a href="#grant-privileges">Grant Privileges</a>.</p>
</div>
<div style="page-break-after: always;"></div>
</li>
<li>
<p>Execute an SPJ by using a CALL statement in a client application.
For example, you can issue a CALL statement in an trafci session, as
shown below, or in a JDBC or ODBC client application:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">SQL&gt; CALL trafodion.persnl.adjustsalary( 29, 2.5, ? ) ;
NEWSALARY
------------
139400.00
--- SQL operation complete.</code></pre>
</div>
</div>
<div class="paragraph">
<p>For details, see <a href="#execute-spjs">Execute SPJs</a>.</p>
</div>
</li>
<li>
<p>Monitor the performance of SPJs and resolve common problems with
SPJs in the database. See <a href="#performance-and-troubleshooting">Performance and Troubleshooting</a>.</p>
</li>
</ol>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="get-started">3. Get Started</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Before you can start using SPJs on Trafodion, verify that
you have the required software installed on the client workstation.
Trafodion is delivered to you ready to use and pre-configured
with the software required to support SPJs.</p>
</div>
<div class="sect2">
<h3 id="required-client-software">3.1. Required Client Software</h3>
<div class="sect3">
<h4 id="java-development-kit">3.1.1. Java Development Kit</h4>
<div class="paragraph">
<p>To develop Java methods to be used as SPJs, you must have a Java
Development Kit (JDK) installed on the client workstation. To download a
JDK, go to
<a href="http://www.oracle.com/technetwork/java/index.html" class="bare">http://www.oracle.com/technetwork/java/index.html</a></p>
</div>
<div class="paragraph">
<p>The version of the JDK that you download and use on the client
workstation should be the same as or lower than the Java version running
on Trafodion. To check the Java version that is running in
Trafodion, use this approach:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Launch <code>trafci</code> on Trafodion, and run the <code>LOCALHOST</code> or <code>lh java -version</code> command.
(To use the on-platform trafci client, see the
<a href="http://trafodion.apache.org/docs/command_interface/index.html">Trafodion Command Interface Guide</a>.</p>
<div class="paragraph">
<p>For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">SQL&gt; lh java -version
java version &quot;1.6.0_06&quot;
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode)
SQL&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>In this example, the returned Java version indicates that the Trafodion
instance supports Java SE 6 or JDK 6 (1.6.0), or earlier versions of the
JDK.</p>
</div>
</li>
</ul>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
If you plan to install the Trafodion JDBC Type-4 Driver on the client
workstation, you must have JDK 6 (1.6.0) or higher installed on the
client workstation.
</td>
</tr>
</table>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
<div class="sect2">
<h3 id="recommended-client-software">3.2. Recommended Client Software</h3>
<div class="sect3">
<h4 id="trafodion-command-interface-trafci">3.2.1. Trafodion Command Interface (trafci)</h4>
<div class="paragraph">
<p><code>trafci</code> is a command-line interface in which you can run SQL statements,
such as GRANT PROCEDURE and CALL statements, interactively or from
script files. To install <code>trafci</code> on a client workstation, see the
<a href="http://trafodion.apache.org/docs/client_install/index.html">Trafodion Client Installation Guide</a>.</p>
</div>
</div>
<div class="sect3">
<h4 id="hp-jdbc-type-4-driver">3.2.2. Trafodion JDBC Type 4 Driver</h4>
<div class="paragraph">
<p>If you plan to use <code>trafci</code>, you must have a compatible version of the Trafodion
JDBC Type-4 Driver installed on the client workstation.</p>
</div>
<div class="paragraph">
<p>To install the JDBC Type-4 driver on the client workstation, see the
<a href="http://trafodion.apache.org/docs/client_install/index.html">Trafodion Client Installation Guide</a>.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="develop-spj-methods">4. Develop SPJ Methods</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Before creating, or registering, an SPJ in the database, you must write
and compile the Java method to be used as the body of the SPJ. The
manual refers to those Java methods as <em>SPJ methods</em>.</p>
</div>
<div class="paragraph">
<p>This chapter requires a familiarity with writing and compiling Java programs.</p>
</div>
<div class="sect2">
<h3 id="guidelines-for-writing-spj-methods">4.1. Guidelines for Writing SPJ Methods</h3>
<div class="paragraph">
<p>Follow the guidelines for these topics when you write SPJ methods to be
used as SPJs in the database:</p>
</div>
<div class="sect3">
<h4 id="signature-of-the-java-method">4.1.1. Signature of the Java Method</h4>
<div class="paragraph">
<p>A Java method that you use as an SPJ must have this general signature:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> myMethodName ( java-parameter-list )</code></pre>
</div>
</div>
<div class="sect4">
<h5 id="public-access-and-static-modifiers">Public Access and Static Modifiers</h5>
<div class="paragraph">
<p>The Java method must be defined as <code>public</code> and <code>static</code>. If a method is
<code>private</code> or <code>protected</code>, then Trafodion is unable to find the Java
method when you try to register the SPJ and returns an error. The Java
method must be defined as <code>static</code> so that the method can be invoked
without having to instantiate its class.</p>
</div>
</div>
<div class="sect4">
<h5 id="void-return-type">Void Return Type</h5>
<div class="paragraph">
<p>The return type of the Java method must be <code>void</code>. The method must not
return a value directly to the caller.</p>
</div>
</div>
<div class="sect4">
<h5 id="java-parameters">Java Parameters</h5>
<div class="paragraph">
<p>Except for result sets, which are described in
<a href="#returning-stored-procedure-result-sets">Returning Stored Procedure Result Sets</a>,
the parameter types in the Java signature must correspond to the SQL
parameters of the stored procedure that you are planning to create. For
type mappings, see the table below.</p>
</div>
<div style="page-break-after: always;"></div>
<table id="table-1" class="tableblock frame-all grid-all spread">
<caption class="title">Table 1. Mapping of Java Data Types to SQL Data Types</caption>
<colgroup>
<col style="width: 60%;">
<col style="width: 40%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">SQL Data Type</th>
<th class="tableblock halign-left valign-top">Maps to Java Data Type&#8230;</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">CHAR[ACTER]<br>
CHAR[ACTER] VARYING<br>
VARCHAR<br>
PIC[TURE] X<sup>1</sup><br>
NCHAR<br>
NCHAR VARYING<br>
NATIONAL CHAR[ACTER]<br>
NATIONAL CHAR[ACTER] VARYING</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">java.lang.String</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">DATE</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">java.sql.Date</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">TIME</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">java.sql.Time</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">TIMESTAMP</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">java.sql.Timestamp</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">DEC<sup class="IMAL">2</sup><br>
PIC[TURE] S9<sup>3</sup><br>
NUMERIC (including numeric with a precision greater than eighteen)<sup>2</sup></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">java.math.BigDecimal</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">SMALLINT<sup>2</sup></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">short</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">INT<sup class="EGER">2</sup></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">int or java.lang.Integer<sup>4</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">LARGEINT<sup>2</sup></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">long or java.lang.Long<sup>4</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">FLOAT</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">double or java.lang.Double<sup>4</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">REAL</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">float or java.lang.Float<sup>4</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">DOUBLE PRECISION</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">double or java.lang.Double<sup>4</sup></p></td>
</tr>
</tbody>
</table>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Trafodion stores PIC X as a CHAR data type.</p>
</li>
<li>
<p>Numeric data types of SQL parameters must be signed, which is the default in Trafodion.</p>
</li>
<li>
<p>Trafodion stores PIC S9 as a DECIMAL or NUMERIC data type.</p>
</li>
<li>
<p>By default, the SQL data type maps to a Java primitive type. The SQL data type maps to a Java wrapper class
only if you specify the wrapper class in the Java signature of the external name clause.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>Output parameters in the Java signature must be arrays (for example,
<code>int[]</code> or <code>String[]</code>) that accept only one value in the first element of
the array at index 0. For more information, see
<a href="#returning-output-values-from-the-java-method">Returning Output Values From the Java Method</a>.</p>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
<div class="sect3">
<h4 id="returning-output-values-from-the-java-method">4.1.2. Returning Output Values From the Java Method</h4>
<div class="paragraph">
<p>The Java method can return data to the calling application in the form
of output parameters or result sets.</p>
</div>
<div class="paragraph">
<p><em>Output parameters</em> in the Java signature are parameter arrays that
accept only one value in the first element of the array at index 0. The
array objects have a fixed size of one element.</p>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
You cannot return more than one value to an output parameter of an SPJ.
Any attempt to return more than one value to an output parameter results in a Java exception,
<code>ArrayIndexOutOfBounds</code>.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p><em>Result sets</em> in the Java signature are one-element <code>java.sql.ResultSet[]</code>
arrays that contain ResultSet objects that have multiple rows of data.
For more information about result sets, see
<a href="#returning-stored-procedure-result-sets">Returning Stored Procedure Result Sets</a></p>
</div>
<div class="paragraph">
<p>This subsection covers these topics related to output parameters:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="#using-arrays-for-output-parameters">Using Arrays for Output Parameters</a></p>
</li>
<li>
<p><a href="#type-mapping-of-output-parameters">Type Mapping of Output Parameters</a></p>
</li>
</ul>
</div>
<div class="sect4">
<h5 id="using-arrays-for-output-parameters">Using Arrays for Output Parameters</h5>
<div class="paragraph">
<p>You must use arrays for the output parameters of a Java method because
of how Java handles the arguments of a method. Java supports arguments
that are passed by value to a method and does not support arguments that
are passed by reference. As a result, Java primitive types can be passed
only to a method, not out of a method. Because a Java array is an
object, its reference is passed by value to a method, and changes to the
array are visible to the caller of the method. Therefore, arrays must be
used for output parameters in a Java method.</p>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
An output parameter accepts only one value in the first element
of the array at index 0. Any attempt to return more than one value to an
output parameter results in a Java exception, <code>ArrayIndexOutOfBounds</code>.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>For each output parameter, specify the Java type followed by empty
square brackets (<code>[]</code>) to indicate that the type is an array. For example,
specify an int type as <code>int[]</code> for an output parameter in the Java
signature.</p>
</div>
<div class="paragraph">
<p>To return multiple values from a Java method, use an output parameter
for each returned value. For example, the <code>supplierInfo()</code> method returns
a supplier&#8217;s name, address, city, state, and post code, each as a single
string in an output parameter:</p>
</div>
<div style="page-break-after: always;"></div>
<div class="paragraph">
<p>The <code>supplyQuantities()</code> method returns an average quantity, a minimum
quantity, and a maximum quantity to separate output parameters of the
integer type:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> supplyQuantities( <span class="type">int</span><span class="type">[]</span> avgQty
, <span class="type">int</span><span class="type">[]</span> minQty
, <span class="type">int</span><span class="type">[]</span> maxQty
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
...
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>For more information about the SPJ examples, see
<a href="#sample-spjs">Appendix A: Sample SPJs</a>.</p>
</div>
</div>
<div class="sect4">
<h5 id="type-mapping-of-output-parameters">Type Mapping of Output Parameters</h5>
<div class="paragraph">
<p>When writing an SPJ method, consider how the output of the SPJ is
used in the calling application. For output parameters, the Java data
type of the SPJ method must map to an SQL data type. See
<a href="#table-1">Table 1</a>.</p>
</div>
<div class="paragraph">
<p>The SQL data type must then map to a compatible data type in the calling
application. For the client application programming interfaces (APIs) that
support SPJs and for cross-references to the appropriate manuals for type
mappings between Trafodion SQL and each API, see
<a href="#execute-spjs">Execute SPJs</a> below.</p>
</div>
</div>
</div>
<div class="sect3">
<h4 id="returning-stored-procedure-result-sets">4.1.3. Returning Stored Procedure Result Sets</h4>
<div class="paragraph">
<p>Trafodion supports SPJs that return stored procedure
result sets. A stored procedure result set is a cursor that is left open
after the SPJ method executes (that is, after the CALL statement
executes successfully). After the CALL statement executes successfully,
the calling application can issue requests to open and then retrieve
multiple rows of data from the returned result sets.</p>
</div>
<div class="paragraph">
<p>An SPJ method returns an ordered collection of result sets to the
calling application by executing SELECT statements and placing each
returned ResultSet object into a one-element Java array of type
<code>java.sql.ResultSet[]</code>. The <code>java.sql.ResultSet[]</code> array is part of the Java
method&#8217;s signature and is recognized by the database engine as a
container for a single stored procedure result set.</p>
</div>
<div class="paragraph">
<p>Place the <code>java.sql.ResultSet[]</code> parameters after the other Java
parameters, if any, in the Java signature. If you do not place the
<code>java.sql.ResultSet[]</code> parameters after the other
parameters in the signature, the database engine prevents you from
creating an SPJ using that Java method. This example shows the
declaration of an SPJ method, <code>orderSummary()</code>, which returns a maximum of
two result sets:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> orderSummary( java.lang.String onOrAfter
, <span class="type">long</span><span class="type">[]</span> numOrders
, java.sql.ResultSet<span class="type">[]</span> orders
, java.sql.ResultSet<span class="type">[]</span> detail
)</code></pre>
</div>
</div>
<div class="paragraph">
<p>This code fragment shows how the <code>orderSummary()</code> method returns one of
its result sets by executing a SELECT statement and assigning the
<code>java.sql.ResultSet</code> object to a <code>java.sql.ResultSet[]</code> output array:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// Open a result set for order num, order info rows</span>
java.lang.String s =
<span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT amounts.*, orders.order_date, emps.last_name </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM ( SELECT o.ordernum, COUNT( d.partnum ) AS num_parts, </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> SUM( d.unit_price * d.qty_ordered ) AS amount </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> FROM trafodion.sales.orders o, trafodion.sales.odetail d </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> WHERE o.ordernum = d.ordernum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> AND o.order_date &gt;= CAST(? AS DATE) </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> GROUP BY o.ordernum ) amounts, </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> trafodion.sales.orders orders, trafodion.persnl.employee emps </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE amounts.ordernum = orders.ordernum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> AND orders.salesrep = emps.empnum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">ORDER BY orders.ordernum </span><span class="delimiter">&quot;</span></span>
;
java.sql.PreparedStatement ps2 = conn.prepareStatement(s) ;
ps2.setString( <span class="integer">1</span>, onOrAfter ) ;
<span class="comment">// Assign the returned result set object to the first element of a</span>
<span class="comment">// java.sql.ResultSet[] output array</span>
orders[<span class="integer">0</span>] = ps2.executeQuery() ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>For the entire example, see
<a href="#ordersummary-procedure">ORDERSUMMARY Procedure</a>.</p>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
In an SPJ method that returns result sets, do not explicitly close
the default connection or the statement object. The database engine closes the
connection used to return result sets after it finishes processing the result
sets. If you close the connection on which the result sets are being returned,
those result sets will be lost, and the calling application will not be able
to process them.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>An SPJ method can return result sets that contain any data types, except
large object (LOB) data. An SPJ method can return a holdable or
updatable cursor as a result set. However, Trafodion SQL does not expose
those attributes in the calling application. An SPJ method can return a
ResultSet object that is a stored procedure result set acquired from a
nested CALL statement executed by the SPJ method. However, you are
discouraged from nesting CALL statements in SPJ methods. For more
information, see <a href="#nested-java-method-invocations">Nested Java Method Invocations</a>.</p>
</div>
<div style="page-break-after: always;"></div>
<div class="paragraph">
<p>If an SPJ method returns multiple ResultSet objects, the database engine
sorts the collection of valid result sets in chronological order
according to when the underlying SQL statements were executed. If the
number of result sets exceeds the declared maximum for the SPJ, only the
first set of result sets up to the maximum number are returned. The
database engine discards the other result sets and returns a warning to
the calling application.</p>
</div>
<div class="paragraph">
<p>When an SPJ method returns a ResultSet object through a
<code>java.sql.ResultSet[]</code> parameter, Trafodion SQL exposes the underlying rows
of data as an SQL cursor in the calling application.</p>
</div>
<div class="paragraph">
<p>If a returned result set is a scrollable cursor, all underlying rows are
included in the result set and are available to the calling application.
If a returned result set is not scrollable, only those rows not
processed by the SPJ method are included in the result set and are
available to the calling application. If an SPJ method returns multiple
occurrences of the same ResultSet object, the database engine ignores
all but one occurrence and makes the underlying rows available to the
calling application as a single result set.</p>
</div>
<div class="paragraph">
<p>For information about processing result sets in different calling
applications, see:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="#returning-result-sets-in-trafci">Returning Result Sets in trafci</a></p>
</li>
<li>
<p><a href="#returning-result-sets-in-an-odbc-client-application">Returning Result Sets in an ODBC Client Application</a></p>
</li>
<li>
<p><a href="#returning-result-sets-in-a-jdbc-client-application">Returning Result Sets in a JDBC Client Application</a></p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="using-the-main-method">4.1.4. Using the main() Method</h4>
<div class="paragraph">
<p>You can use the <code>main()</code> method of a Java class file as an SPJ method. The
<code>main()</code> method is different from other Java methods because it accepts
input values in an array of <code>java.lang.String</code> objects and does not return
any values in its array parameter.</p>
</div>
<div class="paragraph">
<p>For example, you can register this main() method as an SPJ:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> main (java.lang.String <span class="type">[]</span> args)
{
...
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>When you register a <code>main()</code> method as an SPJ, you can specify zero or
more SQL parameters, even though the underlying <code>main()</code> method has only
one array parameter. All the SQL parameters of the SPJ must have the
character string data type, CHAR or VARCHAR, and be declared with the IN
mode.</p>
</div>
<div class="paragraph">
<p>If you specify the optional Java signature, the signature must be
(<code>java.lang.String []</code>). For more information about registering an SPJ,
see <a href="#create-spjs">Create SPJs</a>.</p>
</div>
</div>
<div class="sect3">
<h4 id="null-input-and-output">4.1.5. Null Input and Output</h4>
<div class="paragraph">
<p>You can pass a <code>null</code> value as input to or output from an SPJ method,
provided that the Java data type of the parameter supports nulls. Java
primitive data types do not support nulls. However, Java wrapper classes
that correspond to primitive data types do support nulls. If a null is
input or output for a parameter that does not support nulls, the
database engine raises an error condition.</p>
</div>
<div class="paragraph">
<p>To anticipate null input or output for your SPJ, use Java wrapper
classes instead of primitive data types in the method signature.</p>
</div>
<div class="paragraph">
<p>For example, this Java method uses a Java primitive data type in its
signature where no null values are expected:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> employeeJob( <span class="type">int</span> empNum, <span class="predefined-type">Integer</span><span class="type">[]</span> jobCode )</code></pre>
</div>
</div>
<div class="paragraph">
<p>This Java method also uses a Java wrapper class in its signature to
anticipate a possible returned null value:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> employeeJob( <span class="type">int</span> empNum, <span class="predefined-type">Integer</span><span class="type">[]</span> jobCode )</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="static-java-variables">4.1.6. Static Java Variables</h4>
<div class="paragraph">
<p>To ensure that your SPJ method is portable, you should avoid using
static variables in the method. The database engine does not ensure the
scope and persistence of static Java variables.</p>
</div>
</div>
<div class="sect3">
<h4 id="nested-java-method-invocations">4.1.7. Nested Java Method Invocations</h4>
<div class="paragraph">
<p>An SPJ that invokes another SPJ by issuing a CALL statement causes
additional system resources to be used. If you want an SPJ method to
call another SPJ method, consider invoking the other Java method
directly through Java instead of using a CALL statement. The other Java
method should be packaged in the same JAR file as the SPJ method. For
more information, see
<a href="#compiling-and-packaging-java-classes">Compiling and Packaging Java Classes</a>.</p>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
<div class="sect2">
<h3 id="accessing-a-trafodion-database">4.2. Accessing Trafodion</h3>
<div class="paragraph">
<p>SPJ methods that access Trafodion must be from a Java class
that uses JDBC method calls. Follow these guidelines when writing an SPJ
method that accesses Trafodion:</p>
</div>
<div class="sect3">
<h4 id="use-of-java.sql.connection-objects">4.2.1. Use of java.sql.Connection Objects</h4>
<div class="paragraph">
<p>Trafodion supports a default connection in an SPJ
execution environment, which has a data source URL of
<code>"jdbc:default:connection"</code>. For example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;</code></pre>
</div>
</div>
<div class="paragraph">
<p><code>java.sql.Connection</code> objects that use the <code>"jdbc:default:connection"</code> URL
are portable to Trafodion from other database management
systems (DBMSs).</p>
</div>
<div class="sect4">
<h5 id="closing-default-connections">Closing Default Connections</h5>
<div class="paragraph">
<p>Trafodion controls default connections in the SPJ
environment and closes default connections when they are no longer
needed. Therefore, you do not need to use the <code>close()</code> method in an SPJ
method to explicitly close a default connection when the connection is
no longer needed.</p>
</div>
<div class="admonitionblock important">
<table>
<tr>
<td class="icon">
<i class="fa icon-important" title="Important"></i>
</td>
<td class="content">
If an SPJ method returns result sets, you should not explicitly
close the default connection. The database engine closes the connection used
to return result sets after it finishes processing the result sets. If an SPJ
method closes the connection on which the result sets are being returned, those
result sets will be lost, and the calling application will not be able to
process them. The JVM does not return an error or warning when the
connection is closed.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>A default connection that is acquired when an SPJ method executes does
not necessarily remain open for future invocations of the SPJ method.
Therefore, do not store default connections in static variables for
future use.</p>
</div>
</div>
<div class="sect4">
<h5 id="default-connection-url">Default Connection URL</h5>
<div class="paragraph">
<p>The default connection URL, <code>"jdbc:default:connection"</code>, is invalid when
the Java method is invoked outside the DBMS, such as when you execute
the Java method in a client application. To write an SPJ method that
operates in a DBMS, in a client application, or both, without having to
change and recompile the code, use the <code>sqlj.defaultconnection</code> system
property:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="predefined-type">String</span> s = <span class="predefined-type">System</span>.property( <span class="string"><span class="delimiter">&quot;</span><span class="content">sqlj.defaultconnection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="keyword">if</span> ( s == <span class="predefined-constant">null</span> )
{
s = other-url ;
}
<span class="predefined-type">Connection</span> c = <span class="predefined-type">DriverManager</span>.getConnection( s ) ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The value of <code>sqlj.defaultconnection</code> is <code>"jdbc:default:connection"</code> in a
DBMS and <code>null</code> outside a DBMS.</p>
</div>
</div>
<div class="sect4">
<h5 id="connection-pooling">Connection Pooling</h5>
<div class="paragraph">
<p>Connection pooling, where a cache of database connections is assigned to
a client session and reused, is enabled by default in the SPJ
environment. The SPJ environment sets the initial connection pool size
to <code>1</code>, but it does not limit the number of connections an SPJ method can
make.</p>
</div>
<div class="paragraph">
<p>The SPJ environment also sets the minimum connection pool size to 1 so that
there is always at least one connection available in the pool. The
default settings in the SPJ environment are:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>maxPoolSize=0</code></p>
</li>
<li>
<p><code>minPoolSize=1</code></p>
</li>
<li>
<p><code>initialPoolSize=1</code></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>To change these settings, use the properties parameter of the
<code>DriverManager.getConnection()</code> method as shown below:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java">java.util.Properties props = <span class="keyword">new</span> <span class="predefined-type">Properties</span>() ;
props.setProperty( <span class="string"><span class="delimiter">&quot;</span><span class="content">maxPoolSize</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">10</span><span class="delimiter">&quot;</span></span> ) ;
props.setProperty( <span class="string"><span class="delimiter">&quot;</span><span class="content">minPoolSize</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">5</span><span class="delimiter">&quot;</span></span> ) ;
props.setProperty( <span class="string"><span class="delimiter">&quot;</span><span class="content">initialPoolSize</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">5</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span>, props ) ;</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
<div class="sect3">
<h4 id="using-jdbc-method-calls">4.2.2. Using JDBC Method Calls</h4>
<div class="paragraph">
<p>Trafodion uses a JDBC Type-4 driver internally to execute
the SQL statements inside an SPJ method. To enable an SPJ to perform SQL
operations on a Trafodion database, use JDBC method calls in the SPJ
method. The JDBC method calls must be supported by the JDBC Type-4
driver on Trafodion.</p>
</div>
<div class="paragraph">
<p>For example, if you want the SPJ method to operate on a Trafodion database,
use the JDBC API that is supported by Trafodion.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
You do not have to explicitly load the JDBC driver before
establishing a connection to Trafodion. The database engine
automatically loads the JDBC driver when the SPJ is called.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Here is an example of an SPJ method, <code>adjustSalary()</code>, that uses JDBC
method calls to adjust an employee&#8217;s salary in the EMPLOYEE table:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="type">class</span> <span class="class">Payroll</span>
{
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> adjustSalary( <span class="predefined-type">BigDecimal</span> empNum
, <span class="type">double</span> percent
, <span class="predefined-type">BigDecimal</span><span class="type">[]</span> newSalary
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> setSalary =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">UPDATE trafodion.persnl.employee </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">SET salary = salary * (1 + (? / 100)) </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE empnum = ?</span><span class="delimiter">&quot;</span></span>
) ;
<span class="predefined-type">PreparedStatement</span> getSalary =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT salary </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.persnl.employee </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE empnum = ?</span><span class="delimiter">&quot;</span></span>
) ;
setSalary.setDouble( <span class="integer">1</span>, percent ) ;
setSalary.setBigDecimal( <span class="integer">2</span>, empNum ) ;
setSalary.executeUpdate() ;
getSalary.setBigDecimal( <span class="integer">1</span>, empNum ) ;
<span class="predefined-type">ResultSet</span> rs = getSalary.executeQuery() ;
rs.next() ;
newSalary[<span class="integer">0</span>] = rs.getBigDecimal( <span class="integer">1</span> ) ;
rs.close();
conn.close();
}
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>For other examples of SPJ methods, see <a href="#sample-spjs">Appendix A: Sample SPJs</a>.</p>
</div>
</div>
<div class="sect3">
<h4 id="referring-to-database-objects-in-an-spj-method">4.2.3. Referring to Database Objects in an SPJ Method</h4>
<div class="paragraph">
<p>In an SPJ method, you can refer to SQL database objects by specifying
three-part ANSI names that include the catalog, schema, and object name.
For more information about database object names, see the
<a href="http://trafodion.apache.org/docs/sql_reference/index.hmtl">Trafodion SQL Reference Manual</a>.</p>
</div>
<div class="paragraph">
<p>The database engine propagates the names of the catalog and schema where
the SPJ is registered to the SPJ environment. By default, database
connections created in the SPJ method are associated with that catalog
and schema, meaning that unqualified database objects with one-part or
two-part names in the SPJ method are qualified with the same catalog
and/or schema name as the SPJ. For example, this SPJ method, which is
registered as an SPJ in the TRAFODION.SALES schema, refers to the unqualified
database object, ORDERS:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> numDailyOrders( <span class="predefined-type">Date</span> date
, <span class="type">int</span><span class="type">[]</span> numOrders
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> getNumOrders =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT COUNT( order_date ) </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM orders </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE order_date = ?</span><span class="delimiter">&quot;</span></span>
) ;
getNumOrders.setDate( <span class="integer">1</span>, date ) ;
<span class="predefined-type">ResultSet</span> rs = getNumOrders.executeQuery() ;
rs.next() ;
numOrders[<span class="integer">0</span>] = rs.getInt( <span class="integer">1</span> ) ;
rs.close() ;
conn.close() ;
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>In the SPJ environment, the ORDERS table is qualified by default with
the same catalog and schema as the SPJ, TRAFODION.SALES.</p>
</div>
<div class="paragraph">
<p>The default behavior takes effect only when <code>getConnection()</code> does not
contain catalog and schema properties. Catalog and schema property
values in <code>getConnection()</code> have higher precedence over the default
behavior. To override the default schema name and associate a database
connection with a different schema, specify the schema property during
connection creation. For example, <code>getConnection()</code> in this SPJ method
specifies the schema, SALES2, which overrides the default schema, SALES:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> numDailyOrders( <span class="predefined-type">Date</span> date
, <span class="type">int</span><span class="type">[]</span> numOrders
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Properties</span> prop = <span class="keyword">new</span> <span class="predefined-type">Properties</span>() ;
prop.setProperty( <span class="string"><span class="delimiter">&quot;</span><span class="content">schema</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">SALES2</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span>, prop) ;
<span class="predefined-type">PreparedStatement</span> getNumOrders =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT COUNT( order_date ) </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM orders </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE order_date = ?</span><span class="delimiter">&quot;</span></span>
) ;
getNumOrders.setDate( <span class="integer">1</span>, date ) ;
<span class="predefined-type">ResultSet</span> rs = getNumOrders.executeQuery() ;
rs.next() ;
numOrders[<span class="integer">0</span>] = rs.getInt( <span class="integer">1</span> ) ;
rs.close() ;
conn.close() ;
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Be aware that overriding the default values by using getConnection()
requires you to hard-code the catalog or schema name and might make SPJ
methods less portable across systems.</p>
</div>
</div>
<div class="sect3">
<h4 id="using-the-session_user-or-current_user-function-in-an-spj-method">4.2.4. Using the SESSION_USER or CURRENT_USER Function in an SPJ Method</h4>
<div class="paragraph">
<p>SESSION_USER is an SQL function that returns the name of the
authenticated database user who started the session and invoked the
function, and CURRENT_USER (or USER) is an SQL function that returns the
name of the database user who is authorized to invoke the function. If
you plan to use the SESSION_USER or CURRENT_USER (or USER) function in
an SPJ method, you should be aware of differences in their behavior
depending on how external security is defined for the stored procedure.</p>
</div>
<div class="paragraph">
<p>Suppose that you write this Java method, which uses the CURRENT_USER
function to return the name of the database user who is authorized to
invoke the function:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> getUser( <span class="predefined-type">ResultSet</span> <span class="type">[]</span> rs ) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">Statement</span> stmt = conn.createStatement() ;
rs[<span class="integer">0</span>] =
stmt.executeQuery( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT CURRENT_USER FROM (VALUES(1)) X(A) ; </span><span class="delimiter">&quot;</span></span> ) ;
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>If this method is used in a stored procedure with external security
defined as <em>invoker</em>, the CURRENT_USER function returns the name of
the database user who is authorized to invoke the function, which
happens to be the authenticated database user who started the session
and called the stored procedure.</p>
</div>
<div class="paragraph">
<p>For example, suppose that DB USERADMINUSER creates a stored procedure
named GETINVOKER using the <code>getUser()</code> method and sets the external
security to invoker. If a database user named GTAPPER, who has the
EXECUTE privilege on the stored procedure, calls GETINVOKER, the procedure
returns his name:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">Welcome to Apache Trafodion Command Interface
Copyright (c) 2015 Apache Software Foundation
User Name:GTAPPER Password:
Connected to Data Source: TDM_Default_DataSource
SQL&gt; CALL trafodion.persnl.getinvoker() ;
(EXPR)
--------------------------------------------------------------------------------
GTAPPER
--- 1 row(s) selected.
--- SQL operation complete.</code></pre>
</div>
</div>
<div class="paragraph">
<p>If the method is used in a stored procedure with external security
defined as <em>definer</em>, the CURRENT_USER function returns the name of
the database user who is authorized to invoke the function, which
happens to be the user who created the stored procedure (that is, the
definer of the stored procedure). When a stored procedure&#8217;s external
security is set to definer, any user who has the execute privilege on
the stored procedure can call the procedure using the privileges of the
user who created the stored procedure.</p>
</div>
<div style="page-break-after: always;"></div>
<div class="paragraph">
<p>For example, suppose that DB USERADMINUSER creates a stored procedure
named GETDEFINER using the <code>getUser(</code>) method and sets the external
security to definer. If the database user named GTAPPER, who has the
EXECUTE privilege on the stored procedure, calls GETDEFINER, the procedure
returns the name of the stored procedures&#8217;s creator, DB USERADMINUSER,
whose privileges GTAPPER is using to call the procedure:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">SQL&gt; SHOW USER
USER GTAPPER (NONE)
SQL&gt; CALL trafodion.persnl.getdefiner() ;
(EXPR)
--------------------------------------------------------------------------------
DB USERADMINUSER
--- 1 row(s) selected.
--- SQL operation complete.</code></pre>
</div>
</div>
<div class="paragraph">
<p>Suppose that you write this Java method, which uses the SESSION_USER
function to return the name of the authenticated database user who
started the session and invoked the function:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> getSessionUser( <span class="predefined-type">ResultSet</span> <span class="type">[]</span> rs ) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">Statement</span> stmt = conn.createStatement() ;
rs[<span class="integer">0</span>] = stmt.executeQuery( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT SESSION_USER FROM (VALUES(1) ) X(A) ; </span><span class="delimiter">&quot;</span></span> ) ;
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The SESSION_USER function returns the name of the authenticated database
user who started the session and invoked the function, regardless of the
external security setting of the stored procedure.</p>
</div>
<div style="page-break-after: always;"></div>
<div class="paragraph">
<p>For example, suppose that DB USERADMINUSER creates a stored procedure named
GETSESSIONUSER using the <code>getSessionUser()</code> method and sets the external
security to definer. If the database user named GTAPPER, who has the EXECUTE
privilege on the stored procedure, calls GETSESSIONUSER, the procedure
returns his name because he is the authenticated user who started the
session and invoked the function:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">SQL&gt; SHOW USER
USER GTAPPER (NONE)
SQL&gt; CALL trafodion.persnl.getsessionuser() ;
(EXPR)
--------------------------------------------------------------------------------
GTAPPER
--- 1 row(s) selected.
--- SQL operation complete.</code></pre>
</div>
</div>
<div class="paragraph">
<p>For more information about external security, see
<a href="#understand-external-security">Understand External Security</a>.</p>
</div>
</div>
<div class="sect3">
<h4 id="exception-handling">4.2.5. Exception Handling</h4>
<div class="paragraph">
<p>For SPJ methods that access Trafodion, no special code is
necessary for handling exceptions. If an SQL operation fails inside an
SPJ, the error message associated with the failure is returned to the
application that issues the CALL statement.</p>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
<div class="sect2">
<h3 id="handling-java-exceptions">4.3. Handling Java Exceptions</h3>
<div class="paragraph">
<p>If an SPJ method returns an uncaught Java exception or an uncaught chain
of <code>java.sql.SQLException</code> objects, the database engine converts each Java
exception object into an SQL error condition, and the CALL statement
fails. Each SQL error condition contains the message text associated
with one Java exception object.</p>
</div>
<div class="paragraph">
<p>If an SPJ method catches and handles exceptions itself, those exceptions
do not affect SQL processing.</p>
</div>
<div class="sect3">
<h4 id="user-defined-exceptions">4.3.1. User-Defined Exceptions</h4>
<div class="paragraph">
<p>The SQLSTATE values 38001 to 38999 are reserved for you to define your
own error conditions that SPJ methods can return. By coding your SPJ
method to throw a <code>java.sql.SQLException</code> object, you cause the CALL
statement to fail with a specific user-defined SQLSTATE value and your
own error message text.</p>
</div>
<div class="paragraph">
<p>If you define the SQLSTATE to be outside the range of 38001 to 38999,
the database engine raises SQLSTATE 39001, external routine invocation
exception.</p>
</div>
<div class="paragraph">
<p>This example uses the throw statement in the SPJ method named
<code>numMonthlyOrders()</code> to raise a user-defined error condition when an
invalid argument value is entered for the month:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> numMonthlyOrders( <span class="type">int</span> month
, <span class="type">int</span><span class="type">[]</span> numOrders
) <span class="directive">throws</span> java.sql.SQLException
{
<span class="keyword">if</span> ( month &lt; <span class="integer">1</span> || month &gt; <span class="integer">12</span> )
{
<span class="keyword">throw</span> <span class="keyword">new</span>
java.sql.SQLException ( <span class="string"><span class="delimiter">&quot;</span><span class="content">Invalid value for month. </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">Retry the CALL statement using a number </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">from 1 to 12 to represent the month.</span><span class="delimiter">&quot;</span></span>
, <span class="string"><span class="delimiter">&quot;</span><span class="content">38001</span><span class="delimiter">&quot;</span></span>
) ;
}
....
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>For more information about the numMonthlyOrders() method, see the
<a href="#monthlyorders-procedure">MONTHLYORDERS Procedure</a>.</p>
</div>
<div class="paragraph">
<p>For information about specific SQL errors, see the
<a href="http://trafodion.apache.org/docs/messages_guide/index.html">Trafodion Messages Manual</a>, which lists
the SQLCODE, SQLSTATE, message text, and cause-effect-recovery information for all SQL errors.</p>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
<div class="sect2">
<h3 id="compiling-and-packaging-java-classes">4.4. Compiling and Packaging Java Classes</h3>
<div class="paragraph">
<p>On Trafodion, the class files of SPJ methods must be
packaged in Java archive (JAR) files. After writing an SPJ method,
compile the Java source file of the SPJ method into Java bytecode and
package the Java bytecode in a JAR file. A Java method that you register
as an SPJ might need to access, either directly or indirectly, other
Java classes to operate properly. Those Java classes might include other
application classes. To enable an SPJ method to refer to other
application classes, put the application classes in the same JAR file as
the SPJ class. All classes stored in the same JAR file as the SPJ class
are accessible by default to the SPJ method.</p>
</div>
<div class="olist arabic">
<div class="title">After writing the SPJ method</div>
<ol class="arabic">
<li>
<p>Compile the Java source file into Java bytecode by using the Java
programming language compiler, <code>javac</code>:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">javac Payroll.java</code></pre>
</div>
</div>
</li>
<li>
<p>Put the SPJ class file and all associated class files into a Java
archive (JAR) file:</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">jar cvf Payroll.jar Payroll.class</code></pre>
</div>
</div>
<div class="paragraph">
<p>A manifest file is not needed for the JAR file.</p>
</div>
</li>
</ol>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="deploy-spj-jar-files">5. Deploy SPJ JAR Files</h2>
<div class="sectionbody">
<div class="paragraph">
<p>After developing and packaging the SPJ code into JAR files, you must
move the JAR files from the client workstation to Trafodion.</p>
</div>
<div class="paragraph">
<p>You can upload a SPJ JAR file and create a library by using
the CREATE LIBRARY command in the Trafodion Command Interface (trafci).</p>
</div>
<div class="paragraph">
<p>Libraries provide greater security for JAR files because libraries are
database objects whose access is controlled using standard SQL security.</p>
</div>
<div class="paragraph">
<p>Deploying a JAR file to a Trafodion instance requires creating a library,
and users must have the required privileges for creating libraries in order
to deploy JAR files.</p>
</div>
<div class="paragraph">
<p>The examples in this chapter are based on the sample database
documented in <a href="#b-sample-database">Appendix B: Sample Database</a>.</p>
</div>
<div style="page-break-after: always;"></div>
<div class="sect2">
<h3 id="create-a-library">5.1. Create a Library</h3>
<div class="paragraph">
<p>Refer to the
<a href="http://trafodion.apache.org/docs/sql_reference/index.html">Trafodion SQL Reference Manual</a>
for full documentation of the
<a href="http://trafodion.apache.org/docs/sql_reference/index.html#create_library_statement">CREATE LIBRARY</a>
statement including considerations and required privileges.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
You must copy the jar file to the same directory on all the nodes in the cluster before running the CREATE LIBRARY statement.
Otherwise, you will see an error message indicating that the jar file is not found.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p><strong>Example</strong></p>
</div>
<div class="paragraph">
<p>This example uses the sample <a href="#procedures-in-the-sales-schema">Sales Class</a> documented in
<a href="#a-sample-spjs">Appendix A: Sample SPJs</a>.</p>
</div>
<div class="paragraph">
<p>Your task is to add the Sales class jar file as a library object in the <code>SALES</code> schema.
Do the following:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Compile the <code>Sales.java</code> source file.</p>
<div class="paragraph">
<p><strong>Example</strong></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">$ # Set up the environmental variables.
$ cd $HOME/trafodion
$ source env.sh
$ # Prepare the class jar file
$ cd $HOME/trafodion-spjs
$ ls
Inventory.java Payroll.java Sales.java
$ # Compile source
$ javac Sales.java
$ ls Sales.*
Sales.class Sales.java
$ # Package jar file
$ jar cvf Sales.jar Sales.class
$ ls Sales.*
Sales.class Sales.jar Sales.java
$</code></pre>
</div>
</div>
</li>
<li>
<p>Multi-node cluster only: Create the target directory, if necessary.</p>
<div class="paragraph">
<p><strong>Example</strong></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">$ pdsh $MY_NODES -x $HOSTNAME mkdir $HOME/trafodion-spjs</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</li>
<li>
<p>Multi-node cluster only: Copy the jar file to all nodes in the cluster.</p>
<div class="paragraph">
<p><strong>Example</strong></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">$ pdcp $MY_NODES Sales.jar $PWD/.</code></pre>
</div>
</div>
</li>
<li>
<p>Create the library object using trafci.</p>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">$ pwd
/home/trafodion/trafodion-jars
$ trafci
Welcome to Apache Trafodion Command Interface
Copyright (c) 2015 Apache Software Foundation
Host Name/IP Address: localhost:23400
User Name: zz
Connected to Trafodion
SQL&gt; CREATE LIBRARY trafodion.sales.sales FILE '/home/trafodion/trafodion-spjs/Sales.jar' ;
--- SQL operation complete.
SQL&gt; get libraries in schema trafodion.sales ;
SALES
--- SQL operation complete.
SQL&gt;</code></pre>
</div>
</div>
</li>
</ol>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect2">
<h3 id="drop-a-library">5.2. Drop a Library</h3>
<div class="paragraph">
<p>Dropping a library removes the library from the schema in the database
and removes the library&#8217;s underlying JAR file from Trafodion.</p>
</div>
<div class="paragraph">
<p>Refer to the
<a href="http://trafodion.apache.org/docs/sql_reference/index.html">Trafodion SQL Reference Manual</a>
for full documentation of the
<a href="http://trafodion.apache.org/docs/sql_reference/index.html#drop_library_statement">DROP LIBRARY</a>
statement including considerations and required privileges.</p>
</div>
<div class="paragraph">
<p><strong>Example</strong></p>
</div>
<div class="paragraph">
<p>Your task is to remove Sales class jar file from the <code>SALES</code> schema.</p>
</div>
<div class="paragraph">
<p>Do the following using trafci:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">$ trafci
Welcome to Apache Trafodion Command Interface
Copyright (c) 2015 Apache Software Foundation
Host Name/IP Address: localhost:23400
User Name: zz
Connected to Trafodion
SQL&gt; get libraries in schema trafodion.sales ;
SALES
--- SQL operation complete.
SQL&gt; DROP LIBRARY trafodion.sales.saleslib ;
--- SQL operation complete.
SQL&gt;</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect2">
<h3 id="display-libraries">5.3. Display Libraries</h3>
<div class="paragraph">
<p>Refer to the
<a href="http://trafodion.apache.org/docs/sql_reference/index.html">Trafodion SQL Reference Manual</a>
for full documentation of the
<a href="http://trafodion.apache.org/docs/sql_reference/index.html#get_statement">GET</a>
statement.</p>
</div>
<div class="paragraph">
<p>Use the `GET libraries [ in schema [ catalog-name.] schema-name ] statement in trafci to
display the libraries in a schema.</p>
</div>
<div class="paragraph">
<p><strong>Example</strong></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">$ trafci
Welcome to Apache Trafodion Command Interface
Copyright (c) 2015 Apache Software Foundation
Host Name/IP Address: localhost:23400
User Name: zz
Connected to Trafodion
SQL&gt; get libraries in schema trafodion.sales ;
SALES
--- SQL operation complete.
SQL&gt;</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="create-spjs">6. Create SPJs</h2>
<div class="sectionbody">
<div class="paragraph">
<p>You can create the procedures in Trafodion after you&#8217;ve deployed the libraries for the SPJ JAR files.
See <a href="#deploy-spj-jar-files">Deploy SPJ JAR Files</a>.</p>
</div>
<div class="paragraph">
<p>The examples in this chapter are based on the sample database documented
in <a href="#b-sample-database">Appendix B: Sample Database</a>. Also, the <code>Sales.java</code> class are assumed to have been
added as a library object using the <code>CREATE LIBRARY</code> statement. See <a href="#deploy-spj-jar-files">Deploy SPJ JAR Files</a>.</p>
</div>
<div class="sect2">
<h3 id="create-a-procedure">6.1. Create a Procedure</h3>
<div class="paragraph">
<p>The Create Procedure tool registers an existing Java method as a stored
procedure in Java (SPJ) within SQL.</p>
</div>
<div class="paragraph">
<p>Refer to the
<a href="http://trafodion.apache.org/docs/sql_reference/index.html">Trafodion SQL Reference Manual</a>
for full documentation of the
<a href="http://trafodion.apache.org/docs/sql_reference/index.html#create_procedure_statement">CREATE PROCEDURE</a>
statement including considerations and required privileges.</p>
</div>
<div class="sect3">
<h4 id="create-procedure-settings">6.1.1. Create Procedure Settings</h4>
<div class="paragraph">
<p>Reference:
<a href="http://trafodion.apache.org/docs/sql_reference/index.html#create_procedure_syntax">Syntax Description of CREATE PROCEDURE</a>.</p>
</div>
<div class="paragraph">
<p>You need to determine the following settings for the CREATE PROCEDURE statement:</p>
</div>
<table class="tableblock frame-all grid-all spread">
<colgroup>
<col style="width: 15%;">
<col style="width: 40%;">
<col style="width: 45%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Attribute</th>
<th class="tableblock halign-left valign-top">Syntax</th>
<th class="tableblock halign-left valign-top">Guidance</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>procedure-ref</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>[[catalog-name.]schema-name.]procedure-name</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">- <strong>catalog</strong>: must be <code>trafodion</code>.<br>
- <strong>schema-name</strong>: the schema the procedure is associated with.<br>
- <strong>procedure-name</strong>: a name that is unique and does not exist for any procedure or function in the same schema. It&#8217;s a good habit to use the lowercase version of the procedure name.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>[parameter-mode] [sql-identifier] sql-datatype</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">- <strong>parameter-mode</strong>: IN (pass data to SPJ), OUT (accept data from SPJ), or INOUT (passed data to and accepts data from SPJ).<br>
- <strong>sql-identifier</strong>: The name of the parameter passed to the SPJ.<br>
- <strong>sql-datatype</strong>: SQL data type mapped to Java data type. See <a href="#java-parameters">Java Parameters</a> for mapping,
<a href="http://trafodion.apache.org/docs/sql_reference/index.html#data_types">Data Types</a> for SQL data types.<br>
<br>
Repeat for each parameter in the SPJ.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external name</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>external name 'java-method-name [( java-signature )]'</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">- <strong>java-method-name</strong>: case-sensitive name of the SPJ method of the form <code>[package-name.]class-name.method-name</code>. The Java method must exist in a
Java class file, <code><em>class-name</em>.class</code>, within a library registered in the database. If the class file that contains the SPJ method is part of a
package, then you must also specify the package name.<br>
- <strong>java-signature</strong>: specifies the signature of the SPJ method and consists of <code>([java-datatype[, java-datatype]&#8230;])</code>
Necessary only if you want to specify a Java wrapper class (for example, <code>java.lang.integer</code>) instead of a java
primitive data type (for example, <code>int</code>). Use the <code>javap</code> utility to determine the correct values for
java-signature.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>library</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>library [[catalog-name.]schema-name.]library-name</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">- <strong>catalog</strong>: must be <code>trafodion</code>.<br>
- <strong>schema-name</strong>: the schema the library is associated with.<br>
- <strong>library-name</strong>: name of library containing the SPJ method.
+
See <a href="#create-a-library">Create a Library</a> for more information about creating libraries.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external security</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>external security [ invoker</code> (default) | <code>definer ]</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">- <strong>invoker</strong>: determines that users can execute, or invoke, the stored procedure using the privileges of the user who invokes
the stored procedure.<br>
- <strong>definer</strong>: determines that users can execute, or invoke, the stored procedure using the privileges of the user who created
the stored procedure.<br>
<br>
See <a href="#understand-external-security">Understand External Security</a> for more information.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>language java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>language java</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Must be set specified the procedure is an SPJ rather than a UDF.
Compare: <a href="http://trafodion.apache.org/docs/sql_reference/index.html#create_function_statement">CREATE FUNCTION</a>.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>parameter style java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>parameter style java</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Must be set specified the procedure is an SPJ rather than a UDF.
Compare: <a href="http://trafodion.apache.org/docs/sql_reference/index.html#create_function_statement">CREATE FUNCTION</a>.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>sql access</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>no sql</code> |<br>
<code>contains sql</code> (default) |<br>
<code>modifies sql data</code> |<br>
<code>reads sql data</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">- <strong>no sql</strong>: the SPJ cannot perform SQL operations.<br>
- <strong>contains sql</strong>: the SPJ can read and modify SQL data.<br>
- <strong>modifies sql data</strong>: the SPJ can read and modify SQL data.<br>
- <strong>reads sql data</strong>: the SPJ can read and modify SQL data.<br>
<br>
It&#8217;s a good practice to specify <code>modifies sql data</code> and <code>reads sql data</code> over <code>contains sql</code> as it helps
users of the procedure to better understand its impact.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dynamic result sets</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>dynamic result sets 0</code> (default) to <code><em>n</em></code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The maximum number of result sets that the SPJ can return. This option is applicable only if the method signature contains a <code>java.sql.resultset[]</code> object.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>transaction</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>transaction required</code> (default) |<br>
<code>no transaction required</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Determines whether the SPJ must run in a transaction inherited from the calling application (<code>transaction required</code> or
whether the SPJ runs without inheriting the calling application&#8217;s transaction (<code>no transaction required</code>). Typically,
you want the stored procedure to inherit the transaction from the calling application.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>determinism</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>deterministic</code> |<br>
<code>not deterministic</code> (default)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Whether the SPJ always returns the same values for out and inout parameters for a given set of argument values
(<code>deterministic</code>) or does not return the same values (<code>not deterministic</code>). <code>deterministic</code> means that Trafodion
can cache the result to improve performance.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>isolation</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>isolate</code> (default) |<br>
<code>no isolate</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The SPJ executes either in the environment of the database server (<code>no isolate</code>) or in an isolated environment
(<code>isolate</code>, the default option). Trafodion allows both options but always executes the SPJ in the UDR server process (<code>isolate</code>).</p></td>
</tr>
</tbody>
</table>
<div style="page-break-after: always;"></div>
<div class="paragraph">
<p>Consider the following method in the <code>Sales.java</code> class:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// The TOTALPRICE procedure accepts the quantity, shipping speed, and price</span>
<span class="comment">// of an item, calculates the total price, including tax and shipping</span>
<span class="comment">// charges, and returns the total price to an input/output parameter.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#totalprice-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> totalPrice( <span class="predefined-type">BigDecimal</span> qtyOrdered
, <span class="predefined-type">String</span> shippingSpeed
, <span class="predefined-type">BigDecimal</span><span class="type">[]</span> price
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">BigDecimal</span> shipcharge = <span class="keyword">new</span> <span class="predefined-type">BigDecimal</span>( <span class="integer">0</span> ) ;
<span class="keyword">if</span> ( shippingSpeed.equals( <span class="string"><span class="delimiter">&quot;</span><span class="content">economy</span><span class="delimiter">&quot;</span></span> ) )
{
shipcharge = <span class="keyword">new</span> <span class="predefined-type">BigDecimal</span>( <span class="float">1.95</span> ) ;
}
<span class="keyword">else</span> <span class="keyword">if</span> ( shippingSpeed.equals( <span class="string"><span class="delimiter">&quot;</span><span class="content">standard</span><span class="delimiter">&quot;</span></span> ) )
{
shipcharge = <span class="keyword">new</span> <span class="predefined-type">BigDecimal</span>( <span class="float">4.99</span> ) ;
}
<span class="keyword">else</span> <span class="keyword">if</span> ( shippingSpeed.equals( <span class="string"><span class="delimiter">&quot;</span><span class="content">nextday</span><span class="delimiter">&quot;</span></span> ) )
{
shipcharge = <span class="keyword">new</span> <span class="predefined-type">BigDecimal</span>( <span class="float">14.99</span> ) ;
}
<span class="keyword">else</span>
{
<span class="keyword">throw</span> <span class="keyword">new</span> <span class="exception">SQLException</span>( <span class="string"><span class="delimiter">&quot;</span><span class="content">Invalid value for shipping speed. </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">Retry the CALL statement using </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">'economy' for 7 to 9 days, </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">'standard' for 3 to 5 days, or </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">'nextday' for one day.</span><span class="delimiter">&quot;</span></span>
, <span class="string"><span class="delimiter">&quot;</span><span class="content">38002</span><span class="delimiter">&quot;</span></span>
) ;
}
<span class="predefined-type">BigDecimal</span> subtotal = price[<span class="integer">0</span>].multiply( qtyOrdered ) ;
<span class="predefined-type">BigDecimal</span> tax = <span class="keyword">new</span> <span class="predefined-type">BigDecimal</span>( <span class="float">0.0825</span> ) ;
<span class="predefined-type">BigDecimal</span> taxcharge = subtotal.multiply( tax ) ;
<span class="predefined-type">BigDecimal</span> charges = taxcharge.add( shipcharge ) ;
<span class="predefined-type">BigDecimal</span> totalprice = subtotal.add( charges ) ;
totalprice = totalprice.setScale( <span class="integer">2</span>, <span class="predefined-type">BigDecimal</span>.ROUND_HALF_EVEN ) ;
price[<span class="integer">0</span>] = totalprice ;
}</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
<div class="paragraph">
<p>The CREATE PROCEDURE attributes for <code>totalPrice</code> are defined as follows:</p>
</div>
<table class="tableblock frame-all grid-all spread">
<colgroup>
<col style="width: 15%;">
<col style="width: 40%;">
<col style="width: 45%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Attribute</th>
<th class="tableblock halign-left valign-top">Definition</th>
<th class="tableblock halign-left valign-top">Discussion</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>procedure-ref</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>trafodion.sales.totalprice</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Used lowercase version of totalPrice for <em>procedure-name</em>.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-1</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>IN <em>qty</em> NUMERIC(18)</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The first argument to the SPJ is defined as: <code>BigDecimal qtyOrdered</code>, which maps to <code>NUMERIC</code>.
The size is chosen to allow for large numbers.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-2</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>IN <em>speed</em> VARCHAR(10)</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The second argument to the SPJ is defined as: <code>String shippingSpeed</code>.
Possible values are: <code>economy</code>, <code>standard</code>, or <code>nextday</code>. <code>VARCHAR(10)</code> is a good choice.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-3</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>INOUT <em>price</em> NUMERIC(18,2)</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The third argument to the SPJ is defines as: <code>BigDecimal[] price</code>.
The SPJ uses an input price to calculate to total price including taxes and shipping cost.
Therefore, <code>INOUT</code> is the appropriate choice. Given that the <code><em>qty</em></code> argument is NUMERIC(18), then this argument should be too. The precision choice fits the the
type of calculation being peformed.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external name</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>EXTERNAL NAME 'Sales.totalPrice'</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The class name is <code>Sales</code>. The procedure name is <code>totalPrice</code>.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>library</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>library trafodion.sales.sales</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The library name was defined using the CREATE LIBRARY statement.
See the example in <a href="#create-a-library">Create a Library</a>.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external security</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>invoker</code><sup>1</sup></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Use the privileges of the SPJ invoker.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>language java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LANGUAGE JAVA</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Required for SPJs.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>parameter style java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>PARAMETER STYLE JAVA</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Required for SPJs.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>sql access</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>NO SQL</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">This SPJ performs no SQL operations, just calculations.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dynamic result sets</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>DYNAMIC RESULT SETS 0</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The method does not contain a <code>java.sql.resultset[]</code> object.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>transaction</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>TRANSACTION REQUIRED</code><sup>1</sup></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The method should inherit the calling application&#8217;s transaction, if any.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>determinism</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>NOT DETERMINISTIC</code><sup>1</sup></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The results must be recalculated each time; that is, cannot be cached.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>isolation</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ISOLATE</code><sup>1</sup></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Execute the SPJ in an isolated environment; that is, the UDR server process.</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><sup>1</sup> Definition represents default value.</p>
</div>
<div style="page-break-after: always;"></div>
<div class="paragraph">
<p>Using the information above, you create the new procedure as follows:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">PROCEDURE</span> trafodion.sales.totalprice( <span class="keyword">IN</span> qty NUMERIC (<span class="integer">18</span>),
<span class="keyword">IN</span> speed <span class="predefined-type">VARCHAR</span> (<span class="integer">10</span>),
INOUT price NUMERIC (<span class="integer">18</span>,<span class="integer">2</span>)
)
EXTERNAL NAME <span class="string"><span class="delimiter">'</span><span class="content">Sales.totalPrice</span><span class="delimiter">'</span></span>
LIBRARY trafodion.sales.sales
LANGUAGE JAVA
PARAMETER STYLE JAVA
NO SQL
DYNAMIC RESULT SETS <span class="integer">0</span>
<span class="type">TRANSACTION</span> REQUIRED
ISOLATE
;</code></pre>
</div>
</div>
<div class="paragraph">
<p>Removing the default values to simplify the statement, you get:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">PROCEDURE</span> trafodion.sales.totalprice( <span class="keyword">IN</span> qty NUMERIC (<span class="integer">18</span>),
<span class="keyword">IN</span> speed <span class="predefined-type">VARCHAR</span> (<span class="integer">10</span>),
INOUT price NUMERIC (<span class="integer">18</span>,<span class="integer">2</span>)
)
EXTERNAL NAME <span class="string"><span class="delimiter">'</span><span class="content">Sales.totalPrice</span><span class="delimiter">'</span></span>
LIBRARY trafodion.sales.sales
LANGUAGE JAVA
PARAMETER STYLE JAVA
NO SQL
;</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
<div class="paragraph">
<p>To understand how to define <code>java-signature</code>, consider the following method in the
<code>Inventory.java</code> class.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> supplierInfo( <span class="predefined-type">BigDecimal</span> suppNum
, <span class="predefined-type">String</span><span class="type">[]</span> suppName
, <span class="predefined-type">String</span><span class="type">[]</span> streetAddr
, <span class="predefined-type">String</span><span class="type">[]</span> cityName
, <span class="predefined-type">String</span><span class="type">[]</span> stateName
, <span class="predefined-type">String</span><span class="type">[]</span> postCode
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> getSupplier =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT suppname, street, city, </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> state, postcode </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.invent.supplier </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE suppnum = ?</span><span class="delimiter">&quot;</span></span>
) ;
getSupplier.setBigDecimal( <span class="integer">1</span>, suppNum ) ;
<span class="predefined-type">ResultSet</span> rs = getSupplier.executeQuery() ;
rs.next() ;
suppName[<span class="integer">0</span>] = rs.getString( <span class="integer">1</span> ) ;
streetAddr[<span class="integer">0</span>] = rs.getString( <span class="integer">2</span> ) ;
cityName[<span class="integer">0</span>] = rs.getString( <span class="integer">3</span> ) ;
stateName[<span class="integer">0</span>] = rs.getString( <span class="integer">4</span> ) ;
postCode[<span class="integer">0</span>] = rs.getString( <span class="integer">5</span> ) ;
rs.close() ;
conn.close() ;
}</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
<div class="paragraph">
<p>The CREATE PROCEDURE attributes for <code>supplierInfo</code> are defined as follows:</p>
</div>
<table class="tableblock frame-all grid-all spread">
<colgroup>
<col style="width: 19.0476%;">
<col style="width: 80.9524%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Attribute</th>
<th class="tableblock halign-left valign-top">Definition</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>procedure-ref</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>trafodion.invent.supplierinfo</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-1</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>IN suppnum NUMERIC(4)</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-2</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>OUT suppname CHARACTER(18)</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-3</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>OUT address CHARACTER(22)</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-4</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>OUT city CHARACTER(14)</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-5</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>OUT state CHARACTER(12)</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-6</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>OUT zipcode CHARACTER(10)</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external name</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>EXTERNAL NAME 'Inventory.supplierInfo ( java.math.BigDecimal, java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[] )'</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>library</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LIBRARY trafodion.invent.inventory</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external security</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>invoker</code><sup>1</sup><br>
<br>
Choice depends on your security requirements, you can select <code>definer</code> instead.
For more information, see <a href="#understand-external-security">Understand External Security</a>.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>language java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LANGUAGE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>parameter style java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>PARAMETER STYLE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>sql access</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>READS SQL DATA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dynamic result sets</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>DYNAMIC RESULT SETS 0</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>transaction</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>TRANSACTION REQUIRED</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>determinism</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>NOT DETERMINISTIC</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>isolation</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ISOLATE</code><sup>1</sup></p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><sup>1</sup> Definition represents default value. Not included in the CREATE PROCEDURE example.</p>
</div>
<div style="page-break-after: always;"></div>
<div class="paragraph">
<p>You can use the <code>javap</code> utility to inspect the attributes of the method.</p>
</div>
<div class="paragraph">
<p><strong>Example</strong></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">$ javap Inventory.class
Compiled from &quot;Inventory.java&quot;
public class Inventory {
public Inventory();
public static void supplierInfo(java.math.BigDecimal, java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[]) throws java.sql.SQLException;
public static void supplyQuantities(int[], int[], int[]) throws java.sql.SQLException;
public static void partLocations(int, int, java.sql.ResultSet[], java.sql.ResultSet[]) throws java.sql.SQLException;
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The entry for <code>supplierInfo</code> method shows the attributes that should be used for <code>java-signature</code>.</p>
</div>
<div class="paragraph">
<p>You don&#8217;t specify for <code>java.sql.ResultSet[]</code> attributes; these are handled via the <code>DYNAMIC RESULTS SET</code> attribute
in the <code>CREATE PROCEDURE</code> statement.</p>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
<div class="sect2">
<h3 id="understand-external-security">6.2. Understand External Security</h3>
<div class="paragraph">
<p>The external security of an SPJ determines the privileges, or rights,
that users have when executing (or calling) the SPJ. An SPJ can be
created with one of these types of external security: invoker or
definer.</p>
</div>
<div class="paragraph">
<p>If an SPJ is created with the invoker type of external security, then the SPJ
is executed with <em>invoker rights</em>.</p>
</div>
<div class="paragraph">
<p>Invoker rights allow a user who has the execute privilege on the SPJ to call
the SPJ using his or her existing privileges.</p>
</div>
<div class="paragraph">
<p>In this case, the user must be granted privileges to access the underlying
database objects on which the SPJ operates. If a user tries to call an SPJ
that has invoker external security and that operates on database objects to
which the user does not have privileges, then the CALL statement fails with
an error message indicating that the user does not have the appropriate permissions.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Granting a user privileges to the underlying database objects gives the
user direct access to those database objects, which could pose a risk to more
sensitive or critical data to which users should not have access. For
example, an SPJ might operate on a subset of the data in an underlying
database object, but that database object might contain other more
sensitive or critical data to which users should not have access.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>If an SPJ is created with the definer type of external security, then the
SPJ is executed with <em>definer rights</em>.</p>
</div>
<div class="paragraph">
<p>Definer rights allow a user who has the execute privilege on an SPJ to
call the SPJ using the privileges of the user who created the SPJ.</p>
</div>
<div class="paragraph">
<p>In this case, the user does not require privileges to access the underlying
database objects on which the SPJ operates. Instead, the user is allowed to
access or manipulate data in the underlying database objects by invoking the
SPJ. That way, users are restricted from directly accessing or manipulating
more sensitive or critical data in the database.</p>
</div>
<div class="paragraph">
<p>However, be careful about the users to whom you grant execute privilege on
an SPJ with definer external security because those users will be able to
execute the SPJ without requiring privileges to the underlying database objects.</p>
</div>
<div class="paragraph">
<p>To set the external security of an SPJ, see <a href="#create-a-procedure">Create a Procedure</a>.</p>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect2">
<h3 id="drop-a-procedure">6.3. Drop a Procedure</h3>
<div class="paragraph">
<p>To drop a procedure, you must own the procedure or have the
DROP_PROCEDURE privilege for the schema. The schema owner can grant such
a schema-level privilege to other users or roles.</p>
</div>
<div class="paragraph">
<p>For example, if the schema owner granted you privileges to drop all objects in the schema,
you could drop procedures. For more information, see the GRANT SCHEMA statement in the
<a href="http://trafodion.apache.org/docs/sql_reference/index.html#grant_statement">Trafodion SQL Reference Manual</a></p>
</div>
<div class="paragraph">
<p>Refer to the
<a href="http://trafodion.apache.org/docs/sql_reference/index.html">Trafodion SQL Reference Manual</a>
for full documentation of the
<a href="http://trafodion.apache.org/docs/sql_reference/index.html#drop_procedure_statement">DROP PROCEDURE</a>
statement including considerations and required privileges.</p>
</div>
<div class="paragraph">
<p><strong>Example</strong></p>
</div>
<div class="paragraph">
<p>Your task is to remove Sales class jar file from the <code>SALES</code> schema.</p>
</div>
<div class="paragraph">
<p>Do the following using trafci:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">$ trafci
Welcome to Apache Trafodion Command Interface
Copyright (c) 2015 Apache Software Foundation
Host Name/IP Address: localhost:23400
User Name: zz
Connected to Trafodion
SQL&gt; get procedures for library trafodion.sales.saleslib ;
TOTALPRICE
--- SQL operation complete.
SQL&gt; DROP PROCEDURE trafodion.sales.totalprice ;
--- SQL operation complete.
SQL&gt;</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect2">
<h3 id="display-procedures-and-their-properties">6.4. Display Procedures and Their Properties</h3>
<div class="paragraph">
<p>In the trafci command-line interface, use the SHOW PROCEDURES command to
display the procedures in a schema. For example, this SHOW PROCEDURES
command displays a list of the procedures in the SALES schema:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">SQL&gt; <span class="class">SET</span> SCHEMA trafodion.sales ;
<span class="comment">--- SQL operation complete.</span>
SQL&gt; <span class="class">SHOW</span> PROCEDURES
<span class="type">PROCEDURE</span> NAMES
<span class="comment">--------------------------------------------------------------------------------</span>
DAILYORDERS LOWERPRICE MONTHLYORDERS ORDERSUMMARY PARTDATA TOTAL PRICE
SQL&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>You can also use a wild-card pattern to search for a particular
procedure. For example, this SHOW PROCEDURES command displays all the
procedures in the SALES schema that have price in their names:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">SQL&gt; <span class="class">SHOW</span> PROCEDURES %price
<span class="type">PROCEDURE</span> NAMES
<span class="comment">--------------------------------------------------------------------------------</span>
LOWERPRICE TOTALPRICE
SQL&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>For more information about trafci, see the
<a href="http://trafodion.apache.org/docs/command_interface/index.html">Trafodion Command Interface Guide</a>.</p>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="grant-privileges">7. Grant Privileges</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Security for SPJs is implemented by schema ownership rules and by
granting privileges to specified database users and roles.</p>
</div>
<div class="paragraph">
<p>The schema in which an SPJ is registered is the unit of ownership. The
database user who creates the schema is the owner of that schema and all
objects associated with it. In Trafodion, the schema owner
automatically has these privileges:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Ability to create and drop SPJs in the schema. You can create SPJs in
the schema provided that you also have the CREATE_PROCEDURE privilege
for the SQL_OPERATIONS component.</p>
</li>
<li>
<p>EXECUTE and WITH GRANT OPTION privileges on the SPJs in the schema</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>To create or drop an SPJ in a schema, you must be the schema owner or
have the appropriate create or drop privileges for the schema. For more
information, see
<a href="#required-privileges-for-creating-or-dropping-an-spj">Required Privileges for Creating or Dropping an SPJ</a>.</p>
</div>
<div class="paragraph">
<p>You must have the EXECUTE privilege on the SPJ to it. The EXECUTE privilege
allows a user to invoke an SPJ by issuing a CALL statement. The WITH GRANT
OPTION privilege allows a user to grant the EXECUTE and WITH GRANT
OPTION privileges to other users and roles. For more information, see:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="#granting-execute-privileges-on-an-spj">Granting Execute Privileges on an SPJ</a></p>
</li>
<li>
<p><a href="#granting-privileges-on-referenced-database-objects">Granting Privileges on Referenced Database Objects</a></p>
</li>
<li>
<p><a href="#revoking-execute-privileges-on-an-spj">Revoking Execute Privileges on an SPJ</a></p>
</li>
<li>
<p><a href="#using-script-files-to-grant-and-revoke-privileges">Using Script Files to Grant and Revoke Privileges</a></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>To display the current ownership and privileges, see
<a href="#display-procedures-and-their-properties">Display Procedures and Their Properties</a>.</p>
</div>
<div style="page-break-after: always;"></div>
<div class="sect2">
<h3 id="granting-execute-privileges-on-an-spj">7.1. Granting Execute Privileges on an SPJ</h3>
<div class="paragraph">
<p>Use the GRANT PROCEDURE or GRANT statement to assign the EXECUTE and
WITH GRANT OPTION privileges on an SPJ to specific database users and
roles. In a GRANT statement, specify ALL PRIVILEGES to grant the EXECUTE
privilege on an SPJ. For the syntax of the GRANT PROCEDURE and GRANT
statements, see the
<a href="http://trafodion.apache.org/docs/sql_reference/index.html">Trafodion SQL Reference Manual</a>.</p>
</div>
<div class="paragraph">
<p>If you own the SPJ, then you can grant the EXECUTE and WITH GRANT OPTION
privileges on the SPJ to any database user or role. If you are not the
owner of the SPJ, then you must have been granted the EXECUTE and WITH GRANT
OPTION privileges on the SPJ to grant privileges to other database users
and roles, or you must be associated with a role that has the EXECUTE
and WITH GRANT OPTION privileges on the SPJ.</p>
</div>
<div class="paragraph">
<p>As the owner of an SPJ, you can selectively grant the EXECUTE and WITH
GRANT OPTION privileges to specified database users and roles. For some
SPJs, particularly ones that handle sensitive information or modify
data, you should grant the EXECUTE and WITH GRANT OPTION privileges to a
restricted group of users or roles.</p>
</div>
<div class="paragraph">
<p>For example, the SPJ named ADJUSTSALARY changes an employee&#8217;s salary in the
database. Therefore, only specific users or roles should be allowed to invoke
this SPJ. In this example, the SPJ owner (or creator) grants the EXECUTE and
WITH GRANT OPTION privileges on ADJUSTSALARY to the Payroll directors.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">GRANT</span> EXECUTE
<span class="keyword">ON</span> <span class="type">PROCEDURE</span> trafodion.persnl.adjustsalary
<span class="keyword">TO</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">payrolldir1</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">payrolldir2</span><span class="delimiter">&quot;</span></span> WITH <span class="class">GRANT</span> OPTION ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>One of the Payroll directors grants the EXECUTE privilege on
ADJUSTSALARY to the regional department managers:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">GRANT</span> EXECUTE
<span class="keyword">ON</span> <span class="type">PROCEDURE</span> trafodion.persnl.adjustsalary <span class="keyword">TO</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">rgn1mgr</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">rgn2mgr</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">rgn3mgr</span><span class="delimiter">&quot;</span></span>
WITH <span class="class">GRANT</span> OPTION ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>In some cases, all users of a database system might need to invoke an
SPJ.</p>
</div>
<div class="paragraph">
<p>For example, the SPJ named TOTALPRICE calculates the total price of
an item, including tax and shipping charges. This SPJ does not handle
sensitive information or modify data and might be useful to customers or
anyone within the company.</p>
</div>
<div class="paragraph">
<p>Therefore, the SPJ owner (or creator) grants the EXECUTE privilege on
TOTALPRICE to PUBLIC, meaning all present and future database users and roles:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">GRANT</span> EXECUTE
<span class="keyword">ON</span> <span class="type">PROCEDURE</span> trafodion.sales.totalprice <span class="keyword">TO</span> PUBLIC ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>After granting the EXECUTE privilege to PUBLIC, you cannot revoke the
privilege from a subset of database users or roles. You must revoke the
privilege from PUBLIC and then grant the privilege to specific database
users and roles.</p>
</div>
</div>
<div class="sect2">
<h3 id="granting-privileges-on-referenced-database-objects">7.2. Granting Privileges on Referenced Database Objects</h3>
<div class="paragraph">
<p>If the SPJ operates on a database object and the SPJ has been created
with the external security specified as invoker (EXTERNAL SECURITY
INVOKER), then the database users that invoke the SPJ must have the
appropriate privileges on that database object.</p>
</div>
<div class="paragraph">
<p>If the SPJ has been created with the external security specified as definer (EXTERNAL
SECURITY DEFINER), then users other than the procedure&#8217;s creator may invoke
the SPJ without needing privileges on the underlying database objects.</p>
</div>
<div class="paragraph">
<p>When the SPJ&#8217;s external security is definer, users execute, or invoke,
the stored procedure using the privileges of the user who created the
stored procedure. The user who creates the stored procedure must have
the appropriate privileges on the underlying database objects. For more
information, see <a href="#understand-external-security">Understand External Security</a>.</p>
</div>
<div class="paragraph">
<p>For example, users with the EXECUTE privilege on the SPJ named
ADJUSTSALARY, which is defined with EXTERNAL SECURITY INVOKER and which
selects data from and updates the EMPLOYEE table, must have the SELECT
and UPDATE privileges on that SQL table. The SPJ owner (or creator)
grants these access privileges to the Payroll directors:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">GRANT</span> <span class="class">SELECT</span>, <span class="class">UPDATE</span> (salary)
<span class="keyword">ON</span> <span class="type">TABLE</span> trafodion.persnl.employee
<span class="keyword">TO</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">payrolldir1</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">payrolldir2</span><span class="delimiter">&quot;</span></span> WITH <span class="class">GRANT</span> OPTION ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>One of the Payroll directors then grants these access privileges to the
regional department managers:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">GRANT</span> <span class="class">SELECT</span>, <span class="class">UPDATE</span> (salary)
<span class="keyword">ON</span> <span class="type">TABLE</span> trafodion.persnl.employee
<span class="keyword">TO</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">rgn1mgr</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">rgn2mgr</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">rgn3mgr</span><span class="delimiter">&quot;</span></span> ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>Users with the EXECUTE privilege on the SPJ named TOTALPRICE, which does
not access the database, are not required to have privileges on any
database tables because that SPJ does not access any database tables.</p>
</div>
<div class="paragraph">
<p>The types of SQL statements in the underlying SPJ method, such as
SELECT, UPDATE, DELETE, and INSERT, indicate which types of privileges
are required for the referenced database objects.</p>
</div>
<div class="paragraph">
<p>For the syntax of the GRANT statement, see the
<a href="http://trafodion.apache.org/docs/sql_reference/index.html#grant_statement">Trafodion SQL Reference Manual</a>.</p>
</div>
</div>
<div class="sect2">
<h3 id="revoking-execute-privileges-on-an-spj">7.3. Revoking Execute Privileges on an SPJ</h3>
<div class="paragraph">
<p>Use the REVOKE PROCEDURE or REVOKE statement to remove the EXECUTE or
WITH GRANT OPTION privilege on an SPJ from specific database users or
roles. In a REVOKE statement, specify ALL PRIVILEGES to revoke the
EXECUTE privilege on an SPJ. For the syntax of the REVOKE PROCEDURE and
REVOKE statements, see the
<a href="http://trafodion.apache.org/docs/sql_reference/index.html#revoke_statement">Trafodion SQL Reference Manual</a>.</p>
</div>
<div class="paragraph">
<p>If you own the SPJ, then you can revoke the EXECUTE and WITH GRANT OPTION
privileges on the SPJ from any database user or role to whom you granted
those privileges or, if you did not directly grant those privileges, on
behalf of the role that granted those privileges, provided that you were
granted that role.</p>
</div>
<div class="paragraph">
<p>If you are not the owner of the SPJ, then you must have been granted the
EXECUTE and WITH GRANT OPTION privileges on the SPJ to
revoke privileges from other database users or roles, and you can revoke
the privileges only from other users or roles to whom you have granted
those privileges or, if you did not directly grant those privileges, on
behalf of the role that granted those privileges, provided that you were
granted that role.</p>
</div>
<div class="paragraph">
<p>For example, the <code>payrolldir1</code> user can revoke the EXECUTE privilege on
ADJUSTSALARY from one or more regional department managers to whom the
<code>payrolldir1</code> user granted those privileges.</p>
</div>
<div class="paragraph">
<p>In this example, the <code>payrolldir1</code> user revokes the EXECUTE privilege from the
Region 2 department manager:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">REVOKE EXECUTE
<span class="keyword">ON</span> <span class="type">PROCEDURE</span> trafodion.persnl.adjustsalary <span class="keyword">FROM</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">rgn2mgr</span><span class="delimiter">&quot;</span></span> ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>payrolldir1</code> user cannot revoke the EXECUTE or WITH GRANT OPTION
privilege from the <code>payrolldir2</code> user because it was the SPJ owner (or
creator) who granted those privileges.</p>
</div>
<div class="paragraph">
<p>A user can revoke the WITH GRANT OPTION privilege on ADJUSTSALARY from
any user or role to whom the user granted this privilege.</p>
</div>
<div class="paragraph">
<p>In this example, the SPJ owner (or creator) revokes the WITH GRANT OPTION
privilege from the <code>payrolldir1</code> user:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">REVOKE <span class="class">GRANT</span> OPTION <span class="keyword">FOR</span> EXECUTE
<span class="keyword">ON</span> <span class="type">PROCEDURE</span> trafodion.persnl.adjustsalary <span class="keyword">FROM</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">payrolldir1</span><span class="delimiter">&quot;</span></span> ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>A user can also revoke the EXECUTE privilege from any user or role to
whom the user granted this privilege and from any dependent privileges
by using the CASCADE option.</p>
</div>
<div class="paragraph">
<p>In this example, the SPJ owner (or creator) revokes the EXECUTE privilege
from the <code>payrolldir1</code> user and from the regional department managers to
whom the <code>payrolldir1</code> user granted privileges:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">REVOKE <span class="class">GRANT</span> OPTION <span class="keyword">FOR</span> EXECUTE
<span class="keyword">ON</span> <span class="type">PROCEDURE</span> trafodion.persnl.adjustsalary <span class="keyword">FROM</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">payrolldir1</span><span class="delimiter">&quot;</span></span>
<span class="directive">CASCADE</span> ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>For SPJs on which all users (that is, PUBLIC) have privileges, you can
revoke privileges from PUBLIC but not from one or more specific users or
roles.</p>
</div>
<div class="paragraph">
<p>For example, this statement revokes the EXECUTE privilege on the
SPJ named TOTALPRICE from all users and roles (that is, PUBLIC):</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">REVOKE EXECUTE
<span class="keyword">ON</span> <span class="type">PROCEDURE</span> trafodion.sales.totalprice <span class="keyword">FROM</span> PUBLIC;</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_using_script_files_to_grant_and_revoke_privileges">7.4. Using Script Files to Grant and Revoke Privileges</h3>
<div class="paragraph">
<p>Consider keeping your GRANT or REVOKE statements in script files. That
way, you can quickly and easily grant or revoke privileges to the SPJs,
as needed.</p>
</div>
<div class="sect3">
<h4 id="_script_file_for_granting_privileges">7.4.1. Script File for Granting Privileges</h4>
<div class="paragraph">
<p>You can use another or the same script file to grant privileges on a
series of SPJs.</p>
</div>
<div class="paragraph">
<p>For example, the script file, <code>grantprocs.sql</code>, contains a series of
GRANT PROCEDURE and GRANT statements:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="error">?</span>SECTION GrantSalesProcs
<span class="class">GRANT</span> EXECUTE
<span class="keyword">ON</span> trafodion.sales.monthlyorders
<span class="keyword">TO</span> PUBLIC ;
<span class="class">GRANT</span> <span class="class">SELECT</span>
<span class="keyword">ON</span> <span class="type">TABLE</span> trafodion.sales.orders <span class="keyword">TO</span> PUBLIC ;
<span class="error">?</span>SECTION GrantPersnlProcs
<span class="class">GRANT</span> EXECUTE
<span class="keyword">ON</span> <span class="type">PROCEDURE</span> trafodion.persnl.adjustsalary <span class="keyword">TO</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">payrolldir1</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">payrolldir2</span><span class="delimiter">&quot;</span></span>
WITH <span class="class">GRANT</span> OPTION ;
<span class="class">GRANT</span> <span class="class">SELECT</span>, <span class="class">UPDATE</span>(salary)
<span class="keyword">ON</span> <span class="type">TABLE</span> trafodion.persnl.employee
<span class="keyword">TO</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">payrolldir1</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">payrolldir2</span><span class="delimiter">&quot;</span></span> WITH <span class="class">GRANT</span> OPTION ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>To grant privileges on the SPJs, run the script file in the trafci
interface:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">OBEY c:\grantprocs.sql (GrantSalesProcs)</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_script_file_for_revoking_privileges">7.4.2. Script File for Revoking Privileges</h4>
<div class="paragraph">
<p>You can use another or the same script file to revoke privileges on a
series of SPJs.</p>
</div>
<div class="paragraph">
<p>For example, the script file, <code>revokeprocs.sql</code>, contains
a series of REVOKE PROCEDURE and REVOKE statements:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="error">?</span>SECTION RevokeSalesProcs
REVOKE EXECUTE
<span class="keyword">ON</span> <span class="type">PROCEDURE</span> trafodion.sales.monthlyorders <span class="keyword">FROM</span> PUBLIC ;
REVOKE <span class="class">SELECT</span>
<span class="keyword">ON</span> <span class="type">TABLE</span> trafodion.sales.orders <span class="keyword">FROM</span> PUBLIC ;
<span class="error">?</span>SECTION RevokePersnlProcs
REVOKE EXECUTE
<span class="keyword">ON</span> <span class="type">PROCEDURE</span> trafodion.persnl.adjustsalary <span class="keyword">FROM</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">payrolldir1</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">payrolldir2</span><span class="delimiter">&quot;</span></span>
<span class="directive">CASCADE</span> ;
REVOKE <span class="class">SELECT</span>, <span class="class">UPDATE</span>(salary)
<span class="keyword">ON</span> <span class="type">TABLE</span> trafodion.persnl.employee
<span class="keyword">FROM</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">payrolldir1</span><span class="delimiter">&quot;</span></span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">payrolldir2</span><span class="delimiter">&quot;</span></span> <span class="directive">CASCADE</span> ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>To revoke privileges on the SPJs, run the script file in the trafci
interface:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">OBEY c:\revokeprocs.sql (RevokeSalesProcs)</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="execute-spjs">8. Execute SPJs</h2>
<div class="sectionbody">
<div class="paragraph">
<p>This chapter describes how to execute SPJs by using the CALL statement
and assumes that you have already registered the SPJs in Trafodion
and that you have granted privileges to execute the SPJs to the
appropriate database users. For information, see
<a href="#deploy-spj-jar-files">Deploy SPJ JAR Files</a>
and <a href="#create-spjs">Create SPJs</a>.</p>
</div>
<div class="paragraph">
<p>This chapter covers these topics:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="#required-privileges-for-calling-an-spj">Required Privileges for Calling an SPJ</a></p>
</li>
<li>
<p><a href="#transaction-behavior">Transaction Behavior</a></p>
</li>
<li>
<p><a href="#multithreading">Multithreading</a></p>
</li>
<li>
<p><a href="#using-the-call-statement">Using the CALL Statement</a></p>
</li>
<li>
<p><a href="#calling-spjs-in-trafci">Calling SPJs in trafci</a></p>
</li>
<li>
<p><a href="#calling-spjs-from-an-odbc-client-application">Calling SPJs From an ODBC Client Application</a></p>
</li>
<li>
<p><a href="#calling-spjs-from-a-jdbc-client-application">Calling SPJs From a JDBC Client Application</a></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The CALL statement invokes an SPJ in the database. You can issue a CALL
statement from any of these applications or interfaces supported by Trafodion:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>trafci command-line interface or script file</p>
</li>
<li>
<p>JDBC Type-4 client applications</p>
</li>
<li>
<p>ODBC client applications</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>You can use a CALL statement as a stand-alone SQL statement in
applications or in command-line interfaces, such as trafci. You can also
use a CALL statement in a trigger but not inside a compound statement or
with rowsets. The SPJ that you use in a trigger must not have any OUT or
INOUT parameters or return any result sets.</p>
</div>
<div style="page-break-after: always;"></div>
<div class="sect2">
<h3 id="required-privileges-for-calling-an-spj">8.1. Required Privileges for Calling an SPJ</h3>
<div class="paragraph">
<p>To execute the CALL statement, you must have the EXECUTE privilege on
the procedure. For more information, see
<a href="#grant-privileges">Grant Privileges</a>.</p>
</div>
</div>
<div class="sect2">
<h3 id="transaction-behavior">8.2. Transaction Behavior</h3>
<div class="paragraph">
<p>The stored procedure&#8217;s transaction attribute determines whether it
inherits the transaction from the calling application (TRANSACTION
REQUIRED) or whether it runs without inheriting the calling
application&#8217;s transaction (NO TRANSACTION REQUIRED). The transaction
attribute is set during the creation of the stored procedure. For more
information, see the Transaction Required attribute in
<a href="#create-a-procedure">Create a Procedure</a>.</p>
</div>
<div class="paragraph">
<p>Typically, you want the stored procedure to inherit the transaction
from the calling application. See <a href="#transaction-required">Transaction Required</a>.
However, if the SPJ method does not access the database or if you want the
stored procedure to manage its own transactions, you should set the stored
procedure&#8217;s transaction attribute to NO TRANSACTION REQUIRED.
See <a href="#no-transaction-required">No Transaction Required</a>.</p>
</div>
<div class="sect3">
<h4 id="transaction-required">8.2.1. Transaction Required</h4>
<div class="paragraph">
<p>If you want the SPJ method to inherit the transaction from the calling
application, set the stored procedure&#8217;s transaction attribute to
TRANSACTION REQUIRED (the default setting) when creating the stored
procedure. For more information, see the Transaction Required attribute
in <a href="#create-a-procedure">Create a Procedure</a>. When a stored procedure&#8217;s
transaction attribute is TRANSACTION REQUIRED, a CALL statement
automatically initiates a transaction if there is no active transaction.</p>
</div>
<div class="sect4">
<h5 id="using-transaction-control-statements-or-methods">Using Transaction Control Statements or Methods</h5>
<div class="paragraph">
<p>If you select <code>Yes</code> for the Transaction Required attribute when creating a
stored procedure, then you should not use transaction control statements (or
equivalent JDBC transaction methods) in the SPJ method. Transaction
control statements include COMMIT WORK and ROLLBACK WORK, and the
equivalent JDBC transaction methods are <code>Connection.commit()</code> and
<code>Connection.rollback()</code>.</p>
</div>
<div class="paragraph">
<p>If you try to use transaction control statements or methods in an SPJ method
when the stored procedure&#8217;s transaction attribute is set to TRANSACTION REQUIRED,
then the transaction control statements or methods in the SPJ method are ignored
and the Java virtual machine (JVM) does not report any errors or warnings.</p>
</div>
<div class="paragraph">
<p>When the stored procedure&#8217;s transaction attribute is set to TRANSACTION REQUIRED,
then you should rely on the transaction control statements or methods in the
application that calls the stored procedure and allow the calling
application to manage the transactions.</p>
</div>
<div class="sect5">
<h6 id="committing-or-rolling-back-a-transaction">Committing or Rolling Back a Transaction</h6>
<div class="paragraph">
<p>If you do not use transaction control statements in the calling
application, then the transaction initiated by the CALL statement might not
automatically commit or roll back changes to the database.</p>
</div>
<div class="paragraph">
<p>When AUTOCOMMIT is ON (the default setting), then the database engine
automatically commits or rolls back any changes made to the database at
the end of the CALL statement execution. However, when AUTOCOMMIT is
OFF, the current transaction remains active until the end of the client
session or until you explicitly commit or roll back the transaction.</p>
</div>
<div class="paragraph">
<p>To ensure an atomic unit of work when calling an SPJ, use the COMMIT
WORK statement in the calling application to commit the transaction when
the CALL statement succeeds, and use the ROLLBACK WORK statement to roll
back the transaction when the CALL statement fails. For more information
about transaction management, see the
<a href="http://trafodion.apache.org/docs/sql_reference/index.html">Trafodion SQL Reference Manual</a>.</p>
</div>
</div>
</div>
</div>
<div class="sect3">
<h4 id="no-transaction-required">8.2.2. No Transaction Required</h4>
<div class="paragraph">
<p>In some cases, you might not want the SPJ method to inherit the
transaction from the calling application. Instead, you might want the
stored procedure to manage its own transactions or to run without a
transaction. Not inheriting the calling application&#8217;s transaction is
useful in these cases:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The stored procedure performs several long-running operations, such as
multiple DDL or table maintenance operations, on the database. In this
case, you might want to commit those operations periodically from within
the SPJ method to avoid locking tables for a long time.</p>
</li>
<li>
<p>The stored procedure performs certain SQL operations that must run
without an active transaction. For example, INSERT, UPDATE, and DELETE
statements with the WITH NO ROLLBACK option are rejected when a
transaction is already active, as is the case when a stored procedure
inherits a transaction from the calling application. The PURGEDATA
utility is also rejected when a transaction is already active.</p>
</li>
<li>
<p>The stored procedure does not access the database. (For an example,
see the <a href="#totalprice-procedure">TOTALPRICE Procedure</a>.) In this case,
the stored procedure does not need to inherit the transaction from the
calling application. By setting the stored procedure&#8217;s transaction
attribute to NO TRANSACTION REQUIRED, you can avoid the overhead of
the calling application&#8217;s transaction being propagated to the stored
procedure.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>In these cases, you should set the stored procedure&#8217;s transaction
attribute to NO TRANSACTION REQUIRED when creating the stored procedure.
For more information, see the Transaction Required attribute in
<a href="#create-a-procedure">Create a Procedure</a>.</p>
</div>
<div style="page-break-after: always;"></div>
<div class="paragraph">
<p>If you select <code>No</code> for the Transaction Required attribute when creating a
stored procedure and if the SPJ method creates a JDBC default
connection, then that connection has autocommit enabled by default. You
can either use the autocommit transactions or disable autocommit
(<code>conn.setAutoCommit(false);</code>) and use the JDBC transaction methods,
<code>Connection.commit()</code> and <code>Connection.rollback()</code>, to commit or roll back
work where needed.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="multithreading">8.3. Multithreading</h3>
<div class="paragraph">
<p>Trafodion manages a single thread of execution within
an SPJ environment, even if the application that issues a CALL statement
is a multi-threaded Java application.</p>
</div>
<div class="paragraph">
<p>The CALL statements in a multi-threaded application can execute in a nonblocking manner,
but the SPJ methods underlying those CALL statements execute serially within a
given SPJ environment.</p>
</div>
</div>
<div class="sect2">
<h3 id="using-the-call-statement">8.4. Using the CALL Statement</h3>
<div class="paragraph">
<p>To invoke a stored procedure, specify the name of the stored procedure
and its arguments in a CALL statement, as shown in the figure below.</p>
</div>
<div class="paragraph">
<div class="title">CALL Statement Elements</div>
<p><span class="image"><img src="images/call-statement-elements.jpg" alt="CALL Statement Elements"></span></p>
</div>
<div class="paragraph">
<p>For the syntax of the CALL statement, see the
<a href="http://trafodion.apache.org/docs/sql_reference/index.html#call_statement">Trafodion SQL Reference Manual</a>.</p>
</div>
<div style="page-break-after: always;"></div>
<div class="sect3">
<h4 id="specifying-the-name-of-the-spj">8.4.1. Specifying the Name of the SPJ</h4>
<div class="paragraph">
<p>In the CALL statement, specify the name of an SPJ that you have already
created in the database. Qualify the procedure name with the same
catalog and schema that you specified when you registered the SPJ. For
example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">CALL trafodion.persnl.adjustsalary( <span class="integer">202</span>, <span class="float">5.5</span>, <span class="error">?</span> ) ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>Or, for example:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">SET</span> SCHEMA trafodion.persnl ;
CALL adjustsalary( <span class="integer">202</span>, <span class="float">5.5</span>, <span class="error">?</span> ) ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>If you do not fully qualify the procedure name, then the database engine
qualifies the procedure according to the catalog and schema of the
current session.</p>
</div>
</div>
<div class="sect3">
<h4 id="listing-the-parameter-arguments-of-the-spj">8.4.2. Listing the Parameter Arguments of the SPJ</h4>
<div class="paragraph">
<p>Each argument that you list in the CALL statement must correspond to an
SQL parameter of the SPJ. A result set in the Java signature of the SPJ
method does not correspond to an SQL parameter. Do not specify result
sets in the argument list.</p>
</div>
<div class="paragraph">
<p>For example, if you registered the stored procedure with three SQL
parameters (two IN parameters and one OUT parameter), then you must
list three formal parameter arguments, separated by commas, in the
CALL statement:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">CALL trafodion.persnl.adjustsalary( <span class="integer">202</span>, <span class="integer">5</span>, <span class="error">?</span> ) ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>If the SPJ does not accept arguments, you must specify empty
parentheses, as shown below:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">CALL trafodion.sales.lowerprice() ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>If the SPJ has one IN parameter, one OUT parameter, and two result sets,
you must list the IN and OUT parameters but not the result sets in the
argument list:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">CALL trafodion.sales.ordersummary('01-01-2011', ?);</code></pre>
</div>
</div>
<div class="sect4">
<h5 id="data-conversion-of-parameter-arguments">Data Conversion of Parameter Arguments</h5>
<div class="paragraph">
<p>The database engine performs an implicit data conversion when the data
type of a parameter argument is compatible with but does not match the
formal data type of the stored procedure.</p>
</div>
<div class="paragraph">
<p>For stored procedure input values, the conversion is from the actual
argument value to the formal parameter type.</p>
</div>
<div class="paragraph">
<p>For stored procedure output values, the conversion is from the actual
output value, which has the data type of the formal parameter, to the
declared type of the dynamic parameter.</p>
</div>
</div>
<div class="sect4">
<h5 id="input-parameter-arguments">Input Parameter Arguments</h5>
<div class="paragraph">
<p>To pass data to an IN or INOUT parameter of an SPJ, specify an SQL value
expression that evaluates to a character, date-time, or numeric value.
The SQL value expression can evaluate to NULL provided that the
underlying Java parameter supports null values. For more information,
see <a href="#null-input-and-output">Null Input and Output</a>.</p>
</div>
<div class="paragraph">
<p>For an IN parameter argument, use one of these SQL value expressions in
that table below:</p>
</div>
<table id="table-2" class="tableblock frame-all grid-all spread">
<caption class="title">Table 2. Input Parameter Argument Types</caption>
<colgroup>
<col style="width: 30%;">
<col style="width: 70%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Type of Argument</th>
<th class="tableblock halign-left valign-top">Examples</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Literal</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>CALL adjustsalary( <strong>202</strong>, 5.5, ? ) ;</code><br>
<code>CALL dailyorders( <strong>DATE '2011-03-19'</strong>, ? )</code> ;<br>
<code>CALL totalprice(23, <strong>'nextday'</strong> , ?param ) ;</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">SQL function (including CASE and CAST expressions)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>CALL dailyorders( <strong>CURRENT_DATE</strong>, ? ) ;</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Arithmetic expression</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>CALL adjustsalary( 202, <strong>?percent \</strong> 0.25*, :OUT newsalary ) ;</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Concatenation operation</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>CALL totalprice( 23, <strong>'next' || 'day'</strong>, ?param ) ;</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Scalar subquery</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>CALL totalprice ( ( SELECT qty_ordered FROM odetail WHERE ordernum = 100210 AND partnum = 5100 ) , 'nextday', ?param ) ;</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Dynamic parameter</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>CALL adjustsalary( <strong>?</strong>, ?, ?) ;</code><br>
<code>CALL adjustsalary( <strong>?param1</strong>, ?param2, ?param3 ) ;</code></p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>For more information about SQL value expressions, see the
<a href="http://trafodion.apache.org/docs/sql_reference/index.html">Trafodion SQL Reference Manual</a>.</p>
</div>
<div class="paragraph">
<p>Because an INOUT parameter passes a single value to and accepts a single
value from an SPJ, you can specify only dynamic parameters for INOUT
parameter arguments in a CALL statement.</p>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="output-parameter-arguments">Output Parameter Arguments</h5>
<div class="paragraph">
<p>Except for result sets, an SPJ returns values in OUT and INOUT
parameters. Each OUT or INOUT parameter accepts only one value from an
SPJ. Any attempt to return more than one value to an output parameter
results in a Java exception. See
<a href="#returning-output-values-from-the-java-method">Returning Output Values From the Java Method</a>.</p>
</div>
<div class="paragraph">
<p>OUT and INOUT parameter arguments must be dynamic parameters in a client
application (for example, <code>?</code>) or named or unnamed parameters in trafci
(for example, <code>?param</code> or <code>?</code>).</p>
</div>
<div class="paragraph">
<p>For information about how to call SPJs in different applications, see:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="#calling-spjs-in-trafci">Calling SPJs in trafci</a></p>
</li>
<li>
<p><a href="#calling-spjs-from-an-odbc-client-application">Calling SPJs From an ODBC Client Application</a></p>
</li>
<li>
<p><a href="#calling-spjs-from-a-jdbc-client-application">Calling SPJs From a JDBC Client Application</a></p>
</li>
</ul>
</div>
</div>
<div class="sect4">
<h5 id="result-sets">Result Sets</h5>
<div class="paragraph">
<p>Result sets are an ordered set of open cursors that the SPJ method
returns to the calling application in <code>java.sql.ResultSet[]</code> parameter
arrays. The <code>java.sql.ResultSet[]</code> parameters do not correspond to SQL
parameters, so you must not include them in the parameter argument list
of a CALL statement.</p>
</div>
<div class="paragraph">
<p>The calling application can retrieve multiple rows of data from the
<code>java.sql.ResultSet[]</code> parameters. For information about how to process
result sets in different applications, see:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="#returning-result-sets-in-trafci">Returning Result Sets in trafci</a></p>
</li>
<li>
<p><a href="#returning-result-sets-in-an-odbc-client">Returning Result Sets in an ODBC Client</a></p>
</li>
<li>
<p><a href="#returning-result-sets-in-a-jdbc-client">Returning Result Sets in a JDBC Client</a></p>
</li>
</ul>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="calling-spjs-in-trafci">8.5. Calling SPJs in trafci</h3>
<div class="paragraph">
<p>In trafci, you can invoke an SPJ by issuing a CALL statement directly or
by preparing and executing a CALL statement.</p>
</div>
<div class="paragraph">
<p>Use named or unnamed parameters anywhere in the argument list of an SPJ
invoked in trafci. A named parameter is set by the SET PARAM command, and
an unnamed parameter is set by the USING clause of the EXECUTE
statement.</p>
</div>
<div class="paragraph">
<p>You must use a parameter for an OUT or INOUT parameter argument. trafci
displays all output parameter values and result sets after you issue the
CALL statement. The procedure call changes the value of a named
parameter that you use as an OUT or INOUT parameter.</p>
</div>
<div class="paragraph">
<p>For more information about named and unnamed parameters, see the
<a href="http://trafodion.apache.org/docs/command_interface/index.html">Trafodion Command Interface Guide</a>.</p>
</div>
<div class="sect3">
<h4 id="using-named-parameters">8.5.1. Using Named Parameters</h4>
<div class="paragraph">
<p>In an trafci session, invoke the SPJ named TOTALPRICE, which has two IN
parameters and one INOUT parameter.</p>
</div>
<div class="paragraph">
<p>This SPJ accepts the quantity, shipping speed, and price of an item,
calculates the total price, including tax and shipping charges, and
returns the total price. For more information, see the
<a href="#totalprice-procedure">TOTALPRICE Procedure</a>.</p>
</div>
<div class="paragraph">
<p>Set the input value for the INOUT parameter by entering a SET PARAM
command before calling the SPJ:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">SQL&gt; <span class="class">SET</span> PARAM <span class="error">?</span>p <span class="integer">10</span> ;
SQL&gt; CALL trafodion.sales.totalprice( <span class="integer">23</span>, <span class="string"><span class="delimiter">'</span><span class="content">standard</span><span class="delimiter">'</span></span>, <span class="error">?</span>p ) ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The CALL statement returns the total price of the item:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">p
--------------------
253.97
--- SQL operation complete.</code></pre>
</div>
</div>
<div class="paragraph">
<p>The value of the named parameter, ?p, changes from 10 to the returned
value, 253.97:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">SQL&gt; <span class="class">SHOW</span> PARAM
p <span class="float">253.97</span></code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect3">
<h4 id="using-unnamed-parameters">8.5.2. Using Unnamed Parameters</h4>
<div class="paragraph">
<p>In an trafci session, invoke the SPJ named TOTALPRICE by preparing and
executing a CALL statement. The INOUT parameter accepts a value that is
set by the USING clause of the EXECUTE statement and returns the total
price:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">SQL&gt; PREPARE stmt1 <span class="keyword">FROM</span> CALL trafodion.sales.totalprice( <span class="integer">50</span>, <span class="string"><span class="delimiter">'</span><span class="content">nextday</span><span class="delimiter">'</span></span>, <span class="error">?</span> ) ;
<span class="comment">--- SQL command prepared.</span>
SQL&gt; EXECUTE stmt1 <span class="keyword">USING</span> <span class="float">2.25</span> ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The output of the prepared CALL statement is:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">PRICE
--------------------
136.77
--- SQL operation complete.</code></pre>
</div>
</div>
<div class="paragraph">
<p>In an trafci session, invoke the SPJ named TOTALPRICE again by preparing
and executing a CALL statement in which all three parameters accept
values that are set by the USING clause of the EXECUTE statement. The
INOUT parameter returns the total price:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">SQL&gt; PREPARE stmt2 <span class="keyword">FROM</span> CALL trafodion.sales.totalprice( <span class="error">?</span>, <span class="error">?</span>, <span class="error">?</span> ) ;
<span class="comment">--- SQL command prepared.</span>
SQL&gt; EXECUTE stmt2 <span class="keyword">USING</span> <span class="integer">3</span>, <span class="string"><span class="delimiter">'</span><span class="content">economy</span><span class="delimiter">'</span></span>, <span class="float">16.99</span> ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The output of the prepared CALL statement is:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">PRICE
<span class="comment">--------------------</span>
<span class="float">57.13</span>
<span class="comment">--- SQL operation complete.</span></code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect3">
<h4 id="returning-result-sets-in-trafci">8.5.3. Returning Result Sets in trafci</h4>
<div class="paragraph">
<p>If a CALL statement returns result sets, trafci displays column headings
and data for each returned result set in the same format as SELECT
statements. For example, this CALL statement returns an output parameter
for the number of orders and two result sets in the trafci session:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">SQL&gt; CALL trafodion.sales.ordersummary( <span class="string"><span class="delimiter">'</span><span class="content">01-01-2011</span><span class="delimiter">'</span></span>, <span class="error">?</span> ) ;
NUM_ORDERS
<span class="comment">--------------------</span>
<span class="integer">13</span>
ORDERNUM NUM_PARTS AMOUNT ORDER_DATE LAST_NAME
<span class="comment">-------- -------------------- -------------------- ---------- --------------------</span>
<span class="integer">100210</span> <span class="integer">4</span> <span class="float">19020.00</span> <span class="integer">2011</span><span class="integer">-04</span><span class="integer">-10</span> HUGHES
<span class="integer">100250</span> <span class="integer">4</span> <span class="float">22625.00</span> <span class="integer">2011</span><span class="integer">-01</span><span class="integer">-23</span> HUGHES
<span class="integer">101220</span> <span class="integer">4</span> <span class="float">45525.00</span> <span class="integer">2011</span><span class="integer">-07</span><span class="integer">-21</span> SCHNABL
... ... ... ... ...
<span class="comment">--- 13 row(s) selected.</span>
ORDERNUM PARTNUM UNIT_PRICE QTY_ORDERED PARTDESC
<span class="comment">-------- ------- ---------- ----------- ------------------</span>
<span class="integer">100210</span> <span class="integer">244</span> <span class="float">3500.00</span> <span class="integer">3</span> PC GOLD, <span class="integer">30</span> MB
<span class="integer">100210</span> <span class="integer">2001</span> <span class="float">1100.00</span> <span class="integer">3</span> GRAPHIC PRINTER,M1
<span class="integer">100210</span> <span class="integer">2403</span> <span class="float">620.00</span> <span class="integer">6</span> DAISY PRINTER,T2
... ... ... ... ...
<span class="comment">--- 70 row(s) selected.</span>
<span class="comment">--- SQL operation complete.</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>For other result set examples, see <a href="#sample-spjs">Appendix A: Sample SPJs</a>.</p>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
<div class="sect2">
<h3 id="calling-spjs-from-an-odbc-client-application">8.6. Calling SPJs From an ODBC Client Application</h3>
<div class="paragraph">
<p>You can execute a CALL statement in an ODBC client application.
Microsoft ODBC requires that you put the CALL statement in an escape
clause:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">{ CALL <span class="type">procedure</span>-name ( [ parameter ] [ , [ parameter ] ] ... ) }</code></pre>
</div>
</div>
<div class="paragraph">
<p>For IN or INOUT parameters, use a literal or a parameter marker (?). You
cannot use an empty string as an IN or INOUT parameter in the argument
list. If you specify a literal for an INOUT parameter, the driver
discards the output value.</p>
</div>
<div class="paragraph">
<p>For OUT parameters, you can use only a parameter marker (<code>?</code>). You must
bind all parameter markers with the <code>SQLBindParameter</code> function before you
can execute the CALL statement.</p>
</div>
<div class="paragraph">
<p>In this example, a CALL statement is executed from an ODBC client
application:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="cplusplus"><span class="comment">/* Declare variables. */</span>
SQLHSTMT hstmt ;
SQL_NUMERIC_STRUCT salary ;
SDWORD cbParam = SQL_NTS ;
<span class="comment">/* Bind the parameter markers. */</span>
SQLBindParameter( hstmt, <span class="integer">1</span>, SQL_PARAM_INPUT, SQL_C_NUMERIC, SQL_NUMERIC, <span class="integer">4</span>, <span class="integer">0</span>, <span class="integer">202</span>, <span class="integer">0</span>, &amp;cbParam ) ;
SQLBindParameter( hstmt, <span class="integer">2</span>, SQL_PARAM_INPUT, SQL_C_FLOAT, SQL_FLOAT, <span class="integer">0</span>, <span class="integer">0</span>, <span class="float">5</span><span class="float">.5</span>, <span class="integer">0</span>, &amp;cbParam ) ;
SQLBindParameter( hstmt, <span class="integer">3</span>, SQL_PARAM_OUTPUT, SQL_C_NUMERIC, SQL_NUMERIC, <span class="integer">8</span>, <span class="integer">2</span>, &amp;salary, <span class="integer">0</span>, &amp;cbParam ) ;
<span class="comment">/* Execute the CALL statement. */</span>
SQLExecDirect( hstmt, <span class="string"><span class="delimiter">&quot;</span><span class="content">{ CALL trafodion.persnl.adjustsalary( ?, ?, ? ) }</span><span class="delimiter">&quot;</span></span>, SQL_NTS ) ;</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
<div class="sect3">
<h4 id="returning-result-sets-in-an-odbc-client-application">8.6.1. Returning Result Sets in an ODBC Client Application</h4>
<div class="paragraph">
<p>This example shows how an ODBC client application processes the result
sets returned by a CALL statement. The <code>SQLMoreResults()</code> function closes
the current result set and moves processing to the next available result
set.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
The Trafodion ODBC API does not currently support interleaved result set
processing, where more than one returned result set can be open at a
time.
</td>
</tr>
</table>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="cplusplus"><span class="comment">/* Allocate a statement handle */</span>
SQLHSTMT s ;
RETCODE rc = SQLAllocHandle( SQL_HANDLE_STMT, myConnection, &amp;s ) ;
<span class="comment">/* Prepare a CALL */</span>
<span class="predefined-type">char</span> *stmtText = <span class="string"><span class="delimiter">&quot;</span><span class="content">{ CALL trafodion.sales.ordersummary( '01-01-2011', ? ) } </span><span class="delimiter">&quot;</span></span>;
rc = SQLPrepare( s, (SQLCHAR *) stmtText, strlen( stmtText ) ) ;
<span class="comment">/* Bind the output parameter */</span>
_int64 num_orders = <span class="integer">0</span> ;
SQLINTEGER indicator ;
rc = SQLBindParameter( s
, <span class="integer">2</span>
, SQL_PARAM_OUTPUT
, SQL_C_SBIGINT
, SQL_BIGINT
, <span class="integer">0</span>
, <span class="integer">0</span>
, &amp;num_orders
, <span class="integer">0</span>
, &amp;indicator
) ;
<span class="comment">/* Execute the CALL */</span>
rc = SQLExecute( s ) ;
<span class="comment">/* Process all returned result sets. The outer while loop repeats */</span>
<span class="comment">/* until there are no more result sets. */</span>
<span class="keyword">while</span> ( ( rc = SQLMoreResults( s ) ) != SQL_NO_DATA )
{
<span class="comment">/* The inner while loop processes each row of the current result set */</span>
<span class="keyword">while</span> ( SQL_SUCCEEDED( rc = SQLFetch( hStmt ) ) )
{
<span class="comment">/* Process the row */</span>
}
}</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
<div class="sect2">
<h3 id="calling-spjs-from-a-jdbc-client-application">8.7. Calling SPJs From a JDBC Client Application</h3>
<div class="paragraph">
<p>You can execute a CALL statement in a JDBC client application by using
the JDBC CallableStatement interface. The Trafodion JDBC Type 4 driver requires
that you put the CALL statement in an escape clause:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">{ CALL <span class="type">procedure</span>-name ( [ parameter [ { , parameter } ... ] ] ) }</code></pre>
</div>
</div>
<div class="paragraph">
<p>Set input values for IN and INOUT parameters by using the <code>set_type()</code>
methods of the <code>CallableStatement</code> interface.</p>
</div>
<div class="paragraph">
<p>Retrieve output values from OUT and INOUT parameters by using the
<code>get_type()</code> methods of the <code>CallableStatement</code> interface.</p>
</div>
<div class="paragraph">
<p>If the parameter mode is OUT or INOUT, then you must register the parameter
as an output parameter by using the <code>registerOutParameter()</code> method of the
<code>CallableStatement</code> interface before executing the CALL statement.</p>
</div>
<div class="paragraph">
<p>In this example, a CALL statement is executed from a JDBC client application:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="predefined-type">CallableStatement</span> stmt =
con.prepareCall( <span class="string"><span class="delimiter">&quot;</span><span class="content">{ CALL trafodion.persnl.adjustsalary( ?, ?, ? ) }</span><span class="delimiter">&quot;</span></span> ) ;
stmt.setBigDecimal( <span class="integer">1</span>, <span class="integer">202</span> ) ; <span class="comment">// x = 202</span>
stmt.setDouble( <span class="integer">2</span>, <span class="float">5.5</span> ) ; <span class="comment">// y = 5.5</span>
stmt.registerOutParameter( <span class="integer">3</span>, java.sql.Types.NUMERIC ) ;
stmt.execute() ;
<span class="predefined-type">BigDecimal</span> z = stmt.getBigDecimal( <span class="integer">3</span> ) ; <span class="comment">// Retrieve the value of the OUT parameter</span></code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
<div class="sect3">
<h4 id="returning-result-sets-in-a-jdbc-client-application">8.7.1. Returning Result Sets in a JDBC Client Application</h4>
<div class="paragraph">
<p>This example shows serial result set processing in a JDBC client
application where the result sets are processed in order and one at a
time after the CALL statement executes. The
<code>java.sql.Statement.getMoreResults()</code> method closes the current result set
and moves processing to the next available result set.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// Prepare a CALL statement</span>
java.sql.CallableStatement s =
myConnection.prepareCall( <span class="string"><span class="delimiter">&quot;</span><span class="content">{ CALL trafodion.sales.ordersummary( '01-01-2011', ? ) }</span><span class="delimiter">&quot;</span></span> ) ;
<span class="comment">// Register an output parameter</span>
s.registerOutParameter( <span class="integer">1</span>, java.sql.Types.BIGINT ) ;
<span class="comment">// Execute the CALL</span>
<span class="type">boolean</span> rsAvailable = s.execute() ;
<span class="comment">// Process all returned result sets. The outer while loop continues</span>
<span class="comment">// until there are no more result sets.</span>
<span class="keyword">while</span> ( rsAvailable )
{
<span class="comment">// The inner while loop processes each row of the current result set</span>
java.sql.ResultSet rs = s.getResultSet() ;
<span class="keyword">while</span> ( rs.next() )
{
<span class="comment">// Process the row</span>
}
rsAvailable = s.getMoreResults() ;
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>This example shows how a JDBC client application can have more than one
stored procedure result set open at a given time. The
<code>java.sql.Statement.getMoreResults(int)</code> method
uses its input argument to decide whether currently open result sets
should remain open or be closed before the next result set is made
available.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// Prepare a CALL statement</span>
java.sql.CallableStatement s =
myConnection.prepareCall ( <span class="string"><span class="delimiter">&quot;</span><span class="content">{ CALL trafodion.sales.ordersummary( '01-01-2011', ? ) }</span><span class="delimiter">&quot;</span></span> ) ;
<span class="comment">// Register an output parameter</span>
s.registerOutParameter( <span class="integer">1</span>, java.sql.Types.BIGINT ) ;
<span class="comment">// Execute the CALL</span>
s.execute() ;
<span class="comment">// Open the FIRST result set</span>
java.sql.ResultSet firstRS = s.getResultSet() ;
<span class="comment">// Open the SECOND result set but do not close the FIRST</span>
s.getMoreResults( java.sql.Statement.KEEP_CURRENT_RESULT ) ;
java.sql.ResultSet secondRS = s.getResultSet() ;
<span class="comment">// The outer loop processes each row of the FIRST result set while</span>
( firstRS.next())
{
<span class="comment">// Process a row from the FIRST result set</span>
<span class="comment">// The inner loop processes some number of rows from the SECOND</span>
<span class="comment">// result set. The number depends on data extracted from the</span>
<span class="comment">// current row of the FIRST result set.</span>
<span class="keyword">for</span> ( <span class="type">int</span> i = <span class="integer">0</span> ; i &lt; NUM_ROWS_TO_PROCESS ; i++ )
{
<span class="comment">// Process a row from the SECOND result set</span>
secondRS.next() ;
}
}</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="performance-and-troubleshooting">9. Performance and Troubleshooting</h2>
<div class="sectionbody">
<div class="paragraph">
<p>This chapter describes how to improve and monitor the performance of
SPJs on Trafodion and provides guidelines for
troubleshooting common problems:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="#troubleshooting-common-problems">Troubleshooting Common Problems</a></p>
</li>
<li>
<p><a href="#performance-tip">Performance Tip</a></p>
</li>
<li>
<p><a href="#displaying-an-execution-plan-of-a-call-statement">Displaying an Execution Plan of a CALL Statement</a></p>
</li>
</ul>
</div>
<div class="sect2">
<h3 id="troubleshooting-common-problems">9.1. Troubleshooting Common Problems</h3>
<div class="paragraph">
<p>To resolve problems that occur when you register or execute an SPJ,
follow these guidelines:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Note the SQLCODE or SQLSTATE value of the error messages and locate
the information in the
<a href="http://trafodion.apache.org/docs/messages_guide/index.html">[Trafodion Messages Manual</a>],
which provides cause, effect, and recovery information for all SQL errors.</p>
</li>
<li>
<p>Check that the user has the appropriate permissions to create or call
the SPJ. See these sections:</p>
<div class="ulist">
<ul>
<li>
<p><a href="#required-privileges-for-creating-or-dropping-an-spj">Required Privileges for Creating or Dropping an SPJ</a>.</p>
</li>
<li>
<p><a href="#required-privileges-for-calling-an-spj">Required Privileges for Calling an SPJ</a>.</p>
</li>
</ul>
</div>
</li>
<li>
<p>Check the code of the SPJ method. See <a href="#develop-spj-methods">Develop SPJ Methods</a>.
Fix any problems.</p>
</li>
<li>
<p>If you successfully compiled, deployed, and registered the SPJ but are
receiving errors when calling the SPJ, check that the output parameters
in the Java method are specified as arrays. See
<a href="#returning-output-values-from-the-java-method">Returning Output Values From the Java Method</a>.</p>
</li>
<li>
<p>Verify that someone did not alter the library by selecting a JAR file
that contains a different class name, method name, or method signature
than the original JAR file, without dropping and re-creating the SPJ.</p>
</li>
<li>
<p>Check the syntax of the CALL statement in the application. See
<a href="#execute-spjs">Execute SPJs</a>. Fix any problems.</p>
</li>
<li>
<p>If the SPJ is supposed to return result sets, but the result sets are
not being returned to the calling application, then check that the SPJ method
does not explicitly close a <code>java.sql.Connection</code> object. See
<a href="#Use-of-java-sql-Connection-Objects">Use of java.sql.Connection Objects</a>.</p>
</li>
<li>
<p>If a <code>java.lang.ArrayIndexOutOfBoundsException</code> occurs, then check that the
SPJ method is not trying to insert more than one array element into a
<code>java.sql.ResultSets[]</code> array. For more information, see
<a href="#returning-stored-procedure-result-sets">Returning Stored Procedure Result Sets</a>.</p>
</li>
<li>
<p>To identify Java-related errors, execute the SPJ method outside Trafodion
by invoking the Java method directly in a Java application that you run on a
client workstation, using the Trafodion JDBC Type-4 driver to connect to Trafodion.</p>
</li>
<li>
<p>If you are using JDBC tracing and logging, then follow these guidelines:</p>
<div class="ulist">
<ul>
<li>
<p>Execute the SPJ method outside the database by invoking the Java
method directly from a Java application that you run on a client
workstation, using the Trafodion JDBC Type-4 driver to connect to the Trafodion
platform.</p>
</li>
<li>
<p>Verify that the file directory specified in the <code>T4LogFile</code> property
exists on the client workstation and that you have write access to it.</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="performance-tip">9.2. Performance Tip</h3>
<div class="paragraph">
<p>To ensure the optimal performance of SPJs on Trafodion,
avoid nesting CALL statements in an SPJ method, which wastes resources
and might diminish performance. For more information, see
<a href="#nested-java-method-invocations">Nested Java Method Invocations</a>.</p>
</div>
</div>
<div class="sect2">
<h3 id="displaying-an-execution-plan-of-a-call-statement">9.3. Displaying an Execution Plan of a CALL Statement</h3>
<div class="paragraph">
<p>An execution plan reveals how a CALL statement was optimized. You can
display all or part of the execution plan for a CALL statement by using
the EXPLAIN statement or function.</p>
</div>
<div class="sect3">
<h4 id="using-the-explain-statement">9.3.1. Using the EXPLAIN Statement</h4>
<div class="paragraph">
<p>Suppose that you want to display the execution plan for this CALL
statement:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">CALL trafodion.persnl.adjustsalary( 202, 5.5, ? ) ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>Enter this EXPLAIN statement in an trafci session:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">SQL&gt; PREPARE spj1 <span class="keyword">FROM</span> CALL trafodion.persnl.adjustsalary( <span class="integer">202</span>, <span class="float">5.5</span>, <span class="error">?</span> ) ;
<span class="comment">--- SQL command prepared.</span>
SQL&gt; EXPLAIN spj1 ;
<span class="comment">------------------------------------------------------------------ PLAN SUMMARY</span>
MODULE_NAME .............. DYNAMICALLY COMPILED
STATEMENT_NAME ........... SPJ1
PLAN_ID .................. <span class="integer">212206487012085509</span>
ROWS_OUT ................. <span class="integer">1</span>
EST_TOTAL_COST ........... <span class="integer">0</span>
STATEMENT ................ CALL trafodion.persnl.adjustsalary( <span class="integer">202</span>, <span class="float">5.5</span>, <span class="error">?</span> )
<span class="comment">------------------------------------------------------------------ NODE LISTING</span>
ROOT ====================================== SEQ_NO <span class="integer">2</span> ONLY CHILD <span class="integer">1</span>
REQUESTS_IN .............. <span class="integer">1</span>
ROWS_OUT ................. <span class="integer">1</span>
EST_OPER_COST ............ <span class="integer">0</span>
EST_TOTAL_COST ........... <span class="integer">0</span>
DESCRIPTION
max_card_est ........... <span class="integer">1</span>
fragment_id ............ <span class="integer">0</span>
parent_frag ............ (none)
fragment_type .......... master
statement_index ........ <span class="integer">0</span>
affinity_value ......... <span class="integer">3</span>,<span class="integer">466</span>,<span class="integer">211</span>,<span class="integer">324</span>
max_max_cardinality .... <span class="integer">1</span>
total_overflow_size .... <span class="float">0.00</span> KB xn_autoabort_interval <span class="integer">-1</span>
plan_version ........... <span class="integer">2</span>,<span class="integer">500</span>
LDAP_USERNAME .......... sqluser_admin
NVCI_PROCESS ........... <span class="keyword">ON</span>
SHOWCONTROL_UNEXTERNALI OFF
SCHEMA ................. TRAFODION.INVENT
CATALOG ................ TRAFODION
PRIORITY ............... <span class="integer">9</span> (<span class="keyword">for</span> <span class="type">table</span> SYSTEM_CATALOG.MXCS_SCHEMA.ASSOC2DS)
PRIORITY ............... <span class="integer">9</span> (<span class="keyword">for</span> <span class="type">table</span> SYSTEM_CATALOG.MXCS_SCHEMA.DATASOURCES)
PRIORITY ............... <span class="integer">9</span> (<span class="keyword">for</span> <span class="type">table</span> SYSTEM_CATALOG.MXCS_SCHEMA.ENVIRONMENTVALUES)
PRIORITY ............... <span class="integer">9</span> (<span class="keyword">for</span> <span class="type">table</span> SYSTEM_CATALOG.MXCS_SCHEMA.NAME2ID)
PRIORITY ............... <span class="integer">9</span> (<span class="keyword">for</span> <span class="type">table</span> SYSTEM_CATALOG.MXCS_SCHEMA.RESOURCEPOLICIES)
select_list ............ NUMERIC(<span class="integer">8</span>,<span class="integer">2</span>) SIGNED
input_variables ........ <span class="error">?</span>
CALL ====================================== SEQ_NO <span class="integer">1</span> NO CHILDREN
TABLE_NAME ............... TRAFODION.PERSNL.ADJUSTSALARY
REQUESTS_IN .............. <span class="integer">1</span>
ROWS_OUT ................. <span class="integer">1</span>
EST_OPER_COST ............ <span class="integer">0</span>
EST_TOTAL_COST ........... <span class="integer">0</span>
DESCRIPTION
max_card_est ........... <span class="integer">-1</span>
fragment_id ............ <span class="integer">0</span>
parent_frag ............ (none)
fragment_type .......... master
routine_name ........... TRAFODION.PERSNL.ADJUSTSALARY
parameter_modes ........ I I O
sql_access_mode ........ MODIFIES SQL DATA
external_name .......... adjustSalary
library ................ TRAFODION.PERSNL.PAYROLL
external_file .......... Payroll
signature .............. (Ljava/math/BigDecimal;D[Ljava/math/BigDecimal;)V
language ............... JAVA
parameter_style ........ JAVA
external_security ...... INVOKER
max_result_sets ........ <span class="integer">0</span>
parameters ............. <span class="predefined">cast</span>(<span class="integer">202</span>), <span class="predefined">cast</span>(<span class="predefined">cast</span>((<span class="predefined">cast</span>(<span class="float">5.5</span>) / <span class="predefined">cast</span>(<span class="integer">10</span>)))), NUMERIC(<span class="integer">8</span>,<span class="integer">2</span>) SIGNED
<span class="comment">--- SQL operation complete.</span>
SQL&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The EXPLAIN statement generates and displays all the columns of the
result table of the EXPLAIN function. For the syntax of the EXPLAIN
statement, see the
<a href="http://trafodion.apache.org/docs/sql_reference/index.html#explain_statement">Trafodion SQL Reference Manual</a>.</p>
</div>
</div>
<div class="sect3">
<h4 id="using-the-explain-function">9.3.2. Using the EXPLAIN Function</h4>
<div class="paragraph">
<p>You can also prepare the CALL statement and select specific columns from
the result table of the EXPLAIN function, as shown below:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">SQL&gt; PREPARE spj1 <span class="keyword">FROM</span> CALL trafodion.persnl.adjustsalary( <span class="integer">202</span>, <span class="float">5.5</span>, <span class="error">?</span> ) ;
<span class="comment">--- SQL command prepared.</span>
SQL&gt; <span class="class">SELECT</span> <span class="predefined">SUBSTRING</span>( operator, <span class="integer">1</span>, <span class="integer">8</span> ) <span class="keyword">AS</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">OPERATOR</span><span class="delimiter">&quot;</span></span>, operator_cost,
+&gt; <span class="predefined">SUBSTRING</span>( description, <span class="integer">1</span>, <span class="integer">500</span> ) <span class="keyword">AS</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">DESCRIPTION</span><span class="delimiter">&quot;</span></span>
+&gt; <span class="keyword">FROM</span> <span class="type">TABLE</span> ( EXPLAIN( <span class="predefined-constant">NULL</span>, <span class="string"><span class="delimiter">'</span><span class="content">SPJ1</span><span class="delimiter">'</span></span> ) ) ;
OPERATOR OPERATOR_COST DESCRIPTION
<span class="comment">-------- -------------- --------------------------------------------------------------------------------------</span>
CALL <span class="float">0.0</span> max_card_est: <span class="integer">-1</span> fragment_id: <span class="integer">0</span> parent_frag: (none) fragment_type: master routine_name:
TRAFODION.PERSNL.ADJUSTSALARY parameter_modes: I I O sql_access_mode: MODIFIES SQL DATA external_name: adjustSalary
library: TRAFODION.PERSNL.PAYROLL external_file: Payroll signature: (Ljava/math/BigDecimal;D[Ljava/math/BigDecimal;)V
language: JAVA parameter_style: JAVA external_security: INVOKER max_result_sets: <span class="integer">0</span> parameters: <span class="predefined">cast</span>(<span class="integer">202</span>),
<span class="predefined">cast</span>(<span class="predefined">cast</span>((<span class="predefined">cast</span>(<span class="float">5.5</span>) / <span class="predefined">cast</span>(<span class="integer">10</span>)))), NUMERIC(<span class="integer">8</span>,<span class="integer">2</span>) SIGNED
ROOT <span class="float">0.0</span> max_card_est: <span class="integer">1</span> fragment_id: <span class="integer">0</span> parent_frag: (none) fragment_type: master statement_index:
<span class="integer">0</span> affinity_value: <span class="integer">3466211324</span> max_max_cardinality: <span class="integer">1</span> total_overflow_size: <span class="float">0.00</span> KB statement: call
trafodion.persnl.adjustsalary( <span class="integer">202</span>, <span class="float">5.5</span> ,<span class="error">?</span> ) xn_autoabort_interval: <span class="integer">-1</span> plan_version: <span class="integer">2500</span> LDAP_USERNAME: sqluser_admin
NVCI_PROCESS: <span class="keyword">ON</span> SHOWCONTROL_UNEXTERNALIZED_ATTRS: OFF SCHEMA: TRAFODION.INVENT CATALOG: TRAFODION PRIORITY: <span class="integer">9</span> (<span class="keyword">for</span> <span class="type">table</span>
SYSTEM_CATALOG.MXCS_SCHEMA.ASSOC2DS) PRIORITY: <span class="integer">9</span> (<span class="keyword">for</span> <span class="type">table</span> SYSTEM_CATALOG.MXCS_SCHEMA.D
<span class="comment">--- 2 row(s) selected. SQL&gt;</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>For a CALL statement, the OPERATOR column of the result table contains a
row named CALL. The DESCRIPTION column contains special token pairs for
the CALL operator. For descriptions of the token pairs, see this table:</p>
</div>
<div style="page-break-after: always;"></div>
<table class="tableblock frame-all grid-all spread">
<caption class="title">Table 3. Token Pairs Description</caption>
<colgroup>
<col style="width: 30%;">
<col style="width: 60%;">
<col style="width: 10%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Token</th>
<th class="tableblock halign-left valign-top">Token Description</th>
<th class="tableblock halign-left valign-top">Data Type</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>max_card_est</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The upper limit for the operator cardinality in the query tree.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">integer</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>fragment_id</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">A sequential number assigned to the fragment. 0 is always the master
executor, and 1 is reserved for the Explain plan. Numbers 2 to <em>n</em> are ESP or storage-engine fragments.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">integer</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>parent_frag</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The fragment_id for the parent fragment of the current fragment. The
value is (none) for the master executor.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">integer</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>fragment_type</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Type of fragment, which can be either master, ESP, or storage engine.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">text</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>routine_name</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">ANSI name of the procedure.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">text</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>parameter_modes</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">A sequence of characters that specifies SQL parameter modes for the
procedure. I is used for an IN parameter, O for an OUT parameter, and N
for an INOUT parameter. Characters are separated by a single space. The
value none is returned if the procedure has no SQL parameters.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">text</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>sql_access_mode</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">SQL access mode of the procedure. `</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">text</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>external_name</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Java method name.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">text</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>library</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">ANSI name of the library object that maps to the procedure&#8217;s JAR file.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">text</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>external_file</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Java class name, possibly prefixed by a package name, that contains the SPJ method.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">text</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>signature</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Java signature of the SPJ method in internal Java Virtual Machine (JVM) format.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">text</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>language</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Language in which the SPJ method is written, which is always Java.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">text</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>parameter_style</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Convention of passing parameter arguments to the stored procedure, which
conforms to the Java language for SPJs.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">text</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>external_security</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">External security of the stored procedure, indicating the privileges or
rights that users have when executing (or calling) the procedure. The value is either INVOKER or
DEFINER. For more information, see <a href="#understand-external-security">Understand External Security</a>.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">text</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>max_result_sets</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The maximum number of result sets that this procedure can return.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">integer</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>parameters</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The parameter arguments that are passed to or from the procedure.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">text</p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p>For the syntax of the EXPLAIN function, see the
<a href="http://trafodion.apache.org/docs/sql_reference/index.html#explain_statement">Trafodion SQL Reference Manual</a>.</p>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="a-sample-spjs">10. A Sample SPJs</h2>
<div class="sectionbody">
<div class="paragraph">
<p>This appendix presents the SPJs that are shown in examples throughout
this manual. The class files that contain the SPJ methods use JDBC
method calls to access a sample database. For information about the
sample database, see <a href="#b-sample-database">Sample Database</a> below.</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="#procedures-in-the-sales-schema">Procedures in the SALES Schema</a></p>
</li>
<li>
<p><a href="#procedures-in-the-persnl-schema">Procedures in the PERSNL Schema</a></p>
</li>
<li>
<p><a href="#procedures-in-the-invent-schema">Procedures in the INVENT Schema</a></p>
</li>
</ul>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
You can download each source sample by clicking the link provided with the
sample name. For example, click on
<a href="../../resources/source/Sales.java">Sales.java</a>
to download the sample sales class source file.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>+
You can access the complete source directory at: <a href="http://trafodion.apache.org/docs/spj_guide/resources/source/" class="bare">http://trafodion.apache.org/docs/spj_guide/resources/source/</a></p>
</div>
<div style="page-break-after: always;"></div>
<div class="sect2">
<h3 id="procedures-in-the-sales-schema">10.1. Procedures in the SALES Schema</h3>
<div class="paragraph">
<p>The Sales class contains these SPJ methods, which are useful for
tracking orders and managing sales:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="#lowerprice-procedure">LOWERPRICE Procedure</a></p>
</li>
<li>
<p><a href="#dailyorders-procedure">DAILYORDERS Procedure</a></p>
</li>
<li>
<p><a href="#monthlyorders-procedure">MONTHLYORDERS Procedure</a></p>
</li>
<li>
<p><a href="#totalprice-procedure">TOTALPRICE Procedure</a></p>
</li>
<li>
<p><a href="#partdata-procedure">PARTDATA Procedure</a></p>
</li>
<li>
<p><a href="#ordersummary-procedure">ORDERSUMMARY Procedure</a></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Those methods are registered as stored procedures in the SALES schema.
<a href="#example-1">Example 1</a> shows the code of the
<a href="resources/source/Sales.java">Sales.java</a>
file.</p>
</div>
<div id="example-1" class="listingblock">
<div class="title">Example 1: <a href="resources/source/Sales.java"><code>Sales.java</code></a> - The Sales Class</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="keyword">import</span> <span class="include">java.sql</span>.* ;
<span class="keyword">import</span> <span class="include">java.math</span>.* ;
<span class="directive">public</span> <span class="type">class</span> <span class="class">Sales</span>
{
<span class="comment">// The LOWERPRICE procedure determines which items are selling poorly (that</span>
<span class="comment">// is, have less than 50 orders) and lowers the price of these items in the</span>
<span class="comment">// database by 10 percent.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#lowerprice-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> lowerPrice() <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> getParts =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT p.partnum, </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">SUM(qty_ordered) AS qtyOrdered </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.sales.parts p </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">LEFT JOIN trafodion.sales.odetail o </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">ON p.partnum = o.partnum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">GROUP BY p.partnum</span><span class="delimiter">&quot;</span></span>
) ;
<span class="predefined-type">PreparedStatement</span> updateParts =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">UPDATE trafodion.sales.parts </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">SET price = price * 0.9 </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE partnum = ?</span><span class="delimiter">&quot;</span></span>
) ;
<span class="predefined-type">ResultSet</span> rs = getParts.executeQuery() ;
<span class="keyword">while</span> ( rs.next() )
{
<span class="predefined-type">BigDecimal</span> qtyOrdered = rs.getBigDecimal( <span class="integer">2</span> ) ;
<span class="keyword">if</span> (( qtyOrdered == <span class="predefined-constant">null</span> ) || ( qtyOrdered.intValue() &lt; <span class="integer">50</span> ) )
{
<span class="predefined-type">BigDecimal</span> partnum = rs.getBigDecimal( <span class="integer">1</span> ) ;
updateParts.setBigDecimal( <span class="integer">1</span>, partnum ) ;
updateParts.executeUpdate() ;
}
}
rs.close() ;
conn.close() ;
}
<span class="comment">// The DAILYORDERS procedure accepts a date and returns the number of</span>
<span class="comment">//orders on that date to an output parameter.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#dailyorders-procedure</span>
<span class="comment">// for additional documenation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> numDailyOrders( <span class="predefined-type">Date</span> date
, <span class="type">int</span><span class="type">[]</span> numOrders
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> getNumOrders =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT COUNT(order_date) </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.sales.orders </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE order_date = ?</span><span class="delimiter">&quot;</span></span>
) ;
getNumOrders.setDate( <span class="integer">1</span>, date ) ;
<span class="predefined-type">ResultSet</span> rs = getNumOrders.executeQuery() ;
rs.next() ;
numOrders[<span class="integer">0</span>] = rs.getInt( <span class="integer">1</span> ) ;
rs.close() ;
conn.close() ;
}
<span class="comment">// The MONTHLYORDERS procedure accepts an integer representing the month</span>
<span class="comment">// and returns the number of orders during that month to an output parameter.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#monthlyorders-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> numMonthlyOrders( <span class="type">int</span> month
, <span class="type">int</span><span class="type">[]</span> numOrders
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="keyword">if</span> ( month &lt; <span class="integer">1</span> || month &gt; <span class="integer">12</span> )
{
<span class="keyword">throw</span> <span class="keyword">new</span> <span class="exception">SQLException</span>( <span class="string"><span class="delimiter">&quot;</span><span class="content">Invalid value for month. </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">Retry the CALL statement </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">using a number from 1 to 12 </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">to represent the month.</span><span class="delimiter">&quot;</span></span>
, <span class="string"><span class="delimiter">&quot;</span><span class="content">38001</span><span class="delimiter">&quot;</span></span>
) ;
}
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> getNumOrders =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT COUNT( month( order_date ) ) </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.sales.orders </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE month( order_date ) = ?</span><span class="delimiter">&quot;</span></span>
) ;
getNumOrders.setInt( <span class="integer">1</span>, month ) ;
<span class="predefined-type">ResultSet</span> rs = getNumOrders.executeQuery() ;
rs.next() ;
numOrders[<span class="integer">0</span>] = rs.getInt(<span class="integer">1</span>) ;
rs.close() ;
conn.close();
}
<span class="comment">// The TOTALPRICE procedure accepts the quantity, shipping speed, and price</span>
<span class="comment">// of an item, calculates the total price, including tax and shipping</span>
<span class="comment">// charges, and returns the total price to an input/output parameter.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#totalprice-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> totalPrice( <span class="predefined-type">BigDecimal</span> qtyOrdered
, <span class="predefined-type">String</span> shippingSpeed
, <span class="predefined-type">BigDecimal</span><span class="type">[]</span> price
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">BigDecimal</span> shipcharge = <span class="keyword">new</span> <span class="predefined-type">BigDecimal</span>( <span class="integer">0</span> ) ;
<span class="keyword">if</span> ( shippingSpeed.equals( <span class="string"><span class="delimiter">&quot;</span><span class="content">economy</span><span class="delimiter">&quot;</span></span> ) )
{
shipcharge = <span class="keyword">new</span> <span class="predefined-type">BigDecimal</span>( <span class="float">1.95</span> ) ;
}
<span class="keyword">else</span> <span class="keyword">if</span> ( shippingSpeed.equals( <span class="string"><span class="delimiter">&quot;</span><span class="content">standard</span><span class="delimiter">&quot;</span></span> ) )
{
shipcharge = <span class="keyword">new</span> <span class="predefined-type">BigDecimal</span>( <span class="float">4.99</span> ) ;
}
<span class="keyword">else</span> <span class="keyword">if</span> ( shippingSpeed.equals( <span class="string"><span class="delimiter">&quot;</span><span class="content">nextday</span><span class="delimiter">&quot;</span></span> ) )
{
shipcharge = <span class="keyword">new</span> <span class="predefined-type">BigDecimal</span>( <span class="float">14.99</span> ) ;
}
<span class="keyword">else</span>
{
<span class="keyword">throw</span> <span class="keyword">new</span> <span class="exception">SQLException</span>( <span class="string"><span class="delimiter">&quot;</span><span class="content">Invalid value for shipping speed. </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">Retry the CALL statement using </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">'economy' for 7 to 9 days, </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">'standard' for 3 to 5 days, or </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">'nextday' for one day.</span><span class="delimiter">&quot;</span></span>
, <span class="string"><span class="delimiter">&quot;</span><span class="content">38002</span><span class="delimiter">&quot;</span></span>
) ;
}
<span class="predefined-type">BigDecimal</span> subtotal = price[<span class="integer">0</span>].multiply( qtyOrdered ) ;
<span class="predefined-type">BigDecimal</span> tax = <span class="keyword">new</span> <span class="predefined-type">BigDecimal</span>( <span class="float">0.0825</span> ) ;
<span class="predefined-type">BigDecimal</span> taxcharge = subtotal.multiply( tax ) ;
<span class="predefined-type">BigDecimal</span> charges = taxcharge.add( shipcharge ) ;
<span class="predefined-type">BigDecimal</span> totalprice = subtotal.add( charges ) ;
totalprice = totalprice.setScale( <span class="integer">2</span>, <span class="predefined-type">BigDecimal</span>.ROUND_HALF_EVEN ) ;
price[<span class="integer">0</span>] = totalprice ;
}
<span class="comment">// The PARTDATA procedure accepts a part number and returns this</span>
<span class="comment">// information about the part:</span>
<span class="comment">//</span>
<span class="comment">// * Part description, price, and quantity available as output parameters.</span>
<span class="comment">// * A result set that contains rows from the ORDERS table about when this part was ordered.</span>
<span class="comment">// * A result set that contains rows from the PARTLOC table, listing locations that have this</span>
<span class="comment">// part in stock and the quantity they have on hand.</span>
<span class="comment">// * A result set that contains rows from the PARTSUPP table for suppliers who carry this part.</span>
<span class="comment">// * A result set that contains rows from the EMPLOYEE table for sales reps who have sold this part.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#partdata-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> partData( <span class="type">int</span> partNum
, <span class="predefined-type">String</span><span class="type">[]</span> partDescription
, <span class="predefined-type">BigDecimal</span><span class="type">[]</span> unitPrice
, <span class="type">int</span><span class="type">[]</span> qtyAvailable
, <span class="predefined-type">ResultSet</span><span class="type">[]</span> orders
, <span class="predefined-type">ResultSet</span><span class="type">[]</span> locations
, <span class="predefined-type">ResultSet</span><span class="type">[]</span> suppliers
, <span class="predefined-type">ResultSet</span><span class="type">[]</span> reps
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="comment">// Retrieve detail about this part into the output parameters</span>
<span class="predefined-type">PreparedStatement</span> getPartInfo =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT P.partdesc, P.price, P.qty_available </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.sales.parts P </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE partnum = ? </span><span class="delimiter">&quot;</span></span>
) ;
getPartInfo.setInt( <span class="integer">1</span>, partNum ) ;
<span class="predefined-type">ResultSet</span> rs = getPartInfo.executeQuery() ;
rs.next() ;
partDescription[<span class="integer">0</span>] = rs.getString( <span class="integer">1</span> ) ;
unitPrice[<span class="integer">0</span>] = rs.getBigDecimal( <span class="integer">2</span> ) ;
qtyAvailable[<span class="integer">0</span>] = rs.getInt( <span class="integer">3</span> ) ;
rs.close();
<span class="comment">// Return a result set of rows from the ORDERS table listing orders</span>
<span class="comment">// that included this part. Each ORDERS row is augmented with the</span>
<span class="comment">// quantity of this part that was ordered.</span>
<span class="predefined-type">PreparedStatement</span> getOrders =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT O.*, QTY.QTY_ORDERED </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.sales.orders O </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> , ( select ordernum, sum(qty_ordered) as QTY_ORDERED </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> from trafodion.sales.odetail </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> where partnum = ? </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> group by ordernum ) QTY </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE O.ordernum = QTY.ordernum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">ORDER BY O.ordernum </span><span class="delimiter">&quot;</span></span>
) ;
getOrders.setInt( <span class="integer">1</span>, partNum ) ;
orders[<span class="integer">0</span>] = getOrders.executeQuery() ;
<span class="comment">// Return a result set of rows from the PARTLOC table listing</span>
<span class="comment">// locations that have this part in stock and the quantity they</span>
<span class="comment">// have on hand.</span>
<span class="predefined-type">PreparedStatement</span> getLocations =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT * </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.invent.partloc </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> WHERE partnum = ? </span><span class="delimiter">&quot;</span></span>
) ;
getLocations.setInt( <span class="integer">1</span>, partNum ) ;
locations[<span class="integer">0</span>] = getLocations.executeQuery() ;
<span class="comment">// Return a result set of rows from the PARTSUPP table listing</span>
<span class="comment">// suppliers who supply this part.</span>
<span class="predefined-type">PreparedStatement</span> getSuppliers =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT * </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.invent.partsupp </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE partnum = ? </span><span class="delimiter">&quot;</span></span>
) ;
getSuppliers.setInt( <span class="integer">1</span>, partNum ) ;
suppliers[<span class="integer">0</span>] = getSuppliers.executeQuery() ;
<span class="comment">// Return a result set of rows from the EMPLOYEE table listing</span>
<span class="comment">// sales reps that have sold this part.</span>
<span class="predefined-type">PreparedStatement</span> getReps =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT * </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.persnl.employee </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE empnum in ( SELECT O.salesrep </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> FROM trafodion.sales.orders O, </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> trafodion.sales.odetail D </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> WHERE D.partnum = ? </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> AND O.ordernum = D.ordernum ) </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">ORDER BY empnum </span><span class="delimiter">&quot;</span></span>
) ;
getReps.setInt( <span class="integer">1</span>, partNum ) ;
reps[<span class="integer">0</span>] = getReps.executeQuery() ;
}
<span class="comment">// The ORDERSUMMARY procedure accepts a date, which is formatted as a</span>
<span class="comment">// string, and returns this information about the orders on or after that</span>
<span class="comment">// date:</span>
<span class="comment">//</span>
<span class="comment">// * The number of orders as an output parameter</span>
<span class="comment">// * A result set that contains one row for each order. Each row contains</span>
<span class="comment">// fields for the order number, the number of parts ordered, total dollar</span>
<span class="comment">// amount, order date, and the name of the sales representative.</span>
<span class="comment">// * A result set that contains details about each order. Each order has</span>
<span class="comment">// one or more rows that provide details about the ordered parts. Each row</span>
<span class="comment">// contains fields for the order number, part number, unit price, quantity</span>
<span class="comment">// ordered, and part description.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#ordersummary-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> orderSummary( java.lang.String onOrAfter
, <span class="type">long</span><span class="type">[]</span> numOrders
, java.sql.ResultSet<span class="type">[]</span> orders
, java.sql.ResultSet<span class="type">[]</span> detail
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
java.lang.String s ;
java.sql.Connection conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="comment">// Get the number of orders on or after this date</span>
s = <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT COUNT(ordernum) FROM trafodion.sales.orders </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE order_date &gt;= CAST(? AS DATE) </span><span class="delimiter">&quot;</span></span>
;
java.sql.PreparedStatement ps1 = conn.prepareStatement( s ) ;
ps1.setString( <span class="integer">1</span>, onOrAfter ) ;
java.sql.ResultSet rs = ps1.executeQuery() ;
rs.next() ;
numOrders[<span class="integer">0</span>] = rs.getLong( <span class="integer">1</span> ) ;
rs.close() ;
<span class="comment">// Open a result set for order num, order info rows</span>
s = <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT amounts.*, orders.order_date, emps.last_name </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM ( SELECT </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> o.ordernum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> , COUNT(d.partnum) AS num_parts </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> , SUM(d.unit_price * d.qty_ordered) AS amount </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> FROM trafodion.sales.orders o, trafodion.sales.odetail d </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> WHERE o.ordernum = d.ordernum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> AND o.order_date &gt;= CAST(? AS DATE) </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> GROUP BY o.ordernum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> ) amounts </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> , trafodion.sales.orders orders </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> , trafodion.persnl.employee emps </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE amounts.ordernum = orders.ordernum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> AND orders.salesrep = emps.empnum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">ORDER BY orders.ordernum </span><span class="delimiter">&quot;</span></span>
;
java.sql.PreparedStatement ps2 = conn.prepareStatement( s ) ;
ps2.setString( <span class="integer">1</span>, onOrAfter ) ;
orders[<span class="integer">0</span>] = ps2.executeQuery() ;
<span class="comment">// Open a result set for order detail rows</span>
s = <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT d.*, p.partdesc </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.sales.odetail d, trafodion.sales.parts p, trafodion.sales.orders O </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE d.partnum = p.partnum AND d.ordernum = o.ordernum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> AND o.order_date &gt;= CAST(? AS DATE) </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">ORDER BY d.ordernum </span><span class="delimiter">&quot;</span></span>
;
java.sql.PreparedStatement ps3 = conn.prepareStatement( s ) ;
ps3.setString( <span class="integer">1</span>, onOrAfter ) ;
detail[<span class="integer">0</span>] = ps3.executeQuery() ;
}
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>See the following sections for more information about each SPJ method.</p>
</div>
<div class="sect3">
<h4 id="lowerprice-procedure">10.1.1. LOWERPRICE Procedure</h4>
<div class="paragraph">
<p>The LOWERPRICE procedure determines which items are selling poorly (that
is, have less than 50 orders) and lowers the price of these items in the
database by 10 percent.</p>
</div>
<div style="page-break-after: always;"></div>
<div class="sect4">
<h5 id="java-method-lowerprice">Java Method: lowerPrice()</h5>
<div class="listingblock">
<div class="title">Example 2: <a href="resources/source/lowerPrice.java"><code>lowerPrice()</code></a> Method</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// The LOWERPRICE procedure determines which items are selling poorly (that</span>
<span class="comment">// is, have less than 50 orders) and lowers the price of these items in the</span>
<span class="comment">// database by 10 percent.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#lowerprice-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> lowerPrice() <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> getParts =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT p.partnum, </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">SUM(qty_ordered) AS qtyOrdered </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.sales.parts p </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">LEFT JOIN trafodion.sales.odetail o </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">ON p.partnum = o.partnum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">GROUP BY p.partnum</span><span class="delimiter">&quot;</span></span>
) ;
<span class="predefined-type">PreparedStatement</span> updateParts =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">UPDATE trafodion.sales.parts </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">SET price = price * 0.9 </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE partnum = ?</span><span class="delimiter">&quot;</span></span>
) ;
<span class="predefined-type">ResultSet</span> rs = getParts.executeQuery() ;
<span class="keyword">while</span> ( rs.next() )
{
<span class="predefined-type">BigDecimal</span> qtyOrdered = rs.getBigDecimal( <span class="integer">2</span> ) ;
<span class="keyword">if</span> (( qtyOrdered == <span class="predefined-constant">null</span> ) || ( qtyOrdered.intValue() &lt; <span class="integer">50</span> ) )
{
<span class="predefined-type">BigDecimal</span> partnum = rs.getBigDecimal( <span class="integer">1</span> ) ;
updateParts.setBigDecimal( <span class="integer">1</span>, partnum ) ;
updateParts.executeUpdate() ;
}
}
rs.close() ;
conn.close() ;
}</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="creating-the-procedure-lowerprice">Creating the Procedure: LOWERPRICE</h5>
<div class="paragraph">
<p>Before creating the procedure, create a library named <code>SALES</code>
in the <code>TRAFODION.SALES</code> schema and select the <code>Sales.jar</code> file to upload to
Trafodion for that library. For more information, see
<a href="#create-a-library">Create a Library</a>.</p>
</div>
<div class="paragraph">
<p>After creating the library, use the values listed in the table below to define and execute the
CREATE PROCEDURE command. For more information, see <a href="#create-a-procedure">Create a Procedure</a>.</p>
</div>
<table id="table-3" class="tableblock frame-all grid-all spread">
<caption class="title">Table 4. Create Procedure Settings: LOWERPRICE Procedure</caption>
<colgroup>
<col style="width: 19.0476%;">
<col style="width: 80.9524%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Attribute</th>
<th class="tableblock halign-left valign-top">Definition</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>procedure-ref</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>trafodion.sales.lowerprice</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Not applicable.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external name</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>EXTERNAL NAME 'Sales.lowerPrice'</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>library</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LIBRARY trafodion.sales.sales</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external security</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>invoker</code><sup>1</sup><br>
<br>
Choice depends on your security requirements, you can select <code>definer</code> instead.
For more information, see <a href="#understand-external-security">Understand External Security</a>.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>language java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LANGUAGE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>parameter style java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>PARAMETER STYLE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>sql access</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>MODIFIES SQL DATA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dynamic result sets</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>DYNAMIC RESULT SETS 0</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>transaction</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>TRANSACTION REQUIRED</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>determinism</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>NOT DETERMINISTIC</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>isolation</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ISOLATE</code><sup>1</sup></p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><sup>1</sup> Definition represents default value. Not included in the CREATE PROCEDURE example.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">PROCEDURE</span> trafodion.sales.lowerprice( )
EXTERNAL NAME <span class="string"><span class="delimiter">'</span><span class="content">Sales.lowerPrice</span><span class="delimiter">'</span></span>
LIBRARY trafodion.sales.sales
LANGUAGE JAVA
PARAMETER STYLE JAVA
MODIFIES SQL DATA
;</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="calling-the-procedure-lowerprice">Calling the Procedure: LOWERPRICE</h5>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Make sure that users who will be calling the stored procedure have
the appropriate execute privileges. For more information, see
<a href="#grant-privileges">Grant Privileges</a>.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>To invoke the LOWERPRICE procedure in trafci:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">SQL&gt; CALL trafodion.sales.lowerprice() ;
<span class="comment">--- SQL operation complete.</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>To view the prices and quantities of items in the database with 50 or
fewer orders, issue this query before and after calling the LOWERPRICE
procedure:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">SELECT</span> *
<span class="keyword">FROM</span>
( <span class="class">SELECT</span> p.partnum
, <span class="predefined">SUM</span>(qty_ordered) <span class="keyword">AS</span> qtyOrdered
, p.price
<span class="keyword">FROM</span> trafodion.sales.parts p
<span class="keyword">LEFT</span> <span class="keyword">OUTER</span> <span class="keyword">JOIN</span> trafodion.sales.odetail o <span class="keyword">ON</span> p.partnum = o.partnum
<span class="keyword">GROUP</span> <span class="keyword">BY</span> p.partnum, p.price
) <span class="keyword">AS</span> allparts
<span class="keyword">WHERE</span> qtyOrdered &lt; <span class="integer">51</span>
<span class="keyword">ORDER</span> <span class="keyword">BY</span> partnum <span class="directive">ASC</span>
;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The LOWERPRICE procedure lowers the price of items with 50 or fewer
orders by 10 percent in the database. For example, part number 3103, the
LASER PRINTER, X1, has 40 orders and a price of 3402.00:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">PARTNUM QTYORDERED PRICE
<span class="comment">------- -------------------- ----------</span>
<span class="integer">212</span> <span class="integer">20</span> <span class="float">2025.00</span>
<span class="integer">244</span> <span class="integer">47</span> <span class="float">2430.00</span>
<span class="integer">255</span> <span class="integer">38</span> <span class="float">3240.00</span>
<span class="integer">2002</span> <span class="integer">46</span> <span class="float">1215.00</span>
<span class="integer">2405</span> <span class="integer">18</span> <span class="float">643.95</span>
<span class="integer">3103</span> <span class="integer">40</span> <span class="float">3402.00</span>
... ... ...
<span class="comment">--- 17 row(s) selected.</span></code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
<div class="paragraph">
<p>The invocation of LOWERPRICE lowers the price of this item from 3402.00
to 3061.80:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">PARTNUM QTYORDERED PRICE
<span class="comment">------- -------------------- ----------</span>
<span class="integer">212</span> <span class="integer">20</span> <span class="float">1822.50</span>
<span class="integer">244</span> <span class="integer">47</span> <span class="float">2187.00</span>
<span class="integer">255</span> <span class="integer">38</span> <span class="float">2916.00</span>
<span class="integer">2002</span> <span class="integer">46</span> <span class="float">1093.50</span>
<span class="integer">2405</span> <span class="integer">18</span> <span class="float">579.55</span>
<span class="integer">3103</span> <span class="integer">40</span> <span class="float">3061.80</span>
... ... ...
<span class="comment">--- 17 row(s) selected.</span></code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
<div class="sect3">
<h4 id="dailyorders-procedure">10.1.2. DAILYORDERS Procedure</h4>
<div class="paragraph">
<p>The DAILYORDERS procedure accepts a date and returns the number of
orders on that date to an output parameter.</p>
</div>
<div class="sect4">
<h5 id="java-method-numdailyorders">Java Method: numDailyOrders()</h5>
<div class="listingblock">
<div class="title">Example 3: <a href="resources/source/numDailyOrders.java"><code>numDailyOrders()</code></a> Method</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// The DAILYORDERS procedure accepts a date and returns the number of</span>
<span class="comment">//orders on that date to an output parameter.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#dailyorders-procedure</span>
<span class="comment">// for additional documenation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> numDailyOrders( <span class="predefined-type">Date</span> date
, <span class="type">int</span><span class="type">[]</span> numOrders
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> getNumOrders =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT COUNT(order_date) </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.sales.orders </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE order_date = ?</span><span class="delimiter">&quot;</span></span>
) ;
getNumOrders.setDate( <span class="integer">1</span>, date ) ;
<span class="predefined-type">ResultSet</span> rs = getNumOrders.executeQuery() ;
rs.next() ;
numOrders[<span class="integer">0</span>] = rs.getInt( <span class="integer">1</span> ) ;
rs.close() ;
conn.close() ;
}</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="creating-the-procedure-dailyorders">Creating the Procedure: DAILYORDERS</h5>
<div class="paragraph">
<p>Before creating the procedure, create a library named <code>SALES</code>
in the <code>TRAFODION.SALES</code> schema and select the <code>Sales.jar</code> file to upload to
Trafodion for that library. For more information, see
<a href="#create-a-library">Create a Library</a>.</p>
</div>
<div class="paragraph">
<p>After creating the library, use the values listed in the table below to define and execute the
CREATE PROCEDURE command. For more information, see <a href="#create-a-procedure">Create a Procedure</a>.</p>
</div>
<table id="table-4" class="tableblock frame-all grid-all spread">
<caption class="title">Table 5. Create Procedure Settings: DAILYORDERS Procedure</caption>
<colgroup>
<col style="width: 19.0476%;">
<col style="width: 80.9524%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Attribute</th>
<th class="tableblock halign-left valign-top">Definition</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>procedure-ref</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>trafodion.sales.dailyorders</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-1</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>IN date1 DATE</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-2</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>OUT number INTEGER</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external name</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>EXTERNAL NAME 'Sales.numDailyOrders'</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>library</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LIBRARY trafodion.sales.sales</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external security</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>invoker</code><sup>1</sup><br>
<br>
Choice depends on your security requirements, you can select <code>definer</code> instead.
For more information, see <a href="#understand-external-security">Understand External Security</a>.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>language java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LANGUAGE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>parameter style java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>PARAMETER STYLE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>sql access</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>READS SQL DATA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dynamic result sets</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>DYNAMIC RESULT SETS 0</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>transaction</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>TRANSACTION REQUIRED</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>determinism</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>NOT DETERMINISTIC</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>isolation</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ISOLATE</code><sup>1</sup></p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><sup>1</sup> Definition represents default value. Not included in the CREATE PROCEDURE example.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">PROCEDURE</span> trafodion.sales.dailyorders( <span class="keyword">IN</span> date1 <span class="predefined-type">DATE</span>
, OUT number <span class="predefined-type">INTEGER</span>
)
EXTERNAL NAME <span class="string"><span class="delimiter">'</span><span class="content">Sales.numDailyOrders</span><span class="delimiter">'</span></span>
LIBRARY trafodion.sales.sales
LANGUAGE JAVA
PARAMETER STYLE JAVA
READS SQL DATA
;</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="calling-the-procedure-dailyorders">Calling the Procedure: DAILYORDERS</h5>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Make sure that users who will be calling the stored procedure have
the appropriate execute privileges. For more information, see
<a href="#grant-privileges">Grant Privileges</a>.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>To invoke the DAILYORDERS procedure in trafci:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">SQL&gt; CALL trafodion.sales.dailyorders( <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-03-19</span><span class="delimiter">'</span></span>, <span class="error">?</span> ) ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The DAILYORDERS procedure determines the total number of orders on a
specified date and returns this output in trafci:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">NUMBER
<span class="comment">-----------</span>
<span class="integer">2</span>
<span class="comment">--- SQL operation complete.</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>On March 19, 2011, there were two orders.</p>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
<div class="sect3">
<h4 id="monthlyorders-procedure">10.1.3. MONTHLYORDERS Procedure</h4>
<div class="paragraph">
<p>The MONTHLYORDERS procedure accepts an integer representing the month
and returns the number of orders during that month to an output
parameter.</p>
</div>
<div class="sect4">
<h5 id="java-method-nummonthlyorders">Java Method: numMonthlyOrders()</h5>
<div class="listingblock">
<div class="title">Example 4: <a href="resources/source/numMonthlyOrders.java"><code>numMonthlyOrders()</code></a> Method</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// The MONTHLYORDERS procedure accepts an integer representing the month</span>
<span class="comment">// and returns the number of orders during that month to an output parameter.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#monthlyorders-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> numMonthlyOrders( <span class="type">int</span> month
, <span class="type">int</span><span class="type">[]</span> numOrders
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="keyword">if</span> ( month &lt; <span class="integer">1</span> || month &gt; <span class="integer">12</span> )
{
<span class="keyword">throw</span> <span class="keyword">new</span> <span class="exception">SQLException</span>( <span class="string"><span class="delimiter">&quot;</span><span class="content">Invalid value for month. </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">Retry the CALL statement </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">using a number from 1 to 12 </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">to represent the month.</span><span class="delimiter">&quot;</span></span>
, <span class="string"><span class="delimiter">&quot;</span><span class="content">38001</span><span class="delimiter">&quot;</span></span>
) ;
}
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> getNumOrders =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT COUNT( month( order_date ) ) </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.sales.orders </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE month( order_date ) = ?</span><span class="delimiter">&quot;</span></span>
) ;
getNumOrders.setInt( <span class="integer">1</span>, month ) ;
<span class="predefined-type">ResultSet</span> rs = getNumOrders.executeQuery() ;
rs.next() ;
numOrders[<span class="integer">0</span>] = rs.getInt(<span class="integer">1</span>) ;
rs.close() ;
conn.close();
}</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="creating-the-procedure-monthlyorders">Creating the Procedure: MONTHLYORDERS</h5>
<div class="paragraph">
<p>Before creating the procedure, create a library named <code>SALES</code>
in the <code>TRAFODION.SALES</code> schema and select the <code>Sales.jar</code> file to upload to
Trafodion for that library. For more information, see
<a href="#create-a-library">Create a Library</a>.</p>
</div>
<div class="paragraph">
<p>After creating the library, use the values listed in the table below to define and execute the
CREATE PROCEDURE command. For more information, see <a href="#create-a-procedure">Create a Procedure</a>.</p>
</div>
<table id="table-5" class="tableblock frame-all grid-all spread">
<caption class="title">Table 6. Create Procedure Settings: MONTHLYORDERS Procedure</caption>
<colgroup>
<col style="width: 19.0476%;">
<col style="width: 80.9524%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Attribute</th>
<th class="tableblock halign-left valign-top">Definition</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>procedure-ref</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>trafodion.sales.monthlyorders</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-1</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>IN monthnum INTEGER</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-2</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>OUT ordernum INTEGER</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external name</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>EXTERNAL NAME 'Sales.numMonthlyOrders'</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>library</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LIBRARY trafodion.sales.sales</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external security</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>invoker</code><sup>1</sup><br>
<br>
Choice depends on your security requirements, you can select <code>definer</code> instead.
For more information, see <a href="#understand-external-security">Understand External Security</a>.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>language java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LANGUAGE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>parameter style java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>PARAMETER STYLE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>sql access</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>READS SQL DATA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dynamic result sets</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>DYNAMIC RESULT SETS 0</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>transaction</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>TRANSACTION REQUIRED</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>determinism</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>NOT DETERMINISTIC</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>isolation</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ISOLATE</code><sup>1</sup></p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><sup>1</sup> Definition represents default value. Not included in the CREATE PROCEDURE example.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">PROCEDURE</span> trafodion.sales.monthlyorders( <span class="keyword">IN</span> monthnum <span class="predefined-type">INTEGER</span>
, OUT ordernum <span class="predefined-type">INTEGER</span>
)
EXTERNAL NAME <span class="string"><span class="delimiter">'</span><span class="content">Sales.numMonthlyOrders</span><span class="delimiter">'</span></span>
LIBRARY trafodion.sales.sales
LANGUAGE JAVA
PARAMETER STYLE JAVA
READS SQL DATA
;</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="calling-the-procedure-monthlyorders">Calling the Procedure: MONTHLYORDERS</h5>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Make sure that users who will be calling the stored procedure have
the appropriate execute privileges. For more information, see
<a href="#grant-privileges">Grant Privileges</a>.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>To invoke the MONTHLYORDERS procedure in trafci:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">SQL&gt; CALL trafodion.sales.monthlyorders( <span class="integer">3</span>, <span class="error">?</span> ) ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The MONTHLYORDERS procedure determines the total number of orders during
a specified month and returns this output in trafci:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">ORDERNUM
<span class="comment">-----------</span>
<span class="integer">4</span>
<span class="comment">--- SQL operation complete.</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>In March, there were four orders.</p>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
<div class="sect3">
<h4 id="totalprice-procedure">10.1.4. TOTALPRICE Procedure</h4>
<div class="paragraph">
<p>The TOTALPRICE procedure accepts the quantity, shipping speed, and price
of an item, calculates the total price, including tax and shipping
charges, and returns the total price to an input/output parameter.</p>
</div>
<div style="page-break-after: always;"></div>
<div class="sect4">
<h5 id="java-method-totalprice">Java Method: totalPrice()</h5>
<div class="listingblock">
<div class="title">Example 5: <a href="resources/source/totalPrice.java"><code>totalPrice()</code></a> Method</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// The TOTALPRICE procedure accepts the quantity, shipping speed, and price</span>
<span class="comment">// of an item, calculates the total price, including tax and shipping</span>
<span class="comment">// charges, and returns the total price to an input/output parameter.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#totalprice-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> totalPrice( <span class="predefined-type">BigDecimal</span> qtyOrdered
, <span class="predefined-type">String</span> shippingSpeed
, <span class="predefined-type">BigDecimal</span><span class="type">[]</span> price
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">BigDecimal</span> shipcharge = <span class="keyword">new</span> <span class="predefined-type">BigDecimal</span>( <span class="integer">0</span> ) ;
<span class="keyword">if</span> ( shippingSpeed.equals( <span class="string"><span class="delimiter">&quot;</span><span class="content">economy</span><span class="delimiter">&quot;</span></span> ) )
{
shipcharge = <span class="keyword">new</span> <span class="predefined-type">BigDecimal</span>( <span class="float">1.95</span> ) ;
}
<span class="keyword">else</span> <span class="keyword">if</span> ( shippingSpeed.equals( <span class="string"><span class="delimiter">&quot;</span><span class="content">standard</span><span class="delimiter">&quot;</span></span> ) )
{
shipcharge = <span class="keyword">new</span> <span class="predefined-type">BigDecimal</span>( <span class="float">4.99</span> ) ;
}
<span class="keyword">else</span> <span class="keyword">if</span> ( shippingSpeed.equals( <span class="string"><span class="delimiter">&quot;</span><span class="content">nextday</span><span class="delimiter">&quot;</span></span> ) )
{
shipcharge = <span class="keyword">new</span> <span class="predefined-type">BigDecimal</span>( <span class="float">14.99</span> ) ;
}
<span class="keyword">else</span>
{
<span class="keyword">throw</span> <span class="keyword">new</span> <span class="exception">SQLException</span>( <span class="string"><span class="delimiter">&quot;</span><span class="content">Invalid value for shipping speed. </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">Retry the CALL statement using </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">'economy' for 7 to 9 days, </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">'standard' for 3 to 5 days, or </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">'nextday' for one day.</span><span class="delimiter">&quot;</span></span>
, <span class="string"><span class="delimiter">&quot;</span><span class="content">38002</span><span class="delimiter">&quot;</span></span>
) ;
}
<span class="predefined-type">BigDecimal</span> subtotal = price[<span class="integer">0</span>].multiply( qtyOrdered ) ;
<span class="predefined-type">BigDecimal</span> tax = <span class="keyword">new</span> <span class="predefined-type">BigDecimal</span>( <span class="float">0.0825</span> ) ;
<span class="predefined-type">BigDecimal</span> taxcharge = subtotal.multiply( tax ) ;
<span class="predefined-type">BigDecimal</span> charges = taxcharge.add( shipcharge ) ;
<span class="predefined-type">BigDecimal</span> totalprice = subtotal.add( charges ) ;
totalprice = totalprice.setScale( <span class="integer">2</span>, <span class="predefined-type">BigDecimal</span>.ROUND_HALF_EVEN ) ;
price[<span class="integer">0</span>] = totalprice ;
}</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="creating-the-procedure-totalprice">Creating the Procedure: TOTALPRICE</h5>
<div class="paragraph">
<p>Before creating the procedure, create a library named <code>SALES</code>
in the <code>TRAFODION.SALES</code> schema and select the <code>Sales.jar</code> file to upload to
Trafodion for that library. For more information, see
<a href="#create-a-library">Create a Library</a>.</p>
</div>
<div class="paragraph">
<p>After creating the library, use the values listed in the table below to define and execute the
CREATE PROCEDURE command. For more information, see <a href="#create-a-procedure">Create a Procedure</a>.</p>
</div>
<table id="table-6" class="tableblock frame-all grid-all spread">
<caption class="title">Table 7. Create Procedure Settings: TOTALPRICE Procedure</caption>
<colgroup>
<col style="width: 19.0476%;">
<col style="width: 80.9524%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Attribute</th>
<th class="tableblock halign-left valign-top">Definition</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>procedure-ref</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>trafodion.sales.totalprice</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-1</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>IN gty NUMERIC(18)</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-2</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>IN speed VARCHAR(10)</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-3</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>INOUT price NUMERIC(18,2)</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external name</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>EXTERNAL NAME 'Sales.totalPrice ( java.math.BigDecimal, java.lang.String, java.math.BigDecimal[] )'</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>library</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LIBRARY trafodion.sales.sales</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external security</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>invoker</code><sup>1</sup><br>
<br>
Choice depends on your security requirements, you can select <code>definer</code> instead.
For more information, see <a href="#understand-external-security">Understand External Security</a>.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>language java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LANGUAGE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>parameter style java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>PARAMETER STYLE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>sql access</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>NO SQL</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dynamic result sets</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>DYNAMIC RESULT SETS 0</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>transaction</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>TRANSACTION REQUIRED</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>determinism</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>NOT DETERMINISTIC</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>isolation</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ISOLATE</code><sup>1</sup></p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><sup>1</sup> Definition represents default value. Not included in the CREATE PROCEDURE example.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">PROCEDURE</span> trafodion.sales.totalprice( <span class="keyword">IN</span> gty NUMERIC(<span class="integer">18</span>)
, <span class="keyword">IN</span> speed <span class="predefined-type">VARCHAR</span>(<span class="integer">10</span>)
, INOUT price NUMERIC(<span class="integer">18</span>,<span class="integer">2</span>)
)
EXTERNAL NAME <span class="string"><span class="delimiter">'</span><span class="content">Sales.totalPrice ( java.math.BigDecimal, java.lang.String, java.math.BigDecimal[] )</span><span class="delimiter">'</span></span>
LIBRARY trafodion.sales.sales
LANGUAGE JAVA
PARAMETER STYLE JAVA
NO SQL
;</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="calling-the-procedure-totalprice">Calling the Procedure: TOTALPRICE</h5>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Make sure that users who will be calling the stored procedure have
the appropriate execute privileges. For more information, see
<a href="#grant-privileges">Grant Privileges</a>.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>To invoke the TOTALPRICE procedure in trafci:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">SQL&gt; <span class="class">SET</span> PARAM <span class="error">?</span>p <span class="integer">10</span> ;
SQL&gt; CALL trafodion.sales.totalprice( <span class="integer">23</span>, <span class="string"><span class="delimiter">'</span><span class="content">standard</span><span class="delimiter">'</span></span>, <span class="error">?</span>p ) ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The TOTALPRICE procedure calculates the total price of a purchase and
returns this output in trafci:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">p
<span class="comment">--------------------</span>
<span class="float">253.97</span>
<span class="comment">--- SQL operation complete.</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The total price of 23 items, which cost $10 each and which are shipped
at the standard rate, is $253.97, including sales tax.</p>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
<div class="sect3">
<h4 id="partdata-procedure">10.1.5. PARTDATA Procedure</h4>
<div class="paragraph">
<p>The PARTDATA procedure accepts a part number and returns this
information about the part:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Part description, price, and quantity available as output parameters.</p>
</li>
<li>
<p>A result set that contains rows from the ORDERS table about when this part was ordered.</p>
</li>
<li>
<p>A result set that contains rows from the PARTLOC table, listing locations that have this part in stock and the quantity they have on hand.</p>
</li>
<li>
<p>A result set that contains rows from the PARTSUPP table for suppliers who carry this part.</p>
</li>
<li>
<p>A result set that contains rows from the EMPLOYEE table for sales reps who have sold this part.</p>
</li>
</ul>
</div>
<div class="sect4">
<h5 id="java-method-partdata">Java Method: partData()</h5>
<div class="listingblock">
<div class="title">Example 6: <a href="resources/source/partData.java"><code>partData()</code></a> Method</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// The PARTDATA procedure accepts a part number and returns this</span>
<span class="comment">// information about the part:</span>
<span class="comment">//</span>
<span class="comment">// * Part description, price, and quantity available as output parameters.</span>
<span class="comment">// * A result set that contains rows from the ORDERS table about when this part was ordered.</span>
<span class="comment">// * A result set that contains rows from the PARTLOC table, listing locations that have this</span>
<span class="comment">// part in stock and the quantity they have on hand.</span>
<span class="comment">// * A result set that contains rows from the PARTSUPP table for suppliers who carry this part.</span>
<span class="comment">// * A result set that contains rows from the EMPLOYEE table for sales reps who have sold this part.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#partdata-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> partData( <span class="type">int</span> partNum
, <span class="predefined-type">String</span><span class="type">[]</span> partDescription
, <span class="predefined-type">BigDecimal</span><span class="type">[]</span> unitPrice
, <span class="type">int</span><span class="type">[]</span> qtyAvailable
, <span class="predefined-type">ResultSet</span><span class="type">[]</span> orders
, <span class="predefined-type">ResultSet</span><span class="type">[]</span> locations
, <span class="predefined-type">ResultSet</span><span class="type">[]</span> suppliers
, <span class="predefined-type">ResultSet</span><span class="type">[]</span> reps
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="comment">// Retrieve detail about this part into the output parameters</span>
<span class="predefined-type">PreparedStatement</span> getPartInfo =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT P.partdesc, P.price, P.qty_available </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.sales.parts P </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE partnum = ? </span><span class="delimiter">&quot;</span></span>
) ;
getPartInfo.setInt( <span class="integer">1</span>, partNum ) ;
<span class="predefined-type">ResultSet</span> rs = getPartInfo.executeQuery() ;
rs.next() ;
partDescription[<span class="integer">0</span>] = rs.getString( <span class="integer">1</span> ) ;
unitPrice[<span class="integer">0</span>] = rs.getBigDecimal( <span class="integer">2</span> ) ;
qtyAvailable[<span class="integer">0</span>] = rs.getInt( <span class="integer">3</span> ) ;
rs.close();
<span class="comment">// Return a result set of rows from the ORDERS table listing orders</span>
<span class="comment">// that included this part. Each ORDERS row is augmented with the</span>
<span class="comment">// quantity of this part that was ordered.</span>
<span class="predefined-type">PreparedStatement</span> getOrders =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT O.*, QTY.QTY_ORDERED </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.sales.orders O </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> , ( select ordernum, sum(qty_ordered) as QTY_ORDERED </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> from trafodion.sales.odetail </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> where partnum = ? </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> group by ordernum ) QTY </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE O.ordernum = QTY.ordernum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">ORDER BY O.ordernum </span><span class="delimiter">&quot;</span></span>
) ;
getOrders.setInt( <span class="integer">1</span>, partNum ) ;
orders[<span class="integer">0</span>] = getOrders.executeQuery() ;
<span class="comment">// Return a result set of rows from the PARTLOC table listing</span>
<span class="comment">// locations that have this part in stock and the quantity they</span>
<span class="comment">// have on hand.</span>
<span class="predefined-type">PreparedStatement</span> getLocations =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT * </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.invent.partloc </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE partnum = ? </span><span class="delimiter">&quot;</span></span>
) ;
getLocations.setInt( <span class="integer">1</span>, partNum ) ;
locations[<span class="integer">0</span>] = getLocations.executeQuery() ;
<span class="comment">// Return a result set of rows from the PARTSUPP table listing</span>
<span class="comment">// suppliers who supply this part.</span>
<span class="predefined-type">PreparedStatement</span> getSuppliers =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT * </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.invent.partsupp </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE partnum = ? </span><span class="delimiter">&quot;</span></span>
) ;
getSuppliers.setInt( <span class="integer">1</span>, partNum ) ;
suppliers[<span class="integer">0</span>] = getSuppliers.executeQuery() ;
<span class="comment">// Return a result set of rows from the EMPLOYEE table listing</span>
<span class="comment">// sales reps that have sold this part.</span>
<span class="predefined-type">PreparedStatement</span> getReps =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT * </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.persnl.employee </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE empnum in ( SELECT O.salesrep </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> FROM trafodion.sales.orders O, </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> trafodion.sales.odetail D </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> WHERE D.partnum = ? </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> AND O.ordernum = D.ordernum ) </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">ORDER BY empnum </span><span class="delimiter">&quot;</span></span>
) ;
getReps.setInt( <span class="integer">1</span>, partNum ) ;
reps[<span class="integer">0</span>] = getReps.executeQuery() ;
}</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="creating-the-procedure-partdata">Creating the Procedure: PARTDATA</h5>
<div class="paragraph">
<p>Before creating the procedure, create a library named <code>SALES</code>
in the <code>TRAFODION.SALES</code> schema and select the <code>Sales.jar</code> file to upload to
Trafodion for that library. For more information, see
<a href="#create-a-library">Create a Library</a>.</p>
</div>
<div class="paragraph">
<p>After creating the library, use the values listed in the table below to define and execute the
CREATE PROCEDURE command. For more information, see <a href="#create-a-procedure">Create a Procedure</a>.</p>
</div>
<table id="table-7" class="tableblock frame-all grid-all spread">
<caption class="title">Table 8. Create Procedure Settings: PARTDATA Procedure</caption>
<colgroup>
<col style="width: 19.0476%;">
<col style="width: 80.9524%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Attribute</th>
<th class="tableblock halign-left valign-top">Definition</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>procedure-ref</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>trafodion.sales.partdata</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-1</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>IN partnum INTEGER</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-2</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>OUT partdesc CHARACTER(18)</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-3</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>OUT price NUMERIC(18,2)</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-4</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>OUT qty_available INTEGER</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external name</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>EXTERNAL NAME 'Sales.partData'</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>library</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LIBRARY trafodion.sales.sales</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external security</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>invoker</code><sup>1</sup><br>
<br>
Choice depends on your security requirements, you can select <code>definer</code> instead.
For more information, see <a href="#understand-external-security">Understand External Security</a>.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>language java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LANGUAGE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>parameter style java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>PARAMETER STYLE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>sql access</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>READS SQL DATA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dynamic result sets</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>DYNAMIC RESULT SETS 4</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>transaction</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>TRANSACTION REQUIRED</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>determinism</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>NOT DETERMINISTIC</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>isolation</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ISOLATE</code><sup>1</sup></p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><sup>1</sup> Definition represents default value. Not included in the CREATE PROCEDURE example.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">PROCEDURE</span> trafodion.sales.partdata( <span class="keyword">IN</span> partnum <span class="predefined-type">INTEGER</span>
, OUT partdesc CHARACTER(<span class="integer">18</span>)
, OUT price NUMERIC(<span class="integer">18</span>,<span class="integer">2</span>)
, OUT qty_available <span class="predefined-type">INTEGER</span>
)
EXTERNAL NAME <span class="string"><span class="delimiter">'</span><span class="content">Sales.partData( int, java.lang.String[], java.math.BigDecimal[], int[] )</span><span class="delimiter">'</span></span>
LIBRARY trafodion.sales.sales
LANGUAGE JAVA
PARAMETER STYLE JAVA
DYNAMIC RESULT SETS <span class="integer">4</span>
READS SQL DATA
;</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="calling-the-procedure-partdata">Calling the Procedure: PARTDATA</h5>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Make sure that users who will be calling the stored procedure have
the appropriate execute privileges. For more information, see
<a href="#grant-privileges">Grant Privileges</a>.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>To invoke the PARTDATA procedure in trafci:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">SQL&gt; CALL trafodion.sales.partdata( <span class="integer">212</span>, <span class="error">?</span>, <span class="error">?</span>, <span class="error">?</span>) ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The PARTDATA procedure returns this information about part 212:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">PARTDESC PRICE QTY_AVAILABLE
<span class="comment">------------------ -------------------- -------------</span>
PC SILVER, <span class="integer">20</span> MB <span class="float">1822.50</span> <span class="integer">3525</span>
ORDERNUM ORDER_DATE DELIV_DATE SALESREP CUSTNUM QTY_ORDERED
<span class="comment">-------- ---------- ---------- -------- ------- --------------------</span>
<span class="integer">400410</span> <span class="integer">2011</span><span class="integer">-03</span><span class="integer">-27</span> <span class="integer">2011</span><span class="integer">-09</span><span class="integer">-01</span> <span class="integer">227</span> <span class="integer">7654</span> <span class="integer">12</span>
<span class="integer">500450</span> <span class="integer">2011</span><span class="integer">-04</span><span class="integer">-20</span> <span class="integer">2011</span><span class="integer">-09</span><span class="integer">-15</span> <span class="integer">220</span> <span class="integer">324</span> <span class="integer">8</span>
<span class="comment">--- 2 row(s) selected.</span>
LOC_CODE PARTNUM QTY_ON_HAND
<span class="comment">-------- ------- -----------</span>
A87 <span class="integer">212</span> <span class="integer">18</span>
G87 <span class="integer">212</span> <span class="integer">20</span>
<span class="comment">--- 2 row(s) selected.</span>
PARTNUM SUPPNUM PARTCOST QTY_RECEIVED
<span class="comment">------- ------- ---------- ------------</span>
<span class="integer">212</span> <span class="integer">1</span> <span class="float">2000.00</span> <span class="integer">20</span>
<span class="integer">212</span> <span class="integer">3</span> <span class="float">1900.00</span> <span class="integer">35</span>
<span class="comment">--- 2 row(s) selected.</span>
EMPNUM FIRST_NAME LAST_NAME DEPTNUM JOBCODE SALARY
<span class="comment">------ --------------- -------------------- ------- ------- ----------</span>
<span class="integer">220</span> JOHN HUGHES <span class="integer">3200</span> <span class="integer">300</span> <span class="float">33000.10</span>
<span class="integer">227</span> XAVIER SEDLEMEYER <span class="integer">3300</span> <span class="integer">300</span> <span class="float">30000.00</span>
<span class="comment">--- 2 row(s) selected.</span>
<span class="comment">--- SQL operation complete.</span></code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
<div class="sect3">
<h4 id="ordersummary-procedure">10.1.6. ORDERSUMMARY Procedure</h4>
<div class="paragraph">
<p>The ORDERSUMMARY procedure accepts a date, which is formatted as a
string, and returns this information about the orders on or after that
date:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The number of orders as an output parameter.</p>
</li>
<li>
<p>A result set that contains one row for each order. Each row contains
fields for the order number, the number of parts ordered, total dollar
amount, order date, and the name of the sales representative.</p>
</li>
<li>
<p>A result set that contains details about each order. Each order has
one or more rows that provide details about the ordered parts. Each row
contains fields for the order number, part number, unit price, quantity
ordered, and part description.</p>
</li>
</ul>
</div>
<div class="sect4">
<h5 id="java-method-ordersummary">Java Method: orderSummary()</h5>
<div class="listingblock">
<div class="title">Example 7: <a href="resources/source/orderSummary.java"><code>orderSummary()</code></a> Method</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// The ORDERSUMMARY procedure accepts a date, which is formatted as a</span>
<span class="comment">// string, and returns this information about the orders on or after that</span>
<span class="comment">// date:</span>
<span class="comment">//</span>
<span class="comment">// * The number of orders as an output parameter</span>
<span class="comment">// * A result set that contains one row for each order. Each row contains</span>
<span class="comment">// fields for the order number, the number of parts ordered, total dollar</span>
<span class="comment">// amount, order date, and the name of the sales representative.</span>
<span class="comment">// * A result set that contains details about each order. Each order has</span>
<span class="comment">// one or more rows that provide details about the ordered parts. Each row</span>
<span class="comment">// contains fields for the order number, part number, unit price, quantity</span>
<span class="comment">// ordered, and part description.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#ordersummary-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> orderSummary( java.lang.String onOrAfter
, <span class="type">long</span><span class="type">[]</span> numOrders
, java.sql.ResultSet<span class="type">[]</span> orders
, java.sql.ResultSet<span class="type">[]</span> detail
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
java.lang.String s ;
java.sql.Connection conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="comment">// Get the number of orders on or after this date</span>
s = <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT COUNT(ordernum) FROM trafodion.sales.orders </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE order_date &gt;= CAST(? AS DATE) </span><span class="delimiter">&quot;</span></span>
;
java.sql.PreparedStatement ps1 = conn.prepareStatement( s ) ;
ps1.setString( <span class="integer">1</span>, onOrAfter ) ;
java.sql.ResultSet rs = ps1.executeQuery() ;
rs.next() ;
numOrders[<span class="integer">0</span>] = rs.getLong( <span class="integer">1</span> ) ;
rs.close() ;
<span class="comment">// Open a result set for order num, order info rows</span>
s = <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT amounts.*, orders.order_date, emps.last_name </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM ( SELECT </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> o.ordernum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> , COUNT(d.partnum) AS num_parts </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> , SUM(d.unit_price * d.qty_ordered) AS amount </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> FROM trafodion.sales.orders o, trafodion.sales.odetail d </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> WHERE o.ordernum = d.ordernum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> AND o.order_date &gt;= CAST(? AS DATE) </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> GROUP BY o.ordernum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> ) amounts </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> , trafodion.sales.orders orders </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> , trafodion.persnl.employee emps </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE amounts.ordernum = orders.ordernum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> AND orders.salesrep = emps.empnum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">ORDER BY orders.ordernum </span><span class="delimiter">&quot;</span></span>
;
java.sql.PreparedStatement ps2 = conn.prepareStatement( s ) ;
ps2.setString( <span class="integer">1</span>, onOrAfter ) ;
orders[<span class="integer">0</span>] = ps2.executeQuery() ;
<span class="comment">// Open a result set for order detail rows</span>
s = <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT d.*, p.partdesc </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.sales.odetail d, trafodion.sales.parts p, trafodion.sales.orders O </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE d.partnum = p.partnum AND d.ordernum = o.ordernum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> AND o.order_date &gt;= CAST(? AS DATE) </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">ORDER BY d.ordernum </span><span class="delimiter">&quot;</span></span>
;
java.sql.PreparedStatement ps3 = conn.prepareStatement( s ) ;
ps3.setString( <span class="integer">1</span>, onOrAfter ) ;
detail[<span class="integer">0</span>] = ps3.executeQuery() ;
}</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="creating-the-procedure-ordersummary">Creating the Procedure: ORDERSUMMARY</h5>
<div class="paragraph">
<p>Before creating the procedure, create a library named <code>SALES</code>
in the <code>TRAFODION.SALES</code> schema and select the <code>Sales.jar</code> file to upload to
Trafodion for that library. For more information, see
<a href="#create-a-library">Create a Library</a>.</p>
</div>
<div class="paragraph">
<p>After creating the library, use the values listed in the table below to define and execute the
CREATE PROCEDURE command. For more information, see <a href="#create-a-procedure">Create a Procedure</a>.</p>
</div>
<table id="table-8" class="tableblock frame-all grid-all spread">
<caption class="title">Table 9. Create Procedure Settings: ORDERSUMMARY Procedure</caption>
<colgroup>
<col style="width: 19.0476%;">
<col style="width: 80.9524%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Attribute</th>
<th class="tableblock halign-left valign-top">Definition</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>procedure-ref</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>trafodion.sales.ordersummary</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-1</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>IN on_or_after_date VARCHAR(20)</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-2</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>OUT num_orders LARGEINT</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external name</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>EXTERNAL NAME 'Sales.orderSummary'</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>library</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LIBRARY trafodion.sales.sales</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external security</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>invoker</code><sup>1</sup><br>
<br>
Choice depends on your security requirements, you can select <code>definer</code> instead.
For more information, see <a href="#understand-external-security">Understand External Security</a>.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>language java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LANGUAGE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>parameter style java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>PARAMETER STYLE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>sql access</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>READS SQL DATA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dynamic result sets</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>DYNAMIC RESULT SETS 2</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>transaction</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>TRANSACTION REQUIRED</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>determinism</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>NOT DETERMINISTIC</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>isolation</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ISOLATE</code><sup>1</sup></p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><sup>1</sup> Definition represents default value. Not included in the CREATE PROCEDURE example.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">PROCEDURE</span> trafodion.sales.ordersummary( <span class="keyword">IN</span> on_or_after_date <span class="predefined-type">VARCHAR</span>(<span class="integer">20</span>)
, OUT num_orders LARGEINT
)
EXTERNAL NAME <span class="string"><span class="delimiter">'</span><span class="content">Sales.orderSummary ( java.lang.String, long[] )</span><span class="delimiter">'</span></span>
LIBRARY trafodion.sales.sales
LANGUAGE JAVA
PARAMETER STYLE JAVA
DYNAMIC RESULT SETS <span class="integer">2</span>
READS SQL DATA
;</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="calling-the-procedure-ordersummary">Calling the Procedure: ORDERSUMMARY</h5>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Make sure that users who will be calling the stored procedure have
the appropriate execute privileges. For more information, see
<a href="#grant-privileges">Grant Privileges</a>.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>To invoke the ORDERSUMMARY procedure in trafci:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">SQL&gt; CALL trafodion.sales.ordersummary( <span class="string"><span class="delimiter">'</span><span class="content">2011-01-01</span><span class="delimiter">'</span></span>, <span class="error">?</span> ) ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The ORDERSUMMARY procedure returns this information about the orders on
or after the specified date, 01-01-2011:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">NUM_ORDERS
<span class="comment">--------------------</span>
<span class="integer">13</span>
ORDERNUM NUM_PARTS AMOUNT ORDER_DATE LAST_NAME
<span class="comment">-------- -------------------- -------------------- ---------- --------------------</span>
<span class="integer">100210</span> <span class="integer">4</span> <span class="float">19020.00</span> <span class="integer">2011</span><span class="integer">-04</span><span class="integer">-10</span> HUGHES
<span class="integer">100250</span> <span class="integer">4</span> <span class="float">22625.00</span> <span class="integer">2011</span><span class="integer">-01</span><span class="integer">-23</span> HUGHES
<span class="integer">101220</span> <span class="integer">4</span> <span class="float">45525.00</span> <span class="integer">2011</span><span class="integer">-07</span><span class="integer">-21</span> SCHNABL
... ... ... ... ...
<span class="comment">--- 13 row(s) selected.</span>
ORDERNUM PARTNUM UNIT_PRICE QTY_ORDERED PARTDESC
<span class="comment">-------- ------- ---------- ----------- ------------------</span>
<span class="integer">100210</span> <span class="integer">244</span> <span class="float">3500.00</span> <span class="integer">3</span> PC GOLD, <span class="integer">30</span> MB
<span class="integer">100210</span> <span class="integer">5100</span> <span class="float">150.00</span> <span class="integer">10</span> MONITOR BW, TYPE <span class="integer">1</span>
<span class="integer">100210</span> <span class="integer">2403</span> <span class="float">620.00</span> <span class="integer">6</span> DAISY PRINTER,T2
<span class="integer">100210</span> <span class="integer">2001</span> <span class="float">1100.00</span> <span class="integer">3</span> GRAPHIC PRINTER,M1
<span class="integer">100250</span> <span class="integer">6500</span> <span class="float">95.00</span> <span class="integer">10</span> DISK CONTROLLER
<span class="integer">100250</span> <span class="integer">6301</span> <span class="float">245.00</span> <span class="integer">15</span> GRAPHIC CARD, HR
<span class="integer">100250</span> <span class="integer">244</span> <span class="float">3500.00</span> <span class="integer">4</span> PC GOLD, <span class="integer">30</span> MB
<span class="integer">100250</span> <span class="integer">5103</span> <span class="float">400.00</span> <span class="integer">10</span> MONITOR COLOR, M1
... ... ... ... ...
<span class="comment">--- 70 row(s) selected.</span>
<span class="comment">--- SQL operation complete.</span></code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="procedures-in-the-persnl-schema">10.2. Procedures in the PERSNL Schema</h3>
<div class="paragraph">
<p>The Payroll class contains these SPJ methods, which are useful for
managing personnel data:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="#adjustsalary-procedure">ADJUSTSALARY Procedure</a></p>
</li>
<li>
<p><a href="#employeejob-procedure">EMPLOYEEJOB Procedure</a></p>
</li>
<li>
<p><a href="#projectteam-procedure">PROJECTTEAM Procedure</a></p>
</li>
<li>
<p><a href="#topsalesreps-procedure">TOPSALESREPS Procedure</a></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Those methods are registered as stored procedures in the PERSNL schema.
<a href="#example-6">Example 6</a> shows the code of the
<a href="resources/source/Payroll.java">Payroll.java</a>
file.</p>
</div>
<div id="example-8" class="listingblock">
<div class="title">Example 8: <a href="resources/source/Payroll.java"><code>Payroll.java</code></a> - The Payroll Class</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="keyword">import</span> <span class="include">java.sql</span>.* ;
<span class="keyword">import</span> <span class="include">java.math</span>.* ;
<span class="directive">public</span> <span class="type">class</span> <span class="class">Payroll</span>
{
<span class="comment">// The ADJUSTSALARY procedure accepts an employee number and a percentage</span>
<span class="comment">// value and updates the employee's salary in the database based on that</span>
<span class="comment">// percentage. This method also returns the updated salary to an output</span>
<span class="comment">// parameter.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#adjustsalary-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> adjustSalary( <span class="predefined-type">BigDecimal</span> empNum
, <span class="type">double</span> percent
, <span class="predefined-type">BigDecimal</span><span class="type">[]</span> newSalary
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> setSalary =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">UPDATE trafodion.persnl.employee </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">SET salary = salary * (1 + (? / 100)) </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE empnum = ?</span><span class="delimiter">&quot;</span></span>
) ;
<span class="predefined-type">PreparedStatement</span> getSalary =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT salary </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.persnl.employee </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE empnum = ?</span><span class="delimiter">&quot;</span></span>
) ;
setSalary.setDouble( <span class="integer">1</span>, percent ) ;
setSalary.setBigDecimal( <span class="integer">2</span>, empNum ) ;
setSalary.executeUpdate() ;
getSalary.setBigDecimal( <span class="integer">1</span>, empNum ) ;
<span class="predefined-type">ResultSet</span> rs = getSalary.executeQuery() ;
rs.next() ;
newSalary[<span class="integer">0</span>] = rs.getBigDecimal( <span class="integer">1</span> ) ;
rs.close() ;
conn.close() ;
}
<span class="comment">// The EMPLOYEEJOB procedure accepts an employee number and returns a job</span>
<span class="comment">// code or null value to an output parameter.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#employeejob-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> employeeJob( <span class="type">int</span> empNum
, java.lang.Integer<span class="type">[]</span> jobCode
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> getJobcode =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT jobcode </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.persnl.employee </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE empnum = ?</span><span class="delimiter">&quot;</span></span>
) ;
getJobcode.setInt( <span class="integer">1</span>, empNum ) ;
<span class="predefined-type">ResultSet</span> rs = getJobcode.executeQuery() ;
rs.next() ;
<span class="type">int</span> num = rs.getInt(<span class="integer">1</span>) ;
<span class="keyword">if</span> ( rs.wasNull() )
jobCode[<span class="integer">0</span>] = <span class="predefined-constant">null</span> ;
<span class="keyword">else</span>
jobCode[<span class="integer">0</span>] = <span class="keyword">new</span> <span class="predefined-type">Integer</span>(num) ;
rs.close() ;
conn.close() ;
}
<span class="comment">// The PROJECTTEAM procedure accepts a project code and returns the</span>
<span class="comment">// employee number, first name, last name, and location of the employees</span>
<span class="comment">// assigned to that project.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#projectteam-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> projectTeam( <span class="type">int</span> projectCode
, <span class="predefined-type">ResultSet</span><span class="type">[]</span> members
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> getMembers =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT E.empnum, E.first_name, E.last_name, D.location </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.persnl.employee E, trafodion.persnl.dept D, trafodion.persnl.project P </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE P.projcode = ? </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> AND P.empnum = E.empnum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> AND E.deptnum = D.deptnum </span><span class="delimiter">&quot;</span></span>
) ;
getMembers.setInt( <span class="integer">1</span>, projectCode ) ;
members[<span class="integer">0</span>] = getMembers.executeQuery() ;
}
<span class="comment">// The TOPSALESREPS procedure accepts a number representing the fiscal</span>
<span class="comment">// quarter (1, 2, 3, and 4, with each number representing a range of</span>
<span class="comment">// months) and returns the employee number, first name, last name, and sale</span>
<span class="comment">// figures of the top five sales representatives who had the highest sales</span>
<span class="comment">// (unit_price * qty_ordered) that quarter.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#topsalesreps-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> topSalesReps( <span class="type">int</span> whichQuarter
, <span class="predefined-type">ResultSet</span><span class="type">[]</span> topReps
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="keyword">if</span> ( whichQuarter &lt; <span class="integer">1</span> || whichQuarter &gt; <span class="integer">4</span> )
{
<span class="keyword">throw</span> <span class="keyword">new</span> <span class="exception">SQLException</span> ( <span class="string"><span class="delimiter">&quot;</span><span class="content">Invalid value for quarter. </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">Retry the CALL statement </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">using a number from 1 to 4 </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">to represent the quarter.</span><span class="delimiter">&quot;</span></span>
, <span class="string"><span class="delimiter">&quot;</span><span class="content">38001</span><span class="delimiter">&quot;</span></span>
) ;
}
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> getTopReps =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT [first 5] e.empnum, e.first_name, </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">e.last_name, totals.total </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.persnl.employee e, </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> ( SELECT o.salesrep, </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> SUM( od.unit_price * od.qty_ordered ) as total </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> FROM trafodion.sales.orders o, trafodion.sales.odetail od </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> WHERE o.ordernum = od.ordernum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> AND QUARTER( o.order_date ) = ? </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> GROUP BY o.salesrep </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> ) totals </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE e.empnum = totals.salesrep </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">ORDER BY totals.total DESCENDING </span><span class="delimiter">&quot;</span></span>
) ;
getTopReps.setInt( <span class="integer">1</span>, whichQuarter ) ;
topReps[<span class="integer">0</span>] = getTopReps.executeQuery() ;
}
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>See the following sections for more information about each SPJ method.</p>
</div>
<div style="page-break-after: always;"></div>
<div class="sect3">
<h4 id="adjustsalary-procedure">10.2.1. ADJUSTSALARY Procedure</h4>
<div class="paragraph">
<p>The ADJUSTSALARY procedure accepts an employee number and a percentage
value and updates the employee&#8217;s salary in the database based on that
percentage. This method also returns the updated salary to an output
parameter.</p>
</div>
<div style="page-break-after: always;"></div>
<div class="sect4">
<h5 id="java-method-adjustsalary">Java Method: adjustSalary()</h5>
<div class="listingblock">
<div class="title">Example 9: <a href="resources/source/adjustSalary.java"><code>adjustSalary()</code></a> Method</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// The ADJUSTSALARY procedure accepts an employee number and a percentage</span>
<span class="comment">// value and updates the employee's salary in the database based on that</span>
<span class="comment">// percentage. This method also returns the updated salary to an output</span>
<span class="comment">// parameter.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#adjustsalary-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> adjustSalary( <span class="predefined-type">BigDecimal</span> empNum
, <span class="type">double</span> percent
, <span class="predefined-type">BigDecimal</span><span class="type">[]</span> newSalary
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> setSalary =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">UPDATE trafodion.persnl.employee </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">SET salary = salary * (1 + (? / 100)) </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE empnum = ?</span><span class="delimiter">&quot;</span></span>
) ;
<span class="predefined-type">PreparedStatement</span> getSalary =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT salary </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.persnl.employee </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE empnum = ?</span><span class="delimiter">&quot;</span></span>
) ;
setSalary.setDouble( <span class="integer">1</span>, percent ) ;
setSalary.setBigDecimal( <span class="integer">2</span>, empNum ) ;
setSalary.executeUpdate() ;
getSalary.setBigDecimal( <span class="integer">1</span>, empNum ) ;
<span class="predefined-type">ResultSet</span> rs = getSalary.executeQuery() ;
rs.next() ;
newSalary[<span class="integer">0</span>] = rs.getBigDecimal( <span class="integer">1</span> ) ;
rs.close() ;
conn.close() ;
}</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="creating-the-procedure-adjustsalary">Creating the Procedure: ADJUSTSALARY</h5>
<div class="paragraph">
<p>Before creating the procedure, create a library named <code>PAYROLL</code>
in the <code>TRAFODION.PERSNL</code> schema and select the <code>Payroll.jar</code> file to upload to
Trafodion for that library. For more information, see
<a href="#create-a-library">Create a Library</a>.</p>
</div>
<div class="paragraph">
<p>After creating the library, use the values listed in the table below to define and execute the
CREATE PROCEDURE command. For more information, see <a href="#create-a-procedure">Create a Procedure</a>.</p>
</div>
<table id="table-9" class="tableblock frame-all grid-all spread">
<caption class="title">Table 10. Create Procedure Settings: ADJUSTSALARY Procedure</caption>
<colgroup>
<col style="width: 19.0476%;">
<col style="width: 80.9524%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Attribute</th>
<th class="tableblock halign-left valign-top">Definition</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>procedure-ref</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>trafodion.persnl.adjustsalary</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-1</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>IN empnum NUMERIC(4)</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-2</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>IN percent FLOAT</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-3</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>OUT newsalary NUMERIC(8,2)</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external name</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>EXTERNAL NAME 'Payroll.adjustSalary'</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>library</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LIBRARY trafodion.persnl.payroll</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external security</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>invoker</code><sup>1</sup><br>
<br>
Choice depends on your security requirements, you can select <code>definer</code> instead.
For more information, see <a href="#understand-external-security">Understand External Security</a>.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>language java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LANGUAGE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>parameter style java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>PARAMETER STYLE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>sql access</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>MODIFIES SQL DATA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dynamic result sets</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>DYNAMIC RESULT SETS 0</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>transaction</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>TRANSACTION REQUIRED</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>determinism</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>NOT DETERMINISTIC</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>isolation</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ISOLATE</code><sup>1</sup></p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><sup>1</sup> Definition represents default value. Not included in the CREATE PROCEDURE example.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">PROCEDURE</span> trafodion.persnl.adjustsalary( <span class="keyword">IN</span> empnum NUMERIC(<span class="integer">4</span>)
, <span class="keyword">IN</span> percent <span class="predefined-type">FLOAT</span>
, OUT newsalary NUMERIC(<span class="integer">8</span>,<span class="integer">2</span>)
)
EXTERNAL NAME <span class="string"><span class="delimiter">'</span><span class="content">Payroll.adjustSalary</span><span class="delimiter">'</span></span>
LIBRARY trafodion.persnl.payroll
LANGUAGE JAVA
PARAMETER STYLE JAVA
MODIFIES SQL DATA
;</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="calling-the-procedure-adjustsalary">Calling the Procedure: ADJUSTSALARY</h5>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Make sure that users who will be calling the stored procedure have
the appropriate execute privileges. For more information, see
<a href="#grant-privileges">Grant Privileges</a>.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>To invoke the ADJUSTSALARY procedure in trafci:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">SQL&gt; CALL trafodion.persnl.adjustsalary(<span class="integer">29</span>, <span class="float">2.5</span>, <span class="error">?</span>) ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The ADJUSTSALARY procedure updates the salary of employee number 29 by
2.5 percent and returns this output in trafci:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">NEWSALARY
<span class="comment">----------</span>
<span class="float">139400.00</span>
<span class="comment">--- SQL operation complete.</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The salary of employee number 29 was originally $136,000.00 and became
$139,400.00 after the invocation of ADJUSTSALARY.</p>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
<div class="sect3">
<h4 id="employeejob-procedure">10.2.2. EMPLOYEEJOB Procedure</h4>
<div class="paragraph">
<p>The EMPLOYEEJOB procedure accepts an employee number and returns a job
code or null value to an output parameter.</p>
</div>
<div class="sect4">
<h5 id="java-method-employeejob">Java Method: employeeJob()</h5>
<div class="listingblock">
<div class="title">Example 10:<a href="resources/source/employeeJob.java"><code>employeeJob()</code></a> Method</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// The EMPLOYEEJOB procedure accepts an employee number and returns a job</span>
<span class="comment">// code or null value to an output parameter.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#employeejob-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> employeeJob( <span class="type">int</span> empNum
, java.lang.Integer<span class="type">[]</span> jobCode
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> getJobcode =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT jobcode </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.persnl.employee </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE empnum = ?</span><span class="delimiter">&quot;</span></span>
) ;
getJobcode.setInt( <span class="integer">1</span>, empNum ) ;
<span class="predefined-type">ResultSet</span> rs = getJobcode.executeQuery() ;
rs.next() ;
<span class="type">int</span> num = rs.getInt(<span class="integer">1</span>) ;
<span class="keyword">if</span> ( rs.wasNull() )
jobCode[<span class="integer">0</span>] = <span class="predefined-constant">null</span> ;
<span class="keyword">else</span>
jobCode[<span class="integer">0</span>] = <span class="keyword">new</span> <span class="predefined-type">Integer</span>(num) ;
rs.close() ;
conn.close() ;
}</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="creating-the-procedure-employeejob">Creating the Procedure: EMPLOYEEJOB</h5>
<div class="paragraph">
<p>Before creating the procedure, create a library named <code>PAYROLL</code>
in the <code>TRAFODION.PERSNL</code> schema and select the <code>Payroll.jar</code> file to upload to
Trafodion for that library. For more information, see
<a href="#create-a-library">Create a Library</a>.</p>
</div>
<div class="paragraph">
<p>After creating the library, use these values listed in the table below to define and execute the
CREATE PROCEDURE command. For more information, see <a href="#create-a-procedure">Create a Procedure</a>.</p>
</div>
<table id="table-10" class="tableblock frame-all grid-all spread">
<caption class="title">Table 11. Create Procedure Settings: EMPLOYEEJOB Procedure</caption>
<colgroup>
<col style="width: 19.0476%;">
<col style="width: 80.9524%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Attribute</th>
<th class="tableblock halign-left valign-top">Definition</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>procedure-ref</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>trafodion.persnl.employeejob</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-1</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>IN empnum</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-2</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>OUT jobcode INT</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external name</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>EXTERNAL NAME 'Payroll.employeeJob ( int, java.lang.Integer[] )'</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>library</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LIBRARY trafodion.persnl.payroll</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external security</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>invoker</code><sup>1</sup><br>
<br>
Choice depends on your security requirements, you can select <code>definer</code> instead.
For more information, see <a href="#understand-external-security">Understand External Security</a>.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>language java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LANGUAGE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>parameter style java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>PARAMETER STYLE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>sql access</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>READS SQL DATA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dynamic result sets</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>DYNAMIC RESULT SETS 0</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>transaction</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>TRANSACTION REQUIRED</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>determinism</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>NOT DETERMINISTIC</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>isolation</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ISOLATE</code><sup>1</sup></p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><sup>1</sup> Definition represents default value. Not included in the CREATE PROCEDURE example.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">PROCEDURE</span> trafodion.persnl.employeejob( <span class="keyword">IN</span> empnum <span class="predefined-type">INT</span>
, OUT jobcode <span class="predefined-type">INT</span>
)
EXTERNAL NAME <span class="string"><span class="delimiter">'</span><span class="content">Payroll.employeeJob ( int, java.lang.Integer[] )</span><span class="delimiter">'</span></span>
LIBRARY trafodion.persnl.payroll
LANGUAGE JAVA
PARAMETER STYLE JAVA
READS SQL DATA
;</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="calling-the-procedure-employeejob">Calling the Procedure: EMPLOYEEJOB</h5>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Make sure that users who will be calling the stored procedure have
the appropriate execute privileges. For more information, see
<a href="#grant-privileges">Grant Privileges</a>.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>To invoke the EMPLOYEEJOB procedure in trafci:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">SQL&gt; CALL trafodion.persnl.employeejob(<span class="integer">337</span>, <span class="error">?</span>) ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The EMPLOYEEJOB procedure accepts the employee number 337 and returns
this output in trafci:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">JOBCODE
<span class="comment">-----------</span>
<span class="integer">900</span>
<span class="comment">--- SQL operation complete.</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The job code for employee number 337 is 900.</p>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
<div class="sect3">
<h4 id="projectteam-procedure">10.2.3. PROJECTTEAM Procedure</h4>
<div class="paragraph">
<p>The PROJECTTEAM procedure accepts a project code and returns the
employee number, first name, last name, and location of the employees
assigned to that project.</p>
</div>
<div class="sect4">
<h5 id="java-method-projectteam">Java Method: projectTeam()</h5>
<div class="listingblock">
<div class="title">Example 11:<a href="resources/source/projectTeam.java"><code>projectTeam()</code></a> Method</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// The PROJECTTEAM procedure accepts a project code and returns the</span>
<span class="comment">// employee number, first name, last name, and location of the employees</span>
<span class="comment">// assigned to that project.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#projectteam-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> projectTeam( <span class="type">int</span> projectCode
, <span class="predefined-type">ResultSet</span><span class="type">[]</span> members
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> getMembers =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT E.empnum, E.first_name, E.last_name, D.location </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.persnl.employee E, trafodion.persnl.dept D, trafodion.persnl.project P </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE P.projcode = ? </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> AND P.empnum = E.empnum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> AND E.deptnum = D.deptnum </span><span class="delimiter">&quot;</span></span>
) ;
getMembers.setInt( <span class="integer">1</span>, projectCode ) ;
members[<span class="integer">0</span>] = getMembers.executeQuery() ;
}</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="creating-the-procedure-projectteam">Creating the Procedure: PROJECTTEAM</h5>
<div class="paragraph">
<p>Before creating the procedure, create a library named <code>PAYROLL</code>
in the <code>TRAFODION.PERSNL</code> schema and select the <code>Payroll.jar</code> file to upload to
Trafodion for that library. For more information, see
<a href="#create-a-library">Create a Library</a>.</p>
</div>
<div class="paragraph">
<p>After creating the library, use the values listed in the table below to define and execute the
CREATE PROCEDURE command. For more information, see <a href="#create-a-procedure">Create a Procedure</a>.</p>
</div>
<table id="table-11" class="tableblock frame-all grid-all spread">
<caption class="title">Table 12. Create Procedure Settings: PROJECTTEAM Procedure</caption>
<colgroup>
<col style="width: 19.0476%;">
<col style="width: 80.9524%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Attribute</th>
<th class="tableblock halign-left valign-top">Definition</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>procedure-ref</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>trafodion.persnl.projectteam</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-1</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>IN projectcode INTEGER</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external name</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>EXTERNAL NAME 'Payroll.projectTeam'</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>library</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LIBRARY trafodion.persnl.payroll</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external security</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>invoker</code><sup>1</sup><br>
<br>
Choice depends on your security requirements, you can select <code>definer</code> instead.
For more information, see <a href="#understand-external-security">Understand External Security</a>.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>language java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LANGUAGE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>parameter style java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>PARAMETER STYLE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>sql access</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>READS SQL DATA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dynamic result sets</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>DYNAMIC RESULT SETS 1</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>transaction</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>TRANSACTION REQUIRED</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>determinism</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>NOT DETERMINISTIC</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>isolation</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ISOLATE</code><sup>1</sup></p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><sup>1</sup> Definition represents default value. Not included in the CREATE PROCEDURE example.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">PROCEDURE</span> trafodion.persnl.projectteam( <span class="keyword">IN</span> projectcode <span class="predefined-type">INTEGER</span>
)
EXTERNAL NAME <span class="string"><span class="delimiter">'</span><span class="content">Payroll.projectTeam</span><span class="delimiter">'</span></span>
LIBRARY trafodion.persnl.payroll
LANGUAGE JAVA
PARAMETER STYLE JAVA
DYNAMIC RESULT SETS <span class="integer">1</span>
READS SQL DATA
;</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="calling-the-procedure-projectteam">Calling the Procedure: PROJECTTEAM</h5>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Make sure that users who will be calling the stored procedure have
the appropriate execute privileges. For more information, see
<a href="#grant-privileges">Grant Privileges</a>.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>To invoke the PROJECTTEAM procedure in trafci:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">SQL&gt; CALL trafodion.persnl.projectteam( <span class="integer">5000</span> ) ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The PROJECTTEAM procedure returns this information about the employees
assigned to project number 5000:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">EMPNUM FIRST_NAME LAST_NAME LOCATION
<span class="comment">------ --------------- -------------------- ------------------</span>
<span class="integer">65</span> RACHEL MCKAY NEW YORK
<span class="integer">203</span> KATHRYN HALL NEW YORK
... ... ...
<span class="comment">--- 6 row(s) selected.</span>
<span class="comment">--- SQL operation complete.</span></code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
<div class="sect3">
<h4 id="topsalesreps-procedure">10.2.4. TOPSALESREPS Procedure</h4>
<div class="paragraph">
<p>The TOPSALESREPS procedure accepts a number representing the fiscal
quarter (1, 2, 3, and 4, with each number representing a range of
months) and returns the employee number, first name, last name, and sale
figures of the top five sales representatives who had the highest sales
(unit_price * qty_ordered) that quarter.</p>
</div>
<div style="page-break-after: always;"></div>
<div class="sect4">
<h5 id="java-method-topsalesreps">Java Method: topSalesReps()</h5>
<div class="listingblock">
<div class="title">Example 12: <a href="resources/source/topSalesReps.java"><code>topSalesReps()</code></a> Method</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// The TOPSALESREPS procedure accepts a number representing the fiscal</span>
<span class="comment">// quarter (1, 2, 3, and 4, with each number representing a range of</span>
<span class="comment">// months) and returns the employee number, first name, last name, and sale</span>
<span class="comment">// figures of the top five sales representatives who had the highest sales</span>
<span class="comment">// (unit_price * qty_ordered) that quarter.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#topsalesreps-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> topSalesReps( <span class="type">int</span> whichQuarter
, <span class="predefined-type">ResultSet</span><span class="type">[]</span> topReps
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="keyword">if</span> ( whichQuarter &lt; <span class="integer">1</span> || whichQuarter &gt; <span class="integer">4</span> )
{
<span class="keyword">throw</span> <span class="keyword">new</span> <span class="exception">SQLException</span> ( <span class="string"><span class="delimiter">&quot;</span><span class="content">Invalid value for quarter. </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">Retry the CALL statement </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">using a number from 1 to 4 </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">to represent the quarter.</span><span class="delimiter">&quot;</span></span>
, <span class="string"><span class="delimiter">&quot;</span><span class="content">38001</span><span class="delimiter">&quot;</span></span>
) ;
}
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> getTopReps =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT [first 5] e.empnum, e.first_name, </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">e.last_name, totals.total </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.persnl.employee e, </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> ( SELECT o.salesrep, </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> SUM( od.unit_price * od.qty_ordered ) as total </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> FROM trafodion.sales.orders o, trafodion.sales.odetail od </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> WHERE o.ordernum = od.ordernum </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> AND QUARTER( o.order_date ) = ? </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> GROUP BY o.salesrep </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> ) totals </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE e.empnum = totals.salesrep </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">ORDER BY totals.total DESCENDING </span><span class="delimiter">&quot;</span></span>
) ;
getTopReps.setInt( <span class="integer">1</span>, whichQuarter ) ;
topReps[<span class="integer">0</span>] = getTopReps.executeQuery() ;
}</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="creating-the-procedure-topsalesreps">Creating the Procedure: TOPSALESREPS</h5>
<div class="paragraph">
<p>Before creating the procedure, create a library named <code>PAYROLL</code>
in the <code>TRAFODION.PERSNL</code> schema and select the <code>Payroll.jar</code> file to upload to
Trafodion for that library. For more information, see
<a href="#create-a-library">Create a Library</a>.</p>
</div>
<div class="paragraph">
<p>After creating the library, use the values listed in the table below to define and execute the
CREATE PROCEDURE command. For more information, see <a href="#create-a-procedure">Create a Procedure</a>.</p>
</div>
<table id="table-12" class="tableblock frame-all grid-all spread">
<caption class="title">Table 13. Create Procedure Settings: TOPSALESREPS Procedure</caption>
<colgroup>
<col style="width: 19.0476%;">
<col style="width: 80.9524%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Attribute</th>
<th class="tableblock halign-left valign-top">Definition</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>procedure-ref</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>trafodion.persnl.topsalesreps</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-1</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>IN whichquarter INTEGER</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external name</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>EXTERNAL NAME 'Payroll.topSalesReps'</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>library</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LIBRARY trafodion.persnl.payroll</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external security</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>invoker</code><sup>1</sup><br>
<br>
Choice depends on your security requirements, you can select <code>definer</code> instead.
For more information, see <a href="#understand-external-security">Understand External Security</a>.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>language java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LANGUAGE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>parameter style java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>PARAMETER STYLE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>sql access</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>READS SQL DATA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dynamic result sets</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>DYNAMIC RESULT SETS 1</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>transaction</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>TRANSACTION REQUIRED</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>determinism</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>NOT DETERMINISTIC</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>isolation</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ISOLATE</code><sup>1</sup></p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><sup>1</sup> Definition represents default value. Not included in the CREATE PROCEDURE example.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">PROCEDURE</span> trafodion.persnl.topsalesreps( <span class="keyword">IN</span> whichquarter <span class="predefined-type">INTEGER</span>
)
EXTERNAL NAME <span class="string"><span class="delimiter">'</span><span class="content">Payroll.topSalesReps</span><span class="delimiter">'</span></span>
LIBRARY trafodion.persnl.payroll
LANGUAGE JAVA
PARAMETER STYLE JAVA
DYNAMIC RESULT SETS <span class="integer">1</span>
READS SQL DATA
;</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="calling-the-procedure-topsalesreps">Calling the Procedure: TOPSALESREPS</h5>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Make sure that users who will be calling the stored procedure have
the appropriate execute privileges. For more information, see
<a href="#grant-privileges">Grant Privileges</a>.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>To invoke the TOPSALESREPS procedure in trafci:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">SQL&gt; CALL trafodion.persnl.topsalesreps( <span class="integer">1</span> ) ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The TOPSALESREPS procedure returns this information about the top five
sales representatives during the first fiscal quarter:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">EMPNUM FIRST_NAME LAST_NAME TOTAL
<span class="comment">------ --------------- -------------------- --------------------</span>
<span class="integer">227</span> XAVIER SEDLEMEYER <span class="float">172460.00</span>
<span class="integer">231</span> HERB ALBERT <span class="float">67025.00</span>
<span class="integer">222</span> MARTIN SCHAEFFER <span class="float">52000.00</span>
<span class="integer">226</span> HEIDI WEIGL <span class="float">28985.00</span>
<span class="integer">220</span> JOHN HUGHES <span class="float">22625.00</span>
<span class="comment">--- 5 row(s) selected.</span>
<span class="comment">--- SQL operation complete.</span></code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="procedures-in-the-invent-schema">10.3. Procedures in the INVENT Schema</h3>
<div class="paragraph">
<p>The Inventory class contains these SPJ methods, which are useful for
tracking parts and suppliers:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="#supplierinfo-procedure">SUPPLIERINFO Procedure</a></p>
</li>
<li>
<p><a href="#supplyquantities-procedure">SUPPLYQUANTITIES Procedure</a></p>
</li>
<li>
<p><a href="#partlocs-procedure">PARTLOCS Procedure</a></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Those methods are registered as stored procedures in the INVENT schema.
<a href="#example-13">Example 13</a> shows the code of the
<a href="resources/source/Inventory.java">Inventory.java</a> file.</p>
</div>
<div id="example-13" class="listingblock">
<div class="title">Example 13: <a href="resources/source/Inventory.java"><code>Inventory.java</code></a> - The Inventory Class</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="keyword">import</span> <span class="include">java.sql</span>.* ;
<span class="keyword">import</span> <span class="include">java.math</span>.* ;
<span class="directive">public</span> <span class="type">class</span> <span class="class">Inventory</span>
{
<span class="comment">// The SUPPLIERINFO procedure accepts a supplier number and returns the</span>
<span class="comment">// supplier's name, street, city, state, and post code to separate output</span>
<span class="comment">// parameters.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#supplierinfo-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> supplierInfo( <span class="predefined-type">BigDecimal</span> suppNum
, <span class="predefined-type">String</span><span class="type">[]</span> suppName
, <span class="predefined-type">String</span><span class="type">[]</span> streetAddr
, <span class="predefined-type">String</span><span class="type">[]</span> cityName
, <span class="predefined-type">String</span><span class="type">[]</span> stateName
, <span class="predefined-type">String</span><span class="type">[]</span> postCode
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> getSupplier =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT suppname, street, city, </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> state, postcode </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.invent.supplier </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE suppnum = ?</span><span class="delimiter">&quot;</span></span>
) ;
getSupplier.setBigDecimal( <span class="integer">1</span>, suppNum ) ;
<span class="predefined-type">ResultSet</span> rs = getSupplier.executeQuery() ;
rs.next() ;
suppName[<span class="integer">0</span>] = rs.getString( <span class="integer">1</span> ) ;
streetAddr[<span class="integer">0</span>] = rs.getString( <span class="integer">2</span> ) ;
cityName[<span class="integer">0</span>] = rs.getString( <span class="integer">3</span> ) ;
stateName[<span class="integer">0</span>] = rs.getString( <span class="integer">4</span> ) ;
postCode[<span class="integer">0</span>] = rs.getString( <span class="integer">5</span> ) ;
rs.close() ;
conn.close() ;
}
<span class="comment">// The SUPPLYQUANTITIES procedure returns the average, minimum, and maximum</span>
<span class="comment">// quantities of available parts in inventory to separate output</span>
<span class="comment">// parameters.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#supplyquantities-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> supplyQuantities( <span class="type">int</span><span class="type">[]</span> avgQty
, <span class="type">int</span><span class="type">[]</span> minQty
, <span class="type">int</span><span class="type">[]</span> maxQty
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> getQty =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT AVG(qty_on_hand), </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> MIN(qty_on_hand), </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> MAX(qty_on_hand) </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.invent.partloc</span><span class="delimiter">&quot;</span></span>
) ;
<span class="predefined-type">ResultSet</span> rs = getQty.executeQuery() ;
rs.next() ;
avgQty[<span class="integer">0</span>] = rs.getInt( <span class="integer">1</span> ) ;
minQty[<span class="integer">0</span>] = rs.getInt( <span class="integer">2</span> ) ;
maxQty[<span class="integer">0</span>] = rs.getInt( <span class="integer">3</span> ) ;
rs.close() ;
conn.close() ;
}
<span class="comment">// The PARTLOCATIONS procedure accepts a part number and quantity and returns a</span>
<span class="comment">// set of location codes that have the exact quantity and a set of location</span>
<span class="comment">// codes that have more than that quantity.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#partlocations-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> partLocations( <span class="type">int</span> partNum
, <span class="type">int</span> quantity
, <span class="predefined-type">ResultSet</span> exactly<span class="type">[]</span>
, <span class="predefined-type">ResultSet</span> moreThan<span class="type">[]</span>
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> getLocationsExact =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT L.loc_code, L.partnum, L.qty_on_hand </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.invent.partloc L </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE L.partnum = ? </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> AND L.qty_on_hand = ? </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> ORDER BY L.partnum </span><span class="delimiter">&quot;</span></span>
) ;
getLocationsExact.setInt( <span class="integer">1</span>, partNum ) ;
getLocationsExact.setInt( <span class="integer">2</span>, quantity) ;
<span class="predefined-type">PreparedStatement</span> getLocationsMoreThan =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT L.loc_code, L.partnum, L.qty_on_hand </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.invent.partloc L </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE L.partnum = ? </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> AND L.qty_on_hand &gt; ? </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">ORDER BY L.partnum </span><span class="delimiter">&quot;</span></span>
) ;
getLocationsMoreThan.setInt( <span class="integer">1</span>, partNum ) ;
getLocationsMoreThan.setInt( <span class="integer">2</span>, quantity) ;
exactly[<span class="integer">0</span>] = getLocationsExact.executeQuery() ;
moreThan[<span class="integer">0</span>] = getLocationsMoreThan.executeQuery() ;
}
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>See the following sections for more information about each SPJ method.</p>
</div>
<div style="page-break-after: always;"></div>
<div class="sect3">
<h4 id="supplierinfo-procedure">10.3.1. SUPPLIERINFO Procedure</h4>
<div class="paragraph">
<p>The SUPPLIERINFO procedure accepts a supplier number and returns the
supplier&#8217;s name, street, city, state, and post code to separate output
parameters.</p>
</div>
<div class="sect4">
<h5 id="java-method-supplierinfo">Java Method: supplierInfo()</h5>
<div class="listingblock">
<div class="title">Example 14: <a href="resources/source/supplierInfo.java"><code>supplierInfo()</code></a> Method</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// The SUPPLIERINFO procedure accepts a supplier number and returns the</span>
<span class="comment">// supplier's name, street, city, state, and post code to separate output</span>
<span class="comment">// parameters.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#supplierinfo-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> supplierInfo( <span class="predefined-type">BigDecimal</span> suppNum
, <span class="predefined-type">String</span><span class="type">[]</span> suppName
, <span class="predefined-type">String</span><span class="type">[]</span> streetAddr
, <span class="predefined-type">String</span><span class="type">[]</span> cityName
, <span class="predefined-type">String</span><span class="type">[]</span> stateName
, <span class="predefined-type">String</span><span class="type">[]</span> postCode
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> getSupplier =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT suppname, street, city, </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> state, postcode </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.invent.supplier </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE suppnum = ?</span><span class="delimiter">&quot;</span></span>
) ;
getSupplier.setBigDecimal( <span class="integer">1</span>, suppNum ) ;
<span class="predefined-type">ResultSet</span> rs = getSupplier.executeQuery() ;
rs.next() ;
suppName[<span class="integer">0</span>] = rs.getString( <span class="integer">1</span> ) ;
streetAddr[<span class="integer">0</span>] = rs.getString( <span class="integer">2</span> ) ;
cityName[<span class="integer">0</span>] = rs.getString( <span class="integer">3</span> ) ;
stateName[<span class="integer">0</span>] = rs.getString( <span class="integer">4</span> ) ;
postCode[<span class="integer">0</span>] = rs.getString( <span class="integer">5</span> ) ;
rs.close() ;
conn.close() ;
}</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="creating-the-procedure-supplierinfo">Creating the Procedure: SUPPLIERINFO</h5>
<div class="paragraph">
<p>Before creating the procedure, create a library named <code>INVENTORY</code>
in the <code>TRAFODION.INVENT</code> schema and select the <code>Inventory.jar</code> file to upload to
Trafodion for that library. For more information, see
<a href="#create-a-library">Create a Library</a>.</p>
</div>
<div class="paragraph">
<p>After creating the library, use the values listed in the table below to define and execute the
CREATE PROCEDURE command. For more information, see <a href="#create-a-procedure">Create a Procedure</a>.</p>
</div>
<table id="table-13" class="tableblock frame-all grid-all spread">
<caption class="title">Table 14. Create Procedure Settings: SUPPLIERINFO Procedure</caption>
<colgroup>
<col style="width: 19.0476%;">
<col style="width: 80.9524%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Attribute</th>
<th class="tableblock halign-left valign-top">Definition</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>procedure-ref</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>trafodion.invent.supplierinfo</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-1</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>IN suppnum NUMERIC(4)</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-2</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>OUT suppname CHARACTER(18)</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-3</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>OUT address CHARACTER(22)</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-4</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>OUT city CHARACTER(14)</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-5</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>OUT state CHARACTER(12)</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-6</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>OUT zipcode CHARACTER(10)</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external name</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">`EXTERNAL NAME 'Inventory.supplierInfo ( java.math.BigDecimal, java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[], java.lang.String[] )''</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>library</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LIBRARY trafodion.invent.inventory</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external security</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>invoker</code><sup>1</sup><br>
<br>
Choice depends on your security requirements, you can select <code>definer</code> instead.
For more information, see <a href="#understand-external-security">Understand External Security</a>.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>language java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LANGUAGE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>parameter style java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>PARAMETER STYLE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>sql access</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>READS SQL DATA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dynamic result sets</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>DYNAMIC RESULT SETS 0</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>transaction</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>TRANSACTION REQUIRED</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>determinism</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>NOT DETERMINISTIC</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>isolation</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ISOLATE</code><sup>1</sup></p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><sup>1</sup> Definition represents default value. Not included in the CREATE PROCEDURE example.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">PROCEDURE</span> trafodion.invent.supplierinfo( <span class="keyword">IN</span> suppnum NUMERIC(<span class="integer">4</span>)
, OUT suppname CHARACTER(<span class="integer">18</span>)
, OUT address CHARACTER(<span class="integer">22</span>)
, OUT city CHARACTER(<span class="integer">14</span>)
, OUT state CHARACTER(<span class="integer">12</span>)
, OUT zipcode CHARACTER(<span class="integer">10</span>)
)
EXTERNAL NAME <span class="string"><span class="delimiter">'</span><span class="content">Inventory.supplierInfo ( java.math.BigDecimal
, java.lang.String[]
, java.lang.String[]
, java.lang.String[]
, java.lang.String[]
, java.lang.String[]
)</span><span class="delimiter">'</span></span>
LIBRARY trafodion.invent.inventory
LANGUAGE JAVA
PARAMETER STYLE JAVA
READS SQL DATA
;</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="calling-the-procedure-supplierinfo">Calling the Procedure: SUPPLIERINFO</h5>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Make sure that users who will be calling the stored procedure have
the appropriate execute privileges. For more information, see
<a href="#grant-privileges">Grant Privileges</a>.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>To invoke the SUPPLIERINFO procedure in trafci:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">SQL&gt; CALL trafodion.invent.supplierinfo( <span class="integer">25</span>,<span class="error">?</span>,<span class="error">?</span>,<span class="error">?</span>,<span class="error">?</span>,<span class="error">?</span> ) ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The SUPPLIERINFO procedure accepts the supplier number 25 and returns
this output in trafci:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="text">SUPPNAME ADDRESS CITY STATE ZIPCODE
------------------ ---------------------- -------------- ------------ ---------
Schroeder's Ltd 212 Strasse Blvd West Hamburg Rhode Island 22222
--- SQL operation complete.</code></pre>
</div>
</div>
<div class="paragraph">
<p>Supplier number 25 is Schroeder&#8217;s Ltd. and is located in Hamburg, Rhode Island.</p>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
<div class="sect3">
<h4 id="supplyquantities-procedure">10.3.2. SUPPLYQUANTITIES Procedure</h4>
<div class="paragraph">
<p>The SUPPLYQUANTITIES procedure returns the average, minimum, and maximum
quantities of available parts in inventory to separate output
parameters.</p>
</div>
<div class="sect4">
<h5 id="java-method-supplyquantities">Java Method: supplyQuantities()</h5>
<div class="listingblock">
<div class="title">Example 15: <a href="resources/source/supplyQuantities.java"><code>supplyQuantities()</code></a> Method</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// The SUPPLYQUANTITIES procedure returns the average, minimum, and maximum</span>
<span class="comment">// quantities of available parts in inventory to separate output</span>
<span class="comment">// parameters.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#supplyquantities-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> supplyQuantities( <span class="type">int</span><span class="type">[]</span> avgQty
, <span class="type">int</span><span class="type">[]</span> minQty
, <span class="type">int</span><span class="type">[]</span> maxQty
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> getQty =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT AVG(qty_on_hand), </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> MIN(qty_on_hand), </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> MAX(qty_on_hand) </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.invent.partloc</span><span class="delimiter">&quot;</span></span>
) ;
<span class="predefined-type">ResultSet</span> rs = getQty.executeQuery() ;
rs.next() ;
avgQty[<span class="integer">0</span>] = rs.getInt( <span class="integer">1</span> ) ;
minQty[<span class="integer">0</span>] = rs.getInt( <span class="integer">2</span> ) ;
maxQty[<span class="integer">0</span>] = rs.getInt( <span class="integer">3</span> ) ;
rs.close() ;
conn.close() ;
}</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="creating-the-procedure-supplyquantities">Creating the Procedure: SUPPLYQUANTITIES</h5>
<div class="paragraph">
<p>Before creating the procedure, create a library named <code>INVENTORY</code>
in the <code>TRAFODION.INVENT</code> schema and select the <code>Inventory.jar</code> file to upload to
Trafodion for that library. For more information, see
<a href="#create-a-library">Create a Library</a>.</p>
</div>
<div class="paragraph">
<p>After creating the library, use the values listed in the table below to define and execute the
CREATE PROCEDURE command. For more information, see <a href="#create-a-procedure">Create a Procedure</a>.</p>
</div>
<table id="table-14" class="tableblock frame-all grid-all spread">
<caption class="title">Table 15. Create Procedure Settings: SUPPLYQUANTITIES Procedure</caption>
<colgroup>
<col style="width: 19.0476%;">
<col style="width: 80.9524%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Attribute</th>
<th class="tableblock halign-left valign-top">Definition</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>procedure-ref</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>trafodion.invent.supplyquantities</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-1</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>OUT avrg INT</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-2</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>OUT minm INT</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-3</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>OUT maxm INT</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external name</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>EXTERNAL NAME 'Inventory.supplyQuantities'</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>library</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LIBRARY trafodion.invent.inventory</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external security</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>invoker</code><sup>1</sup><br>
<br>
Choice depends on your security requirements, you can select <code>definer</code> instead.
For more information, see <a href="#understand-external-security">Understand External Security</a>.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>language java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LANGUAGE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>parameter style java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>PARAMETER STYLE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>sql access</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>READS SQL DATA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dynamic result sets</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>DYNAMIC RESULT SETS 0</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>transaction</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>TRANSACTION REQUIRED</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>determinism</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>NOT DETERMINISTIC</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>isolation</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ISOLATE</code><sup>1</sup></p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><sup>1</sup> Definition represents default value. Not included in the CREATE PROCEDURE example.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">PROCEDURE</span> trafodion.invent.supplyquantities( OUT avrg <span class="predefined-type">INT</span>
, OUT minm <span class="predefined-type">INT</span>
, OUT maxm <span class="predefined-type">INT</span>
)
EXTERNAL NAME <span class="string"><span class="delimiter">'</span><span class="content">Inventory.supplyQuantities</span><span class="delimiter">'</span></span>
LIBRARY trafodion.invent.inventory
LANGUAGE JAVA
PARAMETER STYLE JAVA
READS SQL DATA
;</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="calling-the-procedure-supplyquantities">Calling the Procedure: SUPPLYQUANTITIES</h5>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Make sure that users who will be calling the stored procedure have
the appropriate execute privileges. For more information, see
<a href="#grant-privileges">Grant Privileges</a>.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>To invoke the SUPPLYQUANTITIES procedure in trafci:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">SQL&gt; CALL trafodion.invent.supplyquantities( <span class="error">?</span>,<span class="error">?</span>,<span class="error">?</span> ) ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The SUPPLYQUANTITIES procedure returns this output in trafci:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">AVRG MINM MAXM
<span class="comment">----------- ----------- -----------</span>
<span class="integer">167</span> <span class="integer">0</span> <span class="integer">1132</span>
<span class="comment">--- SQL operation complete.</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The average number of items in inventory is 167, the minimum number is
0, and the maximum number is 1132.</p>
</div>
<div style="page-break-after: always;"></div>
</div>
</div>
<div class="sect3">
<h4 id="partlocations-procedure">10.3.3. PARTLOCATIONS Procedure</h4>
<div class="paragraph">
<p>The PARTLOCATIONS procedure accepts a part number and quantity and returns a
set of location codes that have the exact quantity and a set of location
codes that have more than that quantity.</p>
</div>
<div style="page-break-after: always;"></div>
<div class="sect4">
<h5 id="java-method-partlocations">Java Method: partLocations()</h5>
<div class="listingblock">
<div class="title">Example 16: <a href="resources/source/partLocations.java"><code>partLocations()</code></a> Method</div>
<div class="content">
<pre class="CodeRay highlight"><code data-lang="java"><span class="comment">// The PARTLOCATIONS procedure accepts a part number and quantity and returns a</span>
<span class="comment">// set of location codes that have the exact quantity and a set of location</span>
<span class="comment">// codes that have more than that quantity.</span>
<span class="comment">//</span>
<span class="comment">// See http://trafodion.apache.org/docs/spj_guide/index.html#partlocations-procedure</span>
<span class="comment">// for more documentation.</span>
<span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> partLocations( <span class="type">int</span> partNum
, <span class="type">int</span> quantity
, <span class="predefined-type">ResultSet</span> exactly<span class="type">[]</span>
, <span class="predefined-type">ResultSet</span> moreThan<span class="type">[]</span>
) <span class="directive">throws</span> <span class="exception">SQLException</span>
{
<span class="predefined-type">Connection</span> conn =
<span class="predefined-type">DriverManager</span>.getConnection( <span class="string"><span class="delimiter">&quot;</span><span class="content">jdbc:default:connection</span><span class="delimiter">&quot;</span></span> ) ;
<span class="predefined-type">PreparedStatement</span> getLocationsExact =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT L.loc_code, L.partnum, L.qty_on_hand </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.invent.partloc L </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE L.partnum = ? </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> AND L.qty_on_hand = ? </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> ORDER BY L.partnum </span><span class="delimiter">&quot;</span></span>
) ;
getLocationsExact.setInt( <span class="integer">1</span>, partNum ) ;
getLocationsExact.setInt( <span class="integer">2</span>, quantity) ;
<span class="predefined-type">PreparedStatement</span> getLocationsMoreThan =
conn.prepareStatement( <span class="string"><span class="delimiter">&quot;</span><span class="content">SELECT L.loc_code, L.partnum, L.qty_on_hand </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">FROM trafodion.invent.partloc L </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">WHERE L.partnum = ? </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content"> AND L.qty_on_hand &gt; ? </span><span class="delimiter">&quot;</span></span>
+ <span class="string"><span class="delimiter">&quot;</span><span class="content">ORDER BY L.partnum </span><span class="delimiter">&quot;</span></span>
) ;
getLocationsMoreThan.setInt( <span class="integer">1</span>, partNum ) ;
getLocationsMoreThan.setInt( <span class="integer">2</span>, quantity) ;
exactly[<span class="integer">0</span>] = getLocationsExact.executeQuery() ;
moreThan[<span class="integer">0</span>] = getLocationsMoreThan.executeQuery() ;
}</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="creating-the-procedure-partlocs">Creating the Procedure: PARTLOCS</h5>
<div class="paragraph">
<p>Before creating the procedure, create a library named <code>INVENTORY</code>
in the <code>TRAFODION.INVENT</code> schema and select the <code>Inventory.jar</code> file to upload to
Trafodion for that library. For more information, see
<a href="#create-a-library">Create a Library</a>.</p>
</div>
<div class="paragraph">
<p>After creating the library, use the values listed in the table below to define and execute the
CREATE PROCEDURE command. For more information, see <a href="#create-a-procedure">Create a Procedure</a>.</p>
</div>
<table id="table-15" class="tableblock frame-all grid-all spread">
<caption class="title">Table 16. Create Procedure Settings: PARTLOCS Procedure</caption>
<colgroup>
<col style="width: 19.0476%;">
<col style="width: 80.9524%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Attribute</th>
<th class="tableblock halign-left valign-top">Definition</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>procedure-ref</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>trafodion.invent.partlocs</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-1</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>IN partnum INT</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>sql-parameter-2</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>IN qty INT</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external name</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>EXTERNAL NAME 'Inventory.partLocations'</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>library</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LIBRARY trafodion.invent.inventory</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>external security</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>invoker</code><sup>1</sup><br>
<br>
Choice depends on your security requirements, you can select <code>definer</code> instead.
For more information, see <a href="#understand-external-security">Understand External Security</a>.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>language java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>LANGUAGE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>parameter style java</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>PARAMETER STYLE JAVA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>sql access</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>READS SQL DATA</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong>dynamic result sets</strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>DYNAMIC RESULT SETS 2</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>transaction</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>TRANSACTION REQUIRED</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>determinism</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>NOT DETERMINISTIC</code><sup>1</sup></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><strong><em>isolation</em></strong></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ISOLATE</code><sup>1</sup></p></td>
</tr>
</tbody>
</table>
<div class="paragraph">
<p><sup>1</sup> Definition represents default value. Not included in the CREATE PROCEDURE example.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">PROCEDURE</span> trafodion.invent.partlocs( <span class="keyword">IN</span> partnum <span class="predefined-type">INT</span>
, <span class="keyword">IN</span> qty <span class="predefined-type">INT</span>
)
EXTERNAL NAME <span class="string"><span class="delimiter">'</span><span class="content">Inventory.partLocations</span><span class="delimiter">'</span></span>
LIBRARY trafodion.invent.inventory
LANGUAGE JAVA
PARAMETER STYLE JAVA
DYNAMIC RESULT SETS <span class="integer">2</span>
READS SQL DATA
;</code></pre>
</div>
</div>
<div style="page-break-after: always;"></div>
</div>
<div class="sect4">
<h5 id="calling-the-procedure-partlocs">Calling the Procedure: PARTLOCS</h5>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Make sure that users who will be calling the stored procedure have
the appropriate execute privileges. For more information, see
<a href="#grant-privileges">Grant Privileges</a>.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>To invoke the PARTLOCS procedure in trafci:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">SQL&gt; CALL trafodion.invent.partlocs( <span class="integer">212</span>, <span class="integer">18</span> ) ;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The PARTLOCS procedure accepts the part number 212 and returns a set of
locations that have 18 of those parts and a set of locations that have
more than 18 of those parts:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql">LOC_CODE PARTNUM QTY_ON_HAND
<span class="comment">-------- ------- -----------</span>
G87 <span class="integer">212</span> <span class="integer">20</span>
<span class="comment">--- 1 row(s) selected.</span>
LOC_CODE PARTNUM QTY_ON_HAND
<span class="comment">-------- ------- -----------</span>
G87 <span class="integer">212</span> <span class="integer">20</span>
<span class="comment">--- 1 row(s) selected.</span>
<span class="comment">--- SQL operation complete.</span></code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="b-sample-database">11. B Sample Database</h2>
<div class="sectionbody">
<div class="paragraph">
<p>This appendix presents the Sample Database schemas and tables on which
the SPJs in this manual operate:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="#persnl-schema">PERSNL Schema</a></p>
<div class="ulist">
<ul>
<li>
<p><a href="#job-table">JOB Table</a></p>
</li>
<li>
<p><a href="#employee-table">EMPLOYEE Table</a></p>
</li>
<li>
<p><a href="#dept-table">DEPT Table</a></p>
</li>
<li>
<p><a href="#project-table">PROJECT Table</a></p>
</li>
</ul>
</div>
</li>
<li>
<p><a href="#sales-schema">SALES Schema</a></p>
<div class="ulist">
<ul>
<li>
<p><a href="#customer-table">CUSTOMER Table</a></p>
</li>
<li>
<p><a href="#orders-table">ORDERS Table</a></p>
</li>
<li>
<p><a href="#odetail-table">ODETAIL Table</a></p>
</li>
<li>
<p><a href="#parts-table">PARTS Table</a></p>
</li>
</ul>
</div>
</li>
<li>
<p><a href="#invent-schema">INVENT Schema</a></p>
<div class="ulist">
<ul>
<li>
<p><a href="#supplier-table">SUPPLIER Table</a></p>
</li>
<li>
<p><a href="#partsupp-table">PARTSUPP Table</a></p>
</li>
<li>
<p><a href="#partloc-table">PARTLOC Table</a></p>
</li>
</ul>
</div>
</li>
</ul>
</div>
<div class="paragraph">
<p>Click on the link for the schema or table name to download the definition file.</p>
</div>
<div class="sect2">
<h3 id="persnl-schema">11.1. PERSNL Schema</h3>
<div class="paragraph">
<p>The <a href="resources/source/persnl_schema.sql"><code>PERSNL</code> schema</a> stores employee data.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> SCHEMA trafodion.persnl ;
<span class="class">SET</span> SCHEMA trafodion.persnl ;</code></pre>
</div>
</div>
<div class="sect3">
<h4 id="job-table">11.1.1. JOB Table</h4>
<div class="paragraph">
<p>The <a href="resources/source/persnl_job_table.sql"><code>JOB</code> table</a> maps job codes to job descriptions.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">TABLE</span> trafodion.persnl.job
( jobcode NUMERIC (<span class="integer">4</span>) <span class="predefined-type">UNSIGNED</span> NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, jobdesc <span class="predefined-type">VARCHAR</span> (<span class="integer">18</span>) <span class="directive">DEFAULT</span> <span class="string"><span class="delimiter">'</span><span class="content"> </span><span class="delimiter">'</span></span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, <span class="directive">PRIMARY</span> <span class="type">KEY</span> ( jobcode )
) ;
<span class="class">INSERT</span> <span class="class">INTO</span> trafodion.persnl.job <span class="keyword">VALUES</span>
( <span class="integer">100</span>, <span class="string"><span class="delimiter">'</span><span class="content">MANAGER</span><span class="delimiter">'</span></span> )
, ( <span class="integer">200</span>, <span class="string"><span class="delimiter">'</span><span class="content">PRODUCTION SUPV</span><span class="delimiter">'</span></span> )
, ( <span class="integer">250</span>, <span class="string"><span class="delimiter">'</span><span class="content">ASSEMBLER</span><span class="delimiter">'</span></span> )
, ( <span class="integer">300</span>, <span class="string"><span class="delimiter">'</span><span class="content">SALESREP</span><span class="delimiter">'</span></span> )
, ( <span class="integer">400</span>, <span class="string"><span class="delimiter">'</span><span class="content">SYSTEM ANALYST</span><span class="delimiter">'</span></span> )
, ( <span class="integer">420</span>, <span class="string"><span class="delimiter">'</span><span class="content">ENGINEER</span><span class="delimiter">'</span></span> )
, ( <span class="integer">450</span>, <span class="string"><span class="delimiter">'</span><span class="content">PROGRAMMER</span><span class="delimiter">'</span></span> )
, ( <span class="integer">500</span>, <span class="string"><span class="delimiter">'</span><span class="content">ACCOUNTANT</span><span class="delimiter">'</span></span> )
, ( <span class="integer">600</span>, <span class="string"><span class="delimiter">'</span><span class="content">ADMINISTRATOR</span><span class="delimiter">'</span></span> )
, ( <span class="integer">900</span>, <span class="string"><span class="delimiter">'</span><span class="content">SECRETARY</span><span class="delimiter">'</span></span> )
;
<span class="class">UPDATE</span> STATISTICS <span class="keyword">FOR</span> <span class="type">TABLE</span> trafodion.persnl.job <span class="keyword">ON</span> EVERY <span class="type">COLUMN</span> ;</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="employee-table">11.1.2. EMPLOYEE Table</h4>
<div class="paragraph">
<p>The <a href="resources/source/persnl_employee_table.sql"><code>EMPLOYEE</code> table</a> maps records employee information.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">TABLE</span> trafodion.persnl.employee
( empnum NUMERIC (<span class="integer">4</span>) <span class="predefined-type">UNSIGNED</span> NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, first_name CHARACTER (<span class="integer">15</span>) <span class="directive">DEFAULT</span> <span class="string"><span class="delimiter">'</span><span class="content"> </span><span class="delimiter">'</span></span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, last_name CHARACTER (<span class="integer">20</span>) <span class="directive">DEFAULT</span> <span class="string"><span class="delimiter">'</span><span class="content"> </span><span class="delimiter">'</span></span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, deptnum NUMERIC (<span class="integer">4</span>) <span class="predefined-type">UNSIGNED</span> NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, jobcode NUMERIC (<span class="integer">4</span>) <span class="predefined-type">UNSIGNED</span> <span class="directive">DEFAULT</span> <span class="predefined-constant">NULL</span>
, salary NUMERIC (<span class="integer">8</span>, <span class="integer">2</span>) <span class="predefined-type">UNSIGNED</span> <span class="directive">DEFAULT</span> <span class="predefined-constant">NULL</span>
, <span class="directive">PRIMARY</span> <span class="type">KEY</span> ( empnum )
) ;
<span class="class">ALTER</span> <span class="type">TABLE</span> trafodion.persnl.employee
<span class="class">ADD</span> <span class="type">CONSTRAINT</span> empnum_constrnt <span class="keyword">CHECK</span> ( empnum <span class="keyword">BETWEEN</span> <span class="octal">0001</span> <span class="keyword">AND</span> <span class="integer">9999</span> )
;
<span class="class">CREATE</span> <span class="type">INDEX</span> xempname <span class="keyword">ON</span> employee
( last_name
, first_name
) ;
<span class="class">CREATE</span> <span class="type">INDEX</span> xempdept <span class="keyword">ON</span> employee
( deptnum
) ;
<span class="class">CREATE</span> <span class="type">VIEW</span> trafodion.persnl.emplist <span class="keyword">AS</span>
<span class="class">SELECT</span>
empnum
, first_name
, last_name
, deptnum
, jobcode
<span class="keyword">FROM</span> employee
;
<span class="class">INSERT</span> <span class="class">INTO</span> trafodion.persnl.employee <span class="keyword">VALUES</span>
( <span class="integer">1</span>, <span class="string"><span class="delimiter">'</span><span class="content">ROGER</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">GREEN</span><span class="delimiter">'</span></span>, <span class="integer">9000</span>, <span class="integer">100</span>, <span class="float">175500.00</span> )
, ( <span class="integer">23</span>, <span class="string"><span class="delimiter">'</span><span class="content">JERRY</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">HOWARD</span><span class="delimiter">'</span></span>, <span class="integer">1000</span>, <span class="integer">100</span>, <span class="float">137000.10</span> )
, ( <span class="integer">29</span>, <span class="string"><span class="delimiter">'</span><span class="content">JANE</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">RAYMOND</span><span class="delimiter">'</span></span>, <span class="integer">3000</span>, <span class="integer">100</span>, <span class="float">136000.00</span> )
, ( <span class="integer">32</span>, <span class="string"><span class="delimiter">'</span><span class="content">THOMAS</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">RUDLOFF</span><span class="delimiter">'</span></span>, <span class="integer">2000</span>, <span class="integer">100</span>, <span class="float">138000.40</span> )
, ( <span class="integer">39</span>, <span class="string"><span class="delimiter">'</span><span class="content">KLAUS </span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">SAFFERT</span><span class="delimiter">'</span></span>, <span class="integer">3200</span>, <span class="integer">100</span>, <span class="float">75000.00</span> )
, ( <span class="integer">43</span>, <span class="string"><span class="delimiter">'</span><span class="content">PAUL</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">WINTER</span><span class="delimiter">'</span></span>, <span class="integer">3100</span>, <span class="integer">100</span>, <span class="float">90000.00</span> )
, ( <span class="integer">65</span>, <span class="string"><span class="delimiter">'</span><span class="content">RACHEL</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">MCKAY</span><span class="delimiter">'</span></span>, <span class="integer">4000</span>, <span class="integer">100</span>, <span class="float">118000.00</span> )
, ( <span class="integer">72</span>, <span class="string"><span class="delimiter">'</span><span class="content">GLENN</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">THOMAS</span><span class="delimiter">'</span></span>, <span class="integer">3300</span>, <span class="integer">100</span>, <span class="float">80000.00</span> )
, ( <span class="integer">75</span>, <span class="string"><span class="delimiter">'</span><span class="content">TIM</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">WALKER</span><span class="delimiter">'</span></span>, <span class="integer">3000</span>, <span class="integer">300</span>, <span class="float">32000.00</span> )
, ( <span class="integer">87</span>, <span class="string"><span class="delimiter">'</span><span class="content">ERIC</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">BROWN</span><span class="delimiter">'</span></span>, <span class="integer">4000</span>, <span class="integer">400</span>, <span class="float">89000.00</span> )
, ( <span class="integer">89</span>, <span class="string"><span class="delimiter">'</span><span class="content">PETER</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">SMITH</span><span class="delimiter">'</span></span>, <span class="integer">3300</span>, <span class="integer">300</span>, <span class="float">37000.40</span> )
, ( <span class="integer">93</span>, <span class="string"><span class="delimiter">'</span><span class="content">DONALD</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">TAYLOR</span><span class="delimiter">'</span></span>, <span class="integer">3100</span>, <span class="integer">300</span>, <span class="float">33000.00</span> )
, ( <span class="integer">104</span>, <span class="string"><span class="delimiter">'</span><span class="content">DAVID</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">STRAND</span><span class="delimiter">'</span></span>, <span class="integer">4000</span>, <span class="integer">400</span>, <span class="float">69000.00</span> )
, ( <span class="integer">109</span>, <span class="string"><span class="delimiter">'</span><span class="content">STEVE</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">COOK</span><span class="delimiter">'</span></span>, <span class="integer">4000</span>, <span class="integer">400</span>, <span class="float">68000.00</span> )
, ( <span class="integer">111</span>, <span class="string"><span class="delimiter">'</span><span class="content">SHERRIE</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">WONG</span><span class="delimiter">'</span></span>, <span class="integer">3500</span>, <span class="integer">100</span>, <span class="float">70000.00</span> )
, ( <span class="integer">178</span>, <span class="string"><span class="delimiter">'</span><span class="content">JOHN</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">CHOU</span><span class="delimiter">'</span></span>, <span class="integer">3500</span>, <span class="integer">900</span>, <span class="float">28000.00</span> )
, ( <span class="integer">180</span>, <span class="string"><span class="delimiter">'</span><span class="content">MANFRED</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">CONRAD</span><span class="delimiter">'</span></span>, <span class="integer">4000</span>, <span class="integer">450</span>, <span class="float">32000.00</span> )
, ( <span class="integer">201</span>, <span class="string"><span class="delimiter">'</span><span class="content">JIM</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">HERMAN</span><span class="delimiter">'</span></span>, <span class="integer">3000</span>, <span class="integer">300</span>, <span class="float">19000.00</span> )
, ( <span class="integer">202</span>, <span class="string"><span class="delimiter">'</span><span class="content">LARRY</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">CLARK</span><span class="delimiter">'</span></span>, <span class="integer">1000</span>, <span class="integer">500</span>, <span class="float">25000.75</span> )
, ( <span class="integer">203</span>, <span class="string"><span class="delimiter">'</span><span class="content">KATHRYN</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">HALL</span><span class="delimiter">'</span></span>, <span class="integer">4000</span>, <span class="integer">400</span>, <span class="float">96000.00</span> )
, ( <span class="integer">205</span>, <span class="string"><span class="delimiter">'</span><span class="content">GINNY</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">FOSTER</span><span class="delimiter">'</span></span>, <span class="integer">3300</span>, <span class="integer">900</span>, <span class="float">30000.00</span> )
, ( <span class="integer">206</span>, <span class="string"><span class="delimiter">'</span><span class="content">DAVE</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">FISHER</span><span class="delimiter">'</span></span>, <span class="integer">3200</span>, <span class="integer">900</span>, <span class="float">25000.00</span> )
, ( <span class="integer">207</span>, <span class="string"><span class="delimiter">'</span><span class="content">MARK</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">FOLEY</span><span class="delimiter">'</span></span>, <span class="integer">4000</span>, <span class="integer">420</span>, <span class="float">33000.00</span> )
, ( <span class="integer">208</span>, <span class="string"><span class="delimiter">'</span><span class="content">SUE</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">CRAMER</span><span class="delimiter">'</span></span>, <span class="integer">1000</span>, <span class="integer">900</span>, <span class="float">19000.00</span> )
, ( <span class="integer">209</span>, <span class="string"><span class="delimiter">'</span><span class="content">SUSAN</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">CHAPMAN</span><span class="delimiter">'</span></span>, <span class="integer">1500</span>, <span class="integer">900</span>, <span class="float">17000.00</span> )
, ( <span class="integer">210</span>, <span class="string"><span class="delimiter">'</span><span class="content">RICHARD</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">BARTON</span><span class="delimiter">'</span></span>, <span class="integer">1000</span>, <span class="integer">500</span>, <span class="float">29000.00</span> )
, ( <span class="integer">211</span>, <span class="string"><span class="delimiter">'</span><span class="content">JIMMY</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">SCHNEIDER</span><span class="delimiter">'</span></span>, <span class="integer">1500</span>, <span class="integer">600</span>, <span class="float">26000.00</span> )
, ( <span class="integer">212</span>, <span class="string"><span class="delimiter">'</span><span class="content">JONATHAN</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">MITCHELL</span><span class="delimiter">'</span></span>, <span class="integer">1500</span>, <span class="integer">600</span>, <span class="float">32000.00</span> )
, ( <span class="integer">213</span>, <span class="string"><span class="delimiter">'</span><span class="content">ROBERT</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">WHITE</span><span class="delimiter">'</span></span>, <span class="integer">1500</span>, <span class="integer">100</span>, <span class="float">90000.00</span> )
, ( <span class="integer">214</span>, <span class="string"><span class="delimiter">'</span><span class="content">JULIA</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">KELLY</span><span class="delimiter">'</span></span>, <span class="integer">1000</span>, <span class="integer">500</span>, <span class="float">50000.00</span> )
, ( <span class="integer">215</span>, <span class="string"><span class="delimiter">'</span><span class="content">WALTER</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">LANCASTER</span><span class="delimiter">'</span></span>, <span class="integer">4000</span>, <span class="integer">450</span>, <span class="float">33000.50</span> )
, ( <span class="integer">216</span>, <span class="string"><span class="delimiter">'</span><span class="content">JOHN</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">JONES</span><span class="delimiter">'</span></span>, <span class="integer">4000</span>, <span class="integer">450</span>, <span class="float">40000.00</span> )
, ( <span class="integer">217</span>, <span class="string"><span class="delimiter">'</span><span class="content">MARLENE</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">BONNY</span><span class="delimiter">'</span></span>, <span class="integer">4000</span>, <span class="integer">900</span>, <span class="float">24000.90</span> )
, ( <span class="integer">218</span>, <span class="string"><span class="delimiter">'</span><span class="content">GEORGE</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">FRENCHMAN</span><span class="delimiter">'</span></span>, <span class="integer">4000</span>, <span class="integer">420</span>, <span class="float">36000.00</span> )
, ( <span class="integer">219</span>, <span class="string"><span class="delimiter">'</span><span class="content">DAVID</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">TERRY</span><span class="delimiter">'</span></span>, <span class="integer">2000</span>, <span class="integer">250</span>, <span class="float">27000.12</span> )
, ( <span class="integer">220</span>, <span class="string"><span class="delimiter">'</span><span class="content">JOHN</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">HUGHES</span><span class="delimiter">'</span></span>, <span class="integer">3200</span>, <span class="integer">300</span>, <span class="float">33000.10</span> )
, ( <span class="integer">221</span>, <span class="string"><span class="delimiter">'</span><span class="content">OTTO</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">SCHNABL</span><span class="delimiter">'</span></span>, <span class="integer">3200</span>, <span class="integer">300</span>, <span class="float">33000.00</span> )
, ( <span class="integer">222</span>, <span class="string"><span class="delimiter">'</span><span class="content">MARTIN</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">SCHAEFFER</span><span class="delimiter">'</span></span>, <span class="integer">3200</span>, <span class="integer">300</span>, <span class="float">31000.00</span> )
, ( <span class="integer">223</span>, <span class="string"><span class="delimiter">'</span><span class="content">HERBERT</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">KARAJAN</span><span class="delimiter">'</span></span>, <span class="integer">3200</span>, <span class="integer">300</span>, <span class="float">29000.00</span> )
, ( <span class="integer">224</span>, <span class="string"><span class="delimiter">'</span><span class="content">MARIA</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">JOSEF</span><span class="delimiter">'</span></span>, <span class="integer">4000</span>, <span class="integer">420</span>, <span class="float">18000.10</span> )
, ( <span class="integer">225</span>, <span class="string"><span class="delimiter">'</span><span class="content">KARL</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">HELMSTED</span><span class="delimiter">'</span></span>, <span class="integer">4000</span>, <span class="integer">450</span>, <span class="float">32000.00</span> )
, ( <span class="integer">226</span>, <span class="string"><span class="delimiter">'</span><span class="content">HEIDI</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">WEIGL</span><span class="delimiter">'</span></span>, <span class="integer">3200</span>, <span class="integer">300</span>, <span class="float">22000.00</span> )
, ( <span class="integer">227</span>, <span class="string"><span class="delimiter">'</span><span class="content">XAVIER</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">SEDLEMEYER</span><span class="delimiter">'</span></span>, <span class="integer">3300</span>, <span class="integer">300</span>, <span class="float">30000.00</span> )
, ( <span class="integer">228</span>, <span class="string"><span class="delimiter">'</span><span class="content">PETE</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">WELLINGTON</span><span class="delimiter">'</span></span>, <span class="integer">3100</span>, <span class="integer">300</span>, <span class="float">32000.20</span> )
, ( <span class="integer">229</span>, <span class="string"><span class="delimiter">'</span><span class="content">GEORGE</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">STRICKER</span><span class="delimiter">'</span></span>, <span class="integer">3100</span>, <span class="integer">300</span>, <span class="float">32222.00</span> )
, ( <span class="integer">230</span>, <span class="string"><span class="delimiter">'</span><span class="content">ROCKY</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">LEWIS</span><span class="delimiter">'</span></span>, <span class="integer">2000</span>, <span class="integer">200</span>, <span class="float">24000.00</span> )
, ( <span class="integer">231</span>, <span class="string"><span class="delimiter">'</span><span class="content">HERB</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">ALBERT</span><span class="delimiter">'</span></span>, <span class="integer">3300</span>, <span class="integer">300</span>, <span class="float">33000.00</span> )
, ( <span class="integer">232</span>, <span class="string"><span class="delimiter">'</span><span class="content">THOMAS</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">SPINNER</span><span class="delimiter">'</span></span>, <span class="integer">4000</span>, <span class="integer">450</span>, <span class="float">45000.00</span> )
, ( <span class="integer">233</span>, <span class="string"><span class="delimiter">'</span><span class="content">TED</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">MCDONALD</span><span class="delimiter">'</span></span>, <span class="integer">2000</span>, <span class="integer">250</span>, <span class="float">29000.00</span> )
, ( <span class="integer">234</span>, <span class="string"><span class="delimiter">'</span><span class="content">MARY</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">MILLER</span><span class="delimiter">'</span></span>, <span class="integer">2500</span>, <span class="integer">100</span>, <span class="float">56000.00</span> )
, ( <span class="integer">235</span>, <span class="string"><span class="delimiter">'</span><span class="content">MIRIAM</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">KING</span><span class="delimiter">'</span></span>, <span class="integer">2500</span>, <span class="integer">900</span>, <span class="float">18000.00</span> )
, ( <span class="integer">321</span>, <span class="string"><span class="delimiter">'</span><span class="content">BILL</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">WINN</span><span class="delimiter">'</span></span>, <span class="integer">2000</span>, <span class="integer">900</span>, <span class="float">32000.00</span> )
, ( <span class="integer">337</span>, <span class="string"><span class="delimiter">'</span><span class="content">DINAH</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">CLARK</span><span class="delimiter">'</span></span>, <span class="integer">9000</span>, <span class="integer">900</span>, <span class="float">37000.00</span> )
, ( <span class="integer">343</span>, <span class="string"><span class="delimiter">'</span><span class="content">ALAN</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">TERRY</span><span class="delimiter">'</span></span>, <span class="integer">3000</span>, <span class="integer">900</span>, <span class="float">39500.00</span> )
, ( <span class="integer">557</span>, <span class="string"><span class="delimiter">'</span><span class="content">BEN</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">HENDERSON</span><span class="delimiter">'</span></span>, <span class="integer">4000</span>, <span class="integer">400</span>, <span class="float">65000.00</span> )
, ( <span class="integer">568</span>, <span class="string"><span class="delimiter">'</span><span class="content">JESSICA</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">CRINER</span><span class="delimiter">'</span></span>, <span class="integer">3500</span>, <span class="integer">300</span>, <span class="float">39500.00</span> )
, ( <span class="integer">990</span>, <span class="string"><span class="delimiter">'</span><span class="content">THOMAS</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">STIBBS</span><span class="delimiter">'</span></span>, <span class="integer">3500</span>, <span class="predefined-constant">NULL</span>, <span class="predefined-constant">NULL</span> )
, ( <span class="integer">991</span>, <span class="string"><span class="delimiter">'</span><span class="content">WAYNE</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">O''NEIL</span><span class="delimiter">'</span></span>, <span class="integer">3500</span>, <span class="predefined-constant">NULL</span>, <span class="predefined-constant">NULL</span> )
, ( <span class="integer">992</span>, <span class="string"><span class="delimiter">'</span><span class="content">BARRY</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">KINNEY</span><span class="delimiter">'</span></span>, <span class="integer">3500</span>, <span class="predefined-constant">NULL</span>, <span class="predefined-constant">NULL</span> )
, ( <span class="integer">993</span>, <span class="string"><span class="delimiter">'</span><span class="content">PAUL</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">BUSKETT</span><span class="delimiter">'</span></span>, <span class="integer">3100</span>, <span class="predefined-constant">NULL</span>, <span class="predefined-constant">NULL</span> )
, ( <span class="integer">994</span>, <span class="string"><span class="delimiter">'</span><span class="content">EMMY</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">BUSKETT</span><span class="delimiter">'</span></span>, <span class="integer">3100</span>, <span class="predefined-constant">NULL</span>, <span class="predefined-constant">NULL</span> )
, ( <span class="integer">995</span>, <span class="string"><span class="delimiter">'</span><span class="content">WALT</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">FARLEY</span><span class="delimiter">'</span></span>, <span class="integer">3100</span>, <span class="predefined-constant">NULL</span>, <span class="predefined-constant">NULL</span> )
;
<span class="class">UPDATE</span> STATISTICS <span class="keyword">FOR</span> <span class="type">TABLE</span> trafodion.persnl.employee <span class="keyword">ON</span> EVERY <span class="type">COLUMN</span> ;</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="dept-table">11.1.3. DEPT Table</h4>
<div class="paragraph">
<p>The <a href="resources/source/persnl_dept_table.sql"><code>DEPT</code> table</a> maps records department information.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">TABLE</span> trafodion.persnl.dept
( deptnum NUMERIC (<span class="integer">4</span>) <span class="predefined-type">UNSIGNED</span> NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, deptname CHARACTER (<span class="integer">12</span>) NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, manager NUMERIC (<span class="integer">4</span>) <span class="predefined-type">UNSIGNED</span> NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, rptdept NUMERIC (<span class="integer">4</span>) <span class="predefined-type">UNSIGNED</span> <span class="directive">DEFAULT</span> <span class="integer">0</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, location <span class="predefined-type">VARCHAR</span> (<span class="integer">18</span>) <span class="directive">DEFAULT</span> <span class="string"><span class="delimiter">'</span><span class="content"> </span><span class="delimiter">'</span></span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, <span class="directive">PRIMARY</span> <span class="type">KEY</span> ( deptnum )
) ;
<span class="class">CREATE</span> <span class="type">INDEX</span> xdeptmgr <span class="keyword">ON</span> dept
( manager
) ;
<span class="class">CREATE</span> <span class="type">INDEX</span> xdeptrpt <span class="keyword">ON</span> dept
( rptdept
) ;
<span class="class">ALTER</span> <span class="type">TABLE</span> trafodion.persnl.dept
<span class="class">ADD</span> <span class="type">CONSTRAINT</span> mgrnum_constrnt
<span class="keyword">CHECK</span> (manager <span class="keyword">BETWEEN</span> <span class="octal">0000</span> <span class="keyword">AND</span> <span class="integer">9999</span>)
;
<span class="class">ALTER</span> <span class="type">TABLE</span> trafodion.persnl.dept
<span class="class">ADD</span> <span class="type">CONSTRAINT</span> deptnum_constrnt
<span class="keyword">CHECK</span> ( deptnum <span class="keyword">IN</span>
( <span class="integer">1000</span>
, <span class="integer">1500</span>
, <span class="integer">2000</span>
, <span class="integer">2500</span>
, <span class="integer">3000</span>
, <span class="integer">3100</span>
, <span class="integer">3200</span>
, <span class="integer">3300</span>
, <span class="integer">3500</span>
, <span class="integer">4000</span>
, <span class="integer">4100</span>
, <span class="integer">9000</span>
)
)
;
<span class="integer">3</span>
<span class="class">CREATE</span> <span class="type">VIEW</span> trafodion.persnl.mgrlist
( first_name
, last_name
, department
)
<span class="keyword">AS</span> <span class="class">SELECT</span>
first_name
, last_name
, deptname
<span class="keyword">FROM</span> dept, employee
<span class="keyword">WHERE</span> dept.manager = employee.empnum
;
<span class="class">INSERT</span> <span class="class">INTO</span> trafodion.persnl.dept <span class="keyword">VALUES</span>
( <span class="integer">1000</span>, <span class="string"><span class="delimiter">'</span><span class="content">FINANCE</span><span class="delimiter">'</span></span>, <span class="integer">23</span>, <span class="integer">9000</span>, <span class="string"><span class="delimiter">'</span><span class="content">CHICAGO</span><span class="delimiter">'</span></span> )
, ( <span class="integer">1500</span>, <span class="string"><span class="delimiter">'</span><span class="content">PERSONNEL</span><span class="delimiter">'</span></span>, <span class="integer">213</span>, <span class="integer">1000</span>, <span class="string"><span class="delimiter">'</span><span class="content">CHICAGO</span><span class="delimiter">'</span></span> )
, ( <span class="integer">2000</span>, <span class="string"><span class="delimiter">'</span><span class="content">INVENTORY</span><span class="delimiter">'</span></span>, <span class="integer">32</span>, <span class="integer">9000</span>, <span class="string"><span class="delimiter">'</span><span class="content">LOS ANGELES</span><span class="delimiter">'</span></span> )
, ( <span class="integer">2500</span>, <span class="string"><span class="delimiter">'</span><span class="content">SHIPPING</span><span class="delimiter">'</span></span>, <span class="integer">234</span>, <span class="integer">2000</span>, <span class="string"><span class="delimiter">'</span><span class="content">PHOENIX</span><span class="delimiter">'</span></span> )
, ( <span class="integer">3000</span>, <span class="string"><span class="delimiter">'</span><span class="content">MARKETING</span><span class="delimiter">'</span></span>, <span class="integer">29</span>, <span class="integer">9000</span>, <span class="string"><span class="delimiter">'</span><span class="content">NEW YORK</span><span class="delimiter">'</span></span> )
, ( <span class="integer">3100</span>, <span class="string"><span class="delimiter">'</span><span class="content">CANADA SALES</span><span class="delimiter">'</span></span>, <span class="integer">43</span>, <span class="integer">3000</span>, <span class="string"><span class="delimiter">'</span><span class="content">TORONTO</span><span class="delimiter">'</span></span> )
, ( <span class="integer">3200</span>, <span class="string"><span class="delimiter">'</span><span class="content">GERMNY SALES</span><span class="delimiter">'</span></span>, <span class="integer">39</span>, <span class="integer">3000</span>, <span class="string"><span class="delimiter">'</span><span class="content">FRANKFURT</span><span class="delimiter">'</span></span> )
, ( <span class="integer">3300</span>, <span class="string"><span class="delimiter">'</span><span class="content">ENGLND SALES</span><span class="delimiter">'</span></span>, <span class="integer">72</span>, <span class="integer">3000</span>, <span class="string"><span class="delimiter">'</span><span class="content">LONDON</span><span class="delimiter">'</span></span> )
, ( <span class="integer">3500</span>, <span class="string"><span class="delimiter">'</span><span class="content">ASIA SALES</span><span class="delimiter">'</span></span>, <span class="integer">111</span>, <span class="integer">3000</span>, <span class="string"><span class="delimiter">'</span><span class="content">HONG KONG</span><span class="delimiter">'</span></span> )
, ( <span class="integer">4000</span>, <span class="string"><span class="delimiter">'</span><span class="content">RESEARCH</span><span class="delimiter">'</span></span>, <span class="integer">65</span>, <span class="integer">9000</span>, <span class="string"><span class="delimiter">'</span><span class="content">NEW YORK</span><span class="delimiter">'</span></span> )
, ( <span class="integer">4100</span>, <span class="string"><span class="delimiter">'</span><span class="content">PLANNING</span><span class="delimiter">'</span></span>, <span class="integer">87</span>, <span class="integer">4000</span>, <span class="string"><span class="delimiter">'</span><span class="content">NEW YORK</span><span class="delimiter">'</span></span> )
, ( <span class="integer">9000</span>, <span class="string"><span class="delimiter">'</span><span class="content">xxCORPORATE</span><span class="delimiter">'</span></span>, <span class="integer">1</span>, <span class="integer">9000</span>, <span class="string"><span class="delimiter">'</span><span class="content">CHICAGO</span><span class="delimiter">'</span></span> )
;
<span class="class">UPDATE</span> STATISTICS <span class="keyword">FOR</span> <span class="type">TABLE</span> trafodion.persnl.dept <span class="keyword">ON</span> EVERY <span class="type">COLUMN</span> ;</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="project-table">11.1.4. PROJECT Table</h4>
<div class="paragraph">
<p>The <a href="resources/source/persnl_project_table.sql"><code>PROJECT</code> table</a> maps records information about projects.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">TABLE</span> trafodion.persnl.project
( projcode NUMERIC (<span class="integer">4</span>) <span class="predefined-type">UNSIGNED</span> NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, empnum NUMERIC (<span class="integer">4</span>) <span class="predefined-type">UNSIGNED</span> NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, projdesc <span class="predefined-type">VARCHAR</span> (<span class="integer">18</span>) <span class="directive">DEFAULT</span> <span class="string"><span class="delimiter">'</span><span class="content"> </span><span class="delimiter">'</span></span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, start_date <span class="predefined-type">DATE</span> <span class="directive">DEFAULT</span> <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-07-01</span><span class="delimiter">'</span></span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, ship_timestamp <span class="predefined-type">TIMESTAMP</span> <span class="directive">DEFAULT</span> <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-08-01:12:00:00.000000</span><span class="delimiter">'</span></span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, est_complete INTERVAL DAY <span class="directive">DEFAULT</span> INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">30</span><span class="delimiter">'</span></span> DAY <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, <span class="directive">PRIMARY</span> <span class="type">KEY</span> ( projcode, empnum )
) ;
<span class="class">INSERT</span> <span class="class">INTO</span> trafodion.persnl.project
<span class="keyword">VALUES</span>
( <span class="integer">1000</span>, <span class="integer">213</span>, <span class="string"><span class="delimiter">'</span><span class="content">SALT LAKE CITY</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-04-10</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-04-21:08:15:00.00</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">15</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">1000</span>, <span class="integer">211</span>, <span class="string"><span class="delimiter">'</span><span class="content">SALT LAKE CITY</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-04-10</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-04-21:08:15:00.00</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">15</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">1000</span>, <span class="integer">23</span>, <span class="string"><span class="delimiter">'</span><span class="content">SALT LAKE CITY</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-04-10</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-04-21:08:15:00.00</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">15</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">1000</span>, <span class="integer">1</span>, <span class="string"><span class="delimiter">'</span><span class="content">SALT LAKE CITY</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-04-10</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-04-21:08:15:00.00</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">15</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">2000</span>, <span class="integer">227</span>, <span class="string"><span class="delimiter">'</span><span class="content">ROSS PRODUCTS</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-06-10</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-07-21:08:30:00.0000</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">30</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">2000</span>, <span class="integer">109</span>, <span class="string"><span class="delimiter">'</span><span class="content">ROSS PRODUCTS</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-06-10</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-07-21:08:30:00.0000</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">30</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">2000</span>, <span class="integer">215</span>, <span class="string"><span class="delimiter">'</span><span class="content">ROSS PRODUCTS</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-06-10</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-07-21:08:30:00.0000</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">30</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">2000</span>, <span class="integer">65</span>, <span class="string"><span class="delimiter">'</span><span class="content">ROSS PRODUCTS</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-06-10</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-07-21:08:30:00.0000</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">30</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">2500</span>, <span class="integer">65</span>, <span class="string"><span class="delimiter">'</span><span class="content">MONTANA TOOLS</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-10</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-12-21:09:00:00.0000</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">60</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">2500</span>, <span class="integer">207</span>, <span class="string"><span class="delimiter">'</span><span class="content">MONTANA TOOLS</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-10</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-12-21:09:00:00.0000</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">60</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">2500</span>, <span class="integer">232</span>, <span class="string"><span class="delimiter">'</span><span class="content">MONTANA TOOLS</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-10</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-12-21:09:00:00.0000</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">60</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">2500</span>, <span class="integer">180</span>, <span class="string"><span class="delimiter">'</span><span class="content">MONTANA TOOLS</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-10</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-12-21:09:00:00.0000</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">60</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">2500</span>, <span class="integer">93</span>, <span class="string"><span class="delimiter">'</span><span class="content">MONTANA TOOLS</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-10</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-12-21:09:00:00.0000</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">60</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">3000</span>, <span class="integer">65</span>, <span class="string"><span class="delimiter">'</span><span class="content">AHAUS TOOL/SUPPLY</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-08-21</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-21:08:10:00.0000</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">60</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">3000</span>, <span class="integer">221</span>, <span class="string"><span class="delimiter">'</span><span class="content">AHAUS TOOL/SUPPLY</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-08-21</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-21:08:10:00.0000</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">60</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">3000</span>, <span class="integer">226</span>, <span class="string"><span class="delimiter">'</span><span class="content">AHAUS TOOL/SUPPLY</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-08-21</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-21:08:10:00.0000</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">60</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">3000</span>, <span class="integer">224</span>, <span class="string"><span class="delimiter">'</span><span class="content">AHAUS TOOL/SUPPLY</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-08-21</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-21:08:10:00.0000</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">60</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">3000</span>, <span class="integer">225</span>, <span class="string"><span class="delimiter">'</span><span class="content">AHAUS TOOL/SUPPLY</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-08-21</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-21:08:10:00.0000</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">60</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">4000</span>, <span class="integer">75</span>, <span class="string"><span class="delimiter">'</span><span class="content">THE WORKS</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-09-21</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-21:10:15:00.0000</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">30</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">4000</span>, <span class="integer">29</span>, <span class="string"><span class="delimiter">'</span><span class="content">THE WORKS</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-09-21</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-21:10:15:00.0000</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">30</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">4000</span>, <span class="integer">231</span>, <span class="string"><span class="delimiter">'</span><span class="content">THE WORKS</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-09-21</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-21:10:15:00.0000</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">30</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">4000</span>, <span class="integer">228</span>, <span class="string"><span class="delimiter">'</span><span class="content">THE WORKS</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-09-21</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-21:10:15:00.0000</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">30</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">4000</span>, <span class="integer">223</span>, <span class="string"><span class="delimiter">'</span><span class="content">THE WORKS</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-09-21</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-21:10:15:00.0000</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">30</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">4000</span>, <span class="integer">568</span>, <span class="string"><span class="delimiter">'</span><span class="content">THE WORKS</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-09-21</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-21:10:15:00.0000</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">30</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">5000</span>, <span class="integer">65</span>, <span class="string"><span class="delimiter">'</span><span class="content">ASIA PROJECT</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-09-28</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-28:09:25:01.1111</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">30</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">5000</span>, <span class="integer">568</span>, <span class="string"><span class="delimiter">'</span><span class="content">ASIA PROJECT</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-09-28</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-28:09:25:01.1111</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">30</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">5000</span>, <span class="integer">557</span>, <span class="string"><span class="delimiter">'</span><span class="content">ASIA PROJECT</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-09-28</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-28:09:25:01.1111</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">30</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">5000</span>, <span class="integer">216</span>, <span class="string"><span class="delimiter">'</span><span class="content">ASIA PROJECT</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-09-28</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-28:09:25:01.1111</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">30</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">5000</span>, <span class="integer">203</span>, <span class="string"><span class="delimiter">'</span><span class="content">ASIA PROJECT</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-09-28</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-28:09:25:01.1111</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">30</span><span class="delimiter">'</span></span> DAY )
, ( <span class="integer">5000</span>, <span class="integer">218</span>, <span class="string"><span class="delimiter">'</span><span class="content">ASIA PROJECT</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-09-28</span><span class="delimiter">'</span></span>, <span class="predefined-type">TIMESTAMP</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-28:09:25:01.1111</span><span class="delimiter">'</span></span>, INTERVAL <span class="string"><span class="delimiter">'</span><span class="content">30</span><span class="delimiter">'</span></span> DAY )
;
<span class="class">UPDATE</span> STATISTICS <span class="keyword">FOR</span> <span class="type">TABLE</span> trafodion.persnl.project <span class="keyword">ON</span> EVERY <span class="type">COLUMN</span> ;</code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="sales-schema">11.2. SALES Schema</h3>
<div class="paragraph">
<p>The <a href="resources/source/sales_schema.sql"><code>SALES</code> schema</a> stores customer and sales data.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> SCHEMA trafodion.sales ;
<span class="class">SET</span> SCHEMA trafodion.sales ;</code></pre>
</div>
</div>
<div class="sect3">
<h4 id="customer-table">11.2.1. CUSTOMER Table</h4>
<div class="paragraph">
<p>The <a href="resources/source/sales_customer_table.sql"><code>CUSTOMER</code> table</a> maps records information about customers.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">TABLE</span> trafodion.sales.customer
( custnum NUMERIC (<span class="integer">4</span>) <span class="predefined-type">UNSIGNED</span> NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, custname CHARACTER (<span class="integer">18</span>) NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, street CHARACTER (<span class="integer">22</span>) NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, city CHARACTER (<span class="integer">14</span>) NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, state CHARACTER (<span class="integer">12</span>) <span class="directive">DEFAULT</span> <span class="string"><span class="delimiter">'</span><span class="content"> </span><span class="delimiter">'</span></span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, postcode CHARACTER (<span class="integer">10</span>) NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, credit CHARACTER (<span class="integer">2</span>) <span class="directive">DEFAULT</span> <span class="string"><span class="delimiter">'</span><span class="content">C1</span><span class="delimiter">'</span></span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, <span class="directive">PRIMARY</span> <span class="type">KEY</span> ( custnum )
) ;
<span class="class">INSERT</span> <span class="class">INTO</span> trafodion.sales.customer <span class="keyword">VALUES</span>
( <span class="integer">21</span>, <span class="string"><span class="delimiter">'</span><span class="content">CENTRAL UNIVERSITY</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">UNIVERSITY WAY</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">PHILADELPHIA</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">PENNSYLVANIA</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">19104</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">A1</span><span class="delimiter">'</span></span> )
, ( <span class="integer">123</span>, <span class="string"><span class="delimiter">'</span><span class="content">BROWN MEDICAL CO</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">100 CALIFORNIA STREET</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">SAN FRANCISCO</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">CALIFORNIA</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">94944</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">C2</span><span class="delimiter">'</span></span> )
, ( <span class="integer">143</span>, <span class="string"><span class="delimiter">'</span><span class="content">STEVENS SUPPLY</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">2020 HARRIS STREET</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">DENVER</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">COLORADO</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">80734</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">A2</span><span class="delimiter">'</span></span> )
, ( <span class="integer">324</span>, <span class="string"><span class="delimiter">'</span><span class="content">PREMIER INSURANCE</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">3300 WARBASH</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">LUBBOCK</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">TEXAS</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">76308</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">A1</span><span class="delimiter">'</span></span> )
, ( <span class="integer">543</span>, <span class="string"><span class="delimiter">'</span><span class="content">FRESNO STATE BANK</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">2300 BROWN BLVD</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">FRESNO</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">CALIFORNIA</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">93921</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">B3</span><span class="delimiter">'</span></span> )
, ( <span class="integer">926</span>, <span class="string"><span class="delimiter">'</span><span class="content">METALL-AG.</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">12 WAGNERRING</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">FRANKFURT</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">WEST GERMANY</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">34</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">D4</span><span class="delimiter">'</span></span> )
, ( <span class="integer">1234</span>, <span class="string"><span class="delimiter">'</span><span class="content">DATASPEED</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">300 SAN GABRIEL WAY</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">NEW YORK</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">NEW YORK</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">10014</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">C1</span><span class="delimiter">'</span></span> )
, ( <span class="integer">3210</span>, <span class="string"><span class="delimiter">'</span><span class="content">BESTFOOD MARKETS</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">3333 PHELPS STREET</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">LINCOLN</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">NEBRASKA</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">68134</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">A4</span><span class="delimiter">'</span></span> )
, ( <span class="integer">3333</span>, <span class="string"><span class="delimiter">'</span><span class="content">NATIONAL UTILITIES</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">6500 TRANS-CANADIENNE</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">QUEBEC</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">CANADA</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">H4T 1X4</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">A1</span><span class="delimiter">'</span></span> )
, ( <span class="integer">5635</span>, <span class="string"><span class="delimiter">'</span><span class="content">ROYAL CHEMICALS</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">45 NEW BROAD STREET</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">LONDON</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">ENGLAND</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">EC2M 1NH</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">B2</span><span class="delimiter">'</span></span> )
, ( <span class="integer">7654</span>, <span class="string"><span class="delimiter">'</span><span class="content">MOTOR DISTRIBUTING</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">2345 FIRST STREET</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">CHICAGO</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">ILLINOIS</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">60610</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">E4</span><span class="delimiter">'</span></span> )
, ( <span class="integer">7777</span>, <span class="string"><span class="delimiter">'</span><span class="content">SLEEPWELL HOTELS</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">9000 PETERS AVENUE</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">DALLAS</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">TEXAS</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">75244</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">B1</span><span class="delimiter">'</span></span> )
, ( <span class="integer">9000</span>, <span class="string"><span class="delimiter">'</span><span class="content">BUNKNOUGHT INN</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">4738 RALPH STREET</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">BAYONNE</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">NEW JERSEY</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">09520</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">C1</span><span class="delimiter">'</span></span> )
, ( <span class="integer">9010</span>, <span class="string"><span class="delimiter">'</span><span class="content">HOTEL OREGON</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">333 PORTLAND AVE.</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">MEDFORD</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">OREGON</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">97444</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">C2</span><span class="delimiter">'</span></span> )
, ( <span class="integer">9033</span>, <span class="string"><span class="delimiter">'</span><span class="content">ART SUPPLIES, INC.</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">22 SWEET ST.</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">PITTSBURGH</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">PENNA.</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">08333</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">C3</span><span class="delimiter">'</span></span> )
;
<span class="class">UPDATE</span> STATISTICS <span class="keyword">FOR</span> <span class="type">TABLE</span> trafodion.sales.customer <span class="keyword">ON</span> EVERY <span class="type">COLUMN</span>;</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="orders-table">11.2.2. ORDERS Table</h4>
<div class="paragraph">
<p>The <a href="resources/source/sales_orders_table.sql"><code>ORDERS</code> table</a> maps records information about sales orders.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">TABLE</span> trafodion.sales.orders
( ordernum NUMERIC (<span class="integer">6</span>) <span class="predefined-type">UNSIGNED</span> NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, order_date <span class="predefined-type">DATE</span> <span class="directive">DEFAULT</span> <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-07-01</span><span class="delimiter">'</span></span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, deliv_date <span class="predefined-type">DATE</span> <span class="directive">DEFAULT</span> <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-08-01</span><span class="delimiter">'</span></span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, salesrep NUMERIC (<span class="integer">4</span>) <span class="predefined-type">UNSIGNED</span> <span class="directive">DEFAULT</span> <span class="integer">0</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, custnum NUMERIC (<span class="integer">4</span>) <span class="predefined-type">UNSIGNED</span> NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, <span class="directive">PRIMARY</span> <span class="type">KEY</span> ( ordernum )
) ;
<span class="class">ALTER</span> <span class="type">TABLE</span> trafodion.sales.orders
<span class="class">ADD</span> <span class="type">CONSTRAINT</span> trafodion.sales.date_constrnt <span class="keyword">CHECK</span> ( deliv_date &gt;= order_date )
;
<span class="class">CREATE</span> <span class="type">INDEX</span> xordrep <span class="keyword">ON</span> orders
( salesrep
) ;
<span class="class">CREATE</span> <span class="type">INDEX</span> xordcus <span class="keyword">ON</span> orders
( custnum
) ;
<span class="class">CREATE</span> <span class="type">VIEW</span> trafodion.sales.ordrep <span class="keyword">AS</span> <span class="class">SELECT</span>
empnum
, last_name
, ordernum
, o.custnum
<span class="keyword">FROM</span>
trafodion.persnl.employee e
, trafodion.sales.orders o
, trafodion.sales.customer c
<span class="keyword">WHERE</span> e.empnum = o.salesrep
<span class="keyword">AND</span> o.custnum = C.custnum
;
<span class="class">CREATE</span> <span class="type">INDEX</span> xcustnam <span class="keyword">ON</span> customer
(
custname
) ;
<span class="class">CREATE</span> <span class="type">VIEW</span> trafodion.sales.custlist <span class="keyword">AS</span> <span class="class">SELECT</span>
custnum
, custname
, street
, city
, state
, postcode
<span class="keyword">FROM</span> trafodion.sales.customer
;
<span class="class">INSERT</span> <span class="class">INTO</span> trafodion.sales.orders <span class="keyword">VALUES</span>
( <span class="integer">100210</span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-04-10</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-04-10</span><span class="delimiter">'</span></span>, <span class="integer">220</span>, <span class="integer">1234</span> )
, ( <span class="integer">100250</span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-01-23</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-06-15</span><span class="delimiter">'</span></span>, <span class="integer">220</span>, <span class="integer">7777</span> )
, ( <span class="integer">101220</span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-07-21</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-12-15</span><span class="delimiter">'</span></span>, <span class="integer">221</span>, <span class="integer">5635</span> )
, ( <span class="integer">200300</span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-02-06</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-07-01</span><span class="delimiter">'</span></span>, <span class="integer">222</span>, <span class="integer">926</span> )
, ( <span class="integer">200320</span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-02-17</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-07-20</span><span class="delimiter">'</span></span>, <span class="integer">223</span>, <span class="integer">21</span> )
, ( <span class="integer">200490</span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-03-19</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-11-01</span><span class="delimiter">'</span></span>, <span class="integer">226</span>, <span class="integer">123</span> )
, ( <span class="integer">300350</span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-03-03</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-08-10</span><span class="delimiter">'</span></span>, <span class="integer">231</span>, <span class="integer">543</span> )
, ( <span class="integer">300380</span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-03-19</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-08-20</span><span class="delimiter">'</span></span>, <span class="integer">226</span>, <span class="integer">123</span> )
, ( <span class="integer">400410</span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-03-27</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-09-01</span><span class="delimiter">'</span></span>, <span class="integer">227</span>, <span class="integer">7654</span> )
, ( <span class="integer">500450</span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-04-20</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-09-15</span><span class="delimiter">'</span></span>, <span class="integer">220</span>, <span class="integer">324</span> )
, ( <span class="integer">600480</span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-05-12</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-10</span><span class="delimiter">'</span></span>, <span class="integer">226</span>, <span class="integer">3333</span> )
, ( <span class="integer">700510</span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-06-01</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-20</span><span class="delimiter">'</span></span>, <span class="integer">229</span>, <span class="integer">143</span> )
, ( <span class="integer">800660</span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-10-09</span><span class="delimiter">'</span></span>, <span class="predefined-type">DATE</span> <span class="string"><span class="delimiter">'</span><span class="content">2011-11-01</span><span class="delimiter">'</span></span>, <span class="integer">568</span>, <span class="integer">3210</span> )
;
<span class="class">UPDATE</span> STATISTICS <span class="keyword">FOR</span> <span class="type">TABLE</span> trafodion.sales.orders <span class="keyword">ON</span> EVERY <span class="type">COLUMN</span> ;</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="odetail-table">11.2.3. ODETAIL Table</h4>
<div class="paragraph">
<p>The <a href="resources/source/sales_odetail_table.sql"><code>ODETAIL</code> table</a> maps records detailed information about sales orders.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">TABLE</span> trafodion.sales.odetail
( ordernum NUMERIC (<span class="integer">6</span>) <span class="predefined-type">UNSIGNED</span> NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, partnum NUMERIC (<span class="integer">4</span>) <span class="predefined-type">UNSIGNED</span> NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, unit_price NUMERIC (<span class="integer">8</span>, <span class="integer">2</span>) NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, qty_ordered NUMERIC (<span class="integer">5</span>) <span class="predefined-type">UNSIGNED</span> NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, <span class="directive">PRIMARY</span> <span class="type">KEY</span> ( ordernum, partnum )
) ;
<span class="class">INSERT</span> <span class="class">INTO</span> trafodion.sales.odetail <span class="keyword">VALUES</span>
( <span class="integer">100210</span>, <span class="integer">244</span>, <span class="float">3500.00</span>, <span class="integer">3</span> )
, ( <span class="integer">100210</span>, <span class="integer">2001</span>, <span class="float">1100.00</span>, <span class="integer">3</span> )
, ( <span class="integer">100210</span>, <span class="integer">2403</span>, <span class="float">620.00</span>, <span class="integer">6</span> )
, ( <span class="integer">100210</span>, <span class="integer">5100</span>, <span class="float">150.00</span>, <span class="integer">10</span> )
, ( <span class="integer">100250</span>, <span class="integer">244</span>, <span class="float">3500.00</span>, <span class="integer">4</span> )
, ( <span class="integer">100250</span>, <span class="integer">5103</span>, <span class="float">400.00</span>, <span class="integer">10</span> )
, ( <span class="integer">100250</span>, <span class="integer">6301</span>, <span class="float">245.00</span>, <span class="integer">15</span> )
, ( <span class="integer">100250</span>, <span class="integer">6500</span>, <span class="float">95.00</span>, <span class="integer">10</span> )
, ( <span class="integer">101220</span>, <span class="integer">255</span>, <span class="float">3900.00</span>, <span class="integer">10</span> )
, ( <span class="integer">101220</span>, <span class="integer">5103</span>, <span class="float">400.00</span>, <span class="integer">3</span> )
, ( <span class="integer">101220</span>, <span class="integer">7102</span>, <span class="float">275.00</span>, <span class="integer">7</span> )
, ( <span class="integer">101220</span>, <span class="integer">7301</span>, <span class="float">425.00</span>, <span class="integer">8</span> )
, ( <span class="integer">200300</span>, <span class="integer">244</span>, <span class="float">3500.00</span>, <span class="integer">8</span> )
, ( <span class="integer">200300</span>, <span class="integer">2001</span>, <span class="float">1000.00</span>, <span class="integer">10</span> )
, ( <span class="integer">200300</span>, <span class="integer">2002</span>, <span class="float">1400.00</span>, <span class="integer">10</span> )
, ( <span class="integer">200320</span>, <span class="integer">5504</span>, <span class="float">165.00</span>, <span class="integer">5</span> )
, ( <span class="integer">200320</span>, <span class="integer">6201</span>, <span class="float">195.00</span>, <span class="integer">16</span> )
, ( <span class="integer">200320</span>, <span class="integer">6301</span>, <span class="float">245.00</span>, <span class="integer">6</span> )
, ( <span class="integer">200320</span>, <span class="integer">6400</span>, <span class="float">540.00</span>, <span class="integer">7</span> )
, ( <span class="integer">200490</span>, <span class="integer">3210</span>, <span class="float">715.00</span>, <span class="integer">1</span> )
, ( <span class="integer">200490</span>, <span class="integer">5505</span>, <span class="float">350.00</span>, <span class="integer">1</span> )
, ( <span class="integer">300350</span>, <span class="integer">244</span>, <span class="float">2800.00</span>, <span class="integer">20</span> )
, ( <span class="integer">300350</span>, <span class="integer">5100</span>, <span class="float">150.00</span>, <span class="integer">5</span> )
, ( <span class="integer">300350</span>, <span class="integer">5110</span>, <span class="float">525.00</span>, <span class="integer">12</span> )
, ( <span class="integer">300350</span>, <span class="integer">6301</span>, <span class="float">245.00</span>, <span class="integer">5</span> )
, ( <span class="integer">300350</span>, <span class="integer">6400</span>, <span class="float">550.00</span>, <span class="integer">5</span> )
, ( <span class="integer">300380</span>, <span class="integer">244</span>, <span class="float">3000.00</span>, <span class="integer">6</span> )
, ( <span class="integer">300380</span>, <span class="integer">2402</span>, <span class="float">320.00</span>, <span class="integer">12</span> )
, ( <span class="integer">300380</span>, <span class="integer">2405</span>, <span class="float">760.00</span>, <span class="integer">8</span> )
, ( <span class="integer">400410</span>, <span class="integer">212</span>, <span class="float">2450.00</span>, <span class="integer">12</span> )
, ( <span class="integer">400410</span>, <span class="integer">255</span>, <span class="float">3800.00</span>, <span class="integer">12</span> )
, ( <span class="integer">400410</span>, <span class="integer">2001</span>, <span class="float">1000.00</span>, <span class="integer">36</span> )
, ( <span class="integer">400410</span>, <span class="integer">6301</span>, <span class="float">240.00</span>, <span class="integer">48</span> )
, ( <span class="integer">400410</span>, <span class="integer">6400</span>, <span class="float">500.00</span>, <span class="integer">70</span> )
, ( <span class="integer">400410</span>, <span class="integer">7301</span>, <span class="float">415.00</span>, <span class="integer">36</span> )
, ( <span class="integer">500450</span>, <span class="integer">212</span>, <span class="float">2500.00</span>, <span class="integer">8</span> )
, ( <span class="integer">500450</span>, <span class="integer">255</span>, <span class="float">3900.00</span>, <span class="integer">12</span> )
, ( <span class="integer">500450</span>, <span class="integer">2001</span>, <span class="float">1100.00</span>, <span class="integer">16</span> )
, ( <span class="integer">500450</span>, <span class="integer">2002</span>, <span class="float">1500.00</span>, <span class="integer">16</span> )
, ( <span class="integer">500450</span>, <span class="integer">2402</span>, <span class="float">330.00</span>, <span class="integer">48</span> )
, ( <span class="integer">600480</span>, <span class="integer">2001</span>, <span class="float">1000.00</span>, <span class="integer">60</span> )
, ( <span class="integer">600480</span>, <span class="integer">2002</span>, <span class="float">1450.00</span>, <span class="integer">20</span> )
, ( <span class="integer">600480</span>, <span class="integer">2003</span>, <span class="float">1900.00</span>, <span class="integer">40</span> )
, ( <span class="integer">600480</span>, <span class="integer">3103</span>, <span class="float">4000.00</span>, <span class="integer">40</span> )
, ( <span class="integer">600480</span>, <span class="integer">3205</span>, <span class="float">625.00</span>, <span class="integer">20</span> )
, ( <span class="integer">600480</span>, <span class="integer">5100</span>, <span class="float">135.00</span>, <span class="integer">60</span> )
, ( <span class="integer">600480</span>, <span class="integer">5103</span>, <span class="float">390.00</span>, <span class="integer">20</span> )
, ( <span class="integer">600480</span>, <span class="integer">7301</span>, <span class="float">425.00</span>, <span class="integer">40</span> )
, ( <span class="integer">700410</span>, <span class="integer">2003</span>, <span class="float">1900.00</span>, <span class="integer">65</span> )
, ( <span class="integer">700410</span>, <span class="integer">2403</span>, <span class="float">650.00</span>, <span class="integer">10</span> )
, ( <span class="integer">700510</span>, <span class="integer">255</span>, <span class="float">4000.00</span>, <span class="integer">4</span> )
, ( <span class="integer">700510</span>, <span class="integer">6500</span>, <span class="float">95.00</span>, <span class="integer">8</span> )
, ( <span class="integer">700510</span>, <span class="integer">7102</span>, <span class="float">275.00</span>, <span class="integer">5</span> )
, ( <span class="integer">800660</span>, <span class="integer">244</span>, <span class="float">3000.00</span>, <span class="integer">6</span> )
, ( <span class="integer">800660</span>, <span class="integer">2001</span>, <span class="float">1000.00</span>, <span class="integer">30</span> )
, ( <span class="integer">800660</span>, <span class="integer">2403</span>, <span class="float">600.00</span>, <span class="integer">48</span> )
, ( <span class="integer">800660</span>, <span class="integer">2405</span>, <span class="float">795.00</span>, <span class="integer">10</span> )
, ( <span class="integer">800660</span>, <span class="integer">3201</span>, <span class="float">525.00</span>, <span class="integer">6</span> )
, ( <span class="integer">800660</span>, <span class="integer">3205</span>, <span class="float">600.00</span>, <span class="integer">18</span> )
, ( <span class="integer">800660</span>, <span class="integer">3210</span>, <span class="float">715.00</span>, <span class="integer">6</span> )
, ( <span class="integer">800660</span>, <span class="integer">4102</span>, <span class="float">26.00</span>, <span class="integer">130</span> )
, ( <span class="integer">800660</span>, <span class="integer">5100</span>, <span class="float">150.00</span>, <span class="integer">12</span> )
, ( <span class="integer">800660</span>, <span class="integer">5101</span>, <span class="float">200.00</span>, <span class="integer">6</span> )
, ( <span class="integer">800660</span>, <span class="integer">5110</span>, <span class="float">490.00</span>, <span class="integer">48</span> )
, ( <span class="integer">800660</span>, <span class="integer">5504</span>, <span class="float">165.00</span>, <span class="integer">18</span> )
, ( <span class="integer">800660</span>, <span class="integer">6201</span>, <span class="float">195.00</span>, <span class="integer">6</span> )
, ( <span class="integer">800660</span>, <span class="integer">6301</span>, <span class="float">235.00</span>, <span class="integer">24</span> )
, ( <span class="integer">800660</span>, <span class="integer">6400</span>, <span class="float">525.00</span>, <span class="integer">30</span> )
, ( <span class="integer">800660</span>, <span class="integer">6401</span>, <span class="float">700.00</span>, <span class="integer">36</span> )
, ( <span class="integer">800660</span>, <span class="integer">6500</span>, <span class="float">95.00</span>, <span class="integer">22</span> )
, ( <span class="integer">800660</span>, <span class="integer">7102</span>, <span class="float">275.00</span>, <span class="integer">6</span> )
, ( <span class="integer">800660</span>, <span class="integer">7301</span>, <span class="float">425.00</span>, <span class="integer">12</span> )
;
<span class="class">UPDATE</span> STATISTICS <span class="keyword">FOR</span> <span class="type">TABLE</span> trafodion.sales.odetail <span class="keyword">ON</span> EVERY <span class="type">COLUMN</span> ;</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="parts-table">11.2.4. PARTS Table</h4>
<div class="paragraph">
<p>The <a href="resources/source/sales_parts_table.sql"><code>PARTS</code> table</a> maps records information about parts.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">TABLE</span> trafodion.sales.parts
( partnum NUMERIC (<span class="integer">4</span>) <span class="predefined-type">UNSIGNED</span> NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, partdesc CHARACTER (<span class="integer">18</span>) NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, price NUMERIC (<span class="integer">8</span>, <span class="integer">2</span>) NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, qty_available NUMERIC (<span class="integer">5</span>) <span class="directive">DEFAULT</span> <span class="integer">0</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, <span class="directive">PRIMARY</span> <span class="type">KEY</span> ( partnum )
) ;
<span class="class">CREATE</span> <span class="type">INDEX</span> xpartdes <span class="keyword">ON</span> parts
( partdesc
) ;
<span class="class">INSERT</span> <span class="class">INTO</span> trafodion.sales.parts <span class="keyword">VALUES</span>
( <span class="integer">186</span>, <span class="string"><span class="delimiter">'</span><span class="content">186 MegaByte Disk</span><span class="delimiter">'</span></span>, <span class="float">186186.86</span>, <span class="integer">186</span> )
, ( <span class="integer">212</span>, <span class="string"><span class="delimiter">'</span><span class="content">PC SILVER, 20 MB</span><span class="delimiter">'</span></span>, <span class="float">2500.00</span>, <span class="integer">3525</span> )
, ( <span class="integer">244</span>, <span class="string"><span class="delimiter">'</span><span class="content">PC GOLD, 30 MB</span><span class="delimiter">'</span></span>, <span class="float">3000.00</span>, <span class="integer">4426</span> )
, ( <span class="integer">255</span>, <span class="string"><span class="delimiter">'</span><span class="content">PC DIAMOND, 60 MB</span><span class="delimiter">'</span></span>, <span class="float">4000.00</span>, <span class="integer">3321</span> )
, ( <span class="integer">2001</span>, <span class="string"><span class="delimiter">'</span><span class="content">GRAPHIC PRINTER,M1</span><span class="delimiter">'</span></span>, <span class="float">1100.00</span>, <span class="integer">2100</span> )
, ( <span class="integer">2002</span>, <span class="string"><span class="delimiter">'</span><span class="content">GRAPHIC PRINTER,M2</span><span class="delimiter">'</span></span>, <span class="float">1500.00</span>, <span class="integer">3220</span> )
, ( <span class="integer">2003</span>, <span class="string"><span class="delimiter">'</span><span class="content">GRAPHIC PRINTER,M3</span><span class="delimiter">'</span></span>, <span class="float">2000.00</span>, <span class="integer">2200</span> )
, ( <span class="integer">2402</span>, <span class="string"><span class="delimiter">'</span><span class="content">DAISY PRINTER,T1</span><span class="delimiter">'</span></span>, <span class="float">350.00</span>, <span class="integer">4425</span> )
, ( <span class="integer">2403</span>, <span class="string"><span class="delimiter">'</span><span class="content">DAISY PRINTER,T2</span><span class="delimiter">'</span></span>, <span class="float">650.00</span>, <span class="integer">3312</span> )
, ( <span class="integer">2405</span>, <span class="string"><span class="delimiter">'</span><span class="content">DAISY PRINTER, T3</span><span class="delimiter">'</span></span>, <span class="float">795.00</span>, <span class="integer">2712</span> )
, ( <span class="integer">3103</span>, <span class="string"><span class="delimiter">'</span><span class="content">LASER PRINTER, X1</span><span class="delimiter">'</span></span>, <span class="float">4200.00</span>, <span class="integer">3300</span> )
, ( <span class="integer">3201</span>, <span class="string"><span class="delimiter">'</span><span class="content">HARD DISK 20 MB</span><span class="delimiter">'</span></span>, <span class="float">525.00</span>, <span class="integer">4436</span> )
, ( <span class="integer">3205</span>, <span class="string"><span class="delimiter">'</span><span class="content">HARD DISK 30 MB</span><span class="delimiter">'</span></span>, <span class="float">625.00</span>, <span class="integer">2209</span> )
, ( <span class="integer">3210</span>, <span class="string"><span class="delimiter">'</span><span class="content">HARD DISK 40 MB</span><span class="delimiter">'</span></span>, <span class="float">715.00</span>, <span class="integer">3314</span> )
, ( <span class="integer">4102</span>, <span class="string"><span class="delimiter">'</span><span class="content">DISKETTE HD, BOX</span><span class="delimiter">'</span></span>, <span class="float">28.00</span>, <span class="integer">6540</span> )
, ( <span class="integer">5100</span>, <span class="string"><span class="delimiter">'</span><span class="content">MONITOR BW, TYPE 1</span><span class="delimiter">'</span></span>, <span class="float">150.00</span>, <span class="integer">3237</span> )
, ( <span class="integer">5101</span>, <span class="string"><span class="delimiter">'</span><span class="content">MONITOR BW, TYPE 2</span><span class="delimiter">'</span></span>, <span class="float">200.00</span>, <span class="integer">2400</span> )
, ( <span class="integer">5103</span>, <span class="string"><span class="delimiter">'</span><span class="content">MONITOR COLOR, M1</span><span class="delimiter">'</span></span>, <span class="float">400.00</span>, <span class="integer">3328</span> )
, ( <span class="integer">5110</span>, <span class="string"><span class="delimiter">'</span><span class="content">MONITOR COLOR, M2</span><span class="delimiter">'</span></span>, <span class="float">525.00</span>, <span class="integer">3236</span> )
, ( <span class="integer">5504</span>, <span class="string"><span class="delimiter">'</span><span class="content">MEMORY CARD, 512KB</span><span class="delimiter">'</span></span>, <span class="float">165.00</span>, <span class="integer">2630</span> )
, ( <span class="integer">5505</span>, <span class="string"><span class="delimiter">'</span><span class="content">MEMORY CARD, 1 MB</span><span class="delimiter">'</span></span>, <span class="float">315.00</span>, <span class="integer">3830</span> )
, ( <span class="integer">6201</span>, <span class="string"><span class="delimiter">'</span><span class="content">GRAPHIC CARD, LR</span><span class="delimiter">'</span></span>, <span class="float">195.00</span>, <span class="integer">2306</span> )
, ( <span class="integer">6301</span>, <span class="string"><span class="delimiter">'</span><span class="content">GRAPHIC CARD, HR</span><span class="delimiter">'</span></span>, <span class="float">245.00</span>, <span class="integer">2331</span> )
, ( <span class="integer">6400</span>, <span class="string"><span class="delimiter">'</span><span class="content">STREAMING TAPE,M20</span><span class="delimiter">'</span></span>, <span class="float">550.00</span>, <span class="integer">1268</span> )
, ( <span class="integer">6401</span>, <span class="string"><span class="delimiter">'</span><span class="content">STREAMING TAPE,M60</span><span class="delimiter">'</span></span>, <span class="float">725.00</span>, <span class="integer">1308</span> )
, ( <span class="integer">6500</span>, <span class="string"><span class="delimiter">'</span><span class="content">DISK CONTROLLER</span><span class="delimiter">'</span></span>, <span class="float">95.00</span>, <span class="integer">2532</span> )
, ( <span class="integer">6603</span>, <span class="string"><span class="delimiter">'</span><span class="content">PRINTER CONTROLLER</span><span class="delimiter">'</span></span>, <span class="float">45.00</span>, <span class="integer">430</span> )
, ( <span class="integer">7102</span>, <span class="string"><span class="delimiter">'</span><span class="content">SMART MODEM, 1200</span><span class="delimiter">'</span></span>, <span class="float">275.00</span>, <span class="integer">2200</span> )
, ( <span class="integer">7301</span>, <span class="string"><span class="delimiter">'</span><span class="content">SMART MODEM, 2400</span><span class="delimiter">'</span></span>, <span class="float">425.00</span>, <span class="integer">2332</span> )
;
<span class="class">UPDATE</span> STATISTICS <span class="keyword">FOR</span> <span class="type">TABLE</span> trafodion.sales.parts <span class="keyword">ON</span> EVERY <span class="type">COLUMN</span> ;</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="invent-schema">11.2.5. INVENT Schema</h4>
<div class="paragraph">
<p>The <a href="resources/source/invent_schema.sql"><code>INVENT</code> schema</a> stores inventory data.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> SCHEMA trafodion.invent ;
<span class="class">SET</span> SCHEMA trafodion.invent ;</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="supplier-table">11.2.6. SUPPLIER Table</h4>
<div class="paragraph">
<p>The <a href="resources/source/invent_supplier_table.sql"><code>SUPPLIER</code> table</a> maps records information about suppliers.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">TABLE</span> trafodion.invent.supplier
( suppnum NUMERIC (<span class="integer">4</span>) <span class="predefined-type">UNSIGNED</span> NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, suppname CHARACTER (<span class="integer">18</span>) NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, street CHARACTER (<span class="integer">22</span>) NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, city CHARACTER (<span class="integer">14</span>) NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, state CHARACTER (<span class="integer">12</span>) NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, postcode CHARACTER (<span class="integer">10</span>) NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, <span class="directive">PRIMARY</span> <span class="type">KEY</span> ( suppnum )
) ;
<span class="class">CREATE</span> <span class="type">INDEX</span> xsuppnam <span class="keyword">ON</span> supplier
( suppname
) ;
<span class="class">INSERT</span> <span class="class">INTO</span> trafodion.invent.supplier <span class="keyword">VALUES</span>
( <span class="integer">1</span>, <span class="string"><span class="delimiter">'</span><span class="content">NEW COMPUTERS INC</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">1800 KING ST.</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">SAN FRANCISCO</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">CALIFORNIA</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">94112</span><span class="delimiter">'</span></span> )
, ( <span class="integer">2</span>, <span class="string"><span class="delimiter">'</span><span class="content">DATA TERMINAL INC</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">2000 BAKER STREET</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">LAS VEGAS</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">NEVADA</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">66134</span><span class="delimiter">'</span></span> )
, ( <span class="integer">3</span>, <span class="string"><span class="delimiter">'</span><span class="content">HIGH DENSITY INC</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">7600 EMERSON</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">NEW YORK</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">NEW YORK</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">10230</span><span class="delimiter">'</span></span> )
, ( <span class="integer">6</span>, <span class="string"><span class="delimiter">'</span><span class="content">MAGNETICS INC</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">1000 INDUSTRY DRIVE</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">LEXINGTON</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">MASS</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">02159</span><span class="delimiter">'</span></span> )
, ( <span class="integer">8</span>, <span class="string"><span class="delimiter">'</span><span class="content">ATTRACTIVE CORP</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">7777 FOUNTAIN WAY</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">CHICAGO</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">ILLINOIS</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">60610</span><span class="delimiter">'</span></span> )
, ( <span class="integer">10</span>, <span class="string"><span class="delimiter">'</span><span class="content">LEVERAGE INC</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">6000 LINCOLN LANE</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">DENVER</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">COLORADO</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">80712</span><span class="delimiter">'</span></span> )
, ( <span class="integer">15</span>, <span class="string"><span class="delimiter">'</span><span class="content">DATADRIVE CORP</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">100 MAC ARTHUR</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">DALLAS</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">TEXAS</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">75244</span><span class="delimiter">'</span></span> )
, ( <span class="integer">20</span>, <span class="string"><span class="delimiter">'</span><span class="content">Macadam''S PC''s</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">106 River Road</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">New Orleans</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">Louisiana</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">67890</span><span class="delimiter">'</span></span> )
, ( <span class="integer">25</span>, <span class="string"><span class="delimiter">'</span><span class="content">Schroeder''s Ltd</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">212 Strasse Blvd West</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">Hamburg</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">Rhode Island</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">22222</span><span class="delimiter">'</span></span> )
, ( <span class="integer">30</span>, <span class="string"><span class="delimiter">'</span><span class="content">O''Donnell''s Drives</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">729 West Palm Beach </span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">San Antonio</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">Texas</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">78344</span><span class="delimiter">'</span></span> )
, ( <span class="integer">35</span>, <span class="string"><span class="delimiter">'</span><span class="content">Mac''Murphys PC''s</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">93323 Alemeda</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">Menlo Park</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">California</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">94025</span><span class="delimiter">'</span></span> )
, ( <span class="integer">36</span>, <span class="string"><span class="delimiter">'</span><span class="content">MAC''MURPHYS PCB''s</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">93323 Alemeda Suite B</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">Menlo Park</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">California</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">94025</span><span class="delimiter">'</span></span> )
, ( <span class="integer">90</span>, <span class="string"><span class="delimiter">'</span><span class="content">laser jets inc</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">284 blue ridge way</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">levittown</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">penna.</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">09520</span><span class="delimiter">'</span></span> )
, ( <span class="integer">92</span>, <span class="string"><span class="delimiter">'</span><span class="content">watercolors</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">84 north grand avenue</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">menlo park</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">california</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">94025</span><span class="delimiter">'</span></span> )
, ( <span class="integer">95</span>, <span class="string"><span class="delimiter">'</span><span class="content">application do''ers</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">2846 yellowwood drive</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">wayland</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">mass</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">02158</span><span class="delimiter">'</span></span> )
, ( <span class="integer">99</span>, <span class="string"><span class="delimiter">'</span><span class="content">terminals, inc.</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">2 longfellow way</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">heightstown</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">nj</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">08520</span><span class="delimiter">'</span></span> )
, ( <span class="integer">186</span>, <span class="string"><span class="delimiter">'</span><span class="content">186 Disk Makers</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">186 Dis Way</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">Dat Way</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">Wisconsin</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">00186</span><span class="delimiter">'</span></span> )
;
<span class="class">UPDATE</span> STATISTICS <span class="keyword">FOR</span> <span class="type">TABLE</span> trafodion.invent.supplier <span class="keyword">ON</span> EVERY <span class="type">COLUMN</span> ;</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="partsupp-table">11.2.7. PARTSUPP Table</h4>
<div class="paragraph">
<p>The <a href="resources/source/invent_partsupp_table.sql"><code>PARTSUPP</code> table</a> maps parts to suppliers.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">TABLE</span> trafodion.invent.partsupp
( partnum NUMERIC (<span class="integer">4</span>) <span class="predefined-type">UNSIGNED</span> NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, suppnum NUMERIC (<span class="integer">4</span>) <span class="predefined-type">UNSIGNED</span> NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, partcost NUMERIC (<span class="integer">8</span>, <span class="integer">2</span>) NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, qty_received NUMERIC (<span class="integer">5</span>) <span class="predefined-type">UNSIGNED</span> <span class="directive">DEFAULT</span> <span class="integer">0</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, <span class="directive">PRIMARY</span> <span class="type">KEY</span> ( partnum, suppnum )
) ;
<span class="class">CREATE</span> <span class="type">INDEX</span> XSUPORD <span class="keyword">ON</span> partsupp
( suppnum
) ;
<span class="class">CREATE</span> <span class="type">VIEW</span> trafodion.invent.view207
( partnumber
, partdescrpt
, suppnumber
, supplrname
, partprice
, qtyreceived
)
<span class="keyword">AS</span> <span class="class">SELECT</span>
x.partnum
, partdesc
, x.suppnum
, suppname
, partcost
, qty_received
<span class="keyword">FROM</span>
trafodion.invent.partsupp x
, trafodion.sales.parts p
, trafodion.invent.supplier s
<span class="keyword">WHERE</span> x.partnum = p.partnum
<span class="keyword">AND</span> x.suppnum = s.suppnum
;
<span class="class">CREATE</span> <span class="type">VIEW</span> trafodion.invent.view207n
( partnumber
, partdescrpt
, suppnumber
, supplrname
, partprice
, qtyreceived
)
<span class="keyword">AS</span> <span class="class">SELECT</span>
x.partnum
, p.partdesc
, s.suppnum
, s.suppname
, x.partcost
, x.qty_received
<span class="keyword">FROM</span> trafodion.invent.supplier s
<span class="keyword">LEFT</span> <span class="keyword">JOIN</span> trafodion.invent.partsupp x <span class="keyword">ON</span> s.suppnum = x.suppnum
<span class="keyword">LEFT</span> <span class="keyword">JOIN</span> trafodion.sales.parts p <span class="keyword">ON</span> x.partnum = p.partnum
;
<span class="class">CREATE</span> <span class="type">VIEW</span> trafodion.invent.viewcust
( custnumber
, cusname
, ordernum
)
<span class="keyword">AS</span> <span class="class">SELECT</span>
c.custnum
, c.custname
, o.ordernum
<span class="keyword">FROM</span> trafodion.sales.customer c
<span class="keyword">LEFT</span> <span class="keyword">JOIN</span> trafodion.sales.orders o <span class="keyword">ON</span> c.custnum = o.custnum
;
<span class="class">CREATE</span> <span class="type">VIEW</span> trafodion.invent.viewcs <span class="keyword">AS</span> <span class="class">SELECT</span>
custname
<span class="keyword">FROM</span> trafodion.sales.customer
<span class="keyword">UNION</span> <span class="class">SELECT</span>
suppname
<span class="keyword">FROM</span> trafodion.invent.supplier ;
<span class="class">INSERT</span> <span class="class">INTO</span> trafodion.invent.partsupp <span class="keyword">VALUES</span>
( <span class="integer">212</span>, <span class="integer">1</span>, <span class="float">2000.00</span>, <span class="integer">20</span> )
, ( <span class="integer">212</span>, <span class="integer">3</span>, <span class="float">1900.00</span>, <span class="integer">35</span> )
, ( <span class="integer">244</span>, <span class="integer">1</span>, <span class="float">2400.00</span>, <span class="integer">50</span> )
, ( <span class="integer">244</span>, <span class="integer">2</span>, <span class="float">2200.00</span>, <span class="integer">66</span> )
, ( <span class="integer">255</span>, <span class="integer">1</span>, <span class="float">3300.00</span>, <span class="integer">35</span> )
, ( <span class="integer">255</span>, <span class="integer">3</span>, <span class="float">3000.00</span>, <span class="integer">46</span> )
, ( <span class="integer">2001</span>, <span class="integer">1</span>, <span class="float">700.00</span>, <span class="integer">100</span> )
, ( <span class="integer">2001</span>, <span class="integer">2</span>, <span class="float">750.00</span>, <span class="integer">55</span> )
, ( <span class="integer">2002</span>, <span class="integer">1</span>, <span class="float">1000.00</span>, <span class="integer">120</span> )
, ( <span class="integer">2002</span>, <span class="integer">6</span>, <span class="float">1100.00</span>, <span class="integer">20</span> )
, ( <span class="integer">2003</span>, <span class="integer">1</span>, <span class="float">1300.00</span>, <span class="integer">100</span> )
, ( <span class="integer">2003</span>, <span class="integer">2</span>, <span class="float">1400.00</span>, <span class="integer">50</span> )
, ( <span class="integer">2003</span>, <span class="integer">10</span>, <span class="float">1450.00</span>, <span class="integer">50</span> )
, ( <span class="integer">2402</span>, <span class="integer">1</span>, <span class="float">200.00</span>, <span class="integer">35</span> )
, ( <span class="integer">2403</span>, <span class="integer">1</span>, <span class="float">300.00</span>, <span class="integer">200</span> )
, ( <span class="integer">2405</span>, <span class="integer">1</span>, <span class="float">500.00</span>, <span class="integer">40</span> )
, ( <span class="integer">2405</span>, <span class="integer">6</span>, <span class="float">450.00</span>, <span class="integer">50</span> )
, ( <span class="integer">3103</span>, <span class="integer">1</span>, <span class="float">3200.00</span>, <span class="integer">200</span> )
, ( <span class="integer">3103</span>, <span class="integer">15</span>, <span class="float">3300.00</span>, <span class="integer">100</span> )
, ( <span class="integer">3201</span>, <span class="integer">1</span>, <span class="float">380.00</span>, <span class="integer">36</span> )
, ( <span class="integer">3205</span>, <span class="integer">1</span>, <span class="float">425.00</span>, <span class="integer">150</span> )
, ( <span class="integer">3210</span>, <span class="integer">6</span>, <span class="float">470.00</span>, <span class="integer">10</span> )
, ( <span class="integer">3210</span>, <span class="integer">15</span>, <span class="float">450.00</span>, <span class="integer">25</span> )
, ( <span class="integer">4102</span>, <span class="integer">6</span>, <span class="float">20.00</span>, <span class="integer">115</span> )
, ( <span class="integer">4102</span>, <span class="integer">8</span>, <span class="float">19.00</span>, <span class="integer">140</span> )
, ( <span class="integer">4102</span>, <span class="integer">15</span>, <span class="float">21.00</span>, <span class="integer">30</span> )
, ( <span class="integer">5100</span>, <span class="integer">6</span>, <span class="float">100.00</span>, <span class="integer">50</span> )
, ( <span class="integer">5100</span>, <span class="integer">8</span>, <span class="float">105.00</span>, <span class="integer">40</span> )
, ( <span class="integer">5100</span>, <span class="integer">15</span>, <span class="float">95.00</span>, <span class="integer">60</span> )
, ( <span class="integer">5101</span>, <span class="integer">8</span>, <span class="float">135.00</span>, <span class="integer">33</span> )
, ( <span class="integer">5101</span>, <span class="integer">15</span>, <span class="float">125.00</span>, <span class="integer">43</span> )
, ( <span class="integer">5103</span>, <span class="integer">8</span>, <span class="float">265.00</span>, <span class="integer">20</span> )
, ( <span class="integer">5103</span>, <span class="integer">15</span>, <span class="float">250.00</span>, <span class="integer">58</span> )
, ( <span class="integer">5110</span>, <span class="integer">1</span>, <span class="float">335.00</span>, <span class="integer">100</span> )
, ( <span class="integer">5110</span>, <span class="integer">2</span>, <span class="float">350.00</span>, <span class="integer">36</span> )
, ( <span class="integer">5504</span>, <span class="integer">2</span>, <span class="float">85.00</span>, <span class="integer">10</span> )
, ( <span class="integer">5504</span>, <span class="integer">6</span>, <span class="float">75.00</span>, <span class="integer">10</span> )
, ( <span class="integer">5504</span>, <span class="integer">15</span>, <span class="float">78.00</span>, <span class="integer">10</span> )
, ( <span class="integer">5505</span>, <span class="integer">15</span>, <span class="float">200.00</span>, <span class="integer">100</span> )
, ( <span class="integer">6201</span>, <span class="integer">1</span>, <span class="float">100.00</span>, <span class="integer">110</span> )
, ( <span class="integer">6301</span>, <span class="integer">1</span>, <span class="float">150.00</span>, <span class="integer">230</span> )
, ( <span class="integer">6400</span>, <span class="integer">1</span>, <span class="float">390.00</span>, <span class="integer">50</span> )
, ( <span class="integer">6401</span>, <span class="integer">2</span>, <span class="float">500.00</span>, <span class="integer">20</span> )
, ( <span class="integer">6401</span>, <span class="integer">3</span>, <span class="float">480.00</span>, <span class="integer">38</span> )
, ( <span class="integer">6500</span>, <span class="integer">2</span>, <span class="float">60.00</span>, <span class="integer">140</span> )
, ( <span class="integer">6500</span>, <span class="integer">3</span>, <span class="float">65.00</span>, <span class="integer">32</span> )
, ( <span class="integer">6603</span>, <span class="integer">2</span>, <span class="float">25.00</span>, <span class="integer">150</span> )
, ( <span class="integer">7102</span>, <span class="integer">10</span>, <span class="float">165.00</span>, <span class="integer">100</span> )
, ( <span class="integer">7301</span>, <span class="integer">1</span>, <span class="float">300.00</span>, <span class="integer">32</span> )
;
<span class="class">UPDATE</span> STATISTICS <span class="keyword">FOR</span> <span class="type">TABLE</span> trafodion.invent.partsupp <span class="keyword">ON</span> EVERY <span class="type">COLUMN</span> ;</code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="partloc-table">11.2.8. PARTLOC Table</h4>
<div class="paragraph">
<p>The <a href="resources/source/invent_partloc_table.sql"><code>PARTLOC</code> table</a> records number of parts to on hand.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="CodeRay highlight"><code data-lang="sql"><span class="class">CREATE</span> <span class="type">TABLE</span> trafodion.invent.partloc
( loc_code CHARACTER (<span class="integer">3</span>) NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, partnum NUMERIC (<span class="integer">4</span>) <span class="predefined-type">UNSIGNED</span> NO <span class="directive">DEFAULT</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, qty_on_hand NUMERIC (<span class="integer">7</span>) <span class="directive">DEFAULT</span> <span class="integer">0</span> <span class="keyword">NOT</span> <span class="predefined-constant">NULL</span>
, <span class="directive">PRIMARY</span> <span class="type">KEY</span> ( loc_code, partnum )
) ;
<span class="class">INSERT</span> <span class="class">INTO</span> trafodion.invent.partloc <span class="keyword">VALUES</span>
( <span class="string"><span class="delimiter">'</span><span class="content">A10</span><span class="delimiter">'</span></span>, <span class="integer">2001</span>, <span class="integer">800</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">A21</span><span class="delimiter">'</span></span>, <span class="integer">255</span>, <span class="integer">21</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">A34</span><span class="delimiter">'</span></span>, <span class="integer">6201</span>, <span class="integer">0</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">A35</span><span class="delimiter">'</span></span>, <span class="integer">6301</span>, <span class="integer">0</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">A36</span><span class="delimiter">'</span></span>, <span class="integer">6400</span>, <span class="integer">34</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">A66</span><span class="delimiter">'</span></span>, <span class="integer">6603</span>, <span class="integer">300</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">A67</span><span class="delimiter">'</span></span>, <span class="integer">6401</span>, <span class="integer">454</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">A78</span><span class="delimiter">'</span></span>, <span class="integer">244</span>, <span class="integer">43</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">A78</span><span class="delimiter">'</span></span>, <span class="integer">5505</span>, <span class="integer">100</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">A87</span><span class="delimiter">'</span></span>, <span class="integer">212</span>, <span class="integer">18</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">A88</span><span class="delimiter">'</span></span>, <span class="integer">2403</span>, <span class="integer">735</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">A88</span><span class="delimiter">'</span></span>, <span class="integer">5504</span>, <span class="integer">30</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">A94</span><span class="delimiter">'</span></span>, <span class="integer">3205</span>, <span class="integer">200</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">A98</span><span class="delimiter">'</span></span>, <span class="integer">5110</span>, <span class="integer">510</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">G11</span><span class="delimiter">'</span></span>, <span class="integer">2002</span>, <span class="integer">20</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">G34</span><span class="delimiter">'</span></span>, <span class="integer">6201</span>, <span class="integer">106</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">G35</span><span class="delimiter">'</span></span>, <span class="integer">6301</span>, <span class="integer">331</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">G36</span><span class="delimiter">'</span></span>, <span class="integer">6400</span>, <span class="integer">1034</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">G43</span><span class="delimiter">'</span></span>, <span class="integer">5100</span>, <span class="integer">77</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">G45</span><span class="delimiter">'</span></span>, <span class="integer">4102</span>, <span class="integer">69</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">G65</span><span class="delimiter">'</span></span>, <span class="integer">3201</span>, <span class="integer">36</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">G68</span><span class="delimiter">'</span></span>, <span class="integer">6500</span>, <span class="integer">1132</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">G76</span><span class="delimiter">'</span></span>, <span class="integer">2405</span>, <span class="integer">42</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">G76</span><span class="delimiter">'</span></span>, <span class="integer">7301</span>, <span class="integer">32</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">G78</span><span class="delimiter">'</span></span>, <span class="integer">5505</span>, <span class="integer">0</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">G87</span><span class="delimiter">'</span></span>, <span class="integer">212</span>, <span class="integer">20</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">G87</span><span class="delimiter">'</span></span>, <span class="integer">3103</span>, <span class="integer">0</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">G87</span><span class="delimiter">'</span></span>, <span class="integer">3210</span>, <span class="integer">44</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">G87</span><span class="delimiter">'</span></span>, <span class="integer">2402</span>, <span class="integer">0</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">G88</span><span class="delimiter">'</span></span>, <span class="integer">2403</span>, <span class="integer">32</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">G88</span><span class="delimiter">'</span></span>, <span class="integer">5504</span>, <span class="integer">0</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">G89</span><span class="delimiter">'</span></span>, <span class="integer">5101</span>, <span class="integer">86</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">G94</span><span class="delimiter">'</span></span>, <span class="integer">3205</span>, <span class="integer">59</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">G98</span><span class="delimiter">'</span></span>, <span class="integer">5103</span>, <span class="integer">28</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">G98</span><span class="delimiter">'</span></span>, <span class="integer">5110</span>, <span class="integer">136</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">P10</span><span class="delimiter">'</span></span>, <span class="integer">2001</span>, <span class="integer">0</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">P12</span><span class="delimiter">'</span></span>, <span class="integer">2002</span>, <span class="integer">200</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">P12</span><span class="delimiter">'</span></span>, <span class="integer">2003</span>, <span class="integer">0</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">P15</span><span class="delimiter">'</span></span>, <span class="integer">2003</span>, <span class="integer">200</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">P66</span><span class="delimiter">'</span></span>, <span class="integer">6603</span>, <span class="integer">40</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">P67</span><span class="delimiter">'</span></span>, <span class="integer">6401</span>, <span class="integer">54</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">P68</span><span class="delimiter">'</span></span>, <span class="integer">6500</span>, <span class="integer">0</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">P76</span><span class="delimiter">'</span></span>, <span class="integer">7102</span>, <span class="integer">200</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">P78</span><span class="delimiter">'</span></span>, <span class="integer">244</span>, <span class="integer">23</span> )
, ( <span class="string"><span class="delimiter">'</span><span class="content">P87</span><span class="delimiter">'</span></span>, <span class="integer">3103</span>, <span class="integer">300</span> )
;
<span class="class">UPDATE</span> STATISTICS <span class="keyword">FOR</span> <span class="type">TABLE</span> trafodion.invent.partloc <span class="keyword">ON</span> EVERY <span class="type">COLUMN</span> ;</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="footer">
<div id="footer-text">
Version 2.4.0<br>
Last updated 2020-04-17 22:23:23 PDT
</div>
</div>
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount','UA-72491210-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>