I'm trying to port over some statements from Oracle to Postgres.
One specific one that I have a hard time even understanding on the Oracle side is this:
rating_scheme_oid NUMBER;
rs_cnt number;
From what I can understand it seems like these are just defining variables, so I figured I could translate that to this:
CREATE TYPE rating_scheme_oid NUMERIC;
CREATE TYPE rs_cnt NUMERIC;
However this doesn't seem to work:
ERROR: syntax error at or near "NUMERIC"
If anyone with expertise in this area could describe what these are doing and a possible solution, that'd be great.
Here's the full context (this is the working Oracle statement):
DECLARE
CURSOR update_cursor
IS
SELECT oid, subscription_id, configuration_oid
FROM scope
WHERE subscription_id != 1 and subclass_type = 'W' and configuration_oid is not null;
TYPE type
IS
TABLE OF update_cursor%ROWTYPE;
update_array type;
rating_scheme_oid NUMBER;
rs_cnt number;
BEGIN
OPEN update_cursor;
LOOP
FETCH update_cursor BULK COLLECT INTO update_array LIMIT 1000;
FOR i IN 1 .. update_array.COUNT LOOP
BEGIN
select count(*) into rs_cnt from workspace_config where workspace_oid = update_array(i).oid and OBJECTIVE_STATE_SCHEME_OID is null;
IF rs_cnt = 1
THEN
SELECT OID_SEQ.nextval into rating_scheme_oid from DUAL;
INSERT INTO RATING_SCHEME (OID, SUBSCRIPTION_ID, VERSION, NAME, CREATION_DATE, WORKSPACE_OID, UUID)
VALUES (rating_scheme_oid, update_array(i).subscription_id, 1, null, SYSDATE, update_array(i).oid, sys_guid());
UPDATE WORKSPACE_CONFIG set OBJECTIVE_STATE_SCHEME_OID = rating_scheme_oid where oid = update_array(i).configuration_oid;
INSERT INTO RATING (OID, SUBSCRIPTION_ID, WORKSPACE_OID, VERSION, CREATION_DATE, RATING_SCHEME_OID, NAME, ORDINAL_VALUE, UUID)
VALUES (OID_SEQ.nextval, update_array(i).subscription_id, update_array(i).oid, 1, SYSDATE, rating_scheme_oid, 'Defined', 0, sys_guid());
INSERT INTO RATING (OID, SUBSCRIPTION_ID, WORKSPACE_OID, VERSION, CREATION_DATE, RATING_SCHEME_OID, NAME, ORDINAL_VALUE, UUID)
VALUES (OID_SEQ.nextval, update_array(i).subscription_id, update_array(i).oid, 1, SYSDATE, rating_scheme_oid, 'Committed', 1, sys_guid());
INSERT INTO RATING (OID, SUBSCRIPTION_ID, WORKSPACE_OID, VERSION, CREATION_DATE, RATING_SCHEME_OID, NAME, ORDINAL_VALUE, UUID)
VALUES (OID_SEQ.nextval, update_array(i).subscription_id, update_array(i).oid, 1, SYSDATE, rating_scheme_oid, 'In-Progress', 2, sys_guid());
INSERT INTO RATING (OID, SUBSCRIPTION_ID, WORKSPACE_OID, VERSION, CREATION_DATE, RATING_SCHEME_OID, NAME, ORDINAL_VALUE, UUID)
VALUES (OID_SEQ.nextval, update_array(i).subscription_id, update_array(i).oid, 1, SYSDATE, rating_scheme_oid, 'Measuring', 3, sys_guid());
INSERT INTO RATING (OID, SUBSCRIPTION_ID, WORKSPACE_OID, VERSION, CREATION_DATE, RATING_SCHEME_OID, NAME, ORDINAL_VALUE, UUID)
VALUES (OID_SEQ.nextval, update_array(i).subscription_id, update_array(i).oid, 1, SYSDATE, rating_scheme_oid, 'Achieved', 4, sys_guid());
INSERT INTO RATING (OID, SUBSCRIPTION_ID, WORKSPACE_OID, VERSION, CREATION_DATE, RATING_SCHEME_OID, NAME, ORDINAL_VALUE, UUID)
VALUES (OID_SEQ.nextval, update_array(i).subscription_id, update_array(i).oid, 1, SYSDATE, rating_scheme_oid, 'Closed', 5, sys_guid());
END IF;
END;
END LOOP;
COMMIT;
EXIT WHEN update_cursor%NOTFOUND;
END LOOP;
CLOSE update_cursor;
END;