I want to create a script file to INSERT/UPDATE values in to a table. For the sake of maintenance, I want to create an array (multi-dimensional possibly) and loop through it to insert the records. Here are the table columns:
TABLE NAME: REF_PROPERTY
REF_PROPERTY_ID Number PK
PACKAGE_ID Number FK
PROPERTY_NAME VarChar
PROPERTY_VALUE VarChar
OVERRIDE_VALUE Number
TABLE NAME: PACKAGES
PACKAGE_ID Number PK
PACKAGE_NAME VarChar
PACKAGE_VERSION VarChar
We have several packages (10-15) and each package has its own set of properties (40 - 50 properties); some are the same. I want to have one script file for all of these packages rather than separate script files for each of them.
What I want to do is something like this (writing this is sort of in non-PL/SQL format and more of a coding manner): Declare an array variable:
V_MYARR VARRAY;
myArr[1] = ['v2|v3|v4', 'property1', 'propertyValue1', 1];
myArr[2] = ['v1|v2|v3|v4', 'property2', 'propertyValue2', 0];
myArr[3] = ['v2|v3|v4|v5', 'property3', 'propertyValue3', 1];
By doing the above, I can maintain the properties and their values in the scripts. When we add a new property for any package version, we put it here and run the script.
Lets say I want to run the script for package version v2. Declare variables for the package name and version and get the package ID:
V_PKG_NAME VarChar := 'Package1'
V_PKG_VERSION VarChar := 'v2';
V_PKG_ID Number;
SELECT PACKAGE_ID INTO V_PKG_ID WHERE PACKAGE_NAME = V_PKG_NAME AND PACKAGE_VERSION = V_PKG_VERSION;
Now, I want to loop through the array, split up the first element by pipe delimiter (|), check if the version v2 exists there and if so, insert/update the values in the table.
for int arrRow in myArr
--split the first element of myArr[arrRow][0] by | and store in a new array variable splitArr
--loop through splitArr
--if V_PKG_VERSION == splitArr[I] then insert.
v2 exists in myArr[arrRow][0] so the insert would be (check if value exists before insert):
INSERT INTO REF_PROPERTY VALUES (REF_PROP_SEQ.nextval, V_PKG_ID, myArr[arrRow][1], myArr[arrRow][2], myArr[arrRow][3]);
end loop;
Similarly, when I want to run the script for package version v3, I set the package version to v3 and then run the script.
V_PKG_VERSION VarChar := 'v3';
I hope this gives a good idea of what I am looking to do and if this is a good approach to minimalizing the number of script files. And finally, if something like this is doable in Oracle PL/SQL.
Thanks in advance!