I have created a control file using TOADs SQL* Loader Wizard. I have used specified following two tables to load the data but the after running the data has only loaded into one table and a dsc file is generated. Below is the control file I am using:
LOAD DATA
INFILE '\\ANKH\Logs\production export 2012-12-06\BS7666CSV_001.csv'
BADFILE '\\ANKH\Logs\production export 2012-12-06\BS7666CSV_001.bad'
DISCARDFILE '\\ANKH\Logs\production export 2012-12-06\BS7666CSV_001.dsc'
INTO TABLE "STREET"
TRUNCATE
WHEN (record_id = '11')
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"' AND '"'
(RECORD_ID,
CHANGE_TYPE,
PRO_ORDER,
USRN,
TYPE,
AUTH_CODE,
STATE,
STATE_DATE,
SURFACE,
CLASS,
VERSION,
START_DATE,
END_DATE,
LAST_UPDATE_DATE,
ENTRY_DATE,
START_X_COORD,
START_Y_COORD,
END_X_COORD,
END_Y_COORD,
TOLERANCE)
INTO TABLE "STREET_DESCRIPTOR"
TRUNCATE
WHEN (record_id = '15')
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"' AND '"'
(RECORD_ID,
CHANGE_TYPE,
PRO_ORDER,
USRN,
DESCRIPTOR,
LOCALITY,
TOWN,
ADMIN_AREA,
LANGUAGE)
I figured it out that I was missing the keyword POSITION(1) in my second INTO TABLE statement to reset the pointer to the beginning of the record.
Related
I have a TERADATA dataset that resembles the below :
'Project: Hercules IssueType: Improvement Components: core AffectsVersions: 2.4.1 Priority: Minor Time: 15:25:23 04/06/2020'
I want to extract tag value from the above based on the key.
Ex:
with comm as
(
select 'Project: Hercules IssueType: Improvement Components: core AffectsVersions: 2.4.1 Priority: Minor' as text
)
select regexp_substr(comm.text,'[^: ]+',1,4)
from comm where regexp_substr(comm.text,'[^: ]+',1,3) = 'IssueType';
Is there a way to query without having to change the position arguments for every tag.
Also I am finding the last field a little tricky with date & time fields.
Any help is appreciated.
Thank you.
There's the NVP function to access Name/Value-pair data, but to split into multiple rows you need either strtok_split_to_table or regexp_split_to_table. The tricky part in your case are the delimiters, would be easier if they were unique instead of ' 'and ':':
WITH comm AS
(
SELECT 1 as keycol, -- should be a key column in your table, either numeric or varchar
'Project: Hercules IssueType: Improvement Components: core AffectsVersions: 2.4.1 Priority: Minor Time: 15:25:23 04/06/2020' AS text
)
SELECT id, tokennum, token,
-- get the key
StrTok(token,':', 1) AS "Key",
-- get the value (can't use StrTok because of ':' delimiter)
Substring(token From Position(': ' IN token)+2) AS "Value"
FROM TABLE
( RegExp_Split_To_Table(comm.keycol
,comm.text
,'( )(?=[^ ]+: )' -- assuming names don't contain spaces: split at the last space before ': '
, 'c')
RETURNS (id INT , tokennum INTEGER, token VARCHAR(1000) CHARACTER SET Latin)) AS dt
I'm retrieving data from Excel from my asp.net page
The WorkSheet name is StatusPasPorts.
When I remove the column [Account Reference No.] it does work fine, but if I
use it I get
error : '' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.
SELECT [Event Date],[Mobile Number],[Event Type Name],[Identification Method],[Customer DOB],[Account Reference No.] FROM [StatusPasPorts$] where Date] ASC
Any ideas what is missing?
Try removing the dot at the end of the column name - 'Account Reference No.'
Name it as 'Account Reference No'
Insert into emp values
(:FNAME ,.......
Above Sample Code from TPT works fine.
I want to convert null values in flatfile to blank while loading
insert into emp values ( COALESCE(:Fname,' '),.... -- Throws ERROR
TPT_INFRA: TPT04046: Error: Line 193 of Job Script File 'tpscript4.txt': Adjacen
t quoted strings must be separated by the
concatenation operator: '||'.
Job script preprocessing failed.
insert into emp Values ( case when :Fname is null then ' ' else :Fname End,... --Throws Error
Teradata Parallel Transporter Version 13.10.00.02
TPT_INFRA: TPT04046: Error: Line 191 of Job Script File 'tpscript4.txt': Adjacen
t quoted strings must be separated by the
concatenation operator: '||'.
Job script preprocessing failed.
Job terminated with status 8.
When used Case when in Select oerator for fastload:
TO OPERATOR (UPDATE_OPERATOR[2])
SELECT case when FNAME is null then ' ' else FNAME,LNAME,....
FROM OPERATOR (FILE_READER[2]);
ERROR:
TPT_INFRA: Syntax error at or near line 249 of Job Script File 'tpscript4.txt':
TPT_INFRA: At "SELECT" missing SEMICOL_ in Rule: Job Definition Body
Compilation failed due to errors. Execution Plan was not generated.
Job script compilation failed.
Job terminated with status 8.
Note: with out the case in select it is working fine ,
APPLY('insert into emp values ( COALESCE(:Fname,'' ''),....') Worked with Mload
and
SELECT CASE WHEN Fname IS NULL THEN ' ' ELSE Fname END AS Fname,... FROM OPERATOR worked with Fload
You didn't specify which error is returned, i assume it's related to the single quotes. Your INSERT is probably within an APPLY('INSERT ....;') you might try two single quotes to get one quote in a string:
APPLY('insert into emp values ( COALESCE(:Fname,'' ''),....')
Or do it in the SELECT (COALESCE is not supported here):
SELECT
CASE WHEN Fname IS NULL THEN ' ' ELSE Fname END AS Fname,
...
FROM OPERATOR
I have a sqlite3 table with a column by the name Title, which stores the names of the some movies.
Table name - table1
Column name - Title
Examples data: "Casablanca" (1983) {The Cashier and the Belly Dancer (#1.4)}
I have another sqlite3 table with a column that stores movie titles.
Table name - table2
Column name - Title
Examples data: casa blanca
Both these tables were created using different datasets, and as such although the movie name is the same (casa blanca vs "Casablanca" (1983) {The Cashier and the Belly Dancer (#1.4)}), both are stored with extra text.
What i would like to do is to SANITIZE the already stored data in both the columns. By sanitization, I would like to strip the cell content of:
1. spaces
2. spl chars like !, ', ", comma, etc..
3. convert all to lower case
I hope with that atleast some level of matching can be had between both the columns.
My question is, how do i perform these sanitizations on data that is already stored in sqlite tables. I do not have an option to sanitize before loading, as i only have access to the loaded database.
I am using sqlite 3.7.13, and i am using sqlite manager as the gui.
Thank You.
This task is too specialized to be done in SQL only.
You should write simple Perl or Python script which will scan your table, read data row by row, scrub it to meet your requirements and write it back.
This is example in Perl:
use DBI;
my $dbh = DBI->connect("dbi:mysql:database=my.db");
# replace rowid with your primary key, but it should work as is:
my $sth = $dbh->prepare(qq{
SELECT rowid,*
FROM table1
});
while (my $row = $sth->fetchrow_hashref()) {
my $rowid = $row->{rowid};
my $title = $row->{title};
# sanitize title:
$title = lc($title); # convert to lowercase
$title =~ s/,//g; # remove commas
# do more sanitization as you wish
# ...
# write it back to database:
$dbh->do(
qq{
UPDATE table1
SET title = ?
WHERE rowid = ?
}, undef,
$title,
$rowid,
);
}
$sth->finish();
$dbh->disconnect();
I have a flat file table schema (tab delimited) from another type of database (I don't know what type), but it gives me the basics of what I need such as column name, data type, description. This table has many columns.
What is the best way to create a table in SQL Server 2008 from this flat file?
Ex:
You can import file into a table with following columns
TableA:
TABLE_NAME, COLUMN_NAME, DATA_TYPE, DESCRIPTION
Then generate create statement using script below and copy output and save as sql script
SELECT 'CREATE TABLE TABLE1 (' + cols + ')' FROM (
SELECT SUBSTRING(
(SELECT ',' + s.COLUMN_NAME + ' ' DATA_TYPE
FROM tableA s WHERE TABLE_NAME = 'TABLE1'
FOR XML PATH('')),2,200000) AS Cols) A