RE: Help about DML inside SELECTs
m1l,
Thanks for your hints! I tried using a PROCEDURE with a OUT parameter, but I can't realize where the value will go...
The original code is just below...
---
CREATE OR REPLACE PROCEDURE addNode
(
p_namv IN VARCHAR2,
p_desv IN VARCHAR2,
p_parv IN VARCHAR2,
p_lnkv IN VARCHAR2,
p_nhsv IN VARCHAR2,
p_ordv IN VARCHAR2,
p_frv IN OUT NUMBER,
p_idv IN OUT NUMBER
) IS
BEGIN
p_idv := 0;
SELECT first INTO p_frv FROM nodes WHERE id = p_parv;
IF SQL%FOUND THEN
SELECT nodes_id_seq.NEXTVAL INTO p_idv FROM DUAL;
IF( p_parv = 0 ) THEN
p_frv := p_idv;
END IF;
IF( p_idv > 0 ) THEN
INSERT INTO nodes VALUES (p_namv, p_desv, p_frv, p_parv, p_idv, p_ordv);
INSERT INTO nodesAttribs VALUES( p_idv, 'NUMHDS', p_nhsv);
INSERT INTO nodesAttribs VALUES( p_idv, 'LINK', p_lnkv);
END IF;
END IF;
RETURN p_idv;
END;
/
---
As you can see, the INSERTs are not allowed. How people use to work around this situation? I have an alternative plan, which is first get some values and then insert them. But I'd rather do it in one piece...
Re: Help about DML inside SELECTs
Hello,
Thanks for your explanation Chris.
And sorry about my English! I'll try to make myself more clear.
The code I've sent was meant to be a FUNCTION, actually! Otherwise, the RETURN will never make sense! You are right, Chris!
And I also read the info in the link... Thanks! But I've already read about that in "ORACLE Library". And that's the reason why I seek your help!!!
The big problem is that I'm using PostgreSQL. In PostgreSQL, you CAN define a function that 1) gets a value from a sequence; 2) inserts a entry in a table using the value obtained in 1); 3) RETURNS that value.
As you can see, all that operations were done inside onde piece of PostgreSQL PL/PGSQL code. My problem is that I could not do that in ORACLE, using PL/SQL.
1) Can I do all that operations in one single stored procedure (or function) in PL/SQL?
2) If this a impossible desire, how do people use to work around this situation?
I would be very grateful if you could help me...
TIA,
Roberto.