Home » SQL & PL/SQL » SQL & PL/SQL » create dynamic view based on metadata (Oracle 11gR2/12c)
create dynamic view based on metadata [message #634850] |
Mon, 16 March 2015 18:23 |
ravikanth_b
Messages: 42 Registered: November 2007 Location: Bay Area, CA
|
Member |
|
|
Hello Experts,
Need your valuable advise with this problem.
Description.
We have a base table with fixed columns.
We have a metadata table which holds metadata for additional columns for this base table.
We have a table which holds key-value pair data for the additional columns.
Need to create a view listing all the fixed columns plus 'additional columns' that are defined in metadata table.
Following is an example with data structures and expected results.
Actual problem is much more complicated than this but i tried to present it as simple as possible.
DROP TABLE EMPLOYEE;
--base table with fixed columns
CREATE TABLE EMPLOYEE
(EMPLOYEE_ID NUMBER,
NAME VARCHAR2(100),
DEPTNO NUMBER,
SAL NUMBER
);
insert into EMPLOYEE VALUES(10,'BLAKE',500,1000);
insert into EMPLOYEE VALUES(20,'KING',500,2000);
insert into EMPLOYEE VALUES(30,'ROGER',300,3000);
commit;
select * from EMPLOYEE;
DROP TABLE TABS_METADATA;
--metadata table which as definition to additional columns
CREATE TABLE TABS_METADATA
(
TABS_METADATA_ID NUMBER(18,0) CONSTRAINT PK_TABS_METADATA PRIMARY KEY,
OWNER NVARCHAR2(30),
TABLE_NAME NVARCHAR2(30),
COLUMN_NAME NVARCHAR2(30),
COLUMN_LABEL NVARCHAR2(30),
DATA_TYPE NVARCHAR2(106),
DATA_LENGTH NUMBER(18,0),
DATA_PRECISION NUMBER(18,0),
NULLABLE NVARCHAR2(1),
DATA_DEFAULT NVARCHAR2(100),
COLUMN_ORDER NUMBER(18,0)
);
insert into TABS_METADATA VALUES(123,'SCOTT','EMPLOYEE','ADDRESS1','Address1','VARCHAR2',1000,NULL,'Y',NULL,1);
insert into TABS_METADATA VALUES(456,'SCOTT','EMPLOYEE','ADDRESS2','Address2','VARCHAR2',1000,NULL,'Y',NULL,2);
commit;
SELECT * FROM TABS_METADATA;
DROP TABLE TABS_ATTR_DATA;
-- this table has key valaue pair
-- TABS_ATTR_DATA_ID => primarky key
-- UUID => in this example EMPLOYEE_ID from EMPLOYEE table
-- ATTRIBUTE_VALUE => actual value for the attribute
CREATE TABLE TABS_ATTR_DATA
(TABS_ATTR_DATA_ID NUMBER CONSTRAINT PK_TABS_ATTR_DATA PRIMARY KEY,
TABS_METADATA_ID NUMBER,
UUID NUMBER,
DATA_TYPE VARCHAR2(10),
ATTRIBUTE_VALUE VARCHAR(255),
CONSTRAINT FK_TABS_ATTR_DATA FOREIGN KEY (TABS_METADATA_ID)REFERENCES TABS_METADATA(TABS_METADATA_ID)
);
insert into TABS_ATTR_DATA values (1,123,20,'VARCHAR2','999 Abc Ave');
insert into TABS_ATTR_DATA values (2,456,20,'VARCHAR2','CA, 12345');
commit;
select * from TABS_ATTR_DATA;
-- expected output from view
EMPLOYEE_ID NAME DEPTNO SAL ADDRESS1 ADDRESS2
10 BLAKE 500 1000 NULL NULL
20 KING 500 2000 999 Abc Ave CA, 12345
30 ROGER 300 3000 NULL NULL
|
|
|
|
|
|
|
|
|
Re: create dynamic view based on metadata [message #634857 is a reply to message #634856] |
Mon, 16 March 2015 19:11 |
ravikanth_b
Messages: 42 Registered: November 2007 Location: Bay Area, CA
|
Member |
|
|
All in single schema. Facing hell lot of problems as I warned. concurrency issues, locking issues, data inconsistencies, security issues and much more. All these are more amplified in SQL Server.
Someone sent me this reply (copy-and-paste) when asked for suggestion
When we build a house we divide it into different areas. To mention a few...
1. Living room
2. Bed room
3. Bath room
4. Kitchen
What if we don't have any of this and have one big room. You end up spending less money and time on
the construction.
Sit back, put your entire family in a house which does not have any of these partitions and then
write down the consequences.
The consequences could be alarming.
|
|
|
Goto Forum:
Current Time: Fri Apr 19 05:01:24 CDT 2024
|