Create a control file from Table definition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create a control file from Table definition
# 1  
Old 06-10-2014
Create a control file from Table definition

Hi Team,

I need to create a control file with a pre-defined structure for a given table name. The table is in teradata.
Ex: Table Name: TBL1
Code:
Table structure: 
create multiset table tbl1, no fallback,
  no before journal,
  no after journal,
  checksum = default,
  default mergeblockratio (
    col1 VARCHAR(10) not null title 'col1' casespecific,
    col2 VARCHAR(200) casespecific,
    col3 CHAR(1) not null casespecific
)
primary index tbl1 (
col1 );

I need to create a control file which will have tptstream script for this table. In this file I need to replace Varchar with the Char of same length and Integer with Char(11),Decimal with Char(length+2) etc.

User will provide the table name/names only. Please help me how to get the structure from the teradata and then create such file. I am in urgent requirement and any help will be highly appreciated.

Thanks in advance.

Last edited by Don Cragun; 06-10-2014 at 03:16 AM.. Reason: Add CODE tags.
# 2  
Old 06-10-2014
Please use codetags!

You said you have urgent requirement, let us know what you have tried so far ?
# 3  
Old 06-10-2014
Hi Akshay,

I was trying to export the table structure in a file using fastexport but that requires select statement only. Right now the problem is getting the table structure, I am writing a perl script which will read all the columns(row by row in the file) and then will create the control file accordingly. I am working on the perl right now. Any help to extract the table structure in a file will be great.

thanks.
# 4  
Old 06-10-2014
use bteq to get data from teradata onto unix. you can use export option to copy the following command's (show table) output
# 5  
Old 06-10-2014
Hi,

got the Table Structure in a file. Working on creating the control file. Any i/p will be highly appreciated.

Thanks.
# 6  
Old 06-10-2014
provide us the input file and expected output, we can try to provide a solution
# 7  
Old 06-10-2014
Hi Please find the details below:

My DDL structure file will be like this:
Code:
CREATE MULTISET TABLE LMS_STG.tbl1 ,NO FALLBACK ,
     NO BEFORE JOURNAL,
     NO AFTER JOURNAL,
     CHECKSUM = DEFAULT,
     DEFAULT MERGEBLOCKRATIO
     (
      col1 DECIMAL(18,0),
      col2 VARCHAR(100) CHARACTER SET LATIN NOT CASESPECIFIC)
PRIMARY INDEX NUPI_PH_STUD_CPNT ( col1 );

I have to create another control file which will be like this:

