CodeIgniter Forums
(Oracle) Get the value of Declare variable from DB Query - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: (Oracle) Get the value of Declare variable from DB Query (/showthread.php?tid=66158)



(Oracle) Get the value of Declare variable from DB Query - Joel Catantan - 09-14-2016

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!


RE: (Oracle) Get the value of Declare variable from DB Query - Narf - 09-14-2016

That's 2 queries.


RE: (Oracle) Get the value of Declare variable from DB Query - Joel Catantan - 09-14-2016

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

What do you mean 2 queries? Huh


RE: (Oracle) Get the value of Declare variable from DB Query - Narf - 09-14-2016

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.


RE: (Oracle) Get the value of Declare variable from DB Query - Joel Catantan - 09-14-2016

(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.