1 year ago
#361224
Darshak
sql loader case statement- how to populate a column based on another table and column values
I have a table named Addresses(having multiple address line num column) and another table named Phy_Addr
Table 1: Addresses
Columns: EmployeeID, Addr_Line_1, Addr_Line_2, Addr_Line_3
Table 2: Phy_Addr
Column: EmployeeID, Addr_Line_Filled
I would like to populate the value of a column in Phy_Addr(Addr_Line_Filled) based on the which columns in Addresses(Table 1) has a value. e.g.
- If Addr_Line_1 has a Value then put 1 in Addr_Line_Filled
- If Addr_Line_2 also has Value then put 12 in Addr_Line_Filled
- If Addr_Line_3 also has a value then put 123 in Addr_Line_Filled
- and so on for each EmployeeID
How can I do this as part of my sql loader .ctl file? This is what I have currently in both the ctl files
phy_addr.ctl
load data
CHARACTERSET UTF8
replace
into table Phy_Addr
WHEN (01) <> 'TRAILER'
fields terminated by '|'
optionally enclosed by '"'
trailing nullcols
(
EMPLOYEE_ID,
PHYSICAL_ADDRESS_ID,
)
Addresses.ctl
load data
CHARACTERSET UTF8
replace
into table Addresses
WHEN (01) <> 'TRAILER'
fields terminated by '|'
optionally enclosed by '"'
trailing nullcols
(
EMPLOYEE_ID,
ADDRESS_LINE_NUM,
ADDRESS_LINE_TEXT ,
ADDRESS_LINE_LABEL,
PHYSICAL_ADDRESS_ID,
)
DDL Table Phy_Addr
CREATE TABLE Phy_Addr
(
*PK EMPLOYEE_ID VARCHAR2(7 CHAR) NOT NULL
, *PK PHYSICAL_ADDRESS_ID VARCHAR2(100 CHAR) NOT NULL
)
DDL Table Addresses
CREATE TABLE Addresses
(
*PK EMPLOYEE_ID VARCHAR2(7 CHAR) NOT NULL
, *PK ADDRESS_LINE_NUM NUMBER(*, 0) NOT NULL
, ADDRESS_LINE_TEXT1 VARCHAR2(55 CHAR)
, ADDRESS_LINE_TEXT2 VARCHAR2(55 CHAR)
, ADDRESS_LINE_TEXT3 VARCHAR2(55 CHAR)
, ADDRESS_LINE_TEXT4 VARCHAR2(55 CHAR)
, ADDRESS_LINE_LABEL VARCHAR2(50 CHAR)
, *PK PHYSICAL_ADDRESS_ID VARCHAR2(100 CHAR) NOT NULL
)
How can I achieve the same? Should I be making changes in the Addresses.ctl file for the PHYSICAL_ADDR_LINE field to have the common logic across both the columns data in both the tables?
sql
oracle
oracle-sqldeveloper
sql-loader
ctl
0 Answers
Your Answer