DEFINE JOB TBL1
DESCRIPTION 'Load a Teradata table from a file'
(
DEFINE SCHEMA DATA_SCHEMA
(
col1 CHAR(20),
col2 CHAR(11),
col3 CHAR(11),
col4 CHAR(11),
,EOL_PAD CHAR(1)
);
DEFINE OPERATOR FILE_READER
TYPE DATACONNECTOR PRODUCER
SCHEMA DATA_SCHEMA
ATTRIBUTES
(
VARCHAR PrivateLogName='PL_TBL1',
VARCHAR IndicatorMode = 'N',
VARCHAR OpenMode = 'read',
VARCHAR Format = 'Unformatted',
VARCHAR DirectoryPath = '/ngs/app/edwt/INFA/tgtfiles/',
VARCHAR FileName = 'tbl1.out'
);
DEFINE OPERATOR STREAM_OPERATOR
TYPE STREAM
INPUT SCHEMA *
ATTRIBUTES
(
INTEGER TenacityHours = 4,
INTEGER TenacitySleep = 6,
INTEGER MaxSessions = 6,
INTEGER MinSessions = 2,
VARCHAR Robust = 'Y',
VARCHAR ARRAYSUPPORT = 'ON',
INTEGER ErrorLimit = 1,
VARCHAR AppendErrorTable = 'Y',
INTEGER Pack = 600,
VARCHAR TdpId = @tdpid,
VARCHAR UserName = @userid ,
VARCHAR UserPassword  = @password ,
VARCHAR WorkingDatabase = 'LMS_STG',
VARCHAR TargetTable  = 'LMS_STG.PA_tbl1_FL',
VARCHAR ErrorTable = 'LMS_STG.ET_tbl1',
VARCHAR LogTable  = 'LMS_STG.LG_tbl1',
VARCHAR PrivateLogName = 'load_log',
VARCHAR Dateform = 'ANSIDATE'
);
APPLY
('
INSERT INTO LMS_STG.tbl1_FL(
col1,
col2

) VALUES ( 
:col1,
:col2
) ; 
')
SERIALIZE ON (
col1
) 
TO OPERATOR (STREAM_OPERATOR())
SELECT 
CASE WHEN col1 = '*' 
THEN NULL(CHAR(20)) 
ELSE col1 
END AS col1,
CASE WHEN col2 = '*' 
THEN NULL(CHAR(11)) 
ELSE col2 
END AS col2
END AS SEQUENCE_NUM
FROM OPERATOR
(
FILE_READER()
ATTR
(
FileName = 'tbl1.out'
)
);
);

I dont know if i can attach the files.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Create a pivot table from CSV file

Gents, Can you please help me to create a pivot table from a csv file. ( I have zip the csv file) Using the file attached, columns 1,28 and 21 i would like to get something like this output JD Val 1 2 3 4 5 6 7 8 9 10 11 12 Total... (4 Replies)
Discussion started by: jiam912
4 Replies

2. Shell Programming and Scripting

Script to create the SQLLDR control file from Oracle table.

I need to create the shell script load the few 100 table using the SQLLDR. Need to generate the control file for each table using oracle table. table has "table names" and "column names" using this need create the control file. example table rows below table_nme column_nme DEPT ... (2 Replies)
Discussion started by: pimmit22043
2 Replies

3. Shell Programming and Scripting

Create a File for Version Control

Hi , I have to create a file with 3 columns A,B,C. I have to read the column A,B values from a text pad. Where as Column a contains approximately 10 values and column B has 1 value which is constant. Column C is a version control column ,initially the value would be 1. (1 Reply)
Discussion started by: Inform123
1 Replies

4. UNIX for Dummies Questions & Answers

create table file from different files with index

Hi, I've several files with two collumns, where first collumn can be used as index. filename1 and filename2 how to create a file I should start with cat all files and extract first collumn to create an index? (4 Replies)
Discussion started by: sargotrons
4 Replies

5. UNIX and Linux Applications

create table via stored procedure (passing the table name to it)

hi there, I am trying to create a stored procedure that i can pass the table name to and it will create a table with that name. but for some reason it creates with what i have defined as the variable name . In the case of the example below it creates a table called 'tname' for example ... (6 Replies)
Discussion started by: rethink
6 Replies

6. Shell Programming and Scripting

to create an output file as a table

Hi, I have four input files and would like to create an output file as a table. Please check the example below. File 1. 111111 222222 333333 444444 File 2. 555555 666666 777777 888888 File 3. aaaaa bbbbb ccccc ddddd (2 Replies)
Discussion started by: marcelus
2 Replies

7. Shell Programming and Scripting

Extra control characters being added when I create a file using cat command

Hi, I am using Cygwin.I created a new file and type into it using cat > newfile. When I open this using vi editor, it contains loads of extra control characters. Whats happening? (1 Reply)
Discussion started by: erora
1 Replies

8. UNIX for Dummies Questions & Answers

extract table name from a control file

Hi, I need to extract the table name from an oracle control file which comes as the last word in the third line. Ex: LOAD DATA INFILE '/home/user/files/scott.dat' INTO TABLE SCOTT.EMP_SAL FIELDS TERMINATED BY.......... what i want to to is write the table name SCOTT.EMP_SAL to a... (2 Replies)
Discussion started by: mwrg
2 Replies

9. UNIX for Dummies Questions & Answers

create control file in UNIX

UNIX gurus: Following is what I am trying to do: I need to create a control file for another file that I am creating. The information needed in the control file is the date in YYYYMMDD format and then the number of records in the other file right justified and lpadded with spaces of 20. So... (5 Replies)
Discussion started by: alfredo123
5 Replies
Login or Register to Ask a Question