Note that there are some explanatory texts on larger screens.

plurals
  1. POOracle: getting references in PLSQL
    primarykey
    data
    text
    <p>I need to get the reference of :new.OBJECT_VALUE but I don't now how.</p> <p>I tried doing this.</p> <p>Declaration of types:</p> <pre><code>CREATE TYPE Virus_ObjType AS OBJECT ( name VARCHAR2(50), description VARCHAR2(700) ); / CREATE TYPE Paper_ObjType AS OBJECT ( id NUMBER, title VARCHAR(100), magazine VARCHAR2(100), vol NUMBER, num NUMBER, year NUMBER(4) ); / CREATE TYPE Virus_NestTabType AS TABLE OF REF Virus_ObjType; / CREATE TYPE Paper_NestTabType AS TABLE OF REF Paper_ObjType; / ALTER TYPE Virus_ObjType ADD ATTRIBUTE papers Paper_NestTabType CASCADE; / ALTER TYPE Paper_ObjType ADD ATTRIBUTE virus Virus_NestTabType CASCADE; / </code></pre> <p>Declatation of tables:</p> <pre><code>CREATE TABLE Virus_ObjTable OF Virus_ObjType ( PRIMARY KEY(name)) NESTED TABLE papers STORE AS papersVirus_NestTable; CREATE TABLE Paper_ObjTable OF Paper_ObjType ( PRIMARY KEY (id)) NESTED TABLE virus STORE AS virus_NestTable; CREATE GLOBAL TEMPORARY TABLE virus_aux ( type varchar2(1), virus REF Virus_ObjType, paper REF Paper_ObjType) ON COMMIT DELETE ROWS; / </code></pre> <p>Declaration of trigger:</p> <pre><code>create or replace trigger Virus_Trigger_Before BEFORE INSERT ON Virus_ObjTable FOR EACH ROW DECLARE paper REF Paper_ObjType; virus REF Virus_ObjType; BEGIN IF inserting THEN IF :new.papers IS NOT NULL THEN FOR i IN 1..:new.papers.COUNT LOOP -- getting the pointer of the papers SELECT refe INTO paper FROM (SELECT REF(a) as refe FROM Paper_ObjTable a) WHERE refe=:new.papers(i); SELECT REF(:NEW.OBJECT_ID) INTO virus FROM dual; INSERT INTO virus_aux VALUES ('i', virus, paper); END LOOP; END IF; END IF; END; </code></pre> <p>If someone wants to try with data:</p> <pre><code>INSERT INTO paper_objtable (id, title, magazine, vol, num, year) VALUES (1, 'Que mala es la Gripe', 'Fuzzy Sets', 1, 1, 1993); INSERT INTO paper_objtable (id, title, magazine, vol, num, year) VALUES (3, 'La Gripe ataca de nuevo', 'Information Sciences', 1, 1, 1996); INSERT INTO virus_objtable (SELECT 'Gripe', 'Virus de la Gripe', CAST(COLLECT(REF(a)) AS Paper_NestTabType) FROM paper_objtable a); </code></pre> <p>but I get the next error:</p> <pre><code>ORA-01747: invalid user.table.column, table.column, or columns specification </code></pre> <p>Can anyone help me?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload