dbTalk Databases Forums  

Sample Script?

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Sample Script? in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
AP
 
Posts: n/a

Default Sample Script? - 12-20-2007 , 08:50 AM






Hello I am new to Oracle. What I am trying to do is basic, I think. I
typically use toad to run select statements. I want to be able to
create a script that simply when executed, runs the select statement
and exports it to a file. Once I get this figured out, I would use a
command line method to run it on a scheduled basis. Any samples ?

Thanks

Reply With Quote
  #2  
Old   
Terry Dykstra
 
Posts: n/a

Default Re: Sample Script? - 12-20-2007 , 09:48 AM






"AP" <megacrosstab (AT) greenixsolutions (DOT) com> wrote

Quote:
Hello I am new to Oracle. What I am trying to do is basic, I think. I
typically use toad to run select statements. I want to be able to
create a script that simply when executed, runs the select statement
and exports it to a file. Once I get this figured out, I would use a
command line method to run it on a scheduled basis. Any samples ?

Thanks
In its most basic form:


sqlplus userid/passwd@dbname @yourscript.sql

with a spool statement in the yourscript.sql file.

Hardcoding passwords obviously is not very good. There are ways of
redirecting input from another file into your script.
--
Terry Dykstra




Reply With Quote
  #3  
Old   
AP
 
Posts: n/a

Default Re: Sample Script? - 12-20-2007 , 09:54 AM



On Dec 20, 10:48 am, "Terry Dykstra" <tddyks... (AT) forestoil (DOT) ca> wrote:
Quote:
"AP" <megacross... (AT) greenixsolutions (DOT) com> wrote in message

news:804a246f-3fca-4b54-a2bc-aeecac1841eb (AT) j20g2000hsi (DOT) googlegroups.com...

Hello I am new to Oracle. What I am trying to do is basic, I think. I
typically use toad to run select statements. I want to be able to
create a script that simply when executed, runs the select statement
and exports it to a file. Once I get this figured out, I would use a
command line method to run it on a scheduled basis. Any samples ?

Thanks

In its most basic form:

sqlplus userid/passwd@dbname @yourscript.sql

with a spool statement in the yourscript.sql file.

Hardcoding passwords obviously is not very good. There are ways of
redirecting input from another file into your script.
--
Terry Dykstra
Thanks for the reply, but I know the command line part, I do not know
how to do the following:


Select * from mytable;

Save the output as txt to C:\output files.


Not sure how to build the script.
Thanks for your response.



Reply With Quote
  #4  
Old   
Terry Dykstra
 
Posts: n/a

Default Re: Sample Script? - 12-20-2007 , 11:18 AM



"AP" <megacrosstab (AT) greenixsolutions (DOT) com> wrote

Quote:
On Dec 20, 10:48 am, "Terry Dykstra" <tddyks... (AT) forestoil (DOT) ca> wrote:
"AP" <megacross... (AT) greenixsolutions (DOT) com> wrote in message

news:804a246f-3fca-4b54-a2bc-aeecac1841eb (AT) j20g2000hsi (DOT) googlegroups.com...

Hello I am new to Oracle. What I am trying to do is basic, I think. I
typically use toad to run select statements. I want to be able to
create a script that simply when executed, runs the select statement
and exports it to a file. Once I get this figured out, I would use a
command line method to run it on a scheduled basis. Any samples ?

Thanks

In its most basic form:

sqlplus userid/passwd@dbname @yourscript.sql

with a spool statement in the yourscript.sql file.

Hardcoding passwords obviously is not very good. There are ways of
redirecting input from another file into your script.
--
Terry Dykstra

Thanks for the reply, but I know the command line part, I do not know
how to do the following:


Select * from mytable;

Save the output as txt to C:\output files.


Not sure how to build the script.
Thanks for your response.

Using spool:

spool myfile.txt
select a,b,c from mytable;
spool off

Check out the sqlplus user guide.

--
Terry Dykstra




Reply With Quote
  #5  
Old   
Galen Boyer
 
Posts: n/a

Default Re: Sample Script? - 12-22-2007 , 03:04 PM



On Thu, 20 Dec 2007, megacrosstab (AT) greenixsolutions (DOT) com wrote:
Quote:
On Dec 20, 10:48 am, "Terry Dykstra" <tddyks... (AT) forestoil (DOT) ca> wrote:
"AP" <megacross... (AT) greenixsolutions (DOT) com> wrote in message

news:804a246f-3fca-4b54-a2bc-aeecac1841eb (AT) j20g2000hsi (DOT) googlegroups.com...

Hello I am new to Oracle. What I am trying to do is basic, I
think. I typically use toad to run select statements. I want to be
able to create a script that simply when executed, runs the select
statement and exports it to a file. Once I get this figured out, I
would use a command line method to run it on a scheduled basis. Any
samples ?

Thanks

In its most basic form:

sqlplus userid/passwd@dbname @yourscript.sql

with a spool statement in the yourscript.sql file.

Hardcoding passwords obviously is not very good. There are ways of
redirecting input from another file into your script.
--
Terry Dykstra

Thanks for the reply, but I know the command line part, I do not know
how to do the following:


Select * from mytable;

Save the output as txt to C:\output files.


Not sure how to build the script.
Thanks for your response.
Seems that you are struggling with a very simple concept, actually, but
I could see how it might be confusing, especially if all you have worked
with is GUI tools, like TOAD.

sqlplus is an executable. It can be run as an interactive command-line
where you submit sql statements directly. ie,

CMD> sqlplus login/password@instance RETURN
... Now, you see a command-line interface to Oracle sql commands.
SQLPLUS> select blah ...;
SQLPLUS> select bleh ...;

But sqlplus can, ALSO, be run as an executable that is passed a file
containing sql statements.

sqlplus login/password@instance @ScriptWithSqlStatements.sql

Inside ScriptWithSqlStatements.sql, put a spool statement.

All of sqlplus and how to use it is documented quite nicely.

--
Galen Boyer


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.