Selecting a value of column through sqlplus


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Selecting a value of column through sqlplus
# 1  
Old 05-12-2014
Selecting a value of column through sqlplus

Hi All,

The value of a column in my DB table is:
Code:
LOAD DATA
APPEND
INTO TABLE MK9210.EG
FIELDS TERMINATED BY '|'
TRAILING NULLCOLS
(
STUDY CHAR
,PATIENT CHAR
,CPEVENT CHAR
,NAMEG CHAR
,REFIDEG CHAR
,POSEG CHAR
,METHEG CHAR
,EGDAT CHAR
,EGTIM CHAR
,COMEG CHAR
,COM1EG CHAR
,COM2EG CHAR
,COM3EG CHAR
,COM4EG CHAR
,BYRLD INTEGER EXTERNAL
,SEXLD CHAR
,EGCLSIG CHAR
,CATEG CHAR
,TESTEG CHAR
,EVALEG CHAR
,CORESEG CHAR
,CSCDEG CHAR
,CORSNEG INTEGER EXTERNAL
,CORSUEG CHAR
,DATLDFL CHAR
,EGFND CHAR
,EGFNDTP CHAR
)

when i select this column from sqlplus in unix:
Code:
sqlplus apps/apps <<EOF
> set pagesize 5000 feedback off verify off heading off echo off serveroutput on
> spool output.dat
> select control_file from lshadmin.data_domain;
> exit
> EOF

the only thing that gets printed is:
Code:
LOAD DATA
APPEND
INTO TABLE MK9210.EG
FIELDS TERMINATED BY '|'
TRAILING NULLCOLS

Can anyone help with why is it truncating the value

Last edited by Scrutinizer; 05-12-2014 at 08:25 AM.. Reason: CODE tags
# 2  
Old 05-12-2014
i tried to reproduce your problem but getting whole value
Code:
SQL> select C from C;
LOAD DATA
APPEND
INTO TABLE MK9210.EG
FIELDS TERMINATED BY '|'
TRAILING NULLCOLS
(
STUDY CHAR
,PATIENT CHAR
,CPEVENT CHAR
,NAMEG CHAR
,REFIDEG CHAR
,POSEG CHAR
,METHEG CHAR
,EGDAT CHAR
,EGTIM CHAR
,COMEG CHAR
,COM1EG CHAR
,COM2EG CHAR
,COM3EG CHAR
,COM4EG CHAR
,BYRLD INTEGER EXTERNAL
,SEXLD CHAR
,EGCLSIG CHAR
,CATEG CHAR
,TESTEG CHAR
,EVALEG CHAR
,CORESEG CHAR
,CSCDEG CHAR
,CORSNEG INTEGER EXTERNAL
,CORSUEG CHAR
,DATLDFL CHAR
,EGFND CHAR
,EGFNDTP CHAR
)

table
Code:
create table c (C varchar2(2555));

