Welcome Guest, Not a member yet? Register   Sign In
(Oracle) Get the value of Declare variable from DB Query
#1

Hi guys! Just wanna ask if it is possible to get the value of declare variable from query. Let's say:

Code:
DECLARE RID RowId;
BEGIN
 INSERT INTO SOMETABLE (SOMEFIELD) VALUES ('SOMEVALUE')
 RETURNING RowId INTO RID;
END;


As you can see, I just wanted to get the RowId of the new record. Im just doing it using query binding but it returns me an empty array.


PHP Code:
$query ='
DECLARE RID RowId;
BEGIN
  INSERT INTO SOMETABLE (SOMEFIELD) VALUES (?)
  RETURNING RowId INTO RID;
END;'
;

$new_row_id $this->db->query($query'SOMEDATA')->row('RID'); 
Am I doing it correct or Am I just missed some part of the query? I'm just new in this approach. Any suggestion will be appreciated. Thanks!
[Just a programmer] Cool [/Just a programmer]
Reply
#2

That's 2 queries.
Reply
#3

(09-14-2016, 02:28 AM)Narf Wrote: That's 2 queries.

What do you mean 2 queries? Huh
[Just a programmer] Cool [/Just a programmer]
Reply
#4

I mean that you're trying to execute 2 queries as if they are one ... I don't think there's any other way you could interpret what I wrote.

The DECLARE statement is one query, and then the BEGIN statement starts the second one.
Reply
#5

(09-14-2016, 03:00 PM)Narf Wrote: I mean that you're trying to execute 2 queries as if they are one ... I don't think there's any other way you could interpret what I wrote.

The DECLARE statement is one query, and then the BEGIN statement starts the second one.

Thanks for the hint @Narf. Is this not possible to achieve? I mean the two queries in query binding and return some data that have declared within the queries? As what I've said, I am new with this approach so I don't get what you have said at first. Im actually against with Stored Procedure but I think I don't have any choice.
[Just a programmer] Cool [/Just a programmer]
Reply




Theme © iAndrew 2016 - Forum software by © MyBB