Home » SQL & PL/SQL » SQL & PL/SQL » Design to Validate Staging records (merged) (ORACLE 11g)
Design to Validate Staging records (merged) [message #638564] Mon, 15 June 2015 08:10 Go to next message
jagadeesh.nraj
Messages: 3
Registered: June 2015
Location: Bangalore
Junior Member
Hi guys,
Im working on a design to validate staging data,
I have a configuration table which is mapping table which holds the field/column name of the staging table and the data type, length of data, format of the data to be validated
Im using bulk collect to get the data into a table type collection and then validate row wise.
My query is how do i dynamically select columns from the table type collection so that i dont have to write if else condition as staging table will have 30-50 columns in general.
Any advice on the same.

pseudo code

1) following are the bulk collect

select *
bulk collect into l_staging_table_type
from temp_staging_table;

select *
bulk collect into l_param_table_type
from temp_config_param_table;

2) loop the staging collection

for i in 1..l_staging_table_type.last loop
validate (l_staging_table_type(i),l_param_table_type);
end loop;

3)procedure validate (l_staging_table_type temp_staging_table%rowtype,
l_param_table_type
Re: Designing PL/SQL to Validate Staging data [message #638567 is a reply to message #638564] Mon, 15 June 2015 08:13 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Welcome to this forum.

Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/ and read http://www.orafaq.com/forum/t/174502/


Re: Designing PL/SQL to Validate Staging data [message #638584 is a reply to message #638564] Mon, 15 June 2015 10:19 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
jagadeesh.nraj wrote on Mon, 15 June 2015 18:40

I have a configuration table which is mapping table which holds the field/column name of the staging table and the data type


Why? What purpose does it solve by storing the metadata when Oracle already provides the information? Heard about V$ views?
Re: Designing PL/SQL to Validate Staging data [message #638585 is a reply to message #638564] Mon, 15 June 2015 10:28 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
jagadeesh.nraj wrote on Mon, 15 June 2015 18:40


pseudo code

1) following are the bulk collect

select *
bulk collect into l_staging_table_type
from temp_staging_table;

select *
bulk collect into l_param_table_type
from temp_config_param_table;

2) loop the staging collection

for i in 1..l_staging_table_type.last loop
validate (l_staging_table_type(i),l_param_table_type);
end loop;

3)procedure validate (l_staging_table_type temp_staging_table%rowtype,
l_param_table_type


Is this a real problem? Or is it some kind of imaginative/practice/homework/interview question? Don't mind, but seems to be a serious design flaw.
Re: Designing PL/SQL to Validate Staging data [message #638599 is a reply to message #638585] Mon, 15 June 2015 12:43 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>Im working on a design to validate staging data,

If the data already resides in an Oracle table, has not the data already been "validated"?
Explain how the data can reside within existing Oracle table & be incorrect type or size?
Design to Validate Staging records [message #638702 is a reply to message #638564] Thu, 18 June 2015 13:01 Go to previous messageGo to next message
jagadeesh.nraj
Messages: 3
Registered: June 2015
Location: Bangalore
Junior Member
Hi Guys,
I have a query in design implementation of PL/SQL. I was designing a external feed validation for staging data. have a parameter table where technical validation for each field of the feed is configured. Staging data is collected in a Staging table type collection, now the design I thought of implementing was to loop through the parameter data and pick up the column/field from the collection based on the parameter field configured. that would reduce a lot of code if let say i have 200 columns in my staging table say a running sequence Col1,Col2,... and so on. I was wondering how do i dynamically pick up the column from the collection and do the validation accordingly.

------ Staging collection
select *
bulk collect in l_staging_rec
from staging_tab

for i in (select config_field_name,data_type,data_format,data_length,Mandatory
from param_config_validation
where feed_type = 'XZY')
loop
for j in 1..l_staging_rec.count loop
/* Validate data is a proc for validation subroutine*/
validate_data(l_staging_rec(j).col||(i),i.config_field_name,i.data_format,i,data_length,l.Mandatory);
end loop;
end loop;

I thought through to implement this design but collection column/field cannot be dynamically selected (l_staging_rec(j).col||(i)) this wont compile.
So any ideas on the same line guys.

Thanks in advance.
Re: Design to Validate Staging records [message #638703 is a reply to message #638702] Thu, 18 June 2015 13:25 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
How is above different from below?
http://www.orafaq.com/forum/m/638564/#msg_638564
Re: Designing PL/SQL to Validate Staging data [message #638780 is a reply to message #638585] Sat, 20 June 2015 11:55 Go to previous messageGo to next message
jagadeesh.nraj
Messages: 3
Registered: June 2015
Location: Bangalore
Junior Member
Hi Lalith,
I am not sure what made you think saying "imaginative/practice/homework/interview question?". Idea of a custom built PL/SQL proc was to make my validation to parameterizable, whole idea is to keep the code minimum and make use of the parameter to validate for instance I need to validate time field "24HH:MI" for 1 feed and in other feed same feed could come as "HH:MI AM" this is a simple example. Any way, perhaps my description was not clear or you have not understood the whole idea.

There are multiple feeds with same fields coming in, so i cannot and should not have a field specific data type restrictions as i want to use the same staging table for same type of feed irrespective of the minor format change in the data format.

I guess this forum is to get/discuss ideas and share knowledge there is no need for sarcasm. If you really want to say there is a design flaw first understand the design and then definitely i will be happy to take the criticism.
Re: Designing PL/SQL to Validate Staging data [message #638784 is a reply to message #638780] Sat, 20 June 2015 14:47 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
if/when data is stored in correct datatype column, there is no way to get incorrect formatted data into the table.
So by definition, the data has been validated by the Oracle DB engine at the time it is INSERTED into the table.
Re: Designing PL/SQL to Validate Staging data [message #638785 is a reply to message #638780] Sat, 20 June 2015 18:29 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
Hello - I'm not sure I understand the requirement. Is it like this:

You are receiving files of data (perhaps comma separated values, with CR/LF as the record delimiter?) that have differing formats. For example, one file might have the time half past two in the afternoon represented as 14:30 and another file mught have it as 02:30PM. Also, different files may have different number of columns of different types and lengths. And you need to perform some form of validation against the data.

Is that right?
Re: Design to Validate Staging records (merged) [message #638833 is a reply to message #638564] Mon, 22 June 2015 13:39 Go to previous message
ravikanth_b
Messages: 42
Registered: November 2007
Location: Bay Area, CA
Member
Assuming you have data input from a CSV. Say you have a date field from CSV which has value 02/01/2015. How do you validate this? Is it Feb 1st 2015 or Jan 2nd 2015? Do you assume it is and should always be in one single format?
Previous Topic: SQL Query Case and Count
Next Topic: Date Parameter Issue
Goto Forum:
  


Current Time: Fri Apr 26 20:01:55 CDT 2024