value
Code:
insert into c values('LOAD DATA
APPEND
INTO TABLE MK9210.EG
FIELDS TERMINATED BY ''|''
TRAILING NULLCOLS
(
STUDY CHAR
,PATIENT CHAR
,CPEVENT CHAR
,NAMEG CHAR
,REFIDEG CHAR
,POSEG CHAR
,METHEG CHAR
,EGDAT CHAR
,EGTIM CHAR
,COMEG CHAR
,COM1EG CHAR
,COM2EG CHAR
,COM3EG CHAR
,COM4EG CHAR
,BYRLD INTEGER EXTERNAL
,SEXLD CHAR
,EGCLSIG CHAR
,CATEG CHAR
,TESTEG CHAR
,EVALEG CHAR
,CORESEG CHAR
,CSCDEG CHAR
,CORSNEG INTEGER EXTERNAL
,CORSUEG CHAR
,DATLDFL CHAR
,EGFND CHAR
,EGFNDTP CHAR
)
');

mak.sh
Code:
sqlplus << EOSQL
${DB_LOGON}
WHENEVER SQLERROR EXIT FAILURE;
WHENEVER OSERROR EXIT FAILURE;
set pagesize 5000 feedback off verify off heading off echo off serveroutput on
spool output.dat
select C from C;
exit
EOSQL

# 3  
Old 05-12-2014
The table column is of type CLOB..

I had to add this:
set longchunksize 200000 long 200000 pages 0
Now its working for me..

Now I want to get this clob value to a shell variable , ao am using
Code:
  sqlconn=`sqlplus ${sysuser}/${syspwd} <<-EOF 
          set longchunksize 200000 long 200000 pages 0
     SELECT CONTROL_FILE FROM LSHADMIN.DATA_DOMAIN WHERE STUDY_NAME = ${studyName}
     AND DOMAIN_NAME = ${tabname}
     EXIT
     EOF`

when I do echo $sqlconn the value is null..
can we fetch clob into shell variable?
# 4  
Old 05-12-2014
again it is working for me
table structure changed to clob
Code:
create table c (C clob);

mak.sh
Code:
var=`sqlplus -s ${DB_LOGON}<< EOSQL
WHENEVER SQLERROR EXIT FAILURE;
WHENEVER OSERROR EXIT FAILURE;
set longchunksize 200000 long 200000 pages 0
set heading off
spool output.dat
select C from C;
exit
EOSQL`
echo $var

output
Code:
Makarand>./mak.sh
++++ Retrieved Passwords for Interfaces
LOAD DATA APPEND INTO TABLE MK9210.EG FIELDS TERMINATED BY '|' TRAILING NULLCOLS ( STUDY CHAR ,PATIENT CHAR ,CPEVENT CHAR ,NAMEG CHAR ,REFIDEG CHAR ,POSEG CHAR ,METHEG CHAR ,EGDAT CHAR ,EGTIM CHAR ,COMEG CHAR ,COM1EG CHAR ,COM2EG CHAR ,COM3EG CHAR ,COM4EG CHAR ,BYRLD INTEGER EXTERNAL ,SEXLD CHAR ,EGCLSIG CHAR ,CATEG CHAR ,TESTEG CHAR ,EVALEG CHAR ,CORESEG CHAR ,CSCDEG CHAR ,CORSNEG INTEGER EXTERNAL ,CORSUEG CHAR ,DATLDFL CHAR ,EGFND CHAR ,EGFNDTP CHAR )

check your query ...specialy where clause .. did variables setting correctly ..

try to pass variables like below in red
Code:
mak=Makarand
var=`sqlplus -s ${DB_LOGON}<< EOSQL
WHENEVER SQLERROR EXIT FAILURE;
WHENEVER OSERROR EXIT FAILURE;
set longchunksize 200000 long 200000 pages 0
set heading off
spool output.dat
select C from C where D='$mak';
exit
EOSQL`


Last edited by Makarand Dodmis; 05-12-2014 at 08:13 AM..
This User Gave Thanks to Makarand Dodmis For This Post:
# 5  
Old 05-12-2014
Code:
sqlplus ${sysuser}/${syspwd} << EOF > ctl_file.ctl
     WHENEVER SQLERROR EXIT FAILURE;
           WHENEVER OSERROR EXIT FAILURE;
          set longchunksize 200000 long 200000 pages 0  head off feedback off echo off
      set heading off 
     SELECT CONTROL_FILE FROM LSHADMIN.DATA_DOMAIN WHERE STUDY_NAME = '${studyName}'
     AND DOMAIN_NAME = '${tabname}';
     exit
     EOF

the ctl_file.ctl created is
Code:
SQL> SQL> SQL> SQL> SQL> 2 LOAD DATA
APPEND
INTO TABLE MK9210.EG
FIELDS TERMINATED BY '|'
TRAILING NULLCOLS
(
STUDY CHAR
,PATIENT CHAR
,CPEVENT CHAR
,NAMEG CHAR
,REFIDEG CHAR
,POSEG CHAR
,METHEG CHAR
,EGDAT CHAR
,EGTIM CHAR
,COMEG CHAR
,COM1EG CHAR
,COM2EG CHAR
,COM3EG CHAR
,COM4EG CHAR
,BYRLD INTEGER EXTERNAL
,SEXLD CHAR
,EGCLSIG CHAR
,CATEG CHAR
,TESTEG CHAR
,EVALEG CHAR
,CORESEG CHAR
,CSCDEG CHAR
,CORSNEG INTEGER EXTERNAL
,CORSUEG CHAR
,DATLDFL CHAR
,EGFND CHAR
,EGFNDTP CHAR
)

hence,
Code:
nohup sqlldr userid=${sysuser}/${syspwd} control=ctl_file.ctl data=$infile  direct=yes silent=all parallel=true &

is throwing error as:
Code:
SQL*Loader-100: Syntax error on command-line
SQL*Loader-350: Syntax error at line 2.
Expecting keyword LOAD, found "SQL".
SQL*Plus: Release 10.1.0.5.0 - Production on Mon May 12 16:48:45 2014

How to avoid this error?

Last edited by Scrutinizer; 05-12-2014 at 08:25 AM.. Reason: Additional CODE tags
# 6  
Old 05-12-2014
use
Code:
nohup sqlldr <username>/<password>@<oraclesid> control=ctl_file.ctl data=$infile  direct=yes silent=all parallel=true &

use database user_name , password & sid as mention in red

c.ctl
Code:
Makarand>cat c.ctl
LOAD DATA
APPEND
INTO TABLE C
FIELDS TERMINATED BY '|'
TRAILING NULLCOLS
(
C CHAR
)

c.log
Code:
Table C:
  2 Rows successfully loaded.
  0 Rows not loaded due to data errors.
  0 Rows not loaded because all WHEN clauses were failed.
  0 Rows not loaded because all fields were null.

command
Code:
nohup sqlldr <username>/<password>@<oraclesid> control=c.ctl data=data direct=yes silent=all parallel=true &


Last edited by Makarand Dodmis; 05-12-2014 at 08:41 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Selecting lines based on the value in the 3rd column.

Hello, I have a sample data like this: A1 B1 100.00 B1 A1 100.00 A2 B2 90.80 B2 A2 90.80 A3 B3 99.07 B3 A3 99.07 A4 B4 99.00 B4 A4 99.00 A5 B5 97.13 B5 A5 99.53 . . Ax By i By Ax j each two lines are same comparison with opposite order. What I expected is... (3 Replies)
Discussion started by: nengcheng
3 Replies

2. Shell Programming and Scripting

Sqlplus error - sqlplus -s <login/password@dbname> : No such file or directory

i am using bash shell Whenever i declare an array, and then using sqlplus, i am getting sqlplus error and return code 127. IFS="," declare -a Arr=($Variable1); SQLPLUS=sqlplus -s "${DBUSER}"/"${DBPASS}"@"${DBASE} echo "set head off ; " > ${SQLCMD} echo "set PAGESIZE 0 ;" >> ${SQLCMD}... (6 Replies)
Discussion started by: arghadeep adity
6 Replies

3. Shell Programming and Scripting

How to get sqlplus column header once in csv file?

Hi All, Could anyoone please let me know how do I get sqlplus column header once in csv file Scripts are below: cat concreq.sh #!/bin/bash . $HOME/.profile while ; do sqlplus apps/pwd <<-EOF set lines 100 pages 100 col "USER_CONCURRENT_QUEUE_NAME" format a40; --set termout off... (5 Replies)
Discussion started by: a1_win
5 Replies

4. Shell Programming and Scripting

Selecting lowest and highest values in columns 1 and 2, based on subsets in column 3

Hi, I have a file with the following columns: 361459 447394 CHL1 290282 290282 CHL1 361459 447394 CHL1 361459 447394 CHL1 178352861 178363529 AGA 178352861 178363529 AGA 178363657 178363657 AGA Essentially, using CHL1 as an example. For any line that has CHL1 in... (2 Replies)
Discussion started by: hubleo
2 Replies

5. Shell Programming and Scripting

sum of a column and selecting lines with value above threshold

Hi again, I need to further process the results of a previous manipulation. I have a file with three columns e.g. AAA5 0.00175 1.97996e-06 AAA5 0.01334 2.14159e-05 AAA5 0.01340 4.12155e-05 AAA5 0.01496 1.10312e-05 AAA5 0.51401 0.0175308 BB0 0.00204 2.8825e-07 BB0 0.01569 7.94746e-07 BB0... (6 Replies)
Discussion started by: f_o_555
6 Replies

6. Shell Programming and Scripting

Help with selecting column with awk for a txt file generated by excel

I am new to scripting/programming, so I apologize for any novice questions. I have a tab delimited text file that was saved from excel xls file. I am trying to select only the third column using awk command. My command line is as below: cat test.txt | awk '{print $3}' However, above... (8 Replies)
Discussion started by: SangLad
8 Replies

7. Shell Programming and Scripting

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2

Match column 3 in file1 to column 1 in file 2 and replace with column 2 from file2 file 1 sample SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS... (7 Replies)
Discussion started by: rydz00
7 Replies

8. Shell Programming and Scripting

Changing one column of delimited file column to fixed width column

Hi, Iam new to unix. I have one input file . Input file : ID1~Name1~Place1 ID2~Name2~Place2 ID3~Name3~Place3 I need output such that only first column should change to fixed width column of 15 characters of length. Output File: ID1<<12 spaces>>Name1~Place1 ID2<<12... (5 Replies)
Discussion started by: manneni prakash
5 Replies

9. Shell Programming and Scripting

selecting column in perl

Dear all, I have a rather large file of numbers which i would like to read into a script and then do some maths on a specific column( e.g column). so far i have been using the following awk command awk '{print $4}' infile.txt > out.tmp to strip out the desired column within the in perl... (3 Replies)
Discussion started by: Mish_99
3 Replies

10. Shell Programming and Scripting

Selecting a line value

Hello, I just wanted to know if there is a way in UNIX to select a line value from a list of words. there is no line number before each word, hence could not use grep. (4 Replies)
Discussion started by: unibboy
4 Replies
Login or Register to Ask a Question