Missing semicolon (;) at end of SQL statement

I'm getting this error on a form in which I'm trying to upload multiple files as well as populate a database with information about them all in one query. In addition, not every file field will be used every time the form is submitted, so I have some <cfif> tags to prevent errors in the event the fields are empty. I was able to get the form to work with only two file fields (leaving the second one blank to check that there would be no errors with blank fields), but when I expanded it to the full 15 (and all I did is copy and paste the code and update the field numbers), I get this error:
Error Executing Database Query.
Missing semicolon (;) at end of SQL statement.
The error occurred in C:\ColdFusion9\wwwroot\CrimsonTideBand\admin\upload.cfm: line 477
Called from C:\ColdFusion9\wwwroot\CrimsonTideBand\admin\upload.cfm: line 14
Called from C:\ColdFusion9\wwwroot\CrimsonTideBand\admin\upload.cfm: line 1
Called from C:\ColdFusion9\wwwroot\CrimsonTideBand\admin\upload.cfm: line 477
Called from C:\ColdFusion9\wwwroot\CrimsonTideBand\admin\upload.cfm: line 14
Called from C:\ColdFusion9\wwwroot\CrimsonTideBand\admin\upload.cfm: line 1
475:  </cfif>)
476:  </cfif>
477:  <cfif IsDefined("FORM.File15") AND #FORM.File15# NEQ "">,
478:  (<cfif IsDefined("FORM.Ensemble") AND #FORM.Ensemble# NEQ "">
479:  <cfqueryparam value="#FORM.Ensemble# cfsqltype="cf_sql_clob" maxlength="255">
Here is my full SQL for this query. Any help would be greatly appreciated. Also, if there's a more streamlined way to handle this sort of situation, that would be great as well. (Sorry, it's pretty long, but most of it is repetitive):
<cfset CurrentPage=GetFileFromPath(GetBaseTemplatePath())>
<cfif IsDefined("FORM.MM_InsertRecord") AND FORM.MM_InsertRecord EQ "upload">
  <cfquery datasource="ctband">
    INSERT INTO Files (Ensemble, Category, Selection, Part, File_Name, Uploaded_By)
    VALUES (<cfif IsDefined("FORM.Ensemble") AND #FORM.Ensemble# NEQ "">
    <cfqueryparam value="#FORM.Ensemble#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Category") AND #FORM.Category# NEQ "">
    <cfqueryparam value="#FORM.Category#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Selection") AND #FORM.Selection# NEQ "">
    <cfqueryparam value="#FORM.Selection#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Part1") AND #FORM.Part1# NEQ "">
    <cfqueryparam value="#FORM.Part1#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.File1") AND #FORM.File_Name1# NEQ "">
    <cfqueryparam value="#FORM.File_Name1#" cfsqltype="cf_sql_clob" maxlength="255">
    <cffile action="upload" filefield="File1" destination="C:\Coldfusion9\wwwroot\CrimsonTideBand\#FORM.Ensemble#\member_files" nameconflict="overwrite">
    <cfelse>
    </cfif>
    , <cfif IsDefined("SESSION.MM_Username") AND #SESSION.MM_Username# NEQ "">
    <cfqueryparam value="#SESSION.MM_Username#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>)
    <cfif IsDefined("FORM.File2") AND #FORM.File2# NEQ "">,
    (<cfif IsDefined("FORM.Ensemble") AND #FORM.Ensemble# NEQ "">
    <cfqueryparam value="#FORM.Ensemble#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Category") AND #FORM.Category# NEQ "">
    <cfqueryparam value="#FORM.Category#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Selection") AND #FORM.Selection# NEQ "">
    <cfqueryparam value="#FORM.Selection#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Part2") AND #FORM.Part2# NEQ "">
    <cfqueryparam value="#FORM.Part2#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.File2") AND #FORM.File_Name2# NEQ "">
    <cfqueryparam value="#FORM.File_Name2#" cfsqltype="cf_sql_clob" maxlength="255">
    <cffile action="upload" filefield="File2" destination="C:\Coldfusion9\wwwroot\CrimsonTideBand\#FORM.Ensemble#\member_files" nameconflict="overwrite">
    <cfelse>
    </cfif>
    , <cfif IsDefined("SESSION.MM_Username") AND #SESSION.MM_Username# NEQ "">
    <cfqueryparam value="#SESSION.MM_Username#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>)
    </cfif>
    <cfif IsDefined("FORM.File3") AND #FORM.File3# NEQ "">,
    (<cfif IsDefined("FORM.Ensemble") AND #FORM.Ensemble# NEQ "">
    <cfqueryparam value="#FORM.Ensemble#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Category") AND #FORM.Category# NEQ "">
    <cfqueryparam value="#FORM.Category#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Selection") AND #FORM.Selection# NEQ "">
    <cfqueryparam value="#FORM.Selection#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Part3") AND #FORM.Part3# NEQ "">
    <cfqueryparam value="#FORM.Part3#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.File3") AND #FORM.File_Name3# NEQ "">
    <cfqueryparam value="#FORM.File_Name3#" cfsqltype="cf_sql_clob" maxlength="255">
    <cffile action="upload" filefield="File3" destination="C:\Coldfusion9\wwwroot\CrimsonTideBand\#FORM.Ensemble#\member_files" nameconflict="overwrite">
    <cfelse>
    </cfif>
    , <cfif IsDefined("SESSION.MM_Username") AND #SESSION.MM_Username# NEQ "">
    <cfqueryparam value="#SESSION.MM_Username#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>)
    </cfif>
    <cfif IsDefined("FORM.File4") AND #FORM.File4# NEQ "">,
    (<cfif IsDefined("FORM.Ensemble") AND #FORM.Ensemble# NEQ "">
    <cfqueryparam value="#FORM.Ensemble#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Category") AND #FORM.Category# NEQ "">
    <cfqueryparam value="#FORM.Category#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Selection") AND #FORM.Selection# NEQ "">
    <cfqueryparam value="#FORM.Selection#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Part4") AND #FORM.Part4# NEQ "">
    <cfqueryparam value="#FORM.Part4#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.File4") AND #FORM.File_Name4# NEQ "">
    <cfqueryparam value="#FORM.File_Name4#" cfsqltype="cf_sql_clob" maxlength="255">
    <cffile action="upload" filefield="File4" destination="C:\Coldfusion9\wwwroot\CrimsonTideBand\#FORM.Ensemble#\member_files" nameconflict="overwrite">
    <cfelse>
    </cfif>
    , <cfif IsDefined("SESSION.MM_Username") AND #SESSION.MM_Username# NEQ "">
    <cfqueryparam value="#SESSION.MM_Username#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>)
    </cfif>
    <cfif IsDefined("FORM.File5") AND #FORM.File5# NEQ "">,
    (<cfif IsDefined("FORM.Ensemble") AND #FORM.Ensemble# NEQ "">
    <cfqueryparam value="#FORM.Ensemble#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Category") AND #FORM.Category# NEQ "">
    <cfqueryparam value="#FORM.Category#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Selection") AND #FORM.Selection# NEQ "">
    <cfqueryparam value="#FORM.Selection#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Part5") AND #FORM.Part5# NEQ "">
    <cfqueryparam value="#FORM.Part5#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.File5") AND #FORM.File_Name5# NEQ "">
    <cfqueryparam value="#FORM.File_Name5#" cfsqltype="cf_sql_clob" maxlength="255">
    <cffile action="upload" filefield="File5" destination="C:\Coldfusion9\wwwroot\CrimsonTideBand\#FORM.Ensemble#\member_files" nameconflict="overwrite">
    <cfelse>
    </cfif>
    , <cfif IsDefined("SESSION.MM_Username") AND #SESSION.MM_Username# NEQ "">
    <cfqueryparam value="#SESSION.MM_Username#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>)
    </cfif>
    <cfif IsDefined("FORM.File6") AND #FORM.File6# NEQ "">,
    (<cfif IsDefined("FORM.Ensemble") AND #FORM.Ensemble# NEQ "">
    <cfqueryparam value="#FORM.Ensemble#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Category") AND #FORM.Category# NEQ "">
    <cfqueryparam value="#FORM.Category#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Selection") AND #FORM.Selection# NEQ "">
    <cfqueryparam value="#FORM.Selection#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Part6") AND #FORM.Part6# NEQ "">
    <cfqueryparam value="#FORM.Part6#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.File6") AND #FORM.File_Name6# NEQ "">
    <cfqueryparam value="#FORM.File_Name6#" cfsqltype="cf_sql_clob" maxlength="255">
    <cffile action="upload" filefield="File6" destination="C:\Coldfusion9\wwwroot\CrimsonTideBand\#FORM.Ensemble#\member_files" nameconflict="overwrite">
    <cfelse>
    </cfif>
    , <cfif IsDefined("SESSION.MM_Username") AND #SESSION.MM_Username# NEQ "">
    <cfqueryparam value="#SESSION.MM_Username#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>)
    </cfif>
    <cfif IsDefined("FORM.File7") AND #FORM.File7# NEQ "">,
    (<cfif IsDefined("FORM.Ensemble") AND #FORM.Ensemble# NEQ "">
    <cfqueryparam value="#FORM.Ensemble#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Category") AND #FORM.Category# NEQ "">
    <cfqueryparam value="#FORM.Category#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Selection") AND #FORM.Selection# NEQ "">
    <cfqueryparam value="#FORM.Selection#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Part7") AND #FORM.Part7# NEQ "">
    <cfqueryparam value="#FORM.Part7#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.File7") AND #FORM.File_Name7# NEQ "">
    <cfqueryparam value="#FORM.File_Name7#" cfsqltype="cf_sql_clob" maxlength="255">
    <cffile action="upload" filefield="File7" destination="C:\Coldfusion9\wwwroot\CrimsonTideBand\#FORM.Ensemble#\member_files" nameconflict="overwrite">
    <cfelse>
    </cfif>
    , <cfif IsDefined("SESSION.MM_Username") AND #SESSION.MM_Username# NEQ "">
    <cfqueryparam value="#SESSION.MM_Username#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>)
    </cfif>
    <cfif IsDefined("FORM.File8") AND #FORM.File8# NEQ "">,
    (<cfif IsDefined("FORM.Ensemble") AND #FORM.Ensemble# NEQ "">
    <cfqueryparam value="#FORM.Ensemble#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Category") AND #FORM.Category# NEQ "">
    <cfqueryparam value="#FORM.Category#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Selection") AND #FORM.Selection# NEQ "">
    <cfqueryparam value="#FORM.Selection#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Part8") AND #FORM.Part8# NEQ "">
    <cfqueryparam value="#FORM.Part8#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.File8") AND #FORM.File_Name8# NEQ "">
    <cfqueryparam value="#FORM.File_Name8#" cfsqltype="cf_sql_clob" maxlength="255">
    <cffile action="upload" filefield="File8" destination="C:\Coldfusion9\wwwroot\CrimsonTideBand\#FORM.Ensemble#\member_files" nameconflict="overwrite">
    <cfelse>
    </cfif>
    , <cfif IsDefined("SESSION.MM_Username") AND #SESSION.MM_Username# NEQ "">
    <cfqueryparam value="#SESSION.MM_Username#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>)
    </cfif>
    <cfif IsDefined("FORM.File9") AND #FORM.File9# NEQ "">,
    (<cfif IsDefined("FORM.Ensemble") AND #FORM.Ensemble# NEQ "">
    <cfqueryparam value="#FORM.Ensemble#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Category") AND #FORM.Category# NEQ "">
    <cfqueryparam value="#FORM.Category#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Selection") AND #FORM.Selection# NEQ "">
    <cfqueryparam value="#FORM.Selection#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Part9") AND #FORM.Part9# NEQ "">
    <cfqueryparam value="#FORM.Part9#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.File9") AND #FORM.File_Name9# NEQ "">
    <cfqueryparam value="#FORM.File_Name9#" cfsqltype="cf_sql_clob" maxlength="255">
    <cffile action="upload" filefield="File9" destination="C:\Coldfusion9\wwwroot\CrimsonTideBand\#FORM.Ensemble#\member_files" nameconflict="overwrite">
    <cfelse>
    </cfif>
    , <cfif IsDefined("SESSION.MM_Username") AND #SESSION.MM_Username# NEQ "">
    <cfqueryparam value="#SESSION.MM_Username#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>)
    </cfif>
    <cfif IsDefined("FORM.File10") AND #FORM.File10# NEQ "">,
    (<cfif IsDefined("FORM.Ensemble") AND #FORM.Ensemble# NEQ "">
    <cfqueryparam value="#FORM.Ensemble#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Category") AND #FORM.Category# NEQ "">
    <cfqueryparam value="#FORM.Category#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Selection") AND #FORM.Selection# NEQ "">
    <cfqueryparam value="#FORM.Selection#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Part10") AND #FORM.Part10# NEQ "">
    <cfqueryparam value="#FORM.Part10#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.File10") AND #FORM.File_Name10# NEQ "">
    <cfqueryparam value="#FORM.File_Name10#" cfsqltype="cf_sql_clob" maxlength="255">
    <cffile action="upload" filefield="File10" destination="C:\Coldfusion9\wwwroot\CrimsonTideBand\#FORM.Ensemble#\member_files" nameconflict="overwrite">
    <cfelse>
    </cfif>
    , <cfif IsDefined("SESSION.MM_Username") AND #SESSION.MM_Username# NEQ "">
    <cfqueryparam value="#SESSION.MM_Username#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>)
    </cfif>
    <cfif IsDefined("FORM.File11") AND #FORM.File11# NEQ "">,
    (<cfif IsDefined("FORM.Ensemble") AND #FORM.Ensemble# NEQ "">
    <cfqueryparam value="#FORM.Ensemble#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Category") AND #FORM.Category# NEQ "">
    <cfqueryparam value="#FORM.Category#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Selection") AND #FORM.Selection# NEQ "">
    <cfqueryparam value="#FORM.Selection#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Part11") AND #FORM.Part11# NEQ "">
    <cfqueryparam value="#FORM.Part11#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.File11") AND #FORM.File_Name11# NEQ "">
    <cfqueryparam value="#FORM.File_Name11#" cfsqltype="cf_sql_clob" maxlength="255">
    <cffile action="upload" filefield="File11" destination="C:\Coldfusion9\wwwroot\CrimsonTideBand\#FORM.Ensemble#\member_files" nameconflict="overwrite">
    <cfelse>
    </cfif>
    , <cfif IsDefined("SESSION.MM_Username") AND #SESSION.MM_Username# NEQ "">
    <cfqueryparam value="#SESSION.MM_Username#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>)
    </cfif>
    <cfif IsDefined("FORM.File12") AND #FORM.File12# NEQ "">,
    (<cfif IsDefined("FORM.Ensemble") AND #FORM.Ensemble# NEQ "">
    <cfqueryparam value="#FORM.Ensemble#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Category") AND #FORM.Category# NEQ "">
    <cfqueryparam value="#FORM.Category#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Selection") AND #FORM.Selection# NEQ "">
    <cfqueryparam value="#FORM.Selection#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Part12") AND #FORM.Part12# NEQ "">
    <cfqueryparam value="#FORM.Part12#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.File12") AND #FORM.File_Name12# NEQ "">
    <cfqueryparam value="#FORM.File_Name12#" cfsqltype="cf_sql_clob" maxlength="255">
    <cffile action="upload" filefield="File12" destination="C:\Coldfusion9\wwwroot\CrimsonTideBand\#FORM.Ensemble#\member_files" nameconflict="overwrite">
    <cfelse>
    </cfif>
    , <cfif IsDefined("SESSION.MM_Username") AND #SESSION.MM_Username# NEQ "">
    <cfqueryparam value="#SESSION.MM_Username#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>)
    </cfif>
    <cfif IsDefined("FORM.File13") AND #FORM.File13# NEQ "">,
    (<cfif IsDefined("FORM.Ensemble") AND #FORM.Ensemble# NEQ "">
    <cfqueryparam value="#FORM.Ensemble#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Category") AND #FORM.Category# NEQ "">
    <cfqueryparam value="#FORM.Category#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Selection") AND #FORM.Selection# NEQ "">
    <cfqueryparam value="#FORM.Selection#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Part13") AND #FORM.Part13# NEQ "">
    <cfqueryparam value="#FORM.Part13#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.File13") AND #FORM.File_Name13# NEQ "">
    <cfqueryparam value="#FORM.File_Name13#" cfsqltype="cf_sql_clob" maxlength="255">
    <cffile action="upload" filefield="File13" destination="C:\Coldfusion9\wwwroot\CrimsonTideBand\#FORM.Ensemble#\member_files" nameconflict="overwrite">
    <cfelse>
    </cfif>
    , <cfif IsDefined("SESSION.MM_Username") AND #SESSION.MM_Username# NEQ "">
    <cfqueryparam value="#SESSION.MM_Username#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>)
    </cfif>
    <cfif IsDefined("FORM.File14") AND #FORM.File14# NEQ "">,
    (<cfif IsDefined("FORM.Ensemble") AND #FORM.Ensemble# NEQ "">
    <cfqueryparam value="#FORM.Ensemble#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Category") AND #FORM.Category# NEQ "">
    <cfqueryparam value="#FORM.Category#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Selection") AND #FORM.Selection# NEQ "">
    <cfqueryparam value="#FORM.Selection#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Part14") AND #FORM.Part14# NEQ "">
    <cfqueryparam value="#FORM.Part14#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.File14") AND #FORM.File_Name14# NEQ "">
    <cfqueryparam value="#FORM.File_Name14#" cfsqltype="cf_sql_clob" maxlength="255">
    <cffile action="upload" filefield="File14" destination="C:\Coldfusion9\wwwroot\CrimsonTideBand\#FORM.Ensemble#\member_files" nameconflict="overwrite">
    <cfelse>
    </cfif>
    , <cfif IsDefined("SESSION.MM_Username") AND #SESSION.MM_Username# NEQ "">
    <cfqueryparam value="#SESSION.MM_Username#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>)
    </cfif>
    <cfif IsDefined("FORM.File15") AND #FORM.File15# NEQ "">,
    (<cfif IsDefined("FORM.Ensemble") AND #FORM.Ensemble# NEQ "">
    <cfqueryparam value="#FORM.Ensemble#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Category") AND #FORM.Category# NEQ "">
    <cfqueryparam value="#FORM.Category#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Selection") AND #FORM.Selection# NEQ "">
    <cfqueryparam value="#FORM.Selection#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.Part15") AND #FORM.Part15# NEQ "">
    <cfqueryparam value="#FORM.Part15#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>
    , <cfif IsDefined("FORM.File15") AND #FORM.File_Name15# NEQ "">
    <cfqueryparam value="#FORM.File_Name15#" cfsqltype="cf_sql_clob" maxlength="255">
    <cffile action="upload" filefield="File15" destination="C:\Coldfusion9\wwwroot\CrimsonTideBand\#FORM.Ensemble#\member_files" nameconflict="overwrite">
    <cfelse>
    </cfif>
    , <cfif IsDefined("SESSION.MM_Username") AND #SESSION.MM_Username# NEQ "">
    <cfqueryparam value="#SESSION.MM_Username#" cfsqltype="cf_sql_clob" maxlength="255">
    <cfelse>
    </cfif>)
    </cfif>
  </cfquery>
  <cflocation url="/admin/upload_confirm.cfm">
