I want to connect DB Using Unix shell script but i an not able to connect
below mention Code
DB
export ORACLE_HOME="oracle"
value=`/oracle/bin/sqlplus -S user/pwd#SHM4EQ << EOF
SET LINESIZE 300
SET PAGESIZE 300
SET HEADING OFF
SELECT * form dual
EOF`
Try like this...
#!/bin/bash
LogDirectory='/var/tmp/logs'
DataDirectory='/var/tmp/data'
DBUSER='scott'
DBUSERPASSWORD='tiger'
DBSID='oracle'
sqlplus -s ${DBUSER}/${DBUSERPASSWORD}#${DBSID} <<EOF
set linesize 32767
set feedback off
set heading off
select * from dual;
EOF
Related
I am using the Properties file to get the DB connection values and below is shell script file.
....
read -p "Please enter start date and end date " para1 para2
source database.prop
for ((i=1;i<=$Dbcount;i++ )); do
sqlplus -S ${user1}/${Password}#${conn} <<EOF &
spool sqlcsvdb_"$i".csv
#squery.sql $para1 $para2
exit;
EOF
done
....
squery.sql file.
....
SET PAGESIZE 50000
SET COLSEP "|"
SET LINESIZE 20000
SET headsep ON
SET FEEDBACK OFF
SET TRIMSPOOL ON
SET TRIMOUT ON
set verify off
SELECT id|| '|'||date|| '|'|| appid from table where date between '¶1' and '¶2';
exit;
EOF
....
When I execute shell it is not passing the variable values and getting ERROR at line 1:ORA-01722: invalid number error message.
Please help me on how to I resolve this and usage of bind variables.
....
read -p "Please enter start date and end date " para1 para2
Date1=$para1
Date2=$para2
source database.prop
for ((i=1;i<=$Dbcount;i++ )); do
sqlplus -S ${user1}/${Password}#${conn} <<EOF &
spool sqlcsvdb_"$i".csv
#squery.sql $Date1 $Date2
exit;
EOF
done
....
....
SET PAGESIZE 50000
SET COLSEP "|"
SET LINESIZE 20000
SET headsep ON
SET FEEDBACK OFF
SET TRIMSPOOL ON
SET TRIMOUT ON
set verify off
SELECT id|| '|'||date|| '|'|| appid from table where date between '&1' and '&';
exit;
EOF
....
Defining variables again in the shell script file then passing those variables to sql file works, until it is varaibles are defined within the shell script, it does not work.
I am getting this error in sql plus after executing this script . This is header of a file with >150 columns.I tried other options like
rtrim (xmlagg (xmlelement (e, x || '|')).extract ('//text()'), '|')
but no luck.
SP2-0027: Input is too long (> 2499 characters) - line ignored
abc.sh
sqlplus -s /nolog << EOF
connect abc/pwd#orcl;
whenever sqlerror exit sql.sqlcode;
set wrap ON
set trimout ON
set trimspool on
set serveroutput on
set pagesize 0
set long 20000000
set longchunksize 20000000
set linesize 4000
spool abc.sql
select TO_CLOB('SCSTSUMID|IMAILSUMID|FTOMERSUMKY|FGHERNAME|EILSUMADDR|FSTSUMNM|MIHZDLESUMNM|LZSTSUMNM|PRIMSUMADDR|SECSUMADDR|CITY|STATE|POSTALSUMCD|ISOSUMCODE|UNIVSUMDCOM|UNIVSUMDCOMSUMALWSUM13T17|UNIVSUMDCOMSUMALWSUMCAN|UNIVSUMDCOMSUMALWSUMCANSUM13T17|UNIVSUMPRTR|UNIVSUMPRTRSUMALWSUM13T17|UNIVSUMPRTRSUMALWSUMCAN|UNIVSUMPRTRSUMALWSUMCANSUM13T17|UNIVSUMSHOP|UNIVSUMDCOMSUMALWSUMUKDB|UNIVSUMLIVESUMCOMBINE|UNIVSUMLIVESUMDRAFT|UNIVSUMLIVESUMKICKOFF|UNIVSUMLIVESUMISGUKSUMUKDB|UNIVSUMLIVESUMISGUKSUMNOSUMUKDB|UNIVSUMLIVESUMISGMX|UNIVSUMLIVESUMPROBOWL|UNIVSUMLIVESUMSUPERBOWL|UNIVSUMDCOMSUMRECURR|UNIVSUMDCOMSUMRECURRSUM13T17|UNIVSUMDCOMSUMALWSUMHOLDOUT|UNIVSUMDCOMSUMRCRSUMALWSUMHLDOUT|AGE|GENDER|BIRTHSUMDT|CUSTSUMRECENCYSUMDT|HISPANICSUMFLG|FAVSUMTEAMSUMCD|ACTIVESUM0SUM3MSUMFLG|ACTIVESUM4SUM6MSUMFLG|ACTIVESUM7SUM9MSUMFLG|ACTIVESUM10SUM12MSUMFLG|ACTIVESUM0SUM12MSUMFLG|ACTIVESUM13SUM15MSUMFLG|ACTIVESUM16SUM18MSUMFLG|OUT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UMPROBS|SBSPNDSUMPROBS|DRAFTEDSUMFLG|EMAILSUMTIER|TSPSUMZIPSUMCD|TSPSUMSTATESUMABBREVIATION|TSPSUMADDRSUMTYPE|TSPSUMADVSUMHMSUMOWNR|TSPSUMADVSUMHHSUMSIZE|TSPSUMADVSUMHHSUMSIZESUMINDICATOR|TSPSUMADVSUMHHSUMMARITALSUMSTATUS|TSPSUMADVSUMHHSUMMARITALSUMSTATSUMIND|TSPSUMADVSUMDWELLINGSUMTYPE|TSPSUMADVSUMDWELLINGSUMTYPESUMIND|TSPSUMADVSUMTARGETSUMINCOMESUM2|TSPSUMADVSUMTARGETSUMINCOMESUMINDSUM2|TSPSUMADVSUMHHSUMEDUCATION|TSPSUMADVSUMHHSUMEDUCATIONSUMINDICATOR|TSPSUMAGESUMUNK|TSPSUMAGESUM75SUMPLUS|TSPSUMAGESUM65SUM74|TSPSUMAGESUM55SUM64|TSPSUMAGESUM45SUM54|TSPSUMAGESUM35SUM44|TSPSUMAGESUM25SUM34|TSPSUMAGESUM18SUM24|TSPSUMCHILDRENSUMAGESUM0SUM2|TSPSUMCHILDRENSUMAGESUM3SUM5|TSPSUMCHILDRENSUMAGESUM6SUM10|TSPSUMCHILDRENSUMAGESUM11SUM15|TSPSUMCHILDRENSUMAGESUM16SUM17|TSPSUMHHSUMTYPESUMFAMILYSUMCOMP|TSPSUMOCCUPATION|TSPSUMGENDERSUMPRSN|TSPSUMETHNICSUMGRP|TSPSUMETHNICSUMGRPSUMPRSN|TSPSUMLANGUAGESUMPRSN|TSPSUMTARGETSUMVALUESCORESUM2|TSPSUMCCSUMAMERSUMEXPRESS|TSPSUMCCSUMANYSUMCC|TSPSUMCCSUMBANKSUMCARD|TSPSUMCCSUMCATALOGSUMSHOWROOM|TSPSUMCCSUMCOMPUTERSUMELECTRONIC|TSPSUMCCSUMDEBITSUMCARD|TSPSUMCCSUMFINANCESUMCOSUMCARD|TSPSUMCCSUMFURNITURE|TSPSUMCCSUMGROCERY|TSPSUMCCSUMHMSUMIMPROVEMENT|TSPSUMCCSUMHMSUMOFFICESUMSUPPLY|TSPSUMCCSUMLOWSUMENDSUMDEPTSUMSTORE|TSPSUMCCSUMMAINSUMSTREETSUMRETAIL|TSPSUMCCSUMMASTERCARD|TSPSUMCCSUMMBRSHPSUMWHS|TSPSUMCCSUMMISC|TSPSUMCCSUMOILSUMGASSUMCARD|TSPSUMCCSUMSPECIALTYSUMAPPAREL|TSPSUMCCSUMSPORTINGSUMGOODS|TSPSUMCCSUMSTANDARDSUMRETAIL|TSPSUMCCSUMSTANDARDSUMSPECIALTYSUMCARD|TSPSUMCCSUMTRAVELSUMENTERTAINMENT|TSPSUMCCSUMTVSUMMAILSUMORDER|')||'TSPSUMCCSUMUPSCALESUMRETAIL|TSPSUMCCSUMUPSCALESUMSPECSUMRETAIL|TSPSUMCCSUMVISA|TSPSUMMTSUMFOOTBALLSUMENTHUSIASTS|TSPSUMMTSUMSMARTSUMPHONESUMUSER|TSPSUMMTSUMHIGHENDSUMAMSUMRANKSUMTM2|FANTSUMOPPSUMTEAMSUMNMSUMTM2|FANTSUMOPPSUMTEAMSUMRANKSUMTM2|FANTSUMLEAGUESUMIDSUMTM3|FANTSUMTEAMSUMIDSUMTM3|FANTSUMTEAMSUMNMSUMTM3|FANTSUMTEAMSUMRANKSUMTM3|FANTSUMOPPSUMTEAMSUMNMSUMTM3|FANTSUMOPPSUMTEAMSUMRANKSUMTM3|JEBBITSUMATTRIB13SUMFLG|JEBBITSUMATTRIB12SUMFANTSUMFLG|JEBBITSUMATTRIB11SUMKIDSSUMFLG|MSSUMONSUMLOCATION|MSSUMBARCLAY|BARCLAYSUMPASSIONSUMJETSETSUMIND|BARCLAYSUMPASSIONSUMELECSUMIND|BARCLAYSUMPASSIONSUMEGOERSUMIND|LSTSUMGPDSUMSTREAMSUMDT|GPDSUMMINSUMWATCHEDSUMCURRSUMSSN|GPDSUMMINSUMWATCHEDSUMPREV1SUMSSN|GPDSUMMINSUMWATCHEDSUMPREV2SUMSSN|FAVSUMTEAMSUMCDSUMIMPLIED|FAVSUMTEAMSUMCDSUMSUPPLIED|EXTRACTSUMDT' x from dual ;
spool off;
exit;
EOF
any suggestions will be highly appreciated.
You are hitting a physical limit on the length of a line of SQL in SQL*Plus. See this posting for more information on how to resolve: https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:4789399600346029472
Basically you're going to have to break up your input text with line breaks and concatenate the individual lines, like this:
abc.sh
sqlplus -s /nolog << EOF
connect abc/pwd#orcl;
whenever sqlerror exit sql.sqlcode;
set wrap ON
set trimout ON
set trimspool on
set serveroutput on
set pagesize 0
set long 20000000
set longchunksize 20000000
set linesize 4000
spool abc.sql
select TO_CLOB('SCSTSUMID|IMAILSUMID|FTOMERSUMKY|FGHERNAME|EILSUMADDR|FSTSUMNM|MIHZDLESUMNM|LZSTSUMNM|PRIMSUMADDR|SECSUMADDR|CITY|STATE|POSTALSUMCD|ISOSUMCODE|UNIVSUMDCOM|UNIVSUMDCOMSUMALWSUM13T17|UNIVSUMDCOMSUMALWSUMCAN|UNIVSUMDCOMSUMALWSUMCANSUM13T17|UNIVSUMPRTR|UNIVSUMPRTRSUMALWSUM13T17|UNIVSUMPRTRSUMALWSUMCAN|UNIVSUMPRTRSUMALWSUMCANSUM13T17|UNIVSUMSHOP|UNIVSUMDCOMSUMALWSUMUKDB|UNIVSUMLIVESUMCOMBINE|UNIVSUMLIVESUMDRAFT|UNIVSUMLIVESUMKICKOFF|UNIVSUMLIVESUMISGUKSUMUKDB|'
|| 'UNIVSUMLIVESUMISGUKSUMNOSUMUKDB|UNIVSUMLIVESUMISGMX|UNIVSUMLIVESUMPROBOWL|UNIVSUMLIVESUMSUPERBOWL|UNIVSUMDCOMSUMRECURR|UNIVSUMDCOMSUMRECURRSUM13T17|UNIVSUMDCOMSUMALWSUMHOLDOUT|UNIVSUMDCOMSUMRCRSUMALWSUMHLDOUT|AGE|GENDER|BIRTHSUMDT|CUSTSUMRECENCYSUMDT|H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SNSUMVIDEOSUMVIEWSSUMFLG|'
|| 'GPDSUMSTATUS|GPISUMSTATUS|GPESUMSTATUS|MXSUMOPTSUMINSUMFLAG|DESUMOPTSUMINSUMFLAG|CASUMOPTSUMINSUMFLAG|UKSUMOPTSUMINSUMFLAG|CLUSTERSUMN|CLUSTERSUMPNL|LSTSUMPBSUMFMPSUMSSN|EXTRACTSUMSEQ|HASDKSUMPROBS|SBSPNDSUMPROBS|DRAFTEDSUMFLG|EMAILSUMTIER|TSPSUMZIPSUMCD|TSPSUMSTATESUMABBREVIATION|TSPSUMADDRSUMTYPE|TSPSUMADVSUMHMSUMOWNR|TSPSUMADVSUMHHSUMSIZE|TSPSUMADVSUMHHSUMSIZESUMINDICATOR|TSPSUMADVSUMHHSUMMARITALSUMSTATUS|TSPSUMADVSUMHHSUMMARITALSUMSTATSUMIND|TSPSUMADVSUMDWELLINGSUMTYPE|'
|| 'TSPSUMADVSUMDWELLINGSUMTYPESUMIND|TSPSUMADVSUMTARGETSUMINCOMESUM2|TSPSUMADVSUMTARGETSUMINCOMESUMINDSUM2|TSPSUMADVSUMHHSUMEDUCATION|TSPSUMADVSUMHHSUMEDUCATIONSUMINDICATOR|TSPSUMAGESUMUNK|TSPSUMAGESUM75SUMPLUS|TSPSUMAGESUM65SUM74|TSPSUMAGESUM55SUM64|TSPSUMAGESUM45SUM54|TSPSUMAGESUM35SUM44|TSPSUMAGESUM25SUM34|TSPSUMAGESUM18SUM24|TSPSUMCHILDRENSUMAGESUM0SUM2|TSPSUMCHILDRENSUMAGESUM3SUM5|TSPSUMCHILDRENSUMAGESUM6SUM10|TSPSUMCHILDRENSUMAGESUM11SUM15|TSPSUMCHILDRENSUMAGESUM16SUM17|'
|| 'TSPSUMHHSUMTYPESUMFAMILYSUMCOMP|TSPSUMOCCUPATION|TSPSUMGENDERSUMPRSN|TSPSUMETHNICSUMGRP|TSPSUMETHNICSUMGRPSUMPRSN|TSPSUMLANGUAGESUMPRSN|TSPSUMTARGETSUMVALUESCORESUM2|TSPSUMCCSUMAMERSUMEXPRESS|TSPSUMCCSUMANYSUMCC|TSPSUMCCSUMBANKSUMCARD|TSPSUMCCSUMCATALOGSUMSHOWROOM|TSPSUMCCSUMCOMPUTERSUMELECTRONIC|TSPSUMCCSUMDEBITSUMCARD|TSPSUMCCSUMFINANCESUMCOSUMCARD|TSPSUMCCSUMFURNITURE|TSPSUMCCSUMGROCERY|TSPSUMCCSUMHMSUMIMPROVEMENT|TSPSUMCCSUMHMSUMOFFICESUMSUPPLY|TSPSUMCCSUMLOWSUMENDSUMDEPTSUMSTORE|'
|| 'TSPSUMCCSUMMAINSUMSTREETSUMRETAIL|TSPSUMCCSUMMASTERCARD|TSPSUMCCSUMMBRSHPSUMWHS|TSPSUMCCSUMMISC|TSPSUMCCSUMOILSUMGASSUMCARD|TSPSUMCCSUMSPECIALTYSUMAPPAREL|TSPSUMCCSUMSPORTINGSUMGOODS|TSPSUMCCSUMSTANDARDSUMRETAIL|TSPSUMCCSUMSTANDARDSUMSPECIALTYSUMCARD|TSPSUMCCSUMTRAVELSUMENTERTAINMENT|TSPSUMCCSUMTVSUMMAILSUMORDER|')||'TSPSUMCCSUMUPSCALESUMRETAIL|TSPSUMCCSUMUPSCALESUMSPECSUMRETAIL|TSPSUMCCSUMVISA|TSPSUMMTSUMFOOTBALLSUMENTHUSIASTS|TSPSUMMTSUMSMARTSUMPHONESUMUSER|'
|| 'TSPSUMMTSUMHIGHENDSUMAMSUMRANKSUMTM2|FANTSUMOPPSUMTEAMSUMNMSUMTM2|FANTSUMOPPSUMTEAMSUMRANKSUMTM2|FANTSUMLEAGUESUMIDSUMTM3|FANTSUMTEAMSUMIDSUMTM3|FANTSUMTEAMSUMNMSUMTM3|FANTSUMTEAMSUMRANKSUMTM3|FANTSUMOPPSUMTEAMSUMNMSUMTM3|FANTSUMOPPSUMTEAMSUMRANKSUMTM3|JEBBITSUMATTRIB13SUMFLG|JEBBITSUMATTRIB12SUMFANTSUMFLG|JEBBITSUMATTRIB11SUMKIDSSUMFLG|MSSUMONSUMLOCATION|MSSUMBARCLAY|BARCLAYSUMPASSIONSUMJETSETSUMIND|BARCLAYSUMPASSIONSUMELECSUMIND|BARCLAYSUMPASSIONSUMEGOERSUMIND|LSTSUMGPDSUMSTREAMSUMDT|'
|| 'GPDSUMMINSUMWATCHEDSUMCURRSUMSSN|GPDSUMMINSUMWATCHEDSUMPREV1SUMSSN|GPDSUMMINSUMWATCHEDSUMPREV2SUMSSN|FAVSUMTEAMSUMCDSUMIMPLIED|FAVSUMTEAMSUMCDSUMSUPPLIED|EXTRACTSUMDT' x
from dual ;
spool off;
exit;
EOF
I'm creating a Unix shell script in solaris on which my task is to run the sql queries for 35 tables and bring the output to a csv file.For Which what I thought is that I will create an array of and by using for loop I will the pass the table name one by one to sql query.So as a sample I'm trying to pass the table name as variable in sql query.
I'm passing table name is sql query as well as the CSV which I m creating.
But is not working.Please help....
table_nm="PRODUCT"
sqlplus -s admin/admin_123#extend12 <<EOF
SPOOL /data2/interfaces/scripts/`$table_nm`.CSV;
set colsep ,
set feedback off
set trimspool on
set linesize 5000
set pagesize 1000
set heading on
set term off
set verify off
set timing off
set echo off
select * from `$table_nm` where PROD_ID = '1618' AND PROD_SER_NUM = 21 ;
spool off;
EXIT;
EOF
echo "end"
Loop through the array. Don't use back ticks.
tablearry=(PRODUCT SALES EMPLOYEES)
for i in "${tablearry[#]}"
do
table_nm=$i
sqlplus -s admin/admin_123#extend12 <<EOF
SPOOL /data2/interfaces/scripts/${table_nm}.CSV;
set colsep ,
set feedback off
set trimspool on
set linesize 5000
set pagesize 1000
set heading on
set term off
set verify off
set timing off
set echo off
select * from ${table_nm} where PROD_ID = '1618' AND PROD_SER_NUM = 21 ;
spool off;
EXIT;
EOF
echo "end"
done
I want to call a procedure in sqlplus oracle using shell script,
my procedure name is getdate_proc with two parameters, startdate and enddate.
I want to set startdate = sysdate and enddate = sysdate + 5 days
for example :execute getdate_proc(to_date('05/05/2015', 'MM-DD-YYYY'),to_date('05/09/2015','MM-DD-YYYY'))
below is my code:
#!/usr/bin/ksh
sqlplus -s /nolog << EOF
connect scott/tiger
--execute procedure with parameter
execute getdate_proc(to_date(sysdate, 'MM-DD-YYYY'),to_date(sysdate + 5days,'MM-DD-YYYY'))
--set spooling to save in csv
set underline off
SET RECSEP OFF
set verify off
set colsep ','
set linesize 300
set trimspool on
spool /home/user/project/samp.csv
select * from att2;
spool off
set verify off
i solved my problem with this code:
#!/usr/bin/ksh
date1='date'
date1=$(/bin/date --date="$date1" -d "+0 day" +"%F")
date2=$(/bin/date --date="$date1" -d "+4 day" +"%F")
echo $date1
echo $date2
sqlplus -s /nolog << EOF
connect scott/tiger
--execute procedure with parameter
execute attendance(to_date('$date1', 'YYYY-MM-DD'),to_date('$date2','YYYY-MM-DD'))
--set spooling to save in csv
set underline off
SET RECSEP OFF
set verify off
set colsep ','
set linesize 300
set trimspool on
spool /home/user/project/samp.csv
select * from att2;
spool off
set verify off
:) cheers
I want to change output format of my oracle sql script.
Consider I have a script named: active_user.sh which inside it I just write my query. Now the problem is when I bash the script the output displayed without caption and only values are shown.
The script is:
export CONNECT_STRING=$1
if [ x$2 == x ]
then echo First Parameter is connection string to DB and Second parameter have to be ORACLE_HOME variable && exit 1
else export ORACLE_HOME=$2
fi
export ORACLE_SID=OMEGA #fake
export PATH=$ORACLE_HOME/bin:$PATH
RAND=$$
sqlplus -s /nolog <<-EOF > /tmp/${RAND}.sql_out.temp
connect $CONNECT_STRING
set HEADING OFF
set PAGESIZE 0
set linesize 120
col metric_name format a40
col value format 999999990.9999
select count(*) from v\$session where username is not null and status='ACTIVE';
EOF
cat /tmp/${RAND}.sql_out.temp
And this is the command to run the script and the output is:
[root#oracle-test scripts]# ./active_users.sh "ora/orapass123#mydb" /opt/oracle/instantclient_11_2
1
23.0000
But when I run the query in sqlplus it returns something like this:
COUNT(*)
----------
1
If you want to print the column headings, you have to put set HEADING ON.
You can also using SPOOL command, something like this (sorry, I can't testint now):
spool /tmp/${RAND}.sql_out.temp
set heading on
set pagesize 1000
set tab on
set linesize 120 wrap off
column "yourcount" format a40
col metric_name format a40
col value format 999999990.9999
select count(*) yourcount from v\$session where username is not null and status='ACTIVE';