Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are the RAW type variables immutable in PL/SQL code?

Tags:

oracle

plsql

Are the RAW type variables immutable in PL/SQL code? I mean can I alter specific byte of RAW type variable just in place without memory copying?

Of course we have UTL_RAW package with some routines appropriate for spec byte altering but it looks like all of them copy variable instance memory:

UTL_RAW.BIT_AND UTL_RAW.BIT_OR UTL_RAW.OVERLAY

Also this question is closely linked to effective string concatenation problem. For example in Java strings are immutable too and we have the StringBuilder for this task. I've not found clear info in Oracle docs on this. After some googling[1] the answer looks like: Yes. The RAW type variables are immutable in PL/SQL code as well as strings are. Is it really true? It would be better to have more explanation and history of this question.

References:

  1. https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:10445025326812#followup-76860752200038
like image 961
Ilia Maskov Avatar asked Oct 06 '15 09:10

Ilia Maskov


Video Answer


1 Answers

There's no such thing in PL/SQL as altering a specific subpart of the memory allocated to a variable. If it is a function (as is the case with the said utl_raw routines), it always returns a new instance of a value. If it is a procedure with an in out nocopy parameter, it might work on the reference to the argument, not on its copy, but still, the actual work inside the procedure involves copying values, not working in the same memory. (Well, OK, this does not apply to LOBs, but that's not what you've asked about.)

PL/SQL is a procedural language on top of SQL. It is designed to allow the SQL to be used procedurally, it is not designed to be superfast, supereffective. If you need to go as far as altering bytes directly in memory, you may want to use C or assembler.

like image 152
peter.hrasko.sk Avatar answered Sep 18 '22 11:09

peter.hrasko.sk