</cfif>

Okay, I've rewritten the page and sql using loops. The problem I have is that if I don't use all the file fields, I get the error message:
The form field File2 did not contain a file.
(substitute whatever file field is the first empty one).
What I tried to do was insert <cfif> tags to overlook the blank entries. Here's my new SQL:
<cfif IsDefined ("FORM.MM_InsertRecord") AND FORM.MM_InsertRecord EQ "upload">
  <cfloop from="1" to="15" index="counter">
    <cfset CurrentPart="FORM.Part#counter#">
    <cfif #CurrentPart# NEQ "">
      <cffile action="upload" filefield="File#counter#" destination="C:\Coldfusion9\wwwroot\CrimsonTideBand\#FORM.Ensemble#\member_files" nameconflict="overwrite">
      <cfquery datasource="ctband">
        INSERT INTO Files (Ensemble, Category, Selection, File_Name, Part, Uploaded_By)
        VALUES (<cfqueryparam value="#FORM.Ensemble#" cfsqltype="cf_sql_varchar">,
                <cfqueryparam value="#FORM.Category#" cfsqltype="cf_sql_varchar">,
                <cfqueryparam value="#FORM.Selection#" cfsqltype="cf_sql_varchar">,
                "#CFFILE.serverFile#",
                <cfqueryparam value="#CurrentPart#" cfsqltype="cf_sql_varchar">,
                <cfqueryparam value="#SESSION.MM_Username#" cfsqltype="cf_sql_varchar">)
      </cfquery>
    </cfif>
  </cfloop>
</cfif>
Any thoughts on how to get it to overlook the unused file fields, or stop the loop at the last populated field?
Thanks for your help!

