vendredi 6 mars 2015

Creating a table of possible values from multiple inputs


I have a list of datasets. I want to put the column names, and types, into a new consolidated table with a unique reference number. e.g.:


Table 1 has 6 unique columns


Table 2 has 22 unique columns ....


NewConsolTable has 28 records with the fields Ukey, Column_Name and Data_Type


Now, I may be over complicating this, and I am very new to Oracle SQL, but this is how I am approaching it thus far. Again, very new to this coding environment.



--http://ift.tt/1ETQEe5

CREATE OR REPLACE PROCEDURE DD_Procedure_1 IS
Field_Value_Count number := (SELECT COUNT(*) FROM dd_field);
BEGIN
INSERT INTO dd_field (ukey_f, field, description)
VALUES (Field_Value_Count + 1,
(select Column_name FROM (SELECT column_name, data_type
FROM all_tab_cols
WHERE table_name = 'DD_TEST_CARIBOU')
WHERE ROWIDTOCHAR(rowid) LIKE (CASE WHEN r < 27 THEN '%AA'||"'"||(Select COUMN from dd_columns where Key_ = r)||"'"
WHEN r < 104 THEN '%A'||"'"||(Select COUMN from dd_columns where Key_ = r) ||"'"
END)
),
'Description');
END;

--http://ift.tt/1H6MKOd

Declare
--Create list of columns as cursor
r number(9);
CURSOR DD_X IS
SELECT column_name, data_type
FROM all_tab_cols
WHERE table_name = 'DD_TEST_CARIBOU';

BEGIN
--Loop through each column and assign them to dd_Field
r := 1;
FOR X in DD_X

Loop

DD_Procedure_1;
r := r+1;

END LOOP;
END;


dd_field is currently a blank table with the 3 columns I want populated with the resulting values.


dd_columns is a work around table I created to populate the row id search with the current column name. This is ugly and may not work, but in theory, it made sense to me.


Eventually, there will be some code to create the "Description" Value.


There are going to be other loops and procedures to get to my end point, so this may seem a bit cryptic, but this, as a start, will put me on track.


Currently, I cannot create the procedure:



Error at line 31
ORA-06550: line 16, column 1:
PLS-00905: object TSA_TFC.DD_PROCEDURE_1 is invalid
ORA-06550: line 16, column 1:
PL/SQL: Statement ignored


I am working in Toad for Oracle.





Aucun commentaire:

Enregistrer un commentaire