473,379 Members | 1,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

import issue

I have a file with data i'd like to import into my relational dbs.
The file looks like this:

Name age job
Tom 23 Programmer
John 48 Manager
Karin 22 Programmer
Nancy 33 Programmer
Violet 25 Secretary

My tables looks like this:

Table Person
--------------
Name
Age
JobId

Table Job
-----------
JobId
Description
Both tables are empty, and after the import i like the tables to be filled
like this:

Table Person
Name Age JobId
Tom 23 1
John 48 2
Karin 22 1
Nancy 33 1
Violet 25 3

Table Job
JobId Description
1 Programmer
2 Manager
3 Secretary

It seems a simple problem, but the only way to solve this problem as i see
it, is to write some software that will take care of it?

Or am i missing something?

--

Pascal

Jun 28 '06 #1
2 1329
Ian
Pascal wrote:
I have a file with data i'd like to import into my relational dbs.
The file looks like this:

Name age job
Tom 23 Programmer
John 48 Manager
Karin 22 Programmer
Nancy 33 Programmer
Violet 25 Secretary

My tables looks like this:

Table Person
--------------
Name
Age
JobId

Table Job
-----------
JobId
Description
Both tables are empty, and after the import i like the tables to be filled
like this:

Table Person
Name Age JobId
Tom 23 1
John 48 2
Karin 22 1
Nancy 33 1
Violet 25 3

Table Job
JobId Description
1 Programmer
2 Manager
3 Secretary

It seems a simple problem, but the only way to solve this problem as i see
it, is to write some software that will take care of it?

This is an ETL (extract / transform / load) question. The DB2 IMPORT
and LOAD utilities handle the "L" portion of ETL, and as such are not
"smart" - they are written to be as fast as possible.

You need a tool (or a hand written program) to do this for you. You
could certainly load your 2 files into 2 "staging" tables and use SQL
to do the transformation.

Jun 28 '06 #2
Hi PASCAL,

You can create a stored procedure which will help you getting the
desired result.

1.) First make a temp table with the same structure as your file.

Create table schemaname.temp(Name character(),Age
integer,jobdescription character())

2.) Then import your file to the temp table

3.) Create a stored procedure which will get you the desired result.
I am not good in that, but will give you a template from which you can
proceed or some one from the group can give you an enhancement.
Drop PROCEDURE schemaname.import@
CREATE PROCEDURE schemaname.import(IN procname CHARACTER(2))
SPECIFIC schemaname.import
DYNAMIC RESULT SETS 1
P1: BEGIN

DECLARE SQLCODE INTEGER;
DECLARE SPV_ID INTEGER;

---------------------
--- Declare cursors
----------------------
DECLARE C1 CURSOR WITH HOLD FOR
SELECT * from schemaname.temp ;
----------------------
---OPEN CURSOR
-----------------------

OPEN C1;

-----------------------------
--FETCH THE VALUE OF CURSOR
------------------------------

FETCH C1 into
SPV_name,
SPV_age,
SPV_jobdescription;

WHILE SQLCODE <> 100 DO

IF (SPV_job='Programmer')
THEN
SET SPV_ID=1;
END IF;
IF (SPV_job='Manager')
THEN
SET SPV_JOBID=2;
END IF;
IF (SPV_job='Secretary')
THEN
SET SPV_ID=3;
END IF;

INSERT INTO schemaname.tableperson values(SPV_name,SPV_age,SPV_JOBID);
INSERT INTO schemaname.tablejob values(SPV_JOBID,SPV_jobdescription);

END WHILE;

CLOSE C1;
RETURN;

END P1@

Regards
Tariq Rahiman

Jun 29 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bram Stolk | last post by:
Hello, I am using python-2.2.2 on linux-ARM. Python itself works OK. However, importing pickle gives me *very* strange results: The first 'import pickle' fails with "ImportError: No module...
16
by: Manlio Perillo | last post by:
Hi. I'm a new user of Python but I have noted a little problem. Python is a very good language but it is evolving, in particular its library is evolving. This can be a problem when, ad example,...
97
by: Kjetil Torgrim Homme | last post by:
often when re-factoring code, I need to change the indent level of some chunk of code. due to the lack of an end marker, my Emacs has to use heuristics when re-indenting, and this will...
4
by: news | last post by:
Our production database in an exported textfil runs about 60 MB. Compressed that's about 9 MB. I'm trying to import the export into another machine running FC3 and mySQL 11.18, and it appears as...
3
by: Anthony Robinson | last post by:
I have an issue I've been working on that has proven to be quite troublesome. I already have an idea of what the anwser may be, but would like to solicit some suggestions or other ideas from you...
4
by: aj | last post by:
Red Hat Linux AS 2.1 DB2 WSE 8.1 FP5 I installed FP5 on my v8 server this weekend, and I think I have found a new bug in the DB2 IMPORT command. Previously, I would issue a SET SCHEMA...
4
by: Steve Jorgensen | last post by:
I'm restarting this thread with a different focus. The project I'm working on now id coming along and will be made to work, and it's too late to start over with a new strategy. Still, I'm not...
4
by: N. Graves | last post by:
Thanks for taking the time to read this note. I have a Access inventory collection tool that I have automated to build and Export to a CSV file. In the database I have several fields that are...
2
by: Bill Jackson | last post by:
Once again, I am having issues with imports... Until now, I thought the general guidelines were to rarely use 'from x import y' syntax, except when you really want to copy names over. However, I...
5
geolemon
by: geolemon | last post by:
Import text wizard says: I'm banging my head on this one, here's why: I've been importing files using this process and data format, with success! I created a temporary table in Access to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.