Computing.Net > Forums > Unix > Fetching records from oracle databa

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Fetching records from oracle databa

Reply to Message Icon

Name: ksrao123
Date: April 13, 2004 at 12:13:24 Pacific
OS: UNIX
CPU/Ram: P III / 512
Comment:

I am trying to fetch the records from oracle database and write on to xls file for that I did the following.

I am trying to run the sql script from hockney:/opt/AMS/eINcent/live=>
File name is salesforceupload.sql
File is in the directory hockney:/opt/AMS/eINcent/live/in=>

My sql script contains

ALTER SESSION SET NLS_DATE_FORMAT = 'YYYYMMDD';
select s.OBJECTID, s.SALESFORCEID, c.name AS CHANNELNAME, sfp.name AS SALESFORCEPROFILE, s.status, s.ORGANISATIONNAME, s.ORGANISATIONCONTACTNAME, s.PHONENUMBER, s.EMAILADDRESS, s.STARTDATE, s.RECORDSTARTDATE from salesforce s, channel c, SALESFORCEPROFILE sfp where s.STATUS='active' and s.RECORDSTARTDATE>'20040407' and s.CHANNELID=c.OBJECTID and s.PROFILEID=sfp.OBJECTID;
commit;

to run this sql script I wrote the following shell script

sqlplus eincent/eincent@COMMT01 @ in/salesforceupload.sql > in/salesforce.xls
exit

It is generating the salesforce.xls file but the file contains some error instead of required data.

SQL*Plus: Release 8.1.7.0.0 - Production on Tue Apr 13 19:44:54 2004

(c) Copyright 2000 Oracle Corporation. All rights reserved.


Connected to:
Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
With the Partitioning option
JServer Release 8.1.7.4.0 - Production

SP2-0310: unable to open file ""
SQL>

Query is correct when I am running TOAD it is working fine.

What is wrong I am doing in shell script??
How can I fetch the records and write on to the xls file.

Please help if any body now

Thanks in advance

Rao



Sponsored Link
Ads by Google

Response Number 1
Name: Dlonra
Date: April 14, 2004 at 07:28:18 Pacific
Reply:

try
sqlplus 'eincent/eincent@COMMT01' '@ in/salesforceupload.sql' > in/salesforce.xls



0

Response Number 2
Name: ksrao123
Date: April 14, 2004 at 12:40:55 Pacific
Reply:

Hello,
Thanks for your help
It is working but not as i expect.

The file is containing all the below statements which are not needed in the report
SQL*Plus: Release 8.1.7.0.0 - Production on Wed Apr 14 20:10:02 2004

(c) Copyright 2000 Oracle Corporation. All rights reserved.


Connected to:
Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
With the Partitioning option
JServer Release 8.1.7.4.0 - Production


Session altered.

The data is not in table format.

Column names are repeating again and again.

All the columns are not displaying in the single row and in different column.

And all the data is not displaying in the table format.

OBJECTID SALESFORCEID CHANNELNAM SALESFORCEPROFILE columns are displaying in single column


The following is the sample for one time displayed column heading and data.
This is not in proper table format.

OBJECTID SALESFORCEID CHANNELNAM SALESFORCEPROFILE
---------------
STATUS ORGANISATIONNAME
-------------
ORGANISATIONCONTACTNAME
--
PHONENUMBER EMAILADDRESS STARTDAT
------------- --------
RECORDST
--------
6200 TRT01 SpecRetail Stockist
active Thorpe Supplies (Chatterbox)

I need the table and data in the following format
OBJECTID SALESFORCEID CHANNELNAME SALESFORCEPROFILE STATUS ORGANISATIONNAME ORGANISATIONCONTACTNAME PHONENUMBER EMAILADDRESS STARTDATE RECORDSTARTDATE
6200 TRT01 SpecRetail Stockist active Thorpe Supplies (Chatterbox) 06/23/2003 04/08/2004

Could you please help??

Thanks in advance
Rao



0

Response Number 3
Name: WilliamRobertson
Date: April 14, 2004 at 15:44:12 Pacific
Reply:

Column headings will be repeated each page. The number of lines per page is defined by SET PAGESIZE.

The maximum length of a line before it is wrapped is defined by SET LINESIZE.

You could try SET MARKUP HTML to generate HTML-formatted output, which Excel should be able to read.


0

Response Number 4
Name: ksrao123
Date: April 15, 2004 at 03:23:37 Pacific
Reply:

Hello WilliamRobertson,

Thanks for your advise and help.

I am almost getting the report with your help.

But first line contains the following information with is not needed

SQL*Plus: Release 8.1.7.0.0 - Production on Thu Apr 15 11:17:07 2004 (c) Copyright 2000 Oracle Corporation. All rights reserved. Connected to: Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production With the Partitioning option JServer Release 8.1.7.4.0 - Production Session altered.

And second line is blank whihich is not needed.

and last line contains the following information with is not needed

168 rows selected.
Commit complete.
Input truncated to 5 characters
Disconnected from Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production With the Partitioning option JServer Release 8.1.7.4.0 - Production

How can i avoid to display them on to report?

Can you help me?

Very much thanks in advance
Rao


0

Response Number 5
Name: mrislam
Date: April 15, 2004 at 12:36:53 Pacific
Reply:

Hi folks,

Copy the following script into test.ksh file in UNIX. Then run it.

sqlplus -S dbuser/dbpass@dbbase << EOF
SPOOL /tmp/output.lst
SET HEADING OFF
SET VERIFY OFF
SET FEEDBACK OFF
SET RECSEP OFF
SELECT TABLE_NAME FROM USER_TABLES;
exit;
EOF


This will eleminate un-wanted output and solve your problems.


Thanks.


Mohammed


0

Related Posts

See More



Response Number 6
Name: WilliamRobertson
Date: April 15, 2004 at 12:41:27 Pacific
Reply:

Invoke sqlplus with the -s (silent) option to suppress the startup banner and line prompts. SET FEEDBACK OFF to suppress "n rows selected". "Commit complete" etc messages (actually you don't need to commit anyway since you have not changed any data). Ensure the SQL*Plus script ends with a blank line to avoid the "Input truncated" message.

If you do those, do you still get a blank first line?

btw the .xls extension might be considered misleading since the file is not in MS Excel format. Excel will open .csv files, or even .htm/.html.


0

Response Number 7
Name: ksrao123
Date: April 16, 2004 at 08:09:15 Pacific
Reply:

Hi,

Thanks it works fine.

How can i truncate file extention?

Or

How can i truncate last 4 charectors of a string?

Please help if you can.

Thanks
Rao


0

Response Number 8
Name: WilliamRobertson
Date: April 16, 2004 at 14:35:58 Pacific
Reply:

In ksh:

$ filename=somefile.xls
$ echo $filename

somefile.xls

$ filename=${filename%.*}
$ echo $filename

somefile


0

Response Number 9
Name: ksrao123
Date: April 19, 2004 at 01:09:04 Pacific
Reply:

I am using #! /bin/sh

I am getting the following error
/opt/AMS/eINcent/live/scripts_test/raotest: bad substitution

Could you please help me??

Thanks
Rao


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Fetching records from oracle databa

passing value from oracle to unix www.computing.net/answers/unix/passing-value-from-oracle-to-unix/7327.html

Getting Max record from a file www.computing.net/answers/unix/getting-max-record-from-a-file/7110.html

Finding unique records from file www.computing.net/answers/unix/finding-unique-records-from-file/4591.html