Similar Messages

  • Why is the clause marked red giving error - unexpected end of sql statement

    INSERT INTO APP_PUBLICATION
    (DESCRIPTION1,
    NU,
    NT,
    CANADA)
         SELECT
    DISTINCT(APP_NPS_GROUP_DESC),
                             (select 0 from ape_summary_a where app_nps_group_desc = a.app_nps_group_desc and province_code != 'B'),
                             (select 0 from ape_summary_a where app_nps_group_desc = a.app_nps_group_desc and province_code != 'B'),                         (select 0 from ape_summary_a where app_nps_group_desc = a.app_nps_group_desc and province_code IN('B')
                        FROM ape_summary_a a ;

    I believe you are missing a parenthesis from the last select statement
    INSERT INTO APP_PUBLICATION
    (DESCRIPTION1,
    NU,
    NT,
    CANADA)
    SELECT
    DISTINCT(APP_NPS_GROUP_DESC),
    (select 0 from ape_summary_a where app_nps_group_desc = a.app_nps_group_desc and province_code != 'B'),
    (select 0 from ape_summary_a where app_nps_group_desc = a.app_nps_group_desc and province_code != 'B'), (select 0 from ape_summary_a where app_nps_group_desc = a.app_nps_group_desc and province_code IN('B') )
    FROM ape_summary_a a ;
    Shakti
    http://www.impact-sol.com
    Developers of Guggi Oracle - Tool for DBAs and Developers

  • Update record using SQL statement

    I have VB6.0 and Oracle 10G Express Edition in Windows 2000 Server. My procedure in VB 6.0 can't update record in the table using SQL statement, and the Error Message is " Missing SET keyword ".
    The SQL statement in VB6.0 look like this :
    General Declaration
    Dim conn as New ADODB.Connection
    Dim rs as New ADODB.Recordset
    Private Sub Command1_Click()
    dim sql as string
    sql = " UPDATE my_table " & _
    " SET Name = ' " & Text3.Text & " ' " & _
    " AND Unit = ' " & Text2.Text & " ' " & _
    " WHERE ID = ' " & Text1.Text & " ' "
    conn.Execute (sql)
    Private Sub Form Load()
    Set conn = New ADODB.Connection
    conn.Open "Provider=MSDASQL;" & "Data Source=my_table;"& "User ID =marketing;" & "Password=pass123;"
    I'm sorry about my language.
    What's wrong in my SQL statement, I need help ........ asap
    Best Regards,
    /Harso Adjie

    The syntax should be
    UPDATE TABLE XX
    SET FLD_1 = 'xxxx',
    FLD_2 = 'YYYY'
    WHERE ...
    'AND' is improperly placed in the SET.

  • Multiple sql statements from java

    I am executing sql statements in MaxDB 7.6.04.12 from java using jdbc.
    I want to execute multiple statements at a time, but it seems that however I separate the statements, I get
    com.sap.dbtech.jdbc.exceptions.DatabaseException: [-3014] (at 433): Invalid end of SQL statement
    I have tried separating the statements with just a semi-colon, with a semi-colon and new line, with newline-//-newline (as works with SQL Studio), but whatever I try I get this error or some other.
    Is it possible to do this? and if so how?
    Thanks
    Chris

    Hi Lars,
    Here are the relevant bits of code.
    However I'm not sure how helpful that will be - I'm using the SpringFramework for my jdbc calls, as it saves a lot of time and effort, and my calls are to Spring methods, which are wrappers round the base jdbc calls.
    I'll post it anyway, just in case you're familiar with Spring. I haven't looked at the Spring code, but my understanding is it pretty much just passes the sql to standard jdbc calls.
    I guess my next step would be to trace through the Spring code as it executes and see if anything becomes apparent. However I'm under some time pressure and was hoping to avoid that.
    My other alternative is to create non-temporary tables, and drop them explicitly when I've finished with them.
        public Set<String> getPriceUpdatedProducts() {
            final Set<String> prods = new TreeSet<String>();
            String sql;
            int updates;
            // need single connection template so subsequent statements can access temp tables:
            JdbcTemplate jtSingle = getSingleConTemplate(jdbcTemplate);
            // inDCs is a list of dist channels for an sql 'in' statement:
            String inDCs = "";
            for (String siteId: siteConfig.getAllSiteIds()) {
                if (!"".equals(inDCs)) inDCs += ",";
                inDCs += "'" + siteConfig.getSiteIdProperty(siteId, "distChanId") + "'";
            // Clear all the changed flags from the last run:
            updates = jtSingle.update("update zchangedartdc set changed = '' ");
            // Get the current data into a temp table:
            sql = "create table temp.pricechanges as " +
                  "select A304.matnr, A304.vtweg, konp.kbetr price " +
                  "  from A304 join konp " +
                  "    on A304.knumh = konp.knumh " +
                  "   and A304.mandt = konp.mandt " +
                  "   and A304.vkorg = '" + salesOrg + "' " +
                  "   and A304.vtweg in (" + inDCs + ")" +
                  "   and A304.kschl = '" + rrpCondType + "' " +
                  "   and A304.mandt = '" + sapClient + "' " +
                  "   and konp.kschl = '" + listCondType + "' " +
                  "   and char(date, internal) >= chr(A304.datab) " +
                  "   and char(date, internal) <= chr(A304.datbi) " +
                  "   and A304.kappl = 'V' ";
            jtSingle.execute(sql);
            // Get the changes into a second temp table:
            sql = "create table temp.changedarts as " +
                  "select temp.pricechanges.* " +
                  "  from temp.pricechanges, zchangedartdc " +
                  " where zchangedartdc.matnr = temp.pricechanges.matnr " +
                  "   and zchangedartdc.vtweg = temp.pricechanges.vtweg " +
                  "   and zchangedartdc.price != temp.pricechanges.price ";
            jtSingle.execute(sql);
            // save the changes, and flag them:
            sql = "update zchangedartdc " +
                  "   set (price, changed) = (select price, 'X'  " +
                  "                             from temp.changedarts " +
                  "                            where zchangedartdc.matnr = temp.changedarts.matnr " +
                  "                              and zchangedartdc.vtweg = temp.changedarts.vtweg) " +
                  " where matnr||vtweg in (select matnr||vtweg from temp.changedarts) ";
            updates = jtSingle.update(sql);
            // add the new items that weren't there last time, and flag them:
            sql = "insert into zchangedartdc " +
                  "select '" + sapClient + "', matnr, vtweg, 'X', price " +
                  "  from temp.pricechanges " +
                  " where matnr||vtweg not in (select matnr||vtweg from zchangedartdc) ";
            updates = jtSingle.update(sql);
            // now we've got all the changes flagged, we can get the list of changed products:
            jtSingle.query("select distinct matnr from zchangedartdc " +
                           " where changed = 'X' ",
                           new RowCallbackHandler() {
                               public void processRow(ResultSet rs) throws SQLException {
                                   prods.add(rs.getString("matnr"));
            // release the connection:
            destroySingleConnection(jtSingle);
            return prods;
         * Return a JdbcTemplate which will always use the same connection. Parameter jt is just
         * a convenient way to get a DataSource from which to get a Connection.
         * When the calling prodedure has finished, it MUST call
         * destroySingleConnection(jt)
         * @param jt
         * @return
        private JdbcTemplate getSingleConTemplate(JdbcTemplate jt) {
            Connection con;
            try {
                con = jt.getDataSource().getConnection();
                con.setAutoCommit(true);
            } catch (SQLException e) {
                throw new DataAccessResourceFailureException("Failed to get Connection for SingleConnectionDataSource", e);
            SingleConnectionDataSource singleDs = new SingleConnectionDataSource(con, true);
            return new JdbcTemplate(singleDs);
        private void destroySingleConnection(JdbcTemplate singleConJt) {
            try{
                ((SingleConnectionDataSource)singleConJt.getDataSource()).destroy();
            } catch (SQLException e) {
                throw new DataAccessResourceFailureException("Failed to destroy SingleConnectionDataSource", e);

  • Find start and end execution time of a sql statement?

    I am have databases with 10.2.0.3 and 9.2.0.8 on HP UNIX 11i and Windows 200x.
    I am not in a position to turn on sql tracing in production environment. Yet, I want to find when a sql statement started executing and when it ended. When I look at v$sql, it has information such FIRST_LOAD_TIME, LAST_LOAD_TIME etc. No where it has information last time statement began execution and when it ended execution.. It shows no of executions, elapsed time etc, but they are cumulative. Is there a way to find individual times (time information each time a sql statement was executed. – its start time, its end time ….)? If I were to write my own program how will I do it?
    Along the same line, when an AWR snapshot is shown, does it only include statements executed during that snapshot or it can have statements from the past if they have not been flushed from shared memory. If it only has statements executed in the snapshot period, how does it know when statement began execution?

    Hi,
    For oracle 10g you can use below query to find start and end time, you can see data for last seven days.
    select min(to_char(a.sample_time,'DD-MON-YY HH24:MI:SS')) "Start time", max(to_char(a.sample_time,'DD-MON-YY HH24:MI:SS')) "End Time", b.sql_text
    from dba_HIST_ACTIVE_SESS_HISTORY a,DBA_HIST_SQLTEXT b where
    a.sql_id=b.sql_id
    order by 1;
    Regards
    Jafar

  • SQL STATEMENT NOT PROPERLY ENDED - HELP NEEDED

    Can anyone tell me the error in this code, I get an error message sql statement not properly ended when I run it.
    update MODT set rootobj=(SELECT REF(A) FROM
    OR_COMP_T A
    WHERE A.ID=O.ID)
    AS OR_COMP_T_REF)
    FROM OLD_MODT O where id = 1;

    Hi, here is the schema and the expected results.
    =======================================================================================
    CREATE TYPE OR_MODT_OBJ;
    CREATE TYPE OR_MODT_OBJ_REF AS TABLE OF REF OR_MODT_OBJ;
    =================================================
    CREATE OR REPLACE TYPE OR_COMP_T_OBJ
    (id number (6),
    typ char (4),
    SUPERID REF OR_COMP_T_OBJ,
    MOD REF OR_MODT_OBJ);
    =================================================
    CREATE OR REPLACE TYPE OR_COMP_T_REF AS TABLE OF REF OR_COMP_T_OBJ;
    =================================================
    CREATE TABLE OR_COMP_T OF OR_COMP_T_OBJ
    =================================================
    CREATE TYPE OR_MODT_OBJ
    (id number (6),
    typ char (4),
    rootobj REF OR_COMP_T_OBJ,
    comp_tb     OR_COMP_T_REF);
    =================================================
    CREATE TABLE MODT OF OR_MODT_OBJ
    NESTED COMP_TB STORE AS COMP_TB_NESTED;
    =================================================
    INSERT INTO OR_MODT (ID,TYP,ROOTOBJ,COMP_TB)
    SELECT ID,TYP,NULL,NULL FROM OLD_MODT;
    INSERT INTO OR_COMP_T(ID,TYP,SUPERID,MOD)
    SELECT ID,TYP,NULL,NULL FROM OLD_OR_COMP_T;
    ==================================================
    There are two rows in OLD_MODT, and these two rows are to be inserted into OR_MODT.
    They are:
    Sample data in OLD_MODT are:
    id,      typ,     rootobj
    1     type1     1
    2     type3     365
    =================================================
    Data from OLD_OR_COMP_T is to be inserted into OR_COMP_T as well, and likewise, it has a ref to OR_MODT, so the ref data was not inserted at the same time.
    Now OLD_OR_COMP_T has a number of rows but attribute MOD for two of these rows os the rootobj for OR_MODT,
    such that:
    id     typ     superID     mod
    1     type4     NULL     1
    2     type2     10101     1
    3     type     20202     1
    365     type2     NULL     2
    366     type2     20202     2
    I want to get the ID of OR_COMP_T where ID is 1 and where ID is 365. These values are to be in rootobj.
    I also want to get the value of ID in OR_MODT to be placed in MOD of OR_COMP_T.
    PLEASE HELP ME.

  • Missing or invalid version of SQL library PSORA (200,0)

    I am trying to configure App. Server on Vista laptop machine.
    The machine name is VRGhati03.
    It is a logical 3 tier archtecture. Its a EPM 9.0 Install. My database (PFDMO) is all configured and I am able to signon using a User ID VP1 and password VP1. My connect id is people with password of peop1e.
    My access id is SYSADM.
    I have created a user id in Oracle as VP1 and granted him the PSADMIN role .
    When I try to boot up the App. Server it tells me ' Missing or invalid version of SQL Library PSORA' and 'Could not sign on to database PFDMO with user VP1'
    The VP1 sign on works via SQLPLUS.
    I also created a User Account of VP1 and tried to boot the appserver under that id but still no success.
    I have gone thru some of the postings on this topic but they have not helped me. What am I doing wrong?
    Below are the details of the log files, portion of my psappserv.cng file and the system environment variables.
    Can somebody help. Thanks in advance
    Sudhir
    I) Log from APPSERV:
    PSADMIN.10000 (0) [08/05/09 09:19:24](0) Begin boot attempt on domain PFDMO
    PSWATCHSRV.2556 (0) [08/05/09 09:19:33] Checking process status every 120 seconds
    PSWATCHSRV.2556 (0) [08/05/09 09:19:33] Server started
    PSAPPSRV.5636 (0) [08/05/09 09:19:34](0) PeopleTools Release 8.49 (WinX86) starting
    PSAPPSRV.5636 (0) [08/05/09 09:19:34](0) Cache Directory being used: C:\PT8.49\appserv\PFDMO\CACHE\PSAPPSRV_2\
    PSAPPSRV.5636 (0) [08/05/09 09:19:34](1) GenMessageBox(200, 0, M): PS General SQL Routines: Missing or invalid version of SQL library PSORA (200,0)
    PSAPPSRV.5636 (0) [08/05/09 09:19:34](1) GenMessageBox(0, 0, M): Database Signon: Could not sign on to database PFDMO with user VP1.
    PSAPPSRV.5636 (0) [08/05/09 09:19:34](0) Server failed to start
    PSWATCHSRV.2556 (0) [08/05/09 09:19:35] Shutting down
    PSADMIN.10000 (0) [08/05/09 09:19:41](0) End boot attempt on domain PFDMO
    II) Log from TUXLOG:
    091924.VRGHATI03!PSADMIN.10000: Begin attempt on domain PFDMO
    091927.VRGHATI03!tmadmin.9844.8684.-2: TMADMIN_CAT:1330: INFO: Command: boot -A
    091929.VRGHATI03!tmboot.9720.8272.-2: 08-05-2009: Tuxedo Version 9.1, 32-bit
    091929.VRGHATI03!tmboot.9720.8272.-2: CMDTUX_CAT:1851: INFO: TM_BOOTTIMEOUT is set to 60 seconds
    091929.VRGHATI03!tmboot.9720.8272.-2: CMDTUX_CAT:1855: INFO: TM_BOOTPRESUMEDFAIL option is selected
    091931.VRGHATI03!BBL.8340.3320.0: 08-05-2009: Tuxedo Version 9.1, 32-bit, Patch Level 036
    091931.VRGHATI03!BBL.8340.3320.0: LIBTUX_CAT:262: INFO: Standard main starting
    091933.VRGHATI03!tmboot.9224.8412.-2: 08-05-2009: Tuxedo Version 9.1, 32-bit
    091933.VRGHATI03!tmboot.9224.8412.-2: CMDTUX_CAT:1851: INFO: TM_BOOTTIMEOUT is set to 60 seconds
    091933.VRGHATI03!tmboot.9224.8412.-2: CMDTUX_CAT:1855: INFO: TM_BOOTPRESUMEDFAIL option is selected
    091933.VRGHATI03!PSWATCHSRV.2556.9492.-2: 08-05-2009: Tuxedo Version 9.1, 32-bit
    091933.VRGHATI03!PSWATCHSRV.2556.9492.-2: LIBTUX_CAT:262: INFO: Standard main starting
    091934.VRGHATI03!PSAPPSRV.5636.9008.0: 08-05-2009: Tuxedo Version 9.1, 32-bit
    091934.VRGHATI03!PSAPPSRV.5636.9008.0: LIBTUX_CAT:262: INFO: Standard main starting
    091934.VRGHATI03!PSAPPSRV.5636.9008.0: LIBTUX_CAT:250: ERROR: tpsvrinit() failed
    091934.VRGHATI03!tmboot.9224.8412.-2: tmboot: CMDTUX_CAT:827: ERROR: Fatal error encountered; initiating user error handler
    091938.VRGHATI03!BBL.8340.3320.0: CMDTUX_CAT:26: INFO: The BBL is exiting system
    091941.VRGHATI03!PSADMIN.10000: End boot attempt on domain PFDMO
    III) System Environmental Variables:
    LIBPATH=c:\oracle\product\10.2.0\db_1\LIB
    ORACLE_SID=PFDMO
    OS=Windows_NT
    path=C:\oracle\product\10.2.0\db_1\bin;C:\product\10.1.3.1\OracleAS_1\jdk\bin;C:\product\10.1.3.1\OracleAS_1\ant\bin;C:\product\10.1.3.1\OracleAS_1\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared\10.0\DLLShared\;c:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\bea\Tuxedo9.1\bin
    TUXDIR=C:\bea\Tuxedo9.1
    IV) psappserv.cfg File:
    [Startup]
    ;=========================================================================
    ; Database Signon settings
    ;=========================================================================
    DBName=PFDMO
    DBType=ORACLE
    UserId=VP1
    UserPswd=tRWpMM0Cragi9I0nrWPAxZ+GS1YD0PRXzCrF4YWbe5E=
    ConnectId=people
    ConnectPswd=kyD3QPxnrag=
    ServerName=VRGhati03
    [Database Options]
    ;=========================================================================
    ; Database-specific configuration options
    ;=========================================================================
    SybasePacketSize=
    UseLocalOracleDB=0
    ;ORACLE_SID=
    EnableDBMonitoring=1
    OracleDisableFirstRowsHint=0
    [Security]
    ;=========================================================================
    ; Security settings
    ;=========================================================================
    Validate Signon with Database=0
    [Workstation Listener]
    ;=========================================================================
    ; Settings for Workstation Listener
    ;=========================================================================
    Address=%PS_MACH%
    Port=7000
    Encryption=0
    Min Handlers=1
    Max Handlers=3
    Max Clients per Handler=40
    Client Cleanup Timeout=60
    Init Timeout=5
    Tuxedo Compression Threshold=5000
    [JOLT Listener]
    ;=========================================================================
    ; Settings for JOLT Listener
    ;=========================================================================
    Address=%PS_MACH%
    Port=9000
    Encryption=0
    Min Handlers=5
    Max Handlers=7
    Max Clients per Handler=40
    Client Cleanup Timeout=10
    Init Timeout=5
    Client Connection Mode=ANY
    Jolt Compression Threshold=1000000
    [JOLT Relay Adapter]
    ;=========================================================================
    ; Settings for JOLT Relay Adapter (JRAD)
    ;=========================================================================
    Listener Address=%PS_MACH%
    Listener Port=9100
    [Domain Settings]
    ;=========================================================================
    ; General settings for this Application Server.
    ;=========================================================================
    Domain ID=PFDMO
    Add to PATH=c:\oracle\product\10.2.0\db_1\BIN
    Spawn Threshold=1,600:1,1
    Restartable=Y
    ;Log Directory=%PS_SERVDIR%\LOGS
    ; This allows for dynamic changes to certain setting without having to reboot
    ; the domain. The settings that can be dynamically changed are: Recycle Count,
    ; Consecutive Service failures, Trace SQL, Trace Mask SQL, TracePC, TracePCMask,
    ; TracePpr, TracePprMask, TracePIA, TracePIAMask, Log Fence, Enable DB Monitoring,
    ; Enable Debugging, LogErrorReport, MailErrorReport, DumpMemoryImageAtCrash
    ; These settings are further identified by the "Dynamic change allowed for .."
    ; comment.
    Allow Dynamic Changes=N
    ; Logging detail level
    ; Level Type of information
    ; -100 - Suppress logging
    ; -1 - Protocol, memory errors
    ; 0 - Status information
    ; 1 - General errors
    ; 2 - Warnings
    ; 3 - Tracing Level 1 (default)
    ; 4 - Tracing Level 2
    ; 5 - Tracing Level 3
    ; Dynamic change allowed for LogFence
    LogFence=3
    ; Trace-Log File Character Set: Character set used for log and trace files
    Trace-Log File Character Set=ANSI
    [PeopleCode Debugger]
    ;=========================================================================
    ; PeopleCode Debug Server settings
    ;=========================================================================
    PSDBGSRV Listener Port=9500
    ; PeopleCode Debugger Trace Settings
    ; Level Type of tracing
    ; 0 Off (default)
    ; 1 Level 1 - log connection activity
    ; 2 Level 2 - log debug broker transactions (getsession, register/unregister, acquire/unacquire)
    ; 3 Level 3 - log primary debuggee/debugger transactions (register, modechange, seteventflag, break)
    ; 4 Level 4 - log debuggee/debugger variables transactions
    ; 5 Level 5 - log debuggee/debugger command responses and gotbreaks
    ; Warning: Levels 3 thru 5 result in lots of transaction data being logger and require plenty of disk space.
    DebuggerMsgLogEnable=0
    [Trace]
    ;=========================================================================
    ; Server Trace settings
    ;=========================================================================
    ; SQL Tracing Bitfield
    ; Bit Type of tracing
    ; 1 - SQL statements
    ; 2 - SQL statement variables
    ; 4 - SQL connect, disconnect, commit and rollback
    ; 8 - Row Fetch (indicates that it occurred, not data)
    ; 16 - All other API calls except ssb
    ; 32 - Set Select Buffers (identifies the attributes of columns
    ; to be selected).
    ; 64 - Database API specific calls
    ; 128 - COBOL statement timings
    ; 256 - Sybase Bind information
    ; 512 - Sybase Fetch information
    ; 1024 - SQL Informational Trace
    ; 4096 - Manager information
    ; 8192 - Mapcore information
    ; Dynamic change allowed for TraceSql and TraceSqlMask
    TraceSql=0
    TraceSqlMask=12319
    ; PeopleCode Tracing Bitfield
    ; Bit Type of tracing
    ; 1 - Trace Evaluator instructions (not recommended)
    ; 2 - List Evaluator program (not recommended)
    ; 4 - Show assignments to variables
    ; 8 - Show fetched values
    ; 16 - Show stack
    ; 64 - Trace start of programs
    ; 128 - Trace external function calls
    ; 256 - Trace internal function calls
    ; 512 - Show parameter values
    ; 1024 - Show function return value
    ; 2048 - Trace each statement in program (recommended)
    ; Dynamic change allowed for TracePC and TracePCMask
    TracePC=0
    TracePCMask=4095
    ; Panel Processor Tracing Bitfield
    ; Bit Type of tracing
    ; 1 - Log extra debug messages
    ; 2 - Dump panel after build
    ; 4 - Dump buffers after PPRInit
    ; 8 - Dump buffers before/after service
    ; 16 - Dump buffers after scrollselect
    ; 32 - Dump buffers after modal panel
    ; 64 - Dump buffers before save
    ; 128 - Dump buffers after insertrow
    ; 256 - Trace default processing
    ; 512 - Dump PRM data
    ; 1024 - Show function return value
    ; 2048 - dump memory statistics
    ; 4096 - Trace related display processing
    ; 8192 - Trace keylist generation
    ; 16384 - Trace work record settings
    ; Dynamic change allowed for TracePPR and TracePPRMask
    TracePPR=0
    TracePPRMask=32767
    ; PIA Page Generation Tracing Bitfield
    ; Bit Type of tracing
    ; 1 - Log page generation errors
    ; 2 - Show table layout via cell borders in generated page
    ; 4 - Annotate field overlap in HTML source
    ; 8 - Detailed trace of table generation algorithm
    ; 16 - Inline stylesheet in generated pages
    ; 32 - Inline javascript in generated pages
    ; 64 - QATesting - annotation and extra tags needed by Robot
    ; 128 - Format source. Make HTML more readable
    ; 256 - Save File. Save each generated page in log directory
    ; 512 - Debug JavaScript. Include debug functions in page
    ; 1024 - Log form data. Log all request parameters on each service
    ; 2048 - Log key errors. Write log message for unrecognized query parameters.
    ; Dynamic change allowed for TracePIA and TracePIAMask
    TracePIA=0
    TracePIAMask=32767
    ; AE Tracing Bitfield
    ; Bit Type of tracing
    ; 1 - Trace STEP execution sequence to AET file
    ; 2 - Trace Application SQL statements to AET file
    ; 4 - Trace Dedicated Temp Table Allocation to AET file
    ; 8 - not yet allocated
    ; 16 - not yet allocated
    ; 32 - not yet allocated
    ; 64 - not yet allocated
    ; 128 - Timings Report to AET file
    ; 256 - Method/BuiltIn detail instead of summary in AET Timings Report
    ; 512 - not yet allocated
    ; 1024 - Timings Report to tables, ignored if Process Instance is 0
    ; 2048 - DB optimizer trace to file
    ; 4096 - DB optimizer trace to tables
    ; 8192 - Transform trace
    TraceAE=0
    ; Analytic Server Tracing Bitfield
    ; MostSignificantBit -> LeastSignificantBit
    ; QAS |ACE MODEL | ACE CALC | ACE API| Plugin | DCache | Utils | Analytic Server |
    ; 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    ; Bit Type of tracing 3 bits per component (octal word)
    ; 1 - Analytic Server LSB
    ; 2 - Analytic Server MSB LSB LogFence
    ; 4 - Analytic Server MSB --- --- --------------------
    ; 8 - Utilities LSB 0 0 0 0 (Severity_Status)
    ; 16 - Utilities 0 0 1 1 (Severity_Error)
    ; 32 - Utilities MSB 0 1 0 2 (Severity_Warn)
    ; 64 - DataCache LSB 0 1 1 3 (Severity_Info)
    ; 128 - DataCache 1 0 0 4 (Severity_Trace1)
    ; 256 - DataCache MSB 1 0 1 5 (Severity_Trace2)
    ; 512 - Plug-in LSB 1 1 0 6 (not used)
    ; 1024 - Plug-in 1 1 1 7 (not used)
    ; 2048 - Plug-in MSB
    ; 4096 - ACE API LSB
    ; 8192 - ACE API
    ; 16384 - ACE API MSB
    ; 32768 - ACE CALC LSB
    ; 65536 - ACE CALC
    ; 131072 - ACE CALC MSB
    ; 262144 - ACE MODEL LSB
    ; 524288 - ACE MODEL
    ; 1048576 - ACE MODEL MSB
    ; 2097152 - QAS LSB
    ; 4194304 - QAS
    ; 8388608 - QAS MSB
    ; The bits enable logging for OptEngine components beyond the standard
    ; LogFence setting. E.g., TraceAnalytic=14380470 sets full trace on all components.
    ; Using 110 (1 greater than Severity_Trace2) for each component:
    ; OptEng: 4 + 2
    ; Utils : 32 + 16
    ; DC : 256 + 128
    ; Plugin: 2048 + 1024
    ; ACE API: 16384 + 8192
    ; ACE CALC: 131072 + 65536
    ; ACE MODEL: 1048576 + 524288
    ; QAS : 8388608 + 4194304
    ; Total : 14380470
    TraceAnalytic=9586980
    TraceAnalyticMask=16777215
    ; Performance Monitor Tracing Bitfield
    ; Bit Type of tracing
    ; 1 - Trace All performance monitor agent activity
    TracePPM=0
    ; Create a memory image of the failing process during a crash
    ; Setting Meaning
    ; NONE no memory image
    ; MINI mini memory image
    ; FULL full memory image
    ; If set to MINI or FULL, when a crash occurs, a memory.dmp file is
    ; generated under <log directory>/<server name>.<process id>.
    ; Dynamic change allowed.
    DumpMemoryImageAtCrash=NONE
    ;If set to Y, when a crash occurs, the application server process will write
    ;additional information to help in debugging the crash that occurred.
    ;This consists of the customized object definitions for reproducing
    ;the request on another database.
    DumpManagerObjectsAtCrash=Y
    ; If set to Y, when a runtime error is detected, the message and a dump of
    ; the application state will be written to the current log file.
    ; Dynamic change allowed.
    LogErrorReport=N
    ; When set to an email address, an email will be sent when an error report
    ; or a crash dump is written to the log.
    ; Dynamic change allowed.
    MailErrorReport=
    [Cache Settings]
    ;==============================================================================================
    ; Settings for managed object caching;
    ; Default EnableServerCaching=2, ServerCacheMode=0
    ; Default CacheBaseDir=%PS_SERVDIR% if defined else %PS_HOME/<domain name>/cache
    ; You can change these values by uncommenting and setting to the desired value
    ;==============================================================================================
    ; EnableServerCaching -
    ; 0 Server file caching disabled
    ; 1 Server file caching limited to most used classes
    ; 2 Server file caching for all types
    ;EnableServerCaching=2
    ; CacheBaseDir = the base file cache directory
    ;CacheBaseDir=%PS_SERVDIR%
    ; ServerCacheMode
    ; 0 One file cache directory per app server process
    ; 1 One file cache directory per domain (shared file cache, needs to be preloaded)
    ;ServerCacheMode=0
    ; Deprecated cache settings : MaxInMemoryObjects
    ; MaxCacheMemory - controls cache memory pruning
    ; 0 cache memory pruning disabled
    ; >0 max size of memory cache in MBytes
    MaxCacheMemory=0
    ; Preload Cache projects for file and in memory cache
    ;PreloadFileCache=
    ;PreloadMemoryCache=
    [RemoteCall]
    ;=========================================================================
    ; Settings for RemoteCall
    ;=========================================================================
    ; RemoteCall child process output redirection
    ; If this parameter is non-zero, the child process output is saved to
    ; <Domain Settings\Log Directory>\<program>_<oprid>.out, and any error
    ; output is saved to <program>_<oprid>.err.
    ; By default, the output is not saved
    RCCBL Redirect=0
    ; Location of COBOL programs
    ; NT/Windows 2000: By default, RemoteCall looks for the COBOL programs in
    ; %PS_HOME%\cblbin%PS_COBOLTYPE%. PS_COBOLTYPE is automatically set when
    ; the application server is started. The value depends upon the database.
    ; Possible values:
    ; PS_COBOLTYPE = A (non-Unicode)
    ; PS_COBOLTYPE = E (EBCDIC)
    ; PS_COBOLTYPE = U (Unicode)
    ; UNIX: By default, RemoteCall looks for the COBOL programs in $PS_HOME/cblbin.
    ; You can override the default setting by commenting out the appropriate
    ; line and modifying the setting to fit your requirements.
    ; NT/Windows 2000:
    ;RCCBL PRDBIN=%PS_HOME%\cblbin%PS_COBOLTYPE%
    ; UNIX:
    ;RCCBL PRDBIN=%PS_HOME%/cblbin
    [PSAPPSRV]
    ;=========================================================================
    ; Settings for PSAPPSRV
    ;=========================================================================
    ; UBBGEN settings
    Min Instances=3
    Max Instances=3
    Service Timeout=300
    ; Number of services after which PSAPPSRV will automatically restart.
    ; If the recycle count is set to zero, PSAPPSRV will never be recycled.
    ; The default value is 5000.
    ; Dynamic change allowed for Recycle Count
    Recycle Count=5000
    ; Percentage of Memory Growth after which PSAPPSRV will automatically restart.
    ; Default is 20, meaning additional 20% of memory growth after the process has
    ; built up its memory cache.
    ; Uncomment the setting to use memory growth instead of Recycle Count at
    ; determining the restart point.
    ; Percentage of Memory Growth=20
    ; Number of consecutive service failures after which PSAPPSRV will
    ; automatically restart.
    ; If this is set to zero, PSAPPSRV will never be recycled.
    ; The default value is zero.
    ; Dynamic change allowed for Allowed Consec Service Failures
    Allowed Consec Service Failures=2
    ; Max Fetch Size -- max result set size in KB for a SELECT query
    ; Default is 5000KB. Use 0 for no limit.
    Max Fetch Size=5000
    ; Automatically select prompt, 1 = yes, 0 = no
    Auto Select Prompts=1
    ; This parameter is used for Tuxedo Queue Thresold Determination (used forPub/Sub
    ; processing only). This parameter is the actual Tuxedo message queue size.
    ; This is a kernel parameter in Unix. For Windows, look in BEA Tuxedo, IPC Resources.
    ; A value of 0 will disable Tuxedo Queue threshold Determination and usage.
    ; A value of -1 will use these defaults: Windows = 65535, AIX = 4000000,
    ; Solaris = 65535, HP = 65535
    Tuxedo Queue Size=65535
    [PSANALYTICSRV]
    ;=========================================================================
    ; Settings for PSANALYTICSRV
    ;=========================================================================
    ; UBBGEN settings
    Min Instances=3
    Max Instances=3
    ; Number of Analytic Instances an Analytic Server instance will load and
    ; unload before recycling. If the recycle count is set to zero, the
    ; Analytic Server will never be recycled.
    ; The default value is 1.
    ; Dynamic changes to this setting are allowed. A dynamic change will
    ; affect running Analytic Servers.
    ;Recycle Count=1
    ; Number of minutes an analytic instance will remain loaded without being
    ; accessed when it is auto-loaded by the analytic grid or when a
    ; PeopleCode program loads the instance with a timeout value of -1.
    ; The default value is 30
    ; Setting this to zero will disable timeouts for auto-loaded instances.
    ; Dynamic changes to this setting are allowed.
    ;Analytic Instance Idle Timeout=30
    ; Setting this to 1 will cause each analytic server to log to it's own
    ; file rather than the common PSANALYTICSRV_<Month|Day>.LOG file. The
    ; individual log files will include the Tuxedo server ID.
    ; Dynamic changes to this setting are allowed. Changes will only come
    ; into affect for running analytic servers when they are recycled.
    ; The default value is 0
    ;Analytic Per Server Log=1
    ; This setting determines what is the threshold to enable file swaping
    ; in ACE. Each data block is of 6K. Each data cube is divided into multiple
    ; data blocks. In batch environment this could be configured to a higher value.
    ; The default value is 1024 blocks. If set to zero, the disk swaping is disabled.
    ;ACE Max Memory Data Blocks=1024
    ; Queue size for data loading in batches. If set to zero, batch loading is disabled.
    ;ACE Load Queue Size=100000
    [PSSAMSRV]
    ;=========================================================================
    ; Settings for PSSAMSRV
    ;=========================================================================
    ; UBBGEN settings
    ; PSSAMSRV never spawns, so we set Instances instead of setting a Min and
    ; Max value for Instances.
    Min Instances=1
    Max Instances=3
    Service Timeout=300
    ; Number of services after which PSSAMSRV will automatically restart.
    ; If the recycle count is set to zero, PSSAMSRV will never be recycled.
    ; The default value is zero.
    Recycle Count=100000
    ; Number of consecutive service failures after which PSSAMSRV will
    ; automatically restart.
    ; If this is set to zero, PSSAMSRV will never be recycled.
    ; The default value is zero.
    Allowed Consec Service Failures=2
    ; Max Fetch Size -- max result set size in KB for a SELECT query
    ; Max Fetch Size=n indicates n * 1024 bytes
    ; Default is 32KB. Use 0 for no limit
    Max Fetch Size=32
    [PSQCKSRV]
    ;=========================================================================
    ; Settings for PSQCKSRV
    ;=========================================================================
    ; UBBGEN settings
    Min Instances=1
    Max Instances=3
    Service Timeout=300
    ; Number of services after which PSQCKSRV will automatically restart.
    ; If the recycle count is set to zero, PSQCKSRV will never be recycled.
    ; The default value is zero.
    Recycle Count=100000
    ; Number of consecutive service failures after which PSQCKSRV will
    ; automatically restart.
    ; If this is set to zero, PSQCKSRV will never be recycled.
    ; The default value is zero.
    Allowed Consec Service Failures=2
    ; Max Fetch Size -- max result set size in KB for a SELECT query
    ; Default is 5000KB. Use 0 for no limit.
    Max Fetch Size=5000
    [PSQRYSRV]
    ;=========================================================================
    ; Settings for PSQRYSRV
    ;=========================================================================
    ; UBBGEN settings
    Min Instances=1
    Max Instances=3
    Service Timeout=1200
    ; Number of services after which PSQRYSRV will automatically restart.
    ; If the recycle count is set to zero, PSQRYSRV will never be recycled.
    ; The default value is zero.
    Recycle Count=100000
    ; Number of consecutive service failures after which PSQRYSRV will
    ; automatically restart.
    ; If this is set to zero, PSQRYSRV will never be recycled.
    ; The default value is zero.
    Allowed Consec Service Failures=2
    ; Max Fetch Size -- max result set size in KB for a SELECT query
    ; Default is 10000KB. Use 0 for no limit.
    Max Fetch Size=10000
    ; Use dirty-read(uncommitted read) for PSQRYSRV only on DB2/OS390 or SQL Server
    Use dirty-read=0

    VP1 is an application user, not a database user.
    PS is a database user, the Peoplesoft objects' owner. It is also an application user on some application.
    Did you try to connect onto the database with people user through SQL*Plus ? Are you able to read PSOPRDEFN, PSVERSION, PSACCESSPRFL tables ?
    What Vista version are you on ? What Oracle version ?
    If you have Metalink3 access, you should read the note :
    Missing or invalid version of SQL library libpsora (0,0) or (200,0) (Doc ID 608741.1)+
    Nicolas.

  • HOW TO: Post a SQL statement tuning request - template posting

    This post is not a question, but similar to Rob van Wijk's "When your query takes too long ..." post should help to improve the quality of the requests for SQL statement tuning here on OTN.
    On the OTN forum very often tuning requests about single SQL statements are posted, but the information provided is rather limited, and therefore it's not that simple to provide a meaningful advice. Instead of writing the same requests for additional information over and over again I thought I put together a post that describes how a "useful" post for such a request should look like and what information it should cover.
    I've also prepared very detailed step-by-step instructions how to obtain that information on my blog, which can be used to easily gather the required information. It also covers again the details how to post the information properly here, in particular how to use the \ tag to preserve formatting and get a fixed font output:
    http://oracle-randolf.blogspot.com/2009/02/basic-sql-statement-performance.html
    So again: This post here describes how a "useful" post should look like and what information it ideally covers. The blog post explains in detail how to obtain that information.
    In the future, rather than requesting the same additional information and explaining how to obtain it, I'll simply refer to this HOW TO post and the corresponding blog post which describes in detail how to get that information.
    *Very important:*
    Use the \ tag to enclose any output that should have its formatting preserved as shown below.
    So if you want to use fixed font formatting that preserves the spaces etc., do the following:
    \   This preserves formatting
    \And it will look like this:
       This preserves formatting
       . . .Your post should cover the following information:
    1. The SQL and a short description of its purpose
    2. The version of your database with 4-digits (e.g. 10.2.0.4)
    3. Optimizer related parameters
    4. The TIMING and AUTOTRACE output
    5. The EXPLAIN PLAN output
    6. The TKPROF output snippet that corresponds to your statement
    7. If you're on 10g or later, the DBMS_XPLAN.DISPLAY_CURSOR output
    The above mentioned blog post describes in detail how to obtain that information.
    Your post should have a meaningful subject, e.g. "SQL statement tuning request", and the message body should look similar to the following:
    *-- Start of template body --*
    The following SQL statement has been identified to perform poorly. It currently takes up to 10 seconds to execute, but it's supposed to take a second at most.
    This is the statement:
    select
    from
             t_demo
    where
             type = 'VIEW'
    order by
             id;It should return data from a table in a specific order.
    The version of the database is 11.1.0.7.
    These are the parameters relevant to the optimizer:
    SQL>
    SQL> show parameter optimizer
    NAME                                 TYPE        VALUE
    optimizer_capture_sql_plan_baselines boolean     FALSE
    optimizer_dynamic_sampling           integer     2
    optimizer_features_enable            string      11.1.0.7
    optimizer_index_caching              integer     0
    optimizer_index_cost_adj             integer     100
    optimizer_mode                       string      ALL_ROWS
    optimizer_secure_view_merging        boolean     TRUE
    optimizer_use_invisible_indexes      boolean     FALSE
    optimizer_use_pending_statistics     boolean     FALSE
    optimizer_use_sql_plan_baselines     boolean     TRUE
    SQL>
    SQL> show parameter db_file_multi
    NAME                                 TYPE        VALUE
    db_file_multiblock_read_count        integer     8
    SQL>
    SQL> show parameter db_block_size
    NAME                                 TYPE        VALUE
    db_block_size                        integer     8192
    SQL>
    SQL> show parameter cursor_sharing
    NAME                                 TYPE        VALUE
    cursor_sharing                       string      EXACT
    SQL>
    SQL> column sname format a20
    SQL> column pname format a20
    SQL> column pval2 format a20
    SQL>
    SQL> select
      2             sname
      3           , pname
      4           , pval1
      5           , pval2
      6  from
      7           sys.aux_stats$;
    SNAME                PNAME                     PVAL1 PVAL2
    SYSSTATS_INFO        STATUS                          COMPLETED
    SYSSTATS_INFO        DSTART                          01-30-2009 16:25
    SYSSTATS_INFO        DSTOP                           01-30-2009 16:25
    SYSSTATS_INFO        FLAGS                         0
    SYSSTATS_MAIN        CPUSPEEDNW              494,397
    SYSSTATS_MAIN        IOSEEKTIM                    10
    SYSSTATS_MAIN        IOTFRSPEED                 4096
    SYSSTATS_MAIN        SREADTIM
    SYSSTATS_MAIN        MREADTIM
    SYSSTATS_MAIN        CPUSPEED
    SYSSTATS_MAIN        MBRC
    SYSSTATS_MAIN        MAXTHR
    SYSSTATS_MAIN        SLAVETHR
    13 rows selected.Here is the output of EXPLAIN PLAN:
    SQL> explain plan for
      2  -- put your statement here
      3  select
      4             *
      5  from
      6             t_demo
      7  where
      8             type = 'VIEW'
      9  order by
    10             id;
    Explained.
    Elapsed: 00:00:00.01
    SQL>
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 1390505571
    | Id  | Operation                   | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |          |     1 |    60 |     0   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| T_DEMO   |     1 |    60 |     0   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | IDX_DEMO |     1 |       |     0   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("TYPE"='VIEW')
    14 rows selected.Here is the output of SQL*Plus AUTOTRACE including the TIMING information:
    SQL> rem Set the ARRAYSIZE according to your application
    SQL> set autotrace traceonly arraysize 100
    SQL> select
      2             *
      3  from
      4             t_demo
      5  where
      6             type = 'VIEW'
      7  order by
      8             id;
    149938 rows selected.
    Elapsed: 00:00:02.21
    Execution Plan
    Plan hash value: 1390505571
    | Id  | Operation                   | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |          |     1 |    60 |     0   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| T_DEMO   |     1 |    60 |     0   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | IDX_DEMO |     1 |       |     0   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("TYPE"='VIEW')
    Statistics
              0  recursive calls
              0  db block gets
         149101  consistent gets
            800  physical reads
            196  redo size
        1077830  bytes sent via SQL*Net to client
          16905  bytes received via SQL*Net from client
           1501  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
         149938  rows processed
    SQL>
    SQL> disconnect
    Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing optionsThe TKPROF output for this statement looks like the following:
    TKPROF: Release 11.1.0.7.0 - Production on Mo Feb 23 10:23:08 2009
    Copyright (c) 1982, 2007, Oracle.  All rights reserved.
    Trace file: orcl11_ora_3376_mytrace1.trc
    Sort options: default
    count    = number of times OCI procedure was executed
    cpu      = cpu time in seconds executing
    elapsed  = elapsed time in seconds executing
    disk     = number of physical reads of buffers from disk
    query    = number of buffers gotten for consistent read
    current  = number of buffers gotten in current mode (usually for update)
    rows     = number of rows processed by the fetch or execute call
    select
    from
             t_demo
    where
             type = 'VIEW'
    order by
             id
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch     1501      0.53       1.36        800     149101          0      149938
    total     1503      0.53       1.36        800     149101          0      149938
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 88 
    Rows     Row Source Operation
    149938  TABLE ACCESS BY INDEX ROWID T_DEMO (cr=149101 pr=800 pw=0 time=60042 us cost=0 size=60 card=1)
    149938   INDEX RANGE SCAN IDX_DEMO (cr=1881 pr=1 pw=0 time=0 us cost=0 size=0 card=1)(object id 74895)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                    1501        0.00          0.00
      db file sequential read                       800        0.05          0.80
      SQL*Net message from client                  1501        0.00          0.69
    ********************************************************************************The DBMS_XPLAN.DISPLAY_CURSOR output:
    SQL> -- put your statement here
    SQL> -- use the GATHER_PLAN_STATISTICS hint
    SQL> -- if you're not using STATISTICS_LEVEL = ALL
    SQL> select /*+ gather_plan_statistics */
      2  *
      3  from
      4  t_demo
      5  where
      6  type = 'VIEW'
      7  order by
      8  id;
    149938 rows selected.
    Elapsed: 00:00:02.21
    SQL>
    SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
    PLAN_TABLE_OUTPUT
    SQL_ID  d4k5acu783vu8, child number 0
    select   /*+ gather_plan_statistics */          * from          t_demo
    where          type = 'VIEW' order by          id
    Plan hash value: 1390505571
    | Id  | Operation                   | Name     | Starts | E-Rows | A-Rows |   A-Time   | Buffers | Reads  |
    |   0 | SELECT STATEMENT            |          |      1 |        |    149K|00:00:00.02 |     149K|   1183 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| T_DEMO   |      1 |      1 |    149K|00:00:00.02 |     149K|   1183 |
    |*  2 |   INDEX RANGE SCAN          | IDX_DEMO |      1 |      1 |    149K|00:00:00.02 |    1880 |    383 |
    Predicate Information (identified by operation id):
       2 - access("TYPE"='VIEW')
    20 rows selected.I'm looking forward for suggestions how to improve the performance of this statement.
    *-- End of template body --*
    I'm sure that if you follow these instructions and obtain the information described, post them using a proper formatting (don't forget about the \ tag) you'll receive meaningful advice very soon.
    So, just to make sure you didn't miss this point:Use proper formatting!
    If you think I missed something important in this sample post let me know so that I can improve it.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Alex Nuijten wrote:
    ...you missed the proper formatting of the Autotrace section ;-)Alex,
    can't reproduce, does it still look unformatted? Or are you simply kidding? :-)
    Randolf
    PS: Just noticed that it actually sometimes doesn't show the proper formatting although the code tags are there. Changing to the \ tag helped in this case, but it seems to be odd.
    Edited by: Randolf Geist on Feb 23, 2009 11:28 AM
    Odd behaviour of forum software                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Adding a field to an sql statement in Oracle Reports error ORA-00933

    We have been requested to add a field that already exists in the table referred to by the sql statement in Oracle Reports Builder. The report was set up by a consultant about 3 yrs ago and we don't really have much skill in this area. What is happening when I try to modify the SQL statement, either adding a field or deleting a field to the SELECT statement, causes an error message preventing the statement from being saved. The only way out of the error message is to click Cancel. The error message is
    ORA-00933:SQL command not properly ended
    ORDER BY Program ==> NAME
    Even adding or deleting a space anywhere in the SQL statement causes the error (not adding any new fields). A coworker found that if we comment out the ORDER BY, the statement will accept the new field in the SELECT section, however then we lose the order by functionality. I would like to add one additional field before the FROM. Not sure if any additional data are needed. Thank you.
    SELECT p.person_uid PIDM_KEY, p.id_number ID,
                   p.full_name_lfmi name,            
                    p.BIRTH_DATE, p.GENDER Sex,
                    Decode(a.residency,'D',p.Primary_ethnicity,'F')  Ethn,
                    a.academic_period TERM,        
                    CASE WHEN :p_group_by = 'PROGRAM' THEN a.program
                                 ELSE ' '
                    END AS Program,
                    a.COLLEGE, a.degree, a.major, ' ' rule,
                    a.STUDENT_POPULATION,a.STUDENT_LEVEL,    a.application_status Status,  a.application_status_date app_sts_dte,
                    ad.decision_date1 Last_Dec_Date,
                    ad.decision1||' '||ad.decision2||' '|| ad.decision3||' '|| ad.decision4||' '|| ad.decision5 Decisions,
                    /*  Deposit Date uses the last term entered in :p_term parameter string */
                    (SELECT MAX(deposit_effective_date) FROM usf_as_deposit WHERE account_uid = a.person_uid &term_clause group by account_uid)   AS "DEPOSIT DATE",     
                    ph.phone as PHONE,
                    CASE WHEN PS.FIRST_CONTACT IN ('NET','PAP','COM','COP') THEN PS.First_Contact
                     ELSE CASE WHEN ps.latest_contact IN ('NET','PAP','COM','COP') THEN PS.Latest_Contact
                                ELSE '  '
                                END
                    END AS FIRST_CONTACT,
                    DECODE(:p_address,'Y',REPLACE(adr.street1||' '||adr.street2||' '||adr.street3||' '||adr.city||','||adr.state||' '||adr.nation||' '||adr.zip,'  ',' '),' ') as  address, adr.nation, adr.state,
                    goremal_email_address email, a.residency, a.application_date, p.primary_ethnicity, c.cohort
    FROM MST_ADMISSIONS_APPLICATION A,
               MST_PERSON p,mst_pre_student PS,  Admissions_Cohort c, usf_v_phone_pr_ma ph,
               MST_admissions_decision_slot AD, usf_v_email, usf_v_address_dr_lr_ma_pr adr
    WHERE a.PERSON_UID = p.person_uid
            AND a.curriculum_priority  = 1
            AND a.person_uid = ps.person_uid
           AND a.person_uid = ad.person_Uid(+)
           AND a.person_uid = goremal_pidm(+)
           AND a.person_uid = adr.pidm(+)
           AND a.person_uid = ph.pidm(+)
           AND ph.rnum(+) = 1
           AND a.person_uid = c.person_uid(+)
           AND a.academic_period = c.academic_period(+)
      &Where_Clause
           /*    TAKE OUT FOLLOWING LINE AFTER DATA IS CLEANED UP  */
            AND NOT(p.id_number = '00000000'   OR SUBSTR(p.id_number,1,1) = 'B'  OR UPPER(p.full_name_lfmi)  LIKE '%TESTING%')
           AND  a.application_status_date >= NVL(:p_as_of_date,sysdate-8000)
           AND a.academic_period = ad.academic_period(+)
            AND a.application_number = ad.application_number(+)
            AND a.degree <> 'ND'    /*   AND a.college <> 'LW'                         --  Does not need non-degree and law students    */
           &Cohort_Clause 
    ORDER BY Program  &ORDER_CLAUSE

    Hi Denis,
    I tried your suggestion. The good thing is that adding the comma allowed me to be able to add a.campus to the select statement, unfortunately, another error message happened.
    ORA-00936: missing expression SELECT p . person_uid PIDM_KEY ,
    p . id_number , p . full_name_lfmi name , p . BIRTH_DATE , p . GENDER Sex ,
    Decode ( a . residency , 'D' , p . Primary_Ethnicity , 'F' ) Ethn , a . academic_period TERM ,
    CASE WHEN : P_group_by = 'PROGRAM THEN a I started over and tried only putting in the comma and get the same message even though I didn't add campus. After that, removed the comma which led to the ORA-00933 error message. So once again, I had to close the file without saving, in order for the report to run at all.

  • PL SQL using variable in SQL statement

    I am trying to execute several sql statements, that have the same format but different values. Does this
    mean I need a bind variable?
    ie
    select TO_CHAR ( (SYSDATE - 2), 'YYYY_MM_DD') from dual
    select TO_CHAR ( (SYSDATE - 4), 'YYYY_MM_DD') from dual
    select to_char(add_months(sysdate,-2*1) from dual
    When I try to put the values into a varaiable (date, varchar2 or number) I am getting a conversion
    error.
    Can somebody show me an example of how to do something like this? Or at least point me to the correct
    part of the documentation that provides and example. Pardon my syntax as I know it is incorrect
    val :=add_months(sysdate,-2*1
    select to_char(val) from dual
    Thanks in advance to all who answer

    Hi,
    840386 wrote:
    I am trying to execute several sql statements, that have the same format but different values. Does this
    mean I need a bind variable?No, you don't need a bind variable, though bind variables may be more efficient than using PL/SQL variables. I don't see where you're trying to use any varibables at all in your examples. Is it in place of the literals, such as 2 or 'YYYY_MM_DD'? You can use either bind varibales or PL/SQL variables in those places.
    ie
    select TO_CHAR ( (SYSDATE - 2), 'YYYY_MM_DD') from dual
    select TO_CHAR ( (SYSDATE - 4), 'YYYY_MM_DD') from dual
    select to_char(add_months(sysdate,-2*1) from dualIn PL/SQL, when you have a SELECT statement, you must specify what you want to do with the results. For example, a SELECT ... INTO statement:
    SELECT  AVG (sal)
    INTO    avg_salary
    FROM    scott.emp;There's usually no point in SELECTing from dual in PL/SQL. It's not an error, but it's simpler just to use an assignment statement.
    When I try to put the values into a varaiable (date, varchar2 or number) I am getting a conversion
    error.Post a complete procedure or anonymous block, including variable declarations, that shows exactly what you're trying to do.
    >
    Can somebody show me an example of how to do something like this? Or at least point me to the correct
    part of the documentation that provides and example. Pardon my syntax as I know it is incorrect
    val :=add_months(sysdate,-2*1Assuming val is a DATE, that's basically correct. You have unbalanced parentheses (there's a '(', but no matching ')' ), and you need a semicolon (';') at the end of the statement. Perhaps ');' just got cut off when you were posting this.
    select to_char(val) from dualAgain, SELECTing from dual is unnecessary, but if you had some way to catch the returned value, that would work.
    Usually, the reason why you need to call TO_CHAR is that you want a value in a particular format, which is specified in the 2nd argument to TO_CHAR. Calling TO_CHAR with only one argument is a possible mistake, but not something that would raise an error.
    Here's an example that works:
    SET     SERVEROUTPUT     ON
    DECLARE
         d     DATE;
         v     VARCHAR2 (30);
    BEGIN
         d := ADD_MONTHS (SYSDATE, -2);          -- -2 = (-2*1)
         v := TO_CHAR (d, 'DD-Mon-YYYY');
         dbms_output.put_line (v || ' = v');
    END;
    /Output (when run on March 13, 2011):
    13-Jan-2011 = v

  • This SQL statement always in Top Activity, with PX Deq Credit: send blkd

    Hi gurus,
    The following SQL statement is always among the Top Activity. I can see the details in Enerprise manager that it suffers from PX Deq Credit: send blkd
    This is the statement:
    SELECT S.Product, S.WH_CODE, S.RACK, S.BATCH, S.EXP_DATE, FLOOR(Qty_Beg) QtyBeg_B,
            ROUND(f_convert_qty(S.PRODUCT, Qty_Beg-FLOOR(Qty_Beg), P.UOM_K ), 0) QtyBeg_K,
            FLOOR(Qty_In) QtyIn_B, ROUND(f_convert_qty(S.PRODUCT, Qty_In-FLOOR(Qty_In), P.UOM_K), 0) QtyIn_K,
            FLOOR(Qty_Out) QtyOut_B, ROUND(f_convert_qty(S.PRODUCT, Qty_Out-FLOOR(Qty_Out), P.UOM_K ), 0) QtyOut_K,
            FLOOR(Qty_Adj) QtyAdj_B, ROUND(f_convert_qty(S.PRODUCT, Qty_Adj-FLOOR(Qty_Adj), P.UOM_K ), 0) QtyAdj_K,
            FLOOR(Qty_End) QtyEnd_B, ROUND(f_convert_qty(S.PRODUCT, Qty_End-FLOOR(Qty_End), P.UOM_K ), 0) QtyEnd_K,
            S.LOC_CODE
            FROM V_STOCK_DETAIL S
            JOIN PRODUCTS P ON P.PRODUCT = S.PRODUCT
            WHERE S.Product = :pProduct AND S.WH_CODE = :pWhCode AND S.LOC_CODE = :pLocCode;The statement is invoked by our front end (web based app) for a browse table displayed on a web page. The result can be 10 to 8000. It is used to display the current stock availability for a particular product in a particular warehouse. The stock availability it self is kept in a View : V_Stock_Detail
    These are the parameters relevant to the optimizer:
    SQL> show parameter user_dump_dest
    user_dump_dest                       string   /u01/app/oracle/admin/ITTDB/udump
    SQL> show parameter optimizer
    _optimizer_cost_based_transformation  string   OFF
    optimizer_dynamic_sampling           integer  2
    optimizer_features_enable            string   10.2.0.3
    optimizer_index_caching              integer  0
    optimizer_index_cost_adj             integer  100
    optimizer_mode                       string   ALL_ROWS
    optimizer_secure_view_merging        boolean  TRUE
    SQL> show parameter db_file_multi
    db_file_multiblock_read_count        integer  16
    SQL> show parameter db_block_size column sname format a20 column pname format a20
    db_block_size                        integer  8192Here is the output of EXPLAIN PLAN:
    SQL> explain plan for
    SELECT S.Product, S.WH_CODE, S.RACK, S.BATCH, S.EXP_DATE, FLOOR(Qty_Beg) QtyBeg_B,
        ROUND(f_convert_qty(S.PRODUCT, Qty_Beg-FLOOR(Qty_Beg), P.UOM_K ), 0) QtyBeg_K,
        FLOOR(Qty_In) QtyIn_B, ROUND(f_convert_qty(S.PRODUCT, Qty_In-FLOOR(Qty_In), P.UOM_K), 0) QtyIn_K,
        FLOOR(Qty_Out) QtyOut_B, ROUND(f_convert_qty(S.PRODUCT, Qty_Out-FLOOR(Qty_Out), P.UOM_K ), 0) QtyOut_K,
        FLOOR(Qty_Adj) QtyAdj_B, ROUND(f_convert_qty(S.PRODUCT, Qty_Adj-FLOOR(Qty_Adj), P.UOM_K ), 0) QtyAdj_K,
        FLOOR(Qty_End) QtyEnd_B, ROUND(f_convert_qty(S.PRODUCT, Qty_End-FLOOR(Qty_End), P.UOM_K ), 0) QtyEnd_K,
        S.LOC_CODE
        FROM V_STOCK_DETAIL S
        JOIN PRODUCTS P ON P.PRODUCT = S.PRODUCT
        WHERE S.Product = :pProduct AND S.WH_CODE = :pWhCode AND S.LOC_CODE = :pLocCode
    Explain complete.
    Elapsed: 00:00:00:31
    SQL> select * from table(dbms_xplan.display)
    PLAN_TABLE_OUTPUT
    Plan hash value: 3252950027
    | Id  | Operation                               | Name                | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ
    Distrib |
    |   0 | SELECT STATEMENT                        |                     |     1 |   169 |     6  (17)| 00:00:01 |        |      |
             |
    |   1 |  PX COORDINATOR                         |                     |       |       |            |          |        |      |
             |
    |   2 |   PX SEND QC (RANDOM)                   | :TQ10003            |     1 |   169 |     6  (17)| 00:00:01 |  Q1,03 | P->S | QC
    (RAND)  |
    |   3 |    HASH GROUP BY                        |                     |     1 |   169 |     6  (17)| 00:00:01 |  Q1,03 | PCWP |
             |
    |   4 |     PX RECEIVE                          |                     |     1 |   169 |     6  (17)| 00:00:01 |  Q1,03 | PCWP |
             |
    |   5 |      PX SEND HASH                       | :TQ10002            |     1 |   169 |     6  (17)| 00:00:01 |  Q1,02 | P->P | HA
    SH       |
    |   6 |       HASH GROUP BY                     |                     |     1 |   169 |     6  (17)| 00:00:01 |  Q1,02 | PCWP |
             |
    |   7 |        NESTED LOOPS OUTER               |                     |     1 |   169 |     5   (0)| 00:00:01 |  Q1,02 | PCWP |
             |
    |   8 |         MERGE JOIN CARTESIAN            |                     |     1 |   119 |     4   (0)| 00:00:01 |  Q1,02 | PCWP |
             |
    |   9 |          SORT JOIN                      |                     |       |       |            |          |  Q1,02 | PCWP |
             |
    |  10 |           NESTED LOOPS                  |                     |     1 |    49 |     4   (0)| 00:00:01 |  Q1,02 | PCWP |
             |
    |  11 |            BUFFER SORT                  |                     |       |       |            |          |  Q1,02 | PCWC |
             |
    |  12 |             PX RECEIVE                  |                     |       |       |            |          |  Q1,02 | PCWP |
             |
    |  13 |              PX SEND BROADCAST          | :TQ10000            |       |       |            |          |        | S->P | BR
    OADCAST  |
    |* 14 |               INDEX RANGE SCAN          | PRODUCTS_IDX2       |     1 |    25 |     2   (0)| 00:00:01 |        |      |
             |
    |  15 |            PX BLOCK ITERATOR            |                     |     1 |    24 |     2   (0)| 00:00:01 |  Q1,02 | PCWC |
             |
    |* 16 |             MAT_VIEW ACCESS FULL        | MV_CONVERT_UOM      |     1 |    24 |     2   (0)| 00:00:01 |  Q1,02 | PCWP |
             |
    |  17 |          BUFFER SORT                    |                     |     1 |    70 |     2   (0)| 00:00:01 |  Q1,02 | PCWP |
             |
    |  18 |           BUFFER SORT                   |                     |       |       |            |          |  Q1,02 | PCWC |
             |
    |  19 |            PX RECEIVE                   |                     |     1 |    70 |     4   (0)| 00:00:01 |  Q1,02 | PCWP |
             |
    |  20 |             PX SEND BROADCAST           | :TQ10001            |     1 |    70 |     4   (0)| 00:00:01 |        | S->P | BR
    OADCAST  |
    |* 21 |              TABLE ACCESS BY INDEX ROWID| STOCK               |     1 |    70 |     4   (0)| 00:00:01 |        |      |
             |
    |* 22 |               INDEX RANGE SCAN          | STOCK_PK            |     1 |       |     2   (0)| 00:00:01 |        |      |
             |
    |* 23 |         TABLE ACCESS BY INDEX ROWID     | MV_TRANS_STOCK      |     1 |    50 |     3   (0)| 00:00:01 |  Q1,02 | PCWP |
             |
    |* 24 |          INDEX RANGE SCAN               | MV_TRANS_STOCK_IDX1 |     1 |       |     2   (0)| 00:00:01 |  Q1,02 | PCWP |
             |
    Predicate Information (identified by operation id):
      14 - access("P"."PRODUCT"=:PPRODUCT)
      16 - filter("CON"."PRODUCT"=:PPRODUCT)
      21 - filter("STOCK"."LOC_CODE"=:PLOCCODE)
      22 - access("STOCK"."PRODUCT"=:PPRODUCT AND "STOCK"."WH_CODE"=:PWHCODE)
      23 - filter("STS"(+)='N')
      24 - access("PRODUCT"(+)=:PPRODUCT AND "WH_CODE"(+)=:PWHCODE AND "LOC_CODE"(+)=:PLOCCODE AND "RACK"(+)="STOCK"."RACK" AND
                  "BATCH"(+)="STOCK"."BATCH" AND "EXP_DATE"(+)="STOCK"."EXP_DATE")
    42 rows selected.
    Elapsed: 00:00:00:06Here is the output of SQL*Plus AUTOTRACE including the TIMING information:
    SQL> SELECT S.Product, S.WH_CODE, S.RACK, S.BATCH, S.EXP_DATE, FLOOR(Qty_Beg) QtyBeg_B,
        ROUND(f_convert_qty(S.PRODUCT, Qty_Beg-FLOOR(Qty_Beg), P.UOM_K ), 0) QtyBeg_K,
        FLOOR(Qty_In) QtyIn_B, ROUND(f_convert_qty(S.PRODUCT, Qty_In-FLOOR(Qty_In), P.UOM_K), 0) QtyIn_K,
        FLOOR(Qty_Out) QtyOut_B, ROUND(f_convert_qty(S.PRODUCT, Qty_Out-FLOOR(Qty_Out), P.UOM_K ), 0) QtyOut_K,
        FLOOR(Qty_Adj) QtyAdj_B, ROUND(f_convert_qty(S.PRODUCT, Qty_Adj-FLOOR(Qty_Adj), P.UOM_K ), 0) QtyAdj_K,
        FLOOR(Qty_End) QtyEnd_B, ROUND(f_convert_qty(S.PRODUCT, Qty_End-FLOOR(Qty_End), P.UOM_K ), 0) QtyEnd_K,
        S.LOC_CODE
        FROM V_STOCK_DETAIL S
        JOIN PRODUCTS P ON P.PRODUCT = S.PRODUCT
        WHERE S.Product = :pProduct AND S.WH_CODE = :pWhCode AND S.LOC_CODE = :pLocCode
    Execution Plan
       0      SELECT STATEMENT Optimizer Mode=ALL_ROWS   1   169   6
       1    0   PX COORDINATOR
       2    1     PX SEND QC (RANDOM) SYS.:TQ10003 1   169   6   :Q1003  P->S   QC (RANDOM)
       3    2       HASH GROUP BY   1   169   6   :Q1003  PCWP
       4    3         PX RECEIVE   1   169   6   :Q1003  PCWP
       5    4           PX SEND HASH SYS.:TQ10002 1   169   6   :Q1002  P->P   HASH
       6    5             HASH GROUP BY   1   169   6   :Q1002  PCWP
       7    6               NESTED LOOPS OUTER   1   169   5   :Q1002  PCWP
       8    7                 MERGE JOIN CARTESIAN   1   119   4   :Q1002  PCWP
       9    8                   SORT JOIN          :Q1002  PCWP
      10    9                     NESTED LOOPS   1   49   4   :Q1002  PCWP
      11   10                       BUFFER SORT          :Q1002  PCWC
      12   11                         PX RECEIVE          :Q1002  PCWP
      13   12                           PX SEND BROADCAST SYS.:TQ10000           S->P   BROADCAST
      14   13                             INDEX RANGE SCAN ITT_NEW.PRODUCTS_IDX2 1   25   2
      15   10                       PX BLOCK ITERATOR   1   24   2   :Q1002  PCWC
      16   15                         MAT_VIEW ACCESS FULL ITT_NEW.MV_CONVERT_UOM 1   24   2   :Q1002  PCWP
      17    8                   BUFFER SORT   1   70   2   :Q1002  PCWP
      18   17                     BUFFER SORT          :Q1002  PCWC
      19   18                       PX RECEIVE   1   70   4   :Q1002  PCWP
      20   19                         PX SEND BROADCAST SYS.:TQ10001 1   70   4      S->P   BROADCAST
      21   20                           TABLE ACCESS BY INDEX ROWID ITT_NEW.STOCK 1   70   4
      22   21                             INDEX RANGE SCAN ITT_NEW.STOCK_PK 1     2
      23    7                 TABLE ACCESS BY INDEX ROWID ITT_NEW.MV_TRANS_STOCK 1   50   3   :Q1002  PCWP
      24   23                   INDEX RANGE SCAN ITT_NEW.MV_TRANS_STOCK_IDX1 1     2   :Q1002  PCWP
    Statistics
            570  recursive calls
              0  physical write total IO requests
              0  physical write total multi block requests
              0  physical write total bytes
              0  physical writes direct temporary tablespace
              0  java session heap live size max
              0  java session heap object count
              0  java session heap object count max
              0  java session heap collected count
              0  java session heap collected bytes
             83  rows processed
    Elapsed: 00:00:03:24
    SQL> disconnect
    Commit complete
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining optionsThe TKPROF output for this statement looks like the following:
    TKPROF: Release 10.2.0.3.0 - Production on Thu Apr 23 12:39:29 2009
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Trace file: ittdb_ora_9566_mytrace1.trc
    Sort options: default
    count    = number of times OCI procedure was executed
    cpu      = cpu time in seconds executing
    elapsed  = elapsed time in seconds executing
    disk     = number of physical reads of buffers from disk
    query    = number of buffers gotten for consistent read
    current  = number of buffers gotten in current mode (usually for update)
    rows     = number of rows processed by the fetch or execute call
    SELECT S.Product, S.WH_CODE, S.RACK, S.BATCH, S.EXP_DATE, FLOOR(Qty_Beg) QtyBeg_B,
        ROUND(f_convert_qty(S.PRODUCT, Qty_Beg-FLOOR(Qty_Beg), P.UOM_K ), 0) QtyBeg_K,
        FLOOR(Qty_In) QtyIn_B, ROUND(f_convert_qty(S.PRODUCT, Qty_In-FLOOR(Qty_In), P.UOM_K), 0) QtyIn_K,
        FLOOR(Qty_Out) QtyOut_B, ROUND(f_convert_qty(S.PRODUCT, Qty_Out-FLOOR(Qty_Out), P.UOM_K ), 0) QtyOut_K,
        FLOOR(Qty_Adj) QtyAdj_B, ROUND(f_convert_qty(S.PRODUCT, Qty_Adj-FLOOR(Qty_Adj), P.UOM_K ), 0) QtyAdj_K,
        FLOOR(Qty_End) QtyEnd_B, ROUND(f_convert_qty(S.PRODUCT, Qty_End-FLOOR(Qty_End), P.UOM_K ), 0) QtyEnd_K,
        S.LOC_CODE
        FROM V_STOCK_DETAIL S
        JOIN PRODUCTS P ON P.PRODUCT = S.PRODUCT
        WHERE S.Product = :pProduct AND S.WH_CODE = :pWhCode AND S.LOC_CODE = :pLocCode
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.04       0.12          0         10          4           0
    Fetch       43      0.05       2.02          0         73          0          83
    total       45      0.10       2.15          0         83          4          83
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 164 
    Rows     Row Source Operation
         83  PX COORDINATOR  (cr=83 pr=0 pw=0 time=2086576 us)
          0   PX SEND QC (RANDOM) :TQ10003 (cr=0 pr=0 pw=0 time=0 us)
          0    HASH GROUP BY (cr=0 pr=0 pw=0 time=0 us)
          0     PX RECEIVE  (cr=0 pr=0 pw=0 time=0 us)
          0      PX SEND HASH :TQ10002 (cr=0 pr=0 pw=0 time=0 us)
          0       HASH GROUP BY (cr=0 pr=0 pw=0 time=0 us)
          0        NESTED LOOPS OUTER (cr=0 pr=0 pw=0 time=0 us)
          0         MERGE JOIN CARTESIAN (cr=0 pr=0 pw=0 time=0 us)
          0          SORT JOIN (cr=0 pr=0 pw=0 time=0 us)
          0           NESTED LOOPS  (cr=0 pr=0 pw=0 time=0 us)
          0            BUFFER SORT (cr=0 pr=0 pw=0 time=0 us)
          0             PX RECEIVE  (cr=0 pr=0 pw=0 time=0 us)
          0              PX SEND BROADCAST :TQ10000 (cr=0 pr=0 pw=0 time=0 us)
          1               INDEX RANGE SCAN PRODUCTS_IDX2 (cr=2 pr=0 pw=0 time=62 us)(object id 135097)
          0            PX BLOCK ITERATOR (cr=0 pr=0 pw=0 time=0 us)
          0             MAT_VIEW ACCESS FULL MV_CONVERT_UOM (cr=0 pr=0 pw=0 time=0 us)
          0          BUFFER SORT (cr=0 pr=0 pw=0 time=0 us)
          0           BUFFER SORT (cr=0 pr=0 pw=0 time=0 us)
          0            PX RECEIVE  (cr=0 pr=0 pw=0 time=0 us)
          0             PX SEND BROADCAST :TQ10001 (cr=0 pr=0 pw=0 time=0 us)
         83              TABLE ACCESS BY INDEX ROWID STOCK (cr=78 pr=0 pw=0 time=1635 us)
         83               INDEX RANGE SCAN STOCK_PK (cr=4 pr=0 pw=0 time=458 us)(object id 135252)
          0         TABLE ACCESS BY INDEX ROWID MV_TRANS_STOCK (cr=0 pr=0 pw=0 time=0 us)
          0          INDEX RANGE SCAN MV_TRANS_STOCK_IDX1 (cr=0 pr=0 pw=0 time=0 us)(object id 143537)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      PX Deq: Join ACK                               17        0.00          0.00
      PX qref latch                                   2        0.00          0.00
      PX Deq Credit: send blkd                       72        1.95          2.00
      PX Deq: Parse Reply                            26        0.01          0.01
      SQL*Net message to client                      43        0.00          0.00
      PX Deq: Execute Reply                          19        0.00          0.01
      SQL*Net message from client                    43        0.00          0.04
      PX Deq: Signal ACK                             12        0.00          0.00
      enq: PS - contention                            1        0.00          0.00
    ********************************************************************************The DBMS_XPLAN.DISPLAY_CURSOR output:
    SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'))
    PLAN_TABLE_OUTPUT
    SQL_ID  402b8st7vt6ku, child number 2
    SELECT /*+ gather_plan_statistics */          S.Product, S.WH_CODE, S.RACK, S.BATCH, S.EXP_DATE, FLOOR(Qty_Beg) QtyBeg_B,
    ROUND(f_convert_qty(S.PRODUCT, Qty_Beg-FLOOR(Qty_Beg), P.UOM_K ), 0) QtyBeg_K,      FLOOR(Qty_In) QtyIn_B, ROUND(f_convert_qty(S.P
    RODUCT,
    Qty_In-FLOOR(Qty_In), P.UOM_K), 0) QtyIn_K,      FLOOR(Qty_Out) QtyOut_B, ROUND(f_convert_qty(S.PRODUCT, Qty_Out-FLOOR(Qty_Out), P
    .UOM_K ),
    0) QtyOut_K,      FLOOR(Qty_Adj) QtyAdj_B, ROUND(f_convert_qty(S.PRODUCT, Qty_Adj-FLOOR(Qty_Adj), P.UOM_K ), 0) QtyAdj_K,
    FLOOR(Qty_End) QtyEnd_B, ROUND(f_convert_qty(S.PRODUCT, Qty_End-FLOOR(Qty_End), P.UOM_K ), 0) QtyEnd_K,      S.LOC_CODE      FROM
    V_STOCK_DETAIL S      JOIN PRODUCTS P ON P.PRODUCT = S.PRODUCT      WHERE S.Product = :pProduct AND S.WH_CODE = :pWhCode AND S.LOC
    _CODE =
    :pLocCode
    Plan hash value: 3252950027
    | Id  | Operation                               | Name                | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |
    1Mem | Used-Mem |
    |   1 |  PX COORDINATOR                         |                     |      1 |        |     83 |00:00:02.25 |      83 |       |
          |          |
    |   2 |   PX SEND QC (RANDOM)                   | :TQ10003            |      0 |     21 |      0 |00:00:00.01 |       0 |       |
          |          |
    |   3 |    HASH GROUP BY                        |                     |      0 |     21 |      0 |00:00:00.01 |       0 |       |
          |          |
    |   4 |     PX RECEIVE                          |                     |      0 |     21 |      0 |00:00:00.01 |       0 |       |
          |          |
    |   5 |      PX SEND HASH                       | :TQ10002            |      0 |     21 |      0 |00:00:00.01 |       0 |       |
          |          |
    |   6 |       HASH GROUP BY                     |                     |      0 |     21 |      0 |00:00:00.01 |       0 |       |
          |          |
    |   7 |        NESTED LOOPS OUTER               |                     |      0 |     21 |      0 |00:00:00.01 |       0 |       |
          |          |
    |   8 |         MERGE JOIN CARTESIAN            |                     |      0 |     21 |      0 |00:00:00.01 |       0 |       |
          |          |
    |   9 |          SORT JOIN                      |                     |      0 |        |      0 |00:00:00.01 |       0 | 73728 |
    73728 |          |
    |  10 |           NESTED LOOPS                  |                     |      0 |      1 |      0 |00:00:00.01 |       0 |       |
          |          |
    |  11 |            BUFFER SORT                  |                     |      0 |        |      0 |00:00:00.01 |       0 | 73728 |
    73728 |          |
    |  12 |             PX RECEIVE                  |                     |      0 |        |      0 |00:00:00.01 |       0 |       |
          |          |
    |  13 |              PX SEND BROADCAST          | :TQ10000            |      0 |        |      0 |00:00:00.01 |       0 |       |
          |          |
    |* 14 |               INDEX RANGE SCAN          | PRODUCTS_IDX2       |      1 |      1 |      1 |00:00:00.01 |       2 |       |
          |          |
    |  15 |            PX BLOCK ITERATOR            |                     |      0 |      1 |      0 |00:00:00.01 |       0 |       |
          |          |
    |* 16 |             MAT_VIEW ACCESS FULL        | MV_CONVERT_UOM      |      0 |      1 |      0 |00:00:00.01 |       0 |       |
          |          |
    |  17 |          BUFFER SORT                    |                     |      0 |     21 |      0 |00:00:00.01 |       0 | 73728 |
    73728 |          |
    |  18 |           BUFFER SORT                   |                     |      0 |        |      0 |00:00:00.01 |       0 | 73728 |
    73728 |          |
    |  19 |            PX RECEIVE                   |                     |      0 |     21 |      0 |00:00:00.01 |       0 |       |
          |          |
    |  20 |             PX SEND BROADCAST           | :TQ10001            |      0 |     21 |      0 |00:00:00.01 |       0 |       |
          |          |
    |* 21 |              TABLE ACCESS BY INDEX ROWID| STOCK               |      1 |     21 |     83 |00:00:00.01 |      78 |       |
          |          |
    |* 22 |               INDEX RANGE SCAN          | STOCK_PK            |      1 |     91 |     83 |00:00:00.01 |       4 |       |
          |          |
    |* 23 |         TABLE ACCESS BY INDEX ROWID     | MV_TRANS_STOCK      |      0 |      1 |      0 |00:00:00.01 |       0 |       |
          |          |
    |* 24 |          INDEX RANGE SCAN               | MV_TRANS_STOCK_IDX1 |      0 |      1 |      0 |00:00:00.01 |       0 |       |
          |          |
    Predicate Information (identified by operation id):
      14 - access("P"."PRODUCT"=:PPRODUCT)
      16 - access(:Z>=:Z AND :Z<=:Z)
           filter("CON"."PRODUCT"=:PPRODUCT)
      21 - filter("STOCK"."LOC_CODE"=:PLOCCODE)
      22 - access("STOCK"."PRODUCT"=:PPRODUCT AND "STOCK"."WH_CODE"=:PWHCODE)
      23 - filter("STS"='N')
      24 - access("PRODUCT"=:PPRODUCT AND "WH_CODE"=:PWHCODE AND "LOC_CODE"=:PLOCCODE AND "RACK"="STOCK"."RACK" AND "BATCH"="STOCK"."B
    ATCH" AND
                  "EXP_DATE"="STOCK"."EXP_DATE")
    53 rows selected.
    Elapsed: 00:00:00:12I'm looking forward for suggestions how to improve the performance of this statement.
    Thank you very much,
    xtanto

    xtanto wrote:
    Hi sir,
    How to prevent the query from doing parallel query ?
    Because as you see actually I am not issuing any Parallel hints in the query.
    Thank you,
    xtantoKristanto,
    there are a couple of points to consider:
    1. Your SQL*Plus version seems to be outdated. Please use a SQL*Plus version that corresponds to your database version. E.g. the AUTOTRACE output is odd.
    2. I would suggest to repeat your exercise using serial execution (the plan, the autotrace, the tracing). You can disable parallel queries by issuing this in your session:
    ALTER SESSION DISABLE PARALLEL QUERY;
    This way the output of the tools is much more meaningful, however you might get a different execution plan, therefore the results might not be representative for your parallel execution.
    3. The function calls might pose a problem. If they are, one possible damage limitation has been provided by hoek. Even better would be then to replace the PL/SQL function with equivalent plain SQL. However since you say that it generates not too many rows it might not harm here too much. You can check the impact of the functions by running a similar query but omitting the function calls.
    4. The parallel execution plan contains a MERGE JOIN CARTESIAN operation which could be an issue if the estimates of the optimizer are incorrect. If the serial execution still uses this operation the TKPROF and DBMS_XPLAN.DISPLAY_CURSOR output will reveal whether this is a problem or not.
    5. The execution of the statement seems to take on 2-3 seconds in your tests. Is this in the right ballpark? If yes, why should this statement then be problematic? How often does it get executed?
    6. The statement uses bind variables, so you might have executions that use different execution plans depending on the bind values passed when the statement got optimized. You can use DBMS_XPLAN.DISPLAY_CURSOR using NULL as "child_number" parameter or DBMS_XPLAN.DISPLAY_AWR (if you have a AWR license) to check if you have multiple execution plans for the statement. Please note that older versions might have already been aged out of the shared pool, so the AWR repository might be a more reliable source (but only if the statement has been sampled).
    7. You have disabled cost based transformations: "_optimizer_cost_based_transformation" = OFF. Why?
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Hardcode value in sql statement

    Hi,
    This may be a simple thing which I'm missing.
    I'm trying to hardcode numeric value in my SQL statement
    '1.0000' AS NUMBER (10,4) - It returns value as 1 instead of 1.0000
    '1.1255' AS NUMBER(10,4) - returns 1.1255
    I need my o/p to be as 1.0000 not as 1.Is there anyway I can get the result as I'm looking for
    Thanks in advance

    Hi,
    847750 wrote:
    Hi,
    This may be a simple thing which I'm missing.
    I'm trying to hardcode numeric value in my SQL statement
    '1.0000' AS NUMBER (10,4) - It returns value as 1 instead of 1.0000
    '1.1255' AS NUMBER(10,4) - returns 1.1255
    I need my o/p to be as 1.0000 not as 1.Is there anyway I can get the result as I'm looking for
    Thanks in advance
    It's hard to tell what you really want to do from such a tiny code fragment.
    Whenever you have a question, post a complete test script that people can run to re-create the problem and test their ideas.
    The value 1 is exactly the same as the value 1.0000; there is no difference between those numbers.
    If you want to display a number in a certain format (e.g. '1.0000' instead of '1'), the front end is probably the best place to do that.
    If you're using SQL*Plus as the front end, you can set the display for the column called increase_pct like this:
    COLUMN  increase_pct  FORMAT 990.0000
    This will make it display the numbers in that column with at least 1 digit to the left of the decimal point, and exactly 4 digits to the right of the decimal point.
    Other front end tools have similar features.
    If you need to do the equivalent in SQL, use the TO_CHAR function, like this
    SELECT  ename
    ,       TO_CHAR (sal, '99999.00')   AS salary
    FROM    scott.emp
    If you really are hard-coding literals, you can hard code a string, such as '1.0000'.  Don't CAST it to a NUMBER..

  • SQL Statement not works using functions or subqueries-MAXDB

    Hello All,
    I created an ABAP program to select information about country(table: T005) with the country names (Table: T005T). I tried to create a sql query with a sql subquery to select everything but for some reason that I don't know it doesn't work. Please find the query below.
    DATA:
    resu        TYPE REF TO cl_sql_result_set ,
    stmt         TYPE REF TO cl_sql_statement ,
    qury        TYPE string .
               qury  = `SELECT land1, spras, `
               &&       `(SELECT landx `
               &&         `FROM SAPNSP.T005T `
               &&         `WHERE mandt = '` && sy-mandt && `' `
               &&           `AND spras = 'EN' `
               &&           `AND land1 = ? ), `
               &&       `(SELECT natio `
               &&         `FROM SAPNSP.T005T `
               &&         `WHERE mandt = '` && sy-mandt && `' `
               &&           `AND spras = 'EN' `
               &&           `AND land1 = ? ) `
               &&        `FROM SAPNSP.T005 `
               &&        `WHERE mandt = '` && sy-mandt && `' `
               &&          `AND land1 = ? `
               &&        `GROUP BY land1, spras` .
    resu = stmt->execute_query( qury ) .
    Well, the query above works but the fields LANDX and NATIO are in blank in ALL THE CASES, even with information registred in table T005T.
    So, exploring the SDN forum and after read some documents regarding ADBC, I create a function to handle this sql select and get the correctly the missing informations, but, still don't work. Please find the function below:
    CREATE FUNCTION select_landx (land1 CHAR(3)) RETURNS CHAR(15)
    AS
      VAR landx CHAR(15);
      DECLARE functionresult CURSOR FOR
      SELECT spras, land1, landx
         FROM SAPNSP.t005t
         WHERE spras = 'EN'
             AND land1 = :land1;
         IF $count IS NULL THEN <- | $count is always 0, my SELECT
           BEGIN                                 it's not work but I don't know why
             CLOSE functionresult;
             RETURN NULL;
           END
         ELSE
           SET $rc = 0;
           WHILE $rc = 0 DO
           BEGIN
             FETCH functionresult INTO :landx;
           END;
         CLOSE functionresult;
         RETURN landx;
    Calling the function in a SQL statement:
    DATA:
    resu        TYPE REF TO cl_sql_result_set ,
    stmt         TYPE REF TO cl_sql_statement ,
    qury        TYPE string .
               qury  = `SELECT land1, spras, select_landx(?) landx `
               &&        `FROM SAPNSP.T005 `
               &&        `WHERE mandt = '` && sy-mandt && `' `
               &&          `AND land1 = ? `
               &&        `GROUP BY land1, spras` .
    resu = stmt->execute_query( qury ) .
    Any comments ?
    Best regards,
    Arthur Silva

    Hello,
    Thank's a lot, it works. It's funny because the given solution works using only abap codes.
    It may be happens because the abap interpretor send the sql statement to the db interface that handle the code in the another way.
    Thanks again, it was driving me crazy.
    Best regards,
    Arthur Silva

  • EXECUTE IMMEDIATE problem with long SQL statement

    Hello Experts,
    I am having a BIG problem executing script inside the iSQLPlus. This script has 29 blocks. 27 of those blocks are working OK, but block #26 and #27 are giving me the error on the "EXECUTE IMMEDIATE" statement. The length of the SQL statements in those two blocks is more then 4000 characters and I can not use a string variable to keep the SQL statement. If I pass the entire SQL statement as a string to the "EXECUTE IMMEDIATE" command, I am getting the error inside the iSQLPlus:
    Error writing 26 Bad Value. -907: ORA-00907: missing right parenthesis
    Error writing 27 Bad Value. -907: ORA-00907: missing right parenthesis
    The script code is shown below:
    SET ECHO OFF;
    SET VERIFY OFF;
    SET PAGESIZE 78;
    SET LINESIZE 132;
    SET SERVEROUTPUT ON;
    SET FEEDBACK OFF;
    --PROMPT;
    --PROMPT REPORT BEING PROCESSED - PLEASE WAIT.
    --PROMPT;
    DECLARE
    l_count NUMBER;
    s_user VARCHAR2(50);
    s_command VARCHAR2(4000);
    CURSOR INREC (BATCH_PARAM NUMBER) IS
    SELECT BATCH,
    AK$DEALER,
    FK$TRIP_TICKET,
    INVOICE,
    CONTINUATION_IND,
    TRIP_DATE,
    SPL_NO,
    AK$MRIS_AREA,
    AK$MRIS_COUNTY,
    TIME_FISHED,
    TIME_UNITS,
    DEPTH,
    DEPTH_UNITS
    FROM T$TRIP_TICKET_WORK
    WHERE TO_NUMBER(BATCH) = BATCH_PARAM;
    DATEST DATE;
    BEGDATE DATE;
    ENDATE DATE;
    FLAGCNT NUMBER := 0;
    MSGNUM NUMBER;
    MAXLIC VARCHAR2(7);
    BEGIN
    select sys_context('USERENV','SESSION_USER') into s_user from dual;
    select count(*) into l_count from all_tables where table_name = 'BATCHERS_REPORT' and owner=s_user;
    --the table 'BATCHERS_REPORT' alwase exist for the MRIS user role,co we have to check if more then 1 record exist:
    IF l_count > 0 then
         --TRUNCATE TABLE BATCHERS_REPORT REUSE STORAGE;
         s_command := 'TRUNCATE TABLE BATCHERS_REPORT REUSE STORAGE';
         execute immediate s_command;
    ELSE
         --CREATE TABLE BATCHERS_REPORT AS (SELECT * FROM MRIS.BATCHERS_REPORT);
         --s_command := 'CREATE TABLE BATCHERS_REPORT AS SELECT * FROM MRIS.BATCHERS_REPORT WHERE 1=2';
    s_command := 'CREATE TABLE BATCHERS_REPORT
    (BATCH VARCHAR2(6),
    AK$DEALER VARCHAR2(9),
    FK$TRIP_TICKET NUMBER,
    INVOICE     VARCHAR2(13),
    CONTINUATION_IND VARCHAR2(1),
    TRIP_DATE     VARCHAR2(8),
    SPL_NO          VARCHAR2(9),
    AK$MRIS_AREA VARCHAR2(7),
    AK$MRIS_COUNTY VARCHAR2(3),
    TIME_FISHED VARCHAR2(3),
    TIME_UNITS VARCHAR2(1),
    DEPTH VARCHAR2(5),
    DEPTH_UNITS VARCHAR2(1),
    AK$MRIS_GEAR VARCHAR2(4),
    AK$SPECIES VARCHAR2(4),
    SPECIES_SIZE VARCHAR2(8),
    WEIGHT_IN_POUNDS NUMBER(10,2),
    UNIT_PRICE NUMBER(5,3),
    ERROR_NUM NUMBER)';
         execute immediate s_command;
         execute immediate 'commit';          
    END IF;
    DBMS_OUTPUT.PUT_LINE('.');
    DBMS_OUTPUT.PUT_LINE('. PROCEDURE NAME = BATCHERS');
    DBMS_OUTPUT.PUT_LINE('. STARTING TIME = '||TO_CHAR(SYSDATE,'MM/DD/YYYY HH:MI:SS'));
    SELECT MAX(DATE_B), MAX(DATE_E)
    INTO BEGDATE, ENDATE
    FROM T$BATCH_HEADER
    WHERE PK$BATCH = &BATCHNUM;
    SELECT LPAD(MAX(LIC_NUM),7,'0') INTO MAXLIC
    FROM T$SWP_LICENSE;
    BEGIN
    MSGNUM := 1;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    AK$MRIS_GEAR, ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    G.AK$MRIS_GEAR, '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_GEAR_WORK G,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||') AND (T.FK$TRIP_TICKET = G.AK$TRIP_TICKET)
    AND T.FK$TRIP_TICKET = S.AK$TRIP_TICKET
    AND (G.AK$MRIS_GEAR IS NULL
    OR G.AK$MRIS_GEAR NOT IN (SELECT TO_CHAR(PK$MRIS_GEAR) FROM MT$MRIS_GEAR))
    UNION
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    G.AK$MRIS_GEAR, '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_GEAR_WORK G,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||')
    AND (T.FK$TRIP_TICKET = G.AK$TRIP_TICKET)
    AND T.FK$TRIP_TICKET = S.AK$TRIP_TICKET
    AND (G.AK$MRIS_GEAR IN (110, 120, 130)
    AND NOT EXISTS (SELECT * FROM T$TRIP_TICKET_GEAR_WORK G2
    WHERE G2.AK$TRIP_TICKET = G.AK$TRIP_TICKET
    AND G2.AK$MRIS_GEAR = 40))';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 2;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$MRIS_GEAR,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    NULL,
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T
    WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||')
    AND (T.AK$MRIS_AREA != '||'''0'''||')
    AND (T.AK$MRIS_AREA NOT IN (SELECT TO_CHAR(PK$MRIS_AREA) FROM MT$MRIS_AREA))
    AND NOT (T.AK$DEALER IN ('||'''WD0004606'''||', '||'''WD0003877'''||', '||'''WD0000157'''||', '||'''WD0001326'''||', '||'''WD0000426'''||')
    AND
    T.AK$MRIS_AREA IN ('||'''161.2'''||', '||'''301.2'''||', '||'''720.2'''||', '||'''760.2'''||', '||'''771.2'''||', '||'''772.2'''||', '||'''773.2'''||', '||'''780.2'''||', '||'''800.1'''||', '||'''821.2'''||', '||'''882.2'''||'))
    UNION
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    G.AK$MRIS_GEAR,
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_GEAR_WORK G
    WHERE ((TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'))
    AND ((T.FK$TRIP_TICKET = G.AK$TRIP_TICKET))
    AND ((INSTR(T.AK$MRIS_AREA,'||'''.'''||') = 0) OR
    (INSTR(T.AK$MRIS_AREA,'||'''.'''||') > 0 AND T.AK$MRIS_AREA NOT LIKE '||'''%.9%'''||'))
    AND ((G.AK$MRIS_GEAR IN ('||'''30'''||', '||'''6750'''||', '||'''6760'''||') OR
    G.AK$MRIS_GEAR = '||'''70'''||' OR
    G.AK$MRIS_GEAR BETWEEN '||'''4700'''||' AND '||'''4780'''||' or
    g.ak$mris_gear = '||'''80'''||' or
    g.ak$mris_gear between '||'''5300'''||' and '||'''5360'''||'))';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    -- Error number 3 not in use - Logic moved to ctyarflg.sql
    BEGIN
    MSGNUM := 4;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS, '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T
    WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||')
    AND (T.SPL_NO IS NULL
    OR NOT EXISTS (SELECT * FROM T$SWP_LICENSE L
    WHERE L.AK$LICENSE_TYPE = '||'''SP'''||'
    AND L.LIC_NUM = SUBSTR(T.SPL_NO,3,7)))';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION
    WHEN INVALID_NUMBER THEN
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS, '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T
    WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||')
    AND (T.SPL_NO = '||''' '''||'
    OR T.SPL_NO IS NULL
    OR SUBSTR(T.SPL_NO,3,7) NOT BETWEEN '||'''0000000'''||' AND '||'''9999999'''||'
    OR LPAD(RTRIM(LTRIM(SUBSTR(T.SPL_NO,3,7))),7,'||'''0'''||') > '|| MAXLIC ||')';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 5;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'
    AND T.FK$TRIP_TICKET = S.AK$TRIP_TICKET
    AND S.WEIGHT_IN_POUNDS < 1';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 6;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T
    WHERE ((TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'))
    AND ((T.TIME_UNITS = '||'''D'''||' AND T.TIME_FISHED < 1) OR
    (T.TIME_UNITS = '||'''N'''||'))';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 7;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||')
    AND (T.FK$TRIP_TICKET = S.AK$TRIP_TICKET)
    AND (S.WEIGHT_IN_POUNDS > 5500)
    AND (S.AK$SPECIES BETWEEN 131 AND 150 OR
    S.AK$SPECIES BETWEEN 203 AND 217)';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 8;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE ((TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'))
    AND ((T.FK$TRIP_TICKET = S.AK$TRIP_TICKET))
    AND ((S.AK$SPECIES in (135, 163, 185, 223, 227, 315, 316, 490, 494, 795, 805)) OR
    (S.AK$SPECIES BETWEEN 169 AND 171) OR
    (S.AK$SPECIES IN (263, 265, 310, 311, 312)) OR
    (((S.AK$SPECIES BETWEEN 812 AND 825) OR (S.AK$SPECIES = 255)) AND S.AK$TRIP_TICKET IN (SELECT AK$TRIP_TICKET
    FROM T$TRIP_TICKET_GEAR_WORK
    WHERE AK$MRIS_GEAR != 9955)))';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 9;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||')
    AND (T.FK$TRIP_TICKET = S.AK$TRIP_TICKET)
    AND (S.AK$SPECIES = 0
    OR S.AK$SPECIES IS NULL
    OR S.AK$SPECIES NOT IN (SELECT TO_CHAR(PK$SPECIES)
    FROM MT$SPECIES))';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 10;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE ((TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'))
    AND ((T.FK$TRIP_TICKET = S.AK$TRIP_TICKET))
    AND ((S.AK$SPECIES = 401 AND T.AK$DEALER != '||'''WD000573'''||') OR
    (S.AK$SPECIES = 405 AND T.AK$MRIS_COUNTY != 26) OR
    (S.AK$SPECIES in (187, 239, 307, 324, 341, 342, 363, 365,
    367, 383, 387, 427, 450, 457, 461)))';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 11;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'
    AND T.FK$TRIP_TICKET = S.AK$TRIP_TICKET
    AND S.AK$SPECIES = 251 AND (S.WEIGHT_IN_POUNDS > 49 OR S.UNIT_PRICE > .99)';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 12;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||')
    AND (T.FK$TRIP_TICKET = S.AK$TRIP_TICKET)
    AND (S.WEIGHT_IN_POUNDS > 50)
    AND (S.AK$SPECIES BETWEEN 149 AND 150 OR
    S.AK$SPECIES BETWEEN 217 AND 218)';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 13;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'
    AND T.FK$TRIP_TICKET = S.AK$TRIP_TICKET
    AND S.WEIGHT_IN_POUNDS > 1000
    AND S.AK$SPECIES IN (175, 176, 178)';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 14;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE ((TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'))
    AND ((T.FK$TRIP_TICKET = S.AK$TRIP_TICKET))
    AND ((S.AK$SPECIES = 302 AND S.UNIT_PRICE >= 4.00) OR
    (S.AK$SPECIES = 303 AND (S.UNIT_PRICE > 0 AND S.UNIT_PRICE < 4.00)))';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 15;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'
    AND T.FK$TRIP_TICKET = S.AK$TRIP_TICKET
    AND S.AK$SPECIES = 345
    AND S.UNIT_PRICE > .06';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 16;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE ((TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'))
    AND ((T.FK$TRIP_TICKET = S.AK$TRIP_TICKET))
    AND ((LTRIM(S.SPECIES_SIZE) IS NOT NULL))
    AND ((S.AK$SPECIES = 325 AND RTRIM(ltrim(S.SPECIES_SIZE,'||''' '''||'),'||''' '''||') != '||'''J'''||') OR
    (S.AK$SPECIES = 327 AND RTRIM(ltrim(S.SPECIES_SIZE,'||''' '''||'),'||''' '''||') != '||'''L'''||') OR
    (S.AK$SPECIES = 329 AND RTRIM(ltrim(S.SPECIES_SIZE,'||''' '''||'),'||''' '''||') != '||'''M'''||') OR
    (S.AK$SPECIES = 331 AND RTRIM(ltrim(S.SPECIES_SIZE,'||''' '''||'),'||''' '''||') != '||'''S'''||') OR
    (S.AK$SPECIES = 332 AND RTRIM(ltrim(S.SPECIES_SIZE,'||''' '''||'),'||''' '''||') != '||'''LT'''||'))
    UNION
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||')
    AND (T.FK$TRIP_TICKET = S.AK$TRIP_TICKET)
    AND (S.AK$SPECIES IN (325, 327, 329, 331, 332))
    AND (S.UNIT_PRICE BETWEEN .01 AND 1.50)
    AND NOT (S.AK$SPECIES = 332 AND RTRIM(LTRIM(S.SPECIES_SIZE,'||''' '''||'),'||''' '''||') = '||'''LT'''||')
    UNION
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||')
    AND (T.FK$TRIP_TICKET = S.AK$TRIP_TICKET)
    AND (S.UNIT_PRICE < .01 AND S.AK$SPECIES = 332)
    AND (RTRIM(LTRIM(SPECIES_SIZE,'||''' '''||'),'||''' '''||') != '||'''LT'''||' or species_size is null)';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 17;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||')
    AND (T.FK$TRIP_TICKET = S.AK$TRIP_TICKET)
    AND (S.AK$SPECIES = 103 OR
    S.AK$SPECIES BETWEEN 414 AND 416 OR
    S.AK$SPECIES BETWEEN 471 AND 474)
    AND (SUBSTR(T.TRIP_DATE,5,2) BETWEEN '||'''03'''||' AND '||'''05'''||')
    AND (ROUND(TO_NUMBER(T.AK$MRIS_AREA) * 10, 1) NOT IN
    (19, 29, 39, 49, 59, 69, 79, 89, 99, 109, 119,
    7179, 7229, 7289, 7329, 7369, 7419, 7449, 7489))';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 18;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||')
    AND (T.FK$TRIP_TICKET = S.AK$TRIP_TICKET)
    AND (S.WEIGHT_IN_POUNDS > 50)
    AND (S.AK$SPECIES = 103)
    and substr(t.trip_date,5,2) = '||'''04'''||'
    AND (ROUND(TO_NUMBER(T.AK$MRIS_AREA) * 10, 1) IN
    (19, 7179, 7229, 7289, 7329, 7369, 7419, 7449, 7489))';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 19;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'
    AND T.FK$TRIP_TICKET = S.AK$TRIP_TICKET
    AND S.AK$SPECIES BETWEEN 325 AND 332
    AND SUBSTR(T.TRIP_DATE,5,4) BETWEEN '||'''0516'''||' AND '||'''1014'''||'
    UNION
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE TO_NUMBER(T.BATCH) = &BATCHNUM
    AND T.FK$TRIP_TICKET = S.AK$TRIP_TICKET
    AND S.AK$SPECIES BETWEEN 317 AND 318
    AND SUBSTR(T.TRIP_DATE,5,4) BETWEEN '||'''0401'''||' AND '||'''0805'''||'';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 20;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'
    AND T.FK$TRIP_TICKET = S.AK$TRIP_TICKET
    AND S.AK$SPECIES = 141
    AND S.WEIGHT_IN_POUNDS > 300
    AND T.TRIP_DATE BETWEEN '||'''19971220'''||' AND '||'''19971231'''||'';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 21;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE ((TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'))
    AND ((T.FK$TRIP_TICKET = S.AK$TRIP_TICKET))
    AND ((S.AK$SPECIES = 209))
    AND ((T.AK$MRIS_AREA BETWEEN 0 AND 11))
    AND ((T.TRIP_DATE BETWEEN '||'''19981016'''||' AND '||'''19990131'''||') OR
    (T.TRIP_DATE BETWEEN '||'''19990315'''||' AND '||'''19990401'''||') OR
    (T.TRIP_DATE BETWEEN '||'''19990415'''||' AND '||'''19990901'''||'))';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 22;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'
    AND T.FK$TRIP_TICKET = S.AK$TRIP_TICKET
    AND S.AK$SPECIES = 193
    AND S.WEIGHT_IN_POUNDS > 250
    and substr(t.trip_date,1,4) > '||'''1996'''||'';
    -- AND TO_NUMBER(TO_CHAR(TO_DATE(T.TRIP_DATE,'YYYYMMDD'),'YY')) >= 96;
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 23;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||')
    AND (T.FK$TRIP_TICKET = S.AK$TRIP_TICKET)
    AND (S.AK$SPECIES = 193)
    AND NOT (SUBSTR(T.TRIP_DATE,5,2) BETWEEN '||'''06'''||' AND '||'''08'''||')';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 24;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE ((TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'))
    AND ((T.FK$TRIP_TICKET = S.AK$TRIP_TICKET))
    AND ((S.AK$SPECIES = 458 AND S.WEIGHT_IN_POUNDS > 50) OR
    (S.AK$SPECIES = 449 AND S.WEIGHT_IN_POUNDS > 30) OR
    (S.AK$SPECIES = 113 AND S.WEIGHT_IN_POUNDS > 50))
    and substr(t.trip_date,1,4) >= '||'''1996'''||'';
    -- AND ((TO_NUMBER(TO_CHAR(TO_DATE(T.TRIP_DATE,'||'''YYYYMMDD'''||'),'||'''YY'''||')) >= 96))';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 25;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$MRIS_GEAR,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    G.AK$MRIS_GEAR,
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_GEAR_WORK G
    WHERE ((TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'))
    AND ((T.FK$TRIP_TICKET = G.AK$TRIP_TICKET))
    AND ((G.AK$MRIS_GEAR IN (30, 70, 80)) OR
    (G.AK$MRIS_GEAR BETWEEN 4700 AND 4790) OR
    (G.AK$MRIS_GEAR BETWEEN 5300 AND 5390) OR
    (G.AK$MRIS_GEAR BETWEEN 6700 AND 6790))
    AND ((TO_NUMBER(T.AK$MRIS_AREA) - ROUND(TO_NUMBER(T.AK$MRIS_AREA)) NOT BETWEEN .85 AND .95))
    AND ((ROUND(TO_NUMBER(T.AK$MRIS_AREA)) <= 0))';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 26;
    execute immediate 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$MRIS_GEAR,AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    NULL, S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'
    AND T.FK$TRIP_TICKET = S.AK$TRIP_TICKET
    AND SUBSTR(T.TRIP_DATE,5,2) BETWEEN '||'''04'''||' AND '||'''10'''||'
    AND S.AK$SPECIES = 165
    AND S.WEIGHT_IN_POUNDS > 3500
    AND T.AK$MRIS_COUNTY IN ('||'''26'''||', '||'''28'''||', '||'''55'''||', '||'''65'''||', '||'''74'''||')
    UNION
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    NULL,S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'
    AND T.FK$TRIP_TICKET = S.AK$TRIP_TICKET
    AND SUBSTR(T.TRIP_DATE,5,2) BETWEEN '||'''04'''||' AND '||'''10'''||'
    AND S.AK$SPECIES = 165
    AND S.WEIGHT_IN_POUNDS > 500
    AND T.AK$MRIS_COUNTY IN ('||'''15'''||', '||'''16'''||', '||'''23'''||', '||'''41'''||', '||'''53'''||', '||'''60'''||', '||'''66'''||')
    UNION
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    NULL, S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'
    AND (T.FK$TRIP_TICKET = S.AK$TRIP_TICKET)
    AND (SUBSTR(T.TRIP_DATE,5,2) BETWEEN '||'''04'''||' AND '||'''10'''||')
    AND (S.AK$SPECIES = 165)
    AND ((S.WEIGHT_IN_POUNDS > 1250 AND T.AK$MRIS_COUNTY = '||'''54'''||')
    OR (T.AK$MRIS_AREA > 700 AND S.WEIGHT_IN_POUNDS > 500
    AND T.AK$MRIS_COUNTY != '||'''54'''||'))
    UNION
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    G.AK$MRIS_GEAR, S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S,
    T$TRIP_TICKET_GEAR_WORK G
    WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||')
    AND (T.FK$TRIP_TICKET = S.AK$TRIP_TICKET)
    AND (T.FK$TRIP_TICKET = G.AK$TRIP_TICKET)
    and (substr(t.trip_date,5,2) in ('||'''01'''||','||'''02'''||','||'''03'''||','||'''11'''||','||'''12'''||'))
    and (S.AK$SPECIES = 165)
    AND (S.WEIGHT_IN_POUNDS > 0)
    AND (T.TRIP_DATE BETWEEN '||'''19990331'''||' AND '||'''19990701'''||')
    AND (T.AK$MRIS_COUNTY NOT IN ('||'''15'''||','||'''16'''||','||'''23'''||','||'''26'''||','||'''28'''||','||'''41'''||','||'''53'''||','||'''54'''||','||'''55'''||','||'''60'''||','||'''65'''||','||'''66'''||','||'''74'''||')
    AND ((G.AK$MRIS_GEAR IN (70, 80)) OR
    (G.AK$MRIS_GEAR BETWEEN 4700 AND 4900) OR
    (G.AK$MRIS_GEAR BETWEEN 5300 AND 5390)))
    UNION
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    G.AK$MRIS_GEAR, S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S,
    T$TRIP_TICKET_GEAR_WORK G
    WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||')
    AND (T.FK$TRIP_TICKET = S.AK$TRIP_TICKET)
    AND (T.FK$TRIP_TICKET = G.AK$TRIP_TICKET)
    and (substr(t.trip_date,5,2) in ('||'''01'''||','||'''02'''||','||'''03'''||','||'''11'''||','||'''12'''||'))
    and (S.AK$SPECIES = 165)
    AND (S.WEIGHT_IN_POUNDS > 500)
    AND (T.TRIP_DATE > '||'''19990130'''||')
    AND (T.AK$MRIS_COUNTY NOT IN ('||'''15'''||','||'''16'''||','||'''23'''||','||'''26'''||','||'''28'''||','||'''41'''||','||'''53'''||','||'''54'''||','||'''55'''||','||'''60'''||','||'''65'''||','||'''66'''||','||'''74'''||'))
    AND ((G.AK$MRIS_GEAR = 40) OR
    G.AK$MRIS_GEAR BETWEEN 6100 AND 6190)';
    --execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value'||'. '||SQLCODE||': '||SQLERRM);
    END;
    BEGIN
    MSGNUM := 27;
    execute immediate 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$MRIS_GEAR, AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    NULL, S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'
    AND T.FK$TRIP_TICKET = S.AK$TRIP_TICKET
    AND S.AK$SPECIES = 165
    AND S.WEIGHT_IN_POUNDS > 500
    AND T.AK$MRIS_COUNTY IN (15, 16, 23, 41, 53, 54, 55, 60, 66, 74)
    AND SUBSTR(T.TRIP_DATE,5,2) IN ('||'''01'''||', '||'''02'''||', '||'''03'''||', '||'''11'''||', '||'''12'''||')
    UNION
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    G.AK$MRIS_GEAR, S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S,
    T$TRIP_TICKET_GEAR_WORK G
    WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||')
    AND (T.FK$TRIP_TICKET = S.AK$TRIP_TICKET)
    AND (T.FK$TRIP_TICKET = G.AK$TRIP_TICKET)
    AND (S.AK$SPECIES = 165)
    AND (S.WEIGHT_IN_POUNDS > 1250)
    AND (T.TRIP_DATE > '||'''19990130'''||')
    AND (T.AK$MRIS_COUNTY in ( 15, 16, 23, 26, 28, 41, 53, 54, 55, 60, 65, 66, 74))
    AND (G.AK$MRIS_GEAR = 40 OR G.AK$MRIS_GEAR BETWEEN 6100 AND 6190)
    AND (SUBSTR(T.TRIP_DATE,5,2) IN ('||'''01'''||', '||'''02'''||', '||'''03'''||', '||'''11'''||', '||'''12'''||'))
    UNION
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    G.AK$MRIS_GEAR, S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S,
    T$TRIP_TICKET_GEAR_WORK G
    WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||')
    AND (T.FK$TRIP_TICKET = S.AK$TRIP_TICKET)
    AND (T.FK$TRIP_TICKET = G.AK$TRIP_TICKET)
    AND (S.AK$SPECIES = 165)
    AND (S.WEIGHT_IN_POUNDS > 25000)
    AND (T.TRIP_DATE > '||'''19990119'''||')
    AND (T.AK$MRIS_COUNTY in ( 15, 16, 23, 26, 28, 41, 53, 54, 55, 60, 65, 66, 74))
    AND (G.AK$MRIS_GEAR IN (70, 80) OR
    G.AK$MRIS_GEAR BETWEEN 4700 AND 4790 OR
    G.AK$MRIS_GEAR BETWEEN 5300 AND 5390)
    AND (SUBSTR(T.TRIP_DATE,5,2) IN ('||'''01'''||', '||'''02'''||', '||'''03'''||', '||'''11'''||', '||'''12'''||'))
    UNION
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    G.AK$MRIS_GEAR, S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S,
    T$TRIP_TICKET_GEAR_WORK G
    WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||')
    AND (T.FK$TRIP_TICKET = S.AK$TRIP_TICKET)
    AND (T.FK$TRIP_TICKET = G.AK$TRIP_TICKET)
    AND (S.AK$SPECIES = 165)
    AND (S.WEIGHT_IN_POUNDS > 500)
    AND (T.TRIP_DATE > '||'''19990103'''||')
    AND (T.AK$MRIS_COUNTY in ( 15, 16, 23, 26, 28, 41, 53, 54, 55, 60, 65, 66, 74))
    AND (G.AK$MRIS_GEAR = 40 OR G.AK$MRIS_GEAR BETWEEN 6100 AND 6190)
    AND (SUBSTR(T.TRIP_DATE,5,2) IN ('||'''01'''||', '||'''02'''||', '||'''03'''||', '||'''11'''||', '||'''12'''||'))
    UNION
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    G.AK$MRIS_GEAR, S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S,
    T$TRIP_TICKET_GEAR_WORK G
    WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||')
    AND (T.FK$TRIP_TICKET = S.AK$TRIP_TICKET)
    AND (T.FK$TRIP_TICKET = G.AK$TRIP_TICKET)
    AND (S.AK$SPECIES = 165)
    AND (S.WEIGHT_IN_POUNDS > 0)
    AND (T.TRIP_DATE > '||'''19990119'''||')
    AND (T.AK$MRIS_COUNTY in ( 15, 16, 23, 26, 28, 41, 53, 54, 55, 60, 65, 66, 74))
    AND (G.AK$MRIS_GEAR IN (70, 80) OR
    G.AK$MRIS_GEAR BETWEEN 4700 AND 4790 OR
    G.AK$MRIS_GEAR BETWEEN 5300 AND 5390)
    AND (SUBSTR(T.TRIP_DATE,5,2) IN ('||'''01'''||', '||'''02'''||', '||'''03'''||', '||'''11'''||', '||'''12'''||'))';
    -- execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value'||'. '||SQLCODE||': '||SQLERRM);
    END;
    BEGIN
    MSGNUM := 28;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S
    WHERE TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'
    AND T.FK$TRIP_TICKET = S.AK$TRIP_TICKET
    AND T.AK$MRIS_AREA BETWEEN 0.0 AND 10.99
    AND SUBSTR(T.TRIP_DATE,5,2) IN ('||'''02'''||', '||'''03'''||', '||'''04'''||', '||'''09'''||', '||'''10'''||')
    AND S.AK$SPECIES = 209
    AND S.WEIGHT_IN_POUNDS > 2000';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    BEGIN
    MSGNUM := 29;
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    AK$MRIS_GEAR, AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,
    ERROR_NUM)
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    G.AK$MRIS_GEAR, S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S,
    T$TRIP_TICKET_GEAR_WORK G
    WHERE TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'
    AND T.FK$TRIP_TICKET = S.AK$TRIP_TICKET
    AND T.FK$TRIP_TICKET = G.AK$TRIP_TICKET
    AND S.AK$SPECIES IN (353, 355, 357, 359)
    AND T.AK$MRIS_COUNTY IN ('||'''23'''||', '||'''54'''||')
    AND G.AK$MRIS_GEAR != 9250
    UNION
    SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
    T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
    T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
    G.AK$MRIS_GEAR, S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
    TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
    '||''''||MSGNUM||''''||'
    FROM T$TRIP_TICKET_WORK T,
    T$TRIP_TICKET_SPECIES_WORK S,
    T$TRIP_TICKET_GEAR_WORK G
    WHERE TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'
    AND T.FK$TRIP_TICKET = S.AK$TRIP_TICKET
    AND T.FK$TRIP_TICKET = G.AK$TRIP_TICKET
    AND S.AK$SPECIES IN (353, 355, 357, 359)
    AND G.AK$MRIS_GEAR NOT IN (9250, 9433)';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    EXCEPTION WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('. Error writing '||MSGNUM||' Bad Value');
    END;
    FOR I IN INREC (&BATCHNUM) LOOP
    BEGIN
    IF I.TRIP_DATE IS NULL THEN
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    ERROR_NUM)
    VALUES(I.BATCH, I.AK$DEALER, I.FK$TRIP_TICKET, I.INVOICE,
    I.CONTINUATION_IND, I.TRIP_DATE, I.SPL_NO, I.AK$MRIS_AREA,
    I.AK$MRIS_COUNTY, I.TIME_FISHED, I.TIME_UNITS, I.DEPTH, I.DEPTH_UNITS,
    30)';     
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    ELSE
    DATEST := TO_DATE(I.TRIP_DATE,'YYYYMMDD');
    END IF;
    -- IF DATEST NOT BETWEEN BEGDATE AND ENDATE THEN
    IF datest not between add_months(endate,-6) and endate then
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    ERROR_NUM)
    VALUES(I.BATCH, I.AK$DEALER, I.FK$TRIP_TICKET, I.INVOICE,
    I.CONTINUATION_IND, I.TRIP_DATE, I.SPL_NO, I.AK$MRIS_AREA,
    I.AK$MRIS_COUNTY, I.TIME_FISHED, I.TIME_UNITS, I.DEPTH, I.DEPTH_UNITS,
    30)';     
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    END IF;
    EXCEPTION WHEN OTHERS THEN
    s_command := 'INSERT INTO BATCHERS_REPORT
    (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
    CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
    AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
    ERROR_NUM)
    VALUES(I.BATCH, I.AK$DEALER, I.FK$TRIP_TICKET, I.INVOICE,
    I.CONTINUATION_IND, I.TRIP_DATE, I.SPL_NO, I.AK$MRIS_AREA,
    I.AK$MRIS_COUNTY, I.TIME_FISHED, I.TIME_UNITS, I.DEPTH, I.DEPTH_UNITS,
    30)';
    execute immediate s_command;
    FLAGCNT := FLAGCNT + SQL%ROWCOUNT;
    --COMMIT;
    execute immediate 'commit';
    END;
    END LOOP;
    DBMS_OUTPUT.PUT_LINE('. RECORDS WRITTEN = '||TO_CHAR(FLAGCNT));
    DBMS_OUTPUT.PUT_LINE('. ENDING TIME = '||TO_CHAR(SYSDATE,'MM/DD/YYYY HH:MI:SS'));
    DBMS_OUTPUT.PUT_LINE('.');
    END;
    --SET TERMOUT OFF;
    CLEAR BREAKS;
    BREAK ON BATCH ON AK$DEALER;
    CLEAR COLUMNS;
    --SPOOL BATCHERS.LST;
    --CLEAR COLUMNS;
    COLUMN BATCH NOPRINT;
    COLUMN AK$DEALER HEADING 'DEALER' FORMAT A9 JUSTIFY LEFT;
    COLUMN FK$TRIP_TICKET HEADING 'TTK#' FORMAT 9999999999;
    COLUMN INVOICE HEADING 'INVOICE' FORMAT A13 JUSTIFY LEFT;
    COLUMN CONTINUATION_IND HEADING 'CONT' FORMAT A4 JUSTIFY LEFT;
    COLUMN TRIP_DATE HEADING 'DATE' FORMAT A8 JUSTIFY LEFT;
    COLUMN SPL_NO HEADING 'SPL' FORMAT A9 JUSTIFY LEFT;
    COLUMN AK$MRIS_AREA HEADING 'AREA' FORMAT A7 JUSTIFY LEFT;
    COLUMN AK$MRIS_COUNTY HEADING 'CTY' FORMAT A3 JUSTIFY LEFT;
    COLUMN TIME_FISHED HEADING 'TIME' FORMAT A4 JUSTIFY LEFT;
    COLUMN TIME_UNITS HEADING 'UNIT' FORMAT A4 JUSTIFY LEFT;
    COLUMN DEPTH HEADING 'DEPTH' FORMAT A5 JUSTIFY LEFT;
    COLUMN DEPTH_UNITS HEADING 'UNIT' FORMAT A4 JUSTIFY LEFT;
    COLUMN AK$MRIS_GEAR HEADING 'GEAR' FORMAT A4 JUSTIFY LEFT;
    COLUMN AK$SPECIES HEADING 'SPEC' FORMAT A4 JUSTIFY LEFT;
    COLUMN SPECIES_SIZE HEADING 'SIZE' FORMAT A8 JUSTIFY LEFT;
    COLUMN WEIGHT_IN_POUNDS HEADING 'POUNDS' FORMAT 99999.99;
    COLUMN UNIT_PRICE HEADING 'PRICE' FORMAT 99999.999;
    COLUMN ERROR_NUM NOPRINT;
    --CLEAR BREAKS;
    --BREAK ON BATCH ON AK$DEALER;
    --SPOOL BATCHERS.LST;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Undefined gear codes.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 1
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Undefined or non-Florida area codes.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 2
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    -- Error number 3 not in use - Logic moved to ctyarflg.sql
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Incorrect or no SPL information.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 4
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Reported less than 1 pound weight.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 5
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Bad time fished or time units.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 6
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Weight over 5500 lbs for reef fish.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 7
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Landings in closed fisheries.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 8
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Invalid species codes.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 9
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Unlikely or unusual species codes.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 10
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Food fish > 50 lbs or too expensive.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 11
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Mixed or other grouper or snapper > 50 lbs.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 12
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Over 1000 lbs striped mullet.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 13
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Oysters improperly coded.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 14
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Too expensive bait shrimp.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 15
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Bad stone crab sizes, prices or unidentified lites.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 16
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Reported landings of greater amberjack,' SKIP -
    CENTER 'lesser amberjack, almaco jack and banded rudderfish ' SKIP -
    CENTER 'during the closed season (March-May) from state waters.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 17
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Over the bag limit (1 fish) landings of' SKIP -
    CENTER 'greater amberjack during April from South Atlantic federal waters.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 18
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Landings during closed seasons.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 19
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Snowy grouper > 300 lbs (South Atlantic trip limit from Dec. 20 thru Dec. 31, 1997).' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 20
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Out-of-season Gulf red snapper landings. Commercial harvest closed' SKIP -
    CENTER 'Oct. 16, 1998 - Jan. 31 1999, Mar. 15 - Apr. 1, 1999, and' SKIP -
    CENTER 'Apr. 15 - Sep. 1, 1999.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 21
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Too much spotted seatrout.' SKIP -
    CENTER 'Commercial harvest allows 75 fish daily vessel limit, flagged 250+ lbs.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 22
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Out-of-season spotted seatrout. Commercial harvest allowed June, July, and August only.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 23
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Too much tripletail, cobia, or african pompano.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 24
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Undefined or non-Florida area fished for gear codes.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 25
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'South Atlantic king mackerel fishery (April-October)' SKIP -
    CENTER '- > 3,500lbs in Nassau-Volusia or' SKIP -
    CENTER '- > 500 lbs in Brevard-Dade or' SKIP -
    CENTER '- > 500 lbs H and L in rest of Gulf (until 7/1/1999)' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 26
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Gulf-Atlantic king mackerel fishery (November - March)' SKIP -
    CENTER '- > 500 lbs Volusia-Dade or' SKIP -
    CENTER ' > 1250 lbs H and L (>500 after 1/30/99 or' SKIP -
    CENTER ' > 25,000 lbs gill net (zero after 1/19/99) Monroe Escambia';
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 27
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'More than 2,000 lbs mixed of Gulf red snapper.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 28
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Bad or unusual gears for sponges.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 29
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    TTITLE LEFT 'Page: ' FORMAT 999 SQL.PNO RIGHT 'Batch: ' &BATCHNUM SKIP -
    CENTER 'Date is blank, invalid, before begin date or after end date.' SKIP 2;
    SELECT * FROM BATCHERS_REPORT
    WHERE ERROR_NUM = 30
    ORDER BY AK$DEALER, FK$TRIP_TICKET;
    --SPOOL OFF;
    --SET TERMOUT ON;
    --PROMPT;
    --PROMPT REPORT WRITTEN TO BATCHERS.LST;
    --PROMPT;
    --TTITLE OFF;
    SET FEEDBACK ON;
    SET LINESIZE 72;
    SET PAGESIZE 32;
    --SET NEWPAGE 1;
    SET SERVEROUT OFF;
    SET VERIFY ON;
    SET ECHO ON;
    What is wrong with my syntax or what is I am doing wrong?
    Any help will be appreciated and thanks in advance,
    -Dmitriy

    a workaround was to split the string into 2 but this is not a long term solution:
    e.g.
    vString1 := 'INSERT INTO BATCHERS_REPORT
                  (BATCH, AK$DEALER, FK$TRIP_TICKET, INVOICE,
                  CONTINUATION_IND, TRIP_DATE, SPL_NO, AK$MRIS_AREA,
                  AK$MRIS_COUNTY, TIME_FISHED, TIME_UNITS, DEPTH, DEPTH_UNITS,
                  AK$MRIS_GEAR,AK$SPECIES, SPECIES_SIZE, WEIGHT_IN_POUNDS, UNIT_PRICE,ERROR_NUM)
                  SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
                  T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
                  T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
                  NULL, S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
                  TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
                  '||''''||MSGNUM||''''||'
                  FROM T$TRIP_TICKET_WORK T,
                  T$TRIP_TICKET_SPECIES_WORK S
                  WHERE TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'
                  AND T.FK$TRIP_TICKET = S.AK$TRIP_TICKET
                  AND SUBSTR(T.TRIP_DATE,5,2) BETWEEN '||'''04'''||' AND '||'''10'''||'
                  AND S.AK$SPECIES = 165
                  AND S.WEIGHT_IN_POUNDS > 3500
                  AND T.AK$MRIS_COUNTY IN ('||'''26'''||', '||'''28'''||', '||'''55'''||', '||'''65'''||', '||'''74'''||')
                  UNION
                  SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
                  T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
                  T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
                  NULL,S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
                  TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
                  '||''''||MSGNUM||''''||'
                  FROM T$TRIP_TICKET_WORK T,
                  T$TRIP_TICKET_SPECIES_WORK S
                  WHERE TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'
                  AND T.FK$TRIP_TICKET = S.AK$TRIP_TICKET
                  AND SUBSTR(T.TRIP_DATE,5,2) BETWEEN '||'''04'''||' AND '||'''10'''||'
                  AND S.AK$SPECIES = 165
                  AND S.WEIGHT_IN_POUNDS > 500
                  AND T.AK$MRIS_COUNTY IN ('||'''15'''||', '||'''16'''||', '||'''23'''||', '||'''41'''||', '||'''53'''||', '||'''60'''||', '||'''66'''||')
                  UNION
                  SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
                  T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
                  T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
                  NULL, S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
                  TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
                  '||''''||MSGNUM||''''||'
                  FROM T$TRIP_TICKET_WORK T,
                  T$TRIP_TICKET_SPECIES_WORK S
                  WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||'
                  AND (T.FK$TRIP_TICKET = S.AK$TRIP_TICKET)
                  AND (SUBSTR(T.TRIP_DATE,5,2) BETWEEN '||'''04'''||' AND '||'''10'''||')
                  AND (S.AK$SPECIES = 165)
                  AND ((S.WEIGHT_IN_POUNDS > 1250 AND T.AK$MRIS_COUNTY = '||'''54'''||')
                  OR (T.AK$MRIS_AREA > 700 AND S.WEIGHT_IN_POUNDS > 500
                  AND T.AK$MRIS_COUNTY != '||'''54'''||'))
                  UNION
                  SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
                  T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
                  T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
                  G.AK$MRIS_GEAR, S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
                  TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
                  '||''''||MSGNUM||''''||'
                  FROM T$TRIP_TICKET_WORK T,
                  T$TRIP_TICKET_SPECIES_WORK S,
                  T$TRIP_TICKET_GEAR_WORK G
                  WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||')
                  AND (T.FK$TRIP_TICKET = S.AK$TRIP_TICKET)
                  AND (T.FK$TRIP_TICKET = G.AK$TRIP_TICKET)
                  and (substr(t.trip_date,5,2) in ('||'''01'''||','||'''02'''||','||'''03'''||','||'''11'''||','||'''12'''||'))
                  and (S.AK$SPECIES = 165)
                  AND (S.WEIGHT_IN_POUNDS > 0)
                  AND (T.TRIP_DATE BETWEEN '||'''19990331'''||' AND '||'''19990701'''||')
                  AND (T.AK$MRIS_COUNTY NOT IN ('||'''15'''||','||'''16'''||','||'''23'''||','||'''26'''||','||'''28'''||','||'''41'''||','||'''53'''||','||'''54'''||','||'''55'''||','||'''60'''||','||'''65'''||','||'''66'''||','||'''74'''||')
                  AND ((G.AK$MRIS_GEAR IN (70, 80)) OR
                  (G.AK$MRIS_GEAR BETWEEN 4700 AND 4900) OR
                  (G.AK$MRIS_GEAR BETWEEN 5300 AND 5390)))';
    vString2 := 'UNION
                 SELECT T.BATCH, T.AK$DEALER, T.FK$TRIP_TICKET, T.INVOICE,
                 T.CONTINUATION_IND, T.TRIP_DATE, T.SPL_NO, T.AK$MRIS_AREA,
                 T.AK$MRIS_COUNTY, T.TIME_FISHED, T.TIME_UNITS, T.DEPTH, T.DEPTH_UNITS,
                 G.AK$MRIS_GEAR, S.AK$SPECIES, LTRIM(S.SPECIES_SIZE),
                 TO_NUMBER(S.WEIGHT_IN_POUNDS), TO_NUMBER(S.UNIT_PRICE),
                 '||''''||MSGNUM||''''||'
                 FROM T$TRIP_TICKET_WORK T,
                 T$TRIP_TICKET_SPECIES_WORK S,
                 T$TRIP_TICKET_GEAR_WORK G
                 WHERE (TO_NUMBER(T.BATCH) = '|| &BATCHNUM ||')
                 AND (T.FK$TRIP_TICKET = S.AK$TRIP_TICKET)
                 AND (T.FK$TRIP_TICKET = G.AK$TRIP_TICKET)
                 and (substr(t.trip_date,5,2) in ('||'''01'''||','||'''02'''||','||'''03'''||','||'''11'''||','||'''12'''||'))
                 and (S.AK$SPECIES = 165)
                 AND (S.WEIGHT_IN_POUNDS > 500)
                 AND (T.TRIP_DATE > '||'''19990130'''||')
                 AND (T.AK$MRIS_COUNTY NOT IN ('||'''15'''||','||'''16'''||','||'''23'''||','||'''26'''||','||'''28'''||','||'''41'''||','||'''53'''||','||'''54'''||','||'''55'''||','||'''60'''||','||'''65'''||','||'''66'''||','||'''74'''||'))
                 AND ((G.AK$MRIS_GEAR = 40) OR
                 G.AK$MRIS_GEAR BETWEEN 6100 AND 6190)';
    Execute Immediate vString1||vString2;

  • Parsing a sql statement without executing it

    Hello everybody,
    I'd like to know a way of parsing sql statements in order to validate them, thus I'd get the error messages beforehand without executing them.
    Here we have the hard task of analyzing several sql scripts and then sending corrections to the development team and thirty party companies before applying them in our production databases. I'm willing to create a web/pl sql program that does such hard task, at least a program that identify basic errors such as missing table owner, non-existing tables, sintax errors and so on...
    Any tip will be of great help!
    Thanks in advance.

    Doing an explain plan will parse the statement prior to calculating the plan. Eg:
    SQL> explain plan for select * dual;
    explain plan for select * dual
    ERROR at line 1:
    ORA-00923: FROM keyword not found where expectedEven easier if you use Toad or some other GUI front end where the explain plan is a click of a button (or a keyboard shortcut) away!

Maybe you are looking for

  • Set type is not getting filled

    Hi , I have created a set type ZTLS_ORG, which is organisation dependent. This set type has fields from  table MVKE. I am filling up the fields of  this set type in an enhacement of Badi Definition Customer_product2. But the values are not getting po

  • Problem with Installing 8.0.5 ODBC Drivers

    I have been having a problem getting the ODBC for the 8.0.5 client. The installation runs fine, I use Net8 Easy Config and setup and running. I setup the datasources and sucessfully "Test" the connection with the login and password. When I go to the

  • Faulty WSDL Generated by SOAMANAGER

    Hi, I have created a service for the service definition "ECC_SALESORDER009QR" in SOAMANAGER. After that, I tried to open the generated WSDL from the link "Open WSDL document for selected binding". Unfortunately, it contains only the following data: <

  • Intermedia Database Agent and HTTP Server

    I have intermedia web agent 8.1.5.4 running on nt sp6. i am trying to have a username and password in the database agent for uploading and retrieving files. this works when i use IIS 4.0, however it does not work when i use HTTP server. it will ask f

  • SAPscript export to an external system.

    Dear all, I'm wondering if there are any ways to export a SAPscript which I would made in my company system to my client system. Knowing that those two systems have absolutely no physical links. Best regards. Nozome.