Why my static PL/SQL within SQL local variable is not transformed in space in the shared pool?

Hello everyone,

Oracle version: 12.1.0.1.0 - 64 bit

OS: Linux Fedora Core 17 X86_64

Description of the problem:

I'm reading an interesting book of online oracle named: SQL in PL/SQL

On page 11, it reads the following:

In the absence of a compilation error, the PL/SQL compiler generates an equivalent statement of SQL regular text and stores this with the generated machine code. This instruction uses placeholders where the embedded SQL statement uses identifiers that have been resolved in the PL/SQL unit.

What I understand of this (please, correct me if I'm wrong) is that whenever I write some static/embedded statement SQL within a PL/SQL block in which there are a few local variables in PL/SQL, and then final generated SQL statement (after resolution of identifier) will include placeholders (bind variables) instead of these identifiers the PL/SQL.

I just wanted to see this in practice, so I made the following test:

Test case:

SQL> connect / as sysdba
SQL> alter system flush shared_pool

system altered

So, normally, after execution of the foregoing the shared_pool on my development environment is now empty.

And then I run the following PL/SQL block

<<b>>
declare
    depid hr.employees.department_id%type := 100;
    cnt   pls_integer := 0;
begin
    select
        count(*)
    into
        b.cnt
    from
        hr.employees t1
    where
        t1.department_id = b.depid;
end;
/
--
--
column sql_id new_value sqlid_saved;
--
select
    v1.sql_id
from
    v$sql v1
where
    v1.sql_text like '%t1.department_id = b.depid%';
--     
-- 
select
    v1.sql_text
from
    v$sql v1
where
    v1.sql_id = '&sqlid_saved';

And the result was:

SQL_ID
-------------
687dxvsmrwm9z
g17tjb3f8t94y

6 old: v1.sql_id = "& sqlid_saved"
6 new: v1.sql_id = "g17tjb3f8t94y".

SQL_TEXT
--------------------------------------------------------------------------------
< < b > > declare depid hr.employees.department_id%type: = 100;     CNT pls_in
SEB: = 0; Start select count (*) in b.cnt of
T1 hr. Employees where t1.department_id = b.depid; end;


SQL >

What I don't understand is the main part of the SQL_TEXT I put in red.

Instead of

T1.department_id = b.depid

I expected to see something like

T1.department_id = : B

In other words, some bind variable, because depid is a local variable inside my PL/SQL block used in integrated/static SQL statement, so it must be converted to a reserved space in the shared pool instead of the original identifier.

You kindly could you tell me what I misunderstood?

Thanks in advance

> But once again no variable binding in the stored/parsed SQL statement. That's what I don't understand.

Submitted by PL/SQL SQL is "normalized", which includes (among other things) convert uppercase. Your query on v$ sql is looking for '% hr.employees% '.

Tags: Database

Similar Questions

  • Local Variable is NOT being updated?

    Hi all

    Please see the attached picture for the problem that I am facing. Basically, I want to open multiple files in a folder and file names allows you to derive the other names of files in a different folder and plot the data in all the files.

    Here's what I do:

    1. use the file dialog box to select files

    2. create a local variable to 'selected files' - see below

    3. derive from new files "new files" using the "selected files" and make a local variable of the "new files".

    4 plot data of "selected files".

    5. Drawing data from the files of 'new '.

    The reason for the local variables is that I will access files original and derived from many places in my VI and I want to avoid the eternal wiring or by opening the file several times dialog box (less clicking - my figure of index hurts )

    Problem: Data from "selected files" get traced. However, given "new files" are NOT given in the 'new' files to run it, but run a previous data. Apparently, the local variable "new files" does not get UPDATES

    with the "new files" of the current run. I have to run my VI twice. Why is this? How can I solve this problem?


  • How is it my local variable is not updated its value compared to what is happening in the while loop?

    Hello

    I am trying to extract data from a time that my statements updated in what concerns the number of loop iteration. I tried to use the two local variables and travel records, but without success.

    I also did the following example: http://www.ni.com/white-paper/7585/en and it works like a charm.

    I've attached the PNG file with declaration of the local variable circled in red. Join a VI in the next respnose.

    Thank you

    No, the two while loops are stacked and not parallel, which means the outer loop cannot go to the next iteration until all code in this document, including the inside so that the loop is finished.

  • local variable is not updated

    Hello

    in the example below, the upper loop is not always update the value of the stop command. Why is this?


  • Are constants of body of the PL/SQL Package in the shared or private area

    Based on that it is not clear to me if body Package PL/SQL constants are stored in the shared or private area.

    http://docs.Oracle.com/CD/B28359_01/server.111/b28318/memory.htm

    "PL/SQL program units and the Shared Pool

    Oracle database treats PL/SQL program units (anonymous blocks, procedures, functions, packages and triggers in database) much the same way he treats the individual SQL statements. Oracle database allocates a shared area to hold the shape analyzed, compiled a program unit. Oracle database allocates a private space to hold values specific to the session who runs the program unit, including local, global and package variables (also known as the package is instantiated) and stamps of SQL execution. If more than one user is running the same program unit, a place unique and shared is used by all users, while each user runs a separate copy of his own private SQL area containing session-specific values.

    The individual SQL statements contained in a PL/SQL program unit are processed as described in the previous sections. Despite their origins within a PL/SQL program unit, these SQL statements use a shared area to hold their analysed representations and a private space for each session, who executes the statement. »


    I am also curious to know what are the differences in fine grain in a perspective of memory and performance (multisession) for the two examples below. One is more effective?


    Example 1.

    create or replace
    package body
    application_util
    as

    c_create_metadata constant varchar2 (6000): =...

    procedure process_xxx
    (
    )
    as
    Start
    ...
    end process_xxx;

    end application_util;

    vs.

    Example 2.

    create or replace
    package body
    application_util
    as

    procedure process_xxx
    (
    )
    as

    c_create_metadata constant varchar2 (6000): =...

    Start
    ...
    end process_xxx;

    end application_util;

    881398 wrote:

    But I still have to ask because it seems still more particularly in example 1 that the constant can be attributed to the use that the actual value could be a pointer to a constant string value in a table of symbols or something related to the compilation unit. I'm always curious in a perspective of management of memory if there is a difference between the example 1 and example 2, and if one is better and why.

    The storage is real, references to this storage internal to the PL/SQL engine. And irrelevant to the PL/SQL programmer.

    This question is really a disagreement over the shape is better: example 1 or example 2. I prefer the 1 example, for readability, testability, etc., and so the question is where is the performance of the memory/differences and or is it just preference of developer.

    I agree with rp0428 - he raised a very important point that it is a problem of scope and nothing else.

    Basically is there any trade-off between using one shape on the other insofar as the performance and memory management?

    Not really. Most runtime engines release not just actual system memory when a variable is out of range. the malloc() calls are expensive. Free() calls are expensive (and are not always the result in usable free memory which can be malloc'ed again).

    Several execution engines use what is called a managed heap. A malloc is made of a new process when it is initialized. The heap memory / managed malloc'ed is adjacent. Pointer allocation of memory for this process is initially pointing to the base of the managed heap. As the process allocates / uses memory, the pointer is moved just advance in the managed heap, which indicates the HWM as such - the beginning of the 'free' memory in the heap. Allocation is sequential.

    Reset of your variable execution, or releasing your runtime object, does not reset the HWM as other objects/variables can still be used and located after this place in the bunch. In this case set him free memory by releasing / resetting the language variables does not restore the kernel memory.

    Memory management is a sophisticated process entirely processed by the engine running - and best left to the runtime engine. As you as a programmer do not explicitly control the memory management, it is not a good idea to try to write code that artificially attempt to use 'better' for the runtime engine memory management. The next version of the runtime of that aura of new features, optimizations and so on — and your interference in your code to get the "valorisation" of memory can happen just bite you not bad after an upgrade to execution.

    Regarding the performance aspect - variable initialization is dependent on scope. In order to have a global scope means a one-time initialization, whereas a private scope (created each call) is a multiple unit. If the first is a little faster than the latter.

    However, the performance differences are tiny - IMO too small to justify this as a valid consideration to spend in addition to the decision of functional design on what possibilities a variable or a constant need to have.

    SQL> create or replace package FooLib1 as
      2          procedure Exec;
      3  end;
      4  /
    
    Package created.
    
    SQL>
    SQL> create or replace package body FooLib1 as
      2          const1  constant varchar2(32767) := rpad('-',10000,'-');
      3
      4          procedure Exec is
      5                  var1    varchar2(32767);
      6          begin
      7                  var1 := const1;
      8          end;
      9  end;
     10  /
    
    Package body created.
    
    SQL>
    SQL>
    SQL> create or replace package FooLib2 as
      2          procedure Exec;
      3  end;
      4  /
    
    Package created.
    
    SQL>
    SQL> create or replace package body FooLib2 as
      2          procedure Exec is
      3                  const1  constant varchar2(32767) := rpad('-',10000,'-');
      4                  var1    varchar2(32767);
      5          begin
      6                  var1 := const1;
      7          end;
      8  end;
      9  /
    
    Package body created.
    
    SQL>
    SQL> set timing on
    SQL> exec for i in 1..100000 loop FooLib1.Exec; end loop;
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:00.28
    SQL> exec for i in 1..100000 loop FooLib2.Exec; end loop;
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:00.74
    SQL> 
    

    A second difference 0.0000046 in a single execution for FooLib.Exec between the use of package for the constant scope, against increased private. Which means that the issue of the scope is not a decision of the performance. Not when improving performance overhead is 0,0046 millisecs.

  • Classic report shows wrong "could not parse the SQL query: ORA-00942" error after migrating app to the new environment

    After migrating my APEX 4.1 application to a new environment, one classic report displays a "cannot parse the SQL query: ORA-00942: table or view does not exist" error when the page is displayed. Change the region to report SQL source to somehow (e.g., remove spaces, changing the order of the variables in the WHERE clause) immediately solves the problem, but by returning to the source of the region causes the report error again (the source region valid code without error, however).

    Throw the error message:

    Select v.id,

    v.Col1

    of view_vw v

    where (: P1_FILTER is null or)

    v.col2 = :P1_FILTER)

    Do not throw error:

    Select v.id,

    v.Col1

    of view_vw v

    where (:P1_FILTER is null or)

    v.col2 = :P1_FILTER)

    Changing the order of column in the report has the same effect; i.e. He arranges, but return back to the original column order causes the error to display.

    It's as if a cached result for the correct select statement used by the report is displayed. However, the application does not use the caching of page/region. Any ideas of what could be the cause?

    He solved. Ultimately, all that was necessary was to clear the DB cache using:

    alter system flush shared_pool;

  • How to determine the number of rows in the database and save the result to a local variable?

    Hello

    I'm a newbie in the use of TestStand, databases and SQL, and now I've met difficulties. I use TestStand 2014 (32 bit).

    I have a need to know the number of rows in a database and save that number in a local variable. I tried to practice using the database of the Types of step provided with TS. I tried to use the following in a SQL statement:

    Locals.NumberOfRows = ("SELECT COUNT (*) FROM TEST_TABLE")

    It returns an error: specified value is not the expected type. My goal is possible in this way, or I'm doing this completely wrong?

    -RautSa

    Thank you for your response, Norbert. I have a database of who wins new values at random, and sometimes I need the exact number of rows in this table.

    I managed to achieve my goal by using the SQL statement: "SELECT COUNT (*) as Rowcount OF TEST_TABLE", followed by a data GET operation, which records that number of lines in a local variable.

    -RautSa

  • sons are better than local variables?

    Hello

    I built a vi that eventually became huge with lots of sequence and case. Local variables of course reduces a lot of threads, but at the same time consumes memory. So those who are better? son of current throughout the vi or local variables?

    Concerning

    Simo

    The sons are better.

    DataFlow vs Local Variables

    variables local vs DataFlow

    Another question on local Variables and their use

    Why some people say that local Variables are bad

  • Initialize controls/indicators: invoke node-local variables Vales. Which is faster?

    Hi all

    I would like to get the opinion of the people. This thought just happened for me while I was reading some materials the other day.

    And I have not found any topic which talks specifically about speed after searching the forum.

    It is faster to initialize your controls/indicators using Invoke node OR write directly to the initial value of your local variables?

    From my experience (not large), I have always used the invoke node to initialize controls or indicators.

    But when I but this question, I did a simple reference point and it seems the local variable approach is faster, especially

    If you have the large number of orders/lights to initialize.

    Am I missing something here? The invoke node running something that writing a value of local variable would not do?

    I thought since you need to set the initial state by default for the node to invoke anyway, why not just write the desired initial value

    your local variables?

    I would appreciate if someone can express his own opinion based on their experience and knowledge.

    Thank you ~ ~

    I may need another Cup of coffee this morning, you are in fact callling the reset by default on each individual control.  My last despises, it is that you use the default method Vals.Reinitialize VI all failing.  It will probably be a bit faster than the method on individual controls.  Still not instant, if.

    Are a few msec is worth to you?  If so and you consider the local path, my advice is to group as many controls as possible into clusters for minimize you headaches.

  • How 'local' are local Variables?

    I avoid local variables at any price so don't have much experence with them. Local only 'local' to the subvi in what they are or if you have used the local variable from sale in several subvi in the same program would be that they all share the same varaible?

    I got the task of determining a LabView program that we had subcontracted out. The device, on which he works has three identical modules that are used for the profile and discharge profiles for different types of batteries. In any case, the program has a bug in it where all three on screen V / I charts show the same V / I have curves.

    My original thought CD was the subcontractor got the program works on a module, then reproduced the code to the other two. But did not take a new graphics or was referencing the V / I module of measure 1 in charts 2 and 3. First glance on the code it looked like it should work fine.

    Digging deeper, I see the contractor makes this sup - vi to build the cluster for a waveform graph. In this sub - vi he used a table variable local, called "local".

    When he repeated this for the other two modules, he used the same variable local "local array. Since all three "programs" (one for each module) operate within a larger loop would not all be read and write to the same variable local "local array?

    I have attached the origonal sub - vi (V_WFM.vi) and one of my replacements (V_Wave_1.vi), I've made three copies of my vi and each module will get its own sub - vi.

    I'm not doing correctly?


  • Change local variable boolian Programaticaly

    Hi all

    I came across something today, that I have ever dealt with in Labview...

    I downloaded a driver of instrument for a power supply, and got it working OK (using VISA on the USB communication).

    The example program pilot itself works very well and is a quasi State machine.  It it turns on and off and adjusts the voltage and current correctly, as it should.

    Then I need to edit the .VI to add a time on another timer .VI.  I wrote that the small simple VI and it works properly as it should.

    It's just a boolian power timer.  Lights at 08:00 daily, stops at noon every day.

    The problem I have is the boolian called variable "Output (T:Enable)" which is located in the .VI power supply example is a Panel button, but it is called several times as a local variable.

    (once again, I did not write this part and please no lectures on why you should never use a local variable...)

    When you change the State of the button "Output (T:Enable)" Panel, the power supply turns on and off as it should.

    The problem comes when I try to control this value boolian using my timer VI.  I've tried several things, and using debug, I can't 'Output (T:Enable)"to change state.

    The value will change ONLY if the button is pressed or not.

    ATTENTION: The illustrated local variable condition is also a security in case of short or overload, power off if the name cannot be changed.

    Is there a way I can trigger "Output (T:Enable)" using 'My exit timer' but always make sure that stop you it if there is a short circuit?

    This left me speechless... I tried several different things and just can not understand.  Any help would be appreciated.

    Thank you!

    The guy

    Hello guy!

    You are not sure, I understand the problem in its full extent, but I'm guessing that you want to trigger the event that controls the output (T: Enable)? If you want to programmatically, create a node of the control property and use the property "value (follow the signs). Writing of a local variable will not draw the event, although this will change the value of the façade.

  • Another question on local Variables and their use.

    I have read many many posts on forums how we avoid the use of locals at all costs because they go against the stream of LV paradigm however I tried to find a way to replace them in my programs and do not have.

    Basic explanation:

    I use a state machine to browse specific validation test steps and test of electronic equipment of base. (Panels, timers, relays moduals fuses) Many of these facilities contain LED indicator. In the tests, I took photos of the products and then used the Boolean flags to replicate the LED on the PC so that the test operators can check to make sure the equpiment LED turns on as needed. My problem is that many products contain 20 + LED and have no order to how they are turned on. Because of this that I eventually do a boolean for each LED indicator, put all the indicators in a structure of disabled, then using local Variables at each step to display on the FP LED should now be on. It's often a lot of locals throughout the program.

    I tried to make a very basic sample of VI to try to show what is a normal procedure. How can I reduce the amount of local Variables without increasing the complexity of my VI?

    If the LED change of State within the meaning of the criterion - within the case statement - you need a parallel loop.

    I did a heap of your LED and does an architecture of producer/consumer of your case, 'Test 2' attached.

    Edit: In my table, on the bottom line, the text should read "your 6 LEDS are now a Cluster" rather than "your 6 are LED not a Cluster."

  • How to copy Step.Result.Error.Code in the local Variable

    How can I copy Step.Result.Error.Code to a stage in particulat to a local variable.

    I want to print the value of Step.Result.Error.Code in my test report.

    Help, please. Thanks in advance.

    Kind regards

    Sagar Joshi

    Yes of course!

    This is better handled by the recall of SequenceFilePostStepRuntimeError:

    (1) StepResultCode (number) is added FileGlobals

    (2) add SequenceFilePostStepRuntimeError callback to your movie file

    (3) the next stage of the declaration adds the recall of SequenceFilePostStepRuntimeError :

    FileGlobals.StepErrorCode = Parameters.Step.Result.Error.Code

    Here is an overview of the sequence:

    I hope this helps.

  • Comparative analysis of local Variable Transmission times

    Is it possible to compare the time of transmission of local variables?

    I ran some stuff simple reference before, but never something that would understand how long we had to to get a piece of data in a local variable.

    I have attached a simple program that sends information via a local variable, and there is obviously some lag which is visible, well, I'm running at least visible on the system. I know that this lag depends on the system, the program runs on so I would really like to find a way to test it on the PC we use here.

    Any ideas?

    -Ian

    No, they are not the devil as long as you are aware of their capabilities and their limitations.

    Regarding "some applications cannot always use queues or notifiers accomplish certain requirements", give me an application where you cannot use a queue or the declarant, and I bet you can.

    The problem with your 'reference', is that it's a bad test.  You do a visual aspect to two parallel while loops that have no synchronization between them.  If you used a wait until the next msec in both loops, you would see then better synchronization.  Download the file read out of the loop that could cause a random delay.

    And the biggest concern with local variables is "conditions of competition".  Search the forums to learn more about them.  You cannot control this piece of code is running in what order.  If you have two parallel two loop iterations, if the value is written to the local variable before or after that the local variable is read and written to the other indicator determines if a value new or old is used.  If it's an old value, it will be a new iteration of the loop at the bottom before it is updated.

    Search the forums for the terminals of variables local vs vs property nodes, and you will see that the local variables updated the order of milliseconds.  The only reason you see 'in the Kingdom of less than 250 ms' is because it is the rate of the iteration of the loop at the bottom.

  • By the way the local variable to a default module

    I use LV 8.6 and TS 4.1.

    I made a custom step Type where I specified a default Module to run and I created a substep VI Edit that the user can move the entry to the default maodule.

    If I pass a value it is working properly. So, I want to pass a local variable, so I have a button in the edict Vi, which displays the property browser dialog box I get the name of the selected local variable. How can I pass the local variable to the default input module? (The value of the local variable is installed during the execution of the sequence).

    Thank you.

    Max.

    Hello

    Yes, I see what your problem is.

    If I am proving a means of suppling a variable as a fixed value or a search string then in my step type I organize the property as a container that contains two properties, one to hold the value and one the search string.

    If you don't have what it takes to change your step types, then you must indicate another to contain this search string, IE a local / fileglobal / global station. Or store it in the memory of your labview. None of them are ideal, as it is best to keep the properties of the step in the step.

    Concerning

    Ray Farmer

Maybe you are looking for

  • Pages does not work correctly.

    I am using pages ' 09 and have been happy.  My operating system is OSX 10.9.5.  However, I have worked on several documents and for some reason any, it tries to open all the pages on my desktop, when I open the program.  He just turns and never open

  • Loading stops at 97% battery NB500-108, led light never turns green

    I have a mini laptop, NB500-108, running Windows 7, and he never had a battery up to present problems.For some reason, battery stopped at 99%, 98% and now to 97% of the load.Tray icon says "plugged in, load" but it never reached 100%. In addition, th

  • I can't hear voices in my speakers(3:1) I see the audio button in the taskbar?

    Properties of the system can be seen in image below'http://i50.tinypic.com/35meatc.png '. System taskbarhttp://i50.Tinypic.com/34o7tld.PNG This problem occurs suddenly at one point.I can no longer listen to audio while the video plays, or I start son

  • replace or restore msvcp90.dll

    How to replace or recover msvcp90.dll?

  • Windows security center dissappeared under Vista

    Enter the windows Security Center can't open windows update or Windows defender. The answer I get is: windows update actually cannot look at the updates to the service is not in execution. When I try to go to 'services' to enable the Security Center