Vous êtes sur la page 1sur 2

Passing Param from Unix to TD - Toolbox for IT Groups http://datawarehouse.ittoolbox.com/groups/technical-functional/teradata-l...

HERE documents are way of providing text input to the STDIN of programs from within
the shell.

myprogram <<-END
put commands/data that myprogram reads from it's input
more commands and data ....
END

( END label tells the shell that the text for the program's STDIN ends here , this should
be the same label given after <<- )

For example, let's say, in normal scenario, you would type the bteq command in in your
UNIX shell prompt like this and type into it's input (bteq's prompt).

$ bteq

Teradata BTEQ 08.02.03.02 for UNIX5.


Copyright 1984-2006, NCR Corporation. ALL RIGHTS RESERVED.
Enter your logon or BTEQ command:

run file .mylogon;

run file .mylogon;


Teradata BTEQ 08.02.03.02 for UNIX5. Enter your logon or BTEQ command:

logon tdpid/MYUSERID,

*** Logon successfully completed.


*** Teradata Database Release is V2R.06.01.01.00
*** Teradata Database Version is 06.01.01.00
*** Transaction Semantics are BTET.
*** Character Set Name is 'ASCII'.

*** Total elapsed time was 1 second.

BTEQ -- Enter your DBC/SQL request or BTEQ command:


*** Warning: EOF on INPUT stream.
BTEQ -- Enter your DBC/SQL request or BTEQ command:
SELECT COUNT(*) FROM DBC.TABLES;

SELECT COUNT(*) FROM DBC.TABLES;

*** Query completed. One row found. One column returned.


*** Total elapsed time was 1 second.

Count(*)
-----------
34130

BTEQ -- Enter your DBC/SQL request or BTEQ command:

quit

quit
*** You are now logged off from the DBC.
*** Exiting BTEQ...
*** RC (return code) = 0
$

The same can be done via a HERE DOCUMENT to give the input text commands to
bteq directly from the shell

1 of 2 4/14/2011 9:17 AM
Passing Param from Unix to TD - Toolbox for IT Groups http://datawarehouse.ittoolbox.com/groups/technical-functional/teradata-l...

bteq <<-EOF
run file .mylogon;
SELECT COUNT(*) FROM DBC.TABLES;
quit
EOF

And you would end up with the same objective.

Good thing about here documents is that you can use stuff like shell variables in it. say
you wanted to decided which table to query using a shell variable, you can do it like
this.

QRYTBL=DBC.TABLES

bteq <<-EOF
run file .mylogon;
SELECT COUNT(*) FROM ${QRYTBL};
quit
EOF

before passing the here document text to the bteq, shell will expand it to

run file .mylogon;


SELECT COUNT(*) FROM DBC.TABLES;
quit

You can find further info on HERE documents in any Unix shell tutorials/guides.

regards

2 of 2 4/14/2011 9:17 AM

Vous aimerez peut-être aussi