Spool file is getting duplicates - sqlplus

I have created the following Script ( name.sql ) which is then called from a windows.bat file.
The problem is that the .xls file that is created has twice the resultset from the SQL query.
I send you the script to help me udnerstnad what i do wrong in the .sql script:
set linesize 999 verify off feedback off
set markup html on entmap on spool on preformat off table 'align=right width=40%
border=10 bordercolor=black bgcolor=white'
set echo off pagesize 1000 linesize 255 feedback off heading on;
set serveroutput off
del "D:\weekly_orders.xls"
SPOOL d:\weekly_orders1.xls
select * from x where id='1-6A86P9C' order by x_date;
/
SPOOL OFF;
exit

Remove the slash that is on the line by itself. It tells SQL/Plus to repeat the last command.
See the answers in this question regarding slash vs semi-colon when used in SQL scripts:
When do I need to use a semicolon vs a slash in Oracle SQL? for more information and explanations of what is going on.

Related

How do I execute a SQL script using a bind variable

I'm running Oracle 18.c on a Windows 10 platform.
I have a large DOS script which calls SQL Plus to run the first SQL script, passing a parameter to it.
The parameter is successfully passed to the first SQL script. In that SQL script I'm trying to append some text to the passed parameter so that it can call a second script using the "#" feature.
DOS Script test1.bat
#echo off
SET value1=2020_01_19_17_00_01
sqlplus my_username/my_password#my_TNS as sysdba #C:\Backups\test1.sql %value1%
SQL Script test1.sql
SET SERVEROUTPUT ON
variable param1 varchar2(512);
variable full_file_name varchar2(512);
BEGIN
:param1 := '&&1';
dbms_output.put_line('The value of the passed parameter is: ' || :param1);
:full_file_name := :param1 || '_f104.sql';
dbms_output.put_line('The new filename would be: ' || :full_file_name);
#:full_file_name;
END;
/
I'm having problems getting the value in :full_file_name to execute from the test1.sql script. If a variable were not involved I would simply use the line #2020_01_19_17_00_01_f104.sql
How do I go about getting the script file whose name is stored in :full_file_name to execute?
I found a way to do this. My sql script now looks like:
Define ffn104 = '&&1._f104.sql'
#&ffn104
exit
Note that in the Define statement I had to put a period after the passed variable &&1 to end its definition. Then I appended _f104.sql.
That solved the problem.

Error while creating a simple DB2 sql procedure

I am trying to create a db2 procedure on DB2 z/OS 10.1.5. The code I am using is :
CREATE PROCEDURE WSDIWW16.CALCULATE_SALARY()
LANGUAGE SQL
BEGIN ATOMIC
update wsdiww16.emptable
set dailywage = dailywage * 30;
END;
I am getting sqlcode - 104
SQL0104N An unexpected token "<END-OF-STATEMENT>" was found following "".
Expected tokens may include: "DECLARE".
I haven't created an sql procedure earlier. Can somebody please help ?
You've got two semicolons in that CREATE statement. The first one needs to be a different character that's recognized as a statement terminator.
What development environment are you using? In Rational Developer for z, you can right-click the editor and select the Set Statement Terminator option:
1
Similar options should be available in Data Studio, etc.
You should use end line terminator such as '/' and execute your query using below command -
db2 +c -td/ -vf SQL_file_name
HTH
The answer with the graphical menu worked for me. From inside my SQL script I did a right click anywhere in the white space. The menu above then appeared. I then left clicked on "Set Statement Terminator" (as requested). I then changed my terminator character to "#" (no quote marks). After that the semicolon character ";" started working again.
I hope this helps.
I believe you need to end your procedures with a '/'.

Media Temple php.ini saving

So I am working on my client's website and in order to integrate twitter posts into the website I need to include the following line in PHP.ini:
allow_url_fopen = On;
So now my PHP.ini looks like this:
; Rename this file to php.ini and uncomment or add directives.
; For a complete list of valid directives, visit:
; http://us2.php.net/manual/en/ini.php
[PHP]
; We highly recommend that you leave this options enabled
cgi.fix_pathinfo=1
; Increase maximum post size
;post_max_size = 20M
; Increase execution time
;max_execution_time = 300
; pull in EGPCS [Environment, GET, POST, Cookie, Server] variables as globals
;register_globals = true
; For performance reasons, (mt) does not load all of the modules that are available
; into PHP. You may uncomment any one of the following "extension" lines to enable
; the desired module
; Salblotron XSLT
;extension=xslt.so
; save in local tmp
session.save_path=/home/65994/data/tmp
allow_url_fopen = On;
upload_max_filesize = 20M
For some reason it works... but only for about 15 mins or so before it breaks and comes up with an error.
Nevertheless if I take the line added to php.ini and move it around... and resave, it works again...
ODD...
Does anyone know why or how to fix this?
MT disables insecure php functions by default now, so there's a good chance that your issue may be due to something causing a timeout even though you've re-enabled the 'offensive' option. Try setting the
default_socket_timeout
option to something longer http://php.net/manual/en/filesystem.configuration.php
As an aside, you'll probably save yourself some grief if you switch to cURL with Twitter OAuth instead of direct url open.

Issues while using sqlplus with ruby

I want to use sqlplus within ruby. Dont want to use any gems[bec I cannot get it installed on our servers without much help from other teams ..etc] and want to keep it very minimal.
I am trying something as simple as this in my ruby script:
`rlwrap sqlplus user/pswd#host << EOF`
`set serveroutput on;`
`commit;` #ERROR1: sh: commit: not found
sql = "insert /*+ APPEND*/ INTO table(col1, col2) values (#{data[0]},#{data[1]});"
`#{sql}` #ERROR2: sh: Syntax error: "(" unexpected
Can anyone help me with ERROR1 and ERROR2 above
Basically for "commit: not found" I think its getting executed on shell rather than in sqlplus. However seems like "set serveroutput on" seems to execute fine !
For ERROR2, I am clueless. I also tried using escape slash for the "/" in the sql.
Thanks
The answer is, don't use SQL*Plus. Don't call a command-line utility from inside your script; between the ruby-oci8 gem and the ruby-plsql gem, you can do anything you could accomplish from within SQL*Plus.
The reason you get the errors is that you are sending each line to the shell individually. If your entire statement was wrapped in a single pair of backticks, it might work.
But if you really are unable to install the proper gems, put the commands in a temporary file and tell sqlplus to execute that, eg:
require 'tempfile'
file = Tempfile.open(['test', '.sql'])
file.puts "set serveroutput on;"
file.puts "commit;"
file.puts "insert /*+ APPEND*/ INTO table(col1, col2) values (#{data[0]},#{data[1]});"
file.puts "exit;" # needed or sqlplus will never return control to your script
file.close
output = `sqlplus user/pswd#host ##{file.path}`
file.unlink
You'll have to be very careful about:
Quoting values (if using oci8/dbi you could use bind variables)
Error handling. If using ruby libraries, errors would raise exceptions. Using sqlplus, you'll have to parse the output instead. Yuck!
So it can be done but I highly recommend you jump through whatever hoops are required to get oci8 (and maybe ruby-DBI) installed properly :)
ps are you sure you want to commit before the insert?

Tomcat6 Service Setup; programatically concatenate JvmOptions using Batch File

This may bit a bit of a basic question, but I can't seem to find an answer on the web. I'm trying to automatically set up tomcat as a service through a batch file.
My batch file currently looks like this:
set memSize=512
set jvmOptions="-XX:MaxPermSize=512M"
ECHO Setting up tomcat as a service.
call service.bat install
ECHO Setting the memory allocation to a maximum of %memSize%
ECHO Using JVM options %jvmOptions%
Tomcat6 //US// --JvmMx=%memSize% --Startup="auto" --JvmOptions=%jvmOptions%
The issue I'm facing is that running the --JvmOptions switch overwrites all the current java options that are set in the tomcat6w.exe.
So my question is, does anyone know how to have the --JvmOptions switch concatenate the passed value to the end of the current value?
Thanks in advance
Could it be as simple as this (if I understand your question correctly)
set memSize=512
REM I removed the quotes and reused the variable in its own definition
set jvmOptions=%jvmOptions%-XX:MaxPermSize=512M
ECHO Setting up tomcat as a service.
call service.bat install
ECHO Setting the memory allocation to a maximum of %memSize%
ECHO Using JVM options %jvmOptions%
REM Added the quotes back here
Tomcat6 //US// --JvmMx=%memSize% --Startup="auto" --JvmOptions="%jvmOptions%"
After a long hard search I did manage to find the answer in a code example. But then to make me feel very foolish I noticed that the answer was also here right under my nose on the Tomcat6 Windows Service How To page. By replacing the -- with ++ the option is concatenated rather than replacing the original.
So the batch file became.
set memSize=512
set jvmOptions="-XX:MaxPermSize=512M"
ECHO Setting up tomcat as a service.
call service.bat install
ECHO Setting the memory allocation to a maximum of %memSize%
ECHO Using JVM options %jvmOptions%
Tomcat6 //US// --JvmMx=%memSize% --Startup="auto" ++JvmOptions=%jvmOptions%
Thanks.
A bit of an old post, but I have to do a bunch of Tomcat uninstalls/installs due another application being upgraded (a term I use loosely) and was trying to figure out how to do something similar to avoid using the UI and ensure consistency.
Some scripting tips (based on my experience so far):
REM -- Use variables for the Tomcat install directory & executable:
set TomcatDir=%ProgramFiles%\Tomcat
set TomcatExe=%TomcatDir%\bin\Tomcat7.exe
REM -- If using multiple instances, turn these in to array
set TomcatInstance[1]=Tomcat7
set TomcatInstance[2]=MyAppInstance1
set TomcatInstance[3]=MyAppInstance2
set TomcatInstance[4]=MyAppInstance3
set TomcatInstance[5]=MyAppInstance4
REM -- When updating/adding Java options and you need to use a ";" between
REM -- values, single-quote the semi-colon, ';' so it isn't intepretted as a CrLf
REM -- For example,
call "%TomcatExe%" //US/%TomcatInstance% ++JvmOptions "-Djava.library.path=%TomcatDir%\bin';'%TomcatDir%\endorsed"
REM -- So to ensure all instances have the same settings...
for /L %I in (1,1,5) do (
call "%TomcatExe%" //US/!TomcatInstance[%I]! ++JvmOptions "-Djava.library.path=%TomcatDir%\bin';'%TomcatDir%\endorsed"
)
REM -- Block scripts sections with setlocal/endlocal
REM -- "EnableDelayedExpansion" allows the above delayed variable expansion to occur
::--==--==--==--==--==--==--==--==--==--==
:Routine_Name
::--==--==--==--==--==--==--==--==--==--==
setlocal EnableDelayedExpansion
echo script commands go here
endlocal
goto :EOF
Note: This would be much easier in an actual scripting language (vbs, js or ps), but I need to leave the script "easy" to modify for whomever takes over for me when I leave my current gig.
FWIW, the how to doc for Tomcat7 is http://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html.

Resources