Value of an intem in a PL/SQL in a list of shared values function

Hello


I created a dynamic pl/sql function returns a SQL query in the shared components... But when I run it to debug as an element that displays the result of the function, I get the name of the application element AGENT_ID rather than the element AGENT_ID value:


Lists of values of query:


IF v('AGENT_ID') IS NULL THEN
  RETURN 
  'SELECT LIBELLE d, EQUIPE_ID r '||
  'FROM EQUIPE '||
  'ORDER BY 1';
ELSE
  RETURN 
'select LIBELLE as d, EQUIPE_ID as r
 from  EQUIPE
 where EQUIPE_ID like ''%:'' || ''v(AGENT_ID)'' || '':%''';
END IF;

What is the problem with my syntax here? How can I get the value of the element AGENT_ID?

Thank you.

Hello

I found the correct syntax (I don't like the syntax with a lot of <'''>):

IF v('AGENT_ID') IS NULL THEN
  RETURN
  'SELECT LIBELLE d, EQUIPE_ID r '||
  'FROM  EQUIPE '||
  'ORDER  BY 1' ;
ELSE
  RETURN
'
SELECT  LIBELLE as d, EQUIPE_ID as r
FROM  EQUIPE
WHERE '':'' || :EQUIPE_ID || '':'' like ''%:'' || EQUIPE_ID || '':%''
';
END IF ;

Kind regards.

Tags: Database

Similar Questions

  • Passing the value of the SQL query select list

    Hello

    In my application users have in their homepage to a region which has two simple things, a part of LIST SLECT lov function and a BUTTON

    There is also another page which has a normal life to report which shows the employees.


    Homepage the user can select certain number of Department in its 'SLECT-LIST' and click 'open '.


    For example: If the user has selected a DEP_NUM_5 and click on the BUTTON it will be redirected to the page of a report and gets only showed the employees belonging to the Department 5.


    The report page contains a simple SQL query, and I understand that somehow I must pass the value in the SELECT LIST, where I now have the '?


    How can I do this, where should I start?

    Of course I would really appreciate an example of code, if anyone has time to do a.

    
    select "EMP_ID", 
    "EMP_FORNAME",
    "EMP_SURNAME",
    "DEP_NUMBER"
    from EMP E
    where E.DEP_NUMBER = ????????
    
    

    Hi Sozua,

    1. create an item hidden on the page where you have the report.

    I say P2_DEPT_NO

    2 assign to that in your sql query

    select "EMP_ID",
        "EMP_FORNAME",
        "EMP_SURNAME",
        "DEP_NUMBER"
        from EMP E
        where E.DEP_NUMBER = :P2_DEPT_NO
    

    below the area source ther is also an option

    Elements of page to submit-> put this element in this.

    for example;

    Page to submit items: P2_DEPT_NO

    3. change your button

    Action: Redirecting to page of this application

    Page: 2 / / assuming that page 2 is the report page

    Place these items: P2_DEPT_NO

    with these values: & P1_SELECT_LIST.  assuming that selection list is on page 1

    Hope this helps you,

    Kind regards

    Jitendra

  • Help with the name of the comparison of the output of an sql subquery value function

    Oracle 10 g

    The problem is I want to compare the value obtained from the subquery with the next value in the values of the column from the main query

    Add a view called bioChemCompare to show the content average A-level biology and in the average grade of A-level chemistry for students of each school that has an average GCSE score between 6.5 and 7.0 (inclusive). The
    calculations should be carried out only on students who studied BOTH the biology and chemistry of A'level.

    I have a query like
    select   g.grade from comqdhb.gradevalues@glink g
    where  g.value > ( select avg(g.value)
    from    comqdhb.gradevalues@glink g
    ,         comqdhb.subject@glink sb
    ,         comqdhb.studentingroup@glink sg
    ,         comqdhb.teachinggroup@glink tg
    ,         comqdhb.student@glink s
    ,         average_gcse gc
    where g.grade=sg.grade 
    and     gc.avg_gcse between 6.5 and 7
    and     gc.upn=s.upn
    and     g."LEVEL"='a' and sb.sid=tg.sid
    and     sg.gid=tg.gid and sg.upn=s.upn
    and     (sb.subject ='Biology' or sb.subject='Chemistry'));
    The subquery
    select avg(g.value)
    from    comqdhb.gradevalues@glink g
    ,         comqdhb.subject@glink sb
    ,         comqdhb.studentingroup@glink sg
    ,         comqdhb.teachinggroup@glink tg
    ,         comqdhb.student@glink s
    ,         average_gcse gc
    where g.grade=sg.grade 
    and     gc.avg_gcse between 6.5 and 7
    and     gc.upn=s.upn
    and     g."LEVEL"='a' and sb.sid=tg.sid
    and     sg.gid=tg.gid and sg.upn=s.upn
    and     (sb.subject ='Biology' or sb.subject='Chemistry')
    Returns
    78.88
    In the main query
    select   g.grade from comqdhb.gradevalues@glink g
    where  g.value > 78.8
    g.Value has values such as
    120
    100
    80
    60
    40
    20
    78.8 is close to 80, only 80 must be taken and the corresponding grade will be displayed.

    What is the function to do so.

    I just put > and it displays
    120 A
    100 B
    80 C

    But the ABC should not be visible only C must be taken

    y at - it no fuction as neighbors, cant use between

    Please help, thank you.

    Rider wrote:
    y at - it no fuction as neighbors, cant use between

    The MIN function maybe aggregation?

    select   min(g.grade) from comqdhb.gradevalues@glink g ...
    

    Kind regards
    Rob.

  • Query SQL using Group by and the aggregate function

    Hi all

    I need your help in writing a SQL query to achieve the following objectives.

    Scenario:

    I have a table with 3 columns. There are 3 possible values for col3 - success, failure, and error.
    Now I need a query that can give me the summary figures for distinct values for col3 for each GROUP BY col1 and col2 values. When there is no values for col3, then it should return ZERO count.

    The example data:

    Col1 Col2 Col3

    success of ABC 01
    success of ABC 02
    success of ABC 01
    ABC 01 failure
    ABC 01 error
    ABC 02 failure
    ABC 03 error
    XYZ 07 failure

    Power required:

    C1 c2 s_cnt F_cnt E_cnt (title)
    ABC 01 2 1 1
    ABC 02 1 1 0
    03 0 0 1 ABC
    XYZ 07 0 1 0

    s_cnt = number of success; F_cnt = number of failure; E_cnt = number of errors

    Please note that the exit should have 5 columns col1, col2, group of (col1, col2) count (success), group of (col1, col2) count (failure), group of (col1, col2) count (error)
    and wherever there are n ROWS, then it should return ZERO.

    Thanks in advance.

    Kind regards
    Shiva

    Hi, Shiva,

    Welcome to the forum!

    Here's one way:

    SELECT       col1
    ,       col2
    ,       COUNT ( CASE
                          WHEN  col3 = 'success'
                    THEN  1
                      END
                 )          AS s_cnt
    ,       COUNT ( CASE
                          WHEN  col3 = 'failure'
                    THEN  1
                      END
                 )          AS f_cnt
    ,       COUNT ( CASE
                          WHEN  col3 = 'Error'
                    THEN  1
                      END
                 )          AS e_cnt
    FROM       table_x
    GROUP BY  col1
    ,            col2
    ;
    

    Whenever you have a problem, post a small example data (CREATE TABLE and only relevant columns, INSERT statements). If you do not, then don't expect answers, you can get to test.
    Also post the results desired from these data.

  • SQL statement by using the min aggregate function result extract a line - how?

    Need help, try to do something seemingly simple. I'll give a simple example to illustrate the problem.

    I'll use a simple table of addresses with 4 fields.

    Create the table:
      CREATE TABLE "ADDRESSES" 
       (     "OWNER_NAME" VARCHAR2(20 BYTE), 
         "STREET_NAME" VARCHAR2(20 BYTE), 
         "STREET_NUMBER" NUMBER
       ) ;
    complete with 6 rows
    Insert into ADDRESSES (OWNER_NAME,STREET_NAME,STREET_NUMBER) values ('FRED','MAIN',1);
    Insert into ADDRESSES (OWNER_NAME,STREET_NAME,STREET_NUMBER) values ('JOAN','MAIN',2);
    Insert into ADDRESSES (OWNER_NAME,STREET_NAME,STREET_NUMBER) values ('JEAN','MAIN',3);
    Insert into ADDRESSES (OWNER_NAME,STREET_NAME,STREET_NUMBER) values ('JACK','ELM',1);
    Insert into ADDRESSES (OWNER_NAME,STREET_NAME,STREET_NUMBER) values ('JANE','ELM',2);
    Insert into ADDRESSES (OWNER_NAME,STREET_NAME,STREET_NUMBER) values ('JEFF','ELM',3);
    We now have this:
    Select * from addresses
    OWNER_NAME           STREET_NAME          STREET_NUMBER          
    -------------------- -------------------- ---------------------- 
    FRED                 MAIN                 1                      
    JOAN                 MAIN                 2                      
    JEAN                 MAIN                 3                      
    JACK                 ELM                  1                      
    JANE                 ELM                  2                      
    JEFF                 ELM                  3                      
    
    6 rows selected
    Now, I want to group by street name and obtain a number of houses. At the same time, I would like to know the number of the first and the last House
        select
        street_name,
        count(*) "NBR HOUSES",
        min(street_number) "First Number",
        max(street_number) "Last Number"
         from addresses
        group by street_name
    
    produces
    
    STREET_NAME          NBR HOUSES             First Number           Last Number            
    -------------------- ---------------------- ---------------------- ---------------------- 
    ELM                  3                      1                      3                      
    MAIN                 3                      1                      3                      
    
    2 rows selected
    Excellent. Now for the problem. I would also like to list on each line, the owner who lives at number House first and/or the last. It should be noted, assume that the name of the street and the number is unique

    It seems I have everything that I need. Don't know how to get home.

    I tried:
    select
        street_name,
        count(*) "NBR HOUSES",
        min(street_number) "First Number",
        max(street_number) "Last Number",
        (Select b.owner_name from addresses b where b.street_number = min(street_number) and b.owner_name = owner_name) "First Owner"
         from addresses
        group by street_name
    But getting a syntax error sql group function unauthorized when I add the subselect statement.

    any ideas?

    Thanks for any help.

    Published by: user6876601 on November 19, 2009 19:08

    Published by: user6876601 on November 19, 2009 19:30

    Hello

    Welcome to the forum!

    Get the minimum and maximum number for each street is a pretty simple concept; simpler to describe and simple to code.
    Now you want to the owner_name associate the maximum and minimum, which is a concept more complex; a little more difficult to describe and, unfortunately, much less simple to code and much, much more difficult to explain:

    select
        street_name,
        count (*)                "NBR HOUSES",
        min (street_number)      "First Number",
        min (owner_name) KEEP (DENSE_RANK FIRST ORDER BY street_number)
                        "First Owner",
        max (street_number)      "Last Number",
        min (owner_name) KEEP (DENSE_RANK LAST ORDER BY street_number)
                        "Last Owner"
         from addresses
        group by street_name
    ;
    

    You will notice that I used min for "Original owner" and "last owner". Why is this?
    The key word in these functions is the FIRST or the LAST word that comes after DENSE_RANK and before ORDER BY. The function at the beginning is simply a break.

    In other words, MIN in this context refers only to what needs to happen when there is a link to the first or last in the group. Even if such a thing is impossibe in your data, generic functions must have a mechanism to return a single owner_name when two or more rows have an equal right to having the highest street_number. For example, if we change the address of Joan in 1 hand, then MIN (street_number) is always 1, of course, but who is the person associated with the minimum street_number: Fred or Joan? Both have an equal claim that he owns with the smallest address on Main Street, but aggregate functions must return a single value, so we must have a mechanism to indicate to the system, whether to return 'JOAN' or 'FRED '. In this example, I arbitrarily in the network said een of tie, the lowest name, in alphabetical order, must be returned. In this case, 'FRED' would return, "FRED" prior to "JOAN".

    Thank you for including CREATE TABLE and INSERT!

  • PL/SQL anonymous block - try to call the function within cursor

    Hello-

    I need to create an anonymous block that contains a cursor and function. I want to call the function from the cursor and function will essentially have an ID as parameter and will return a list of values comma separated.

    However, when I try to do it I get the error 'function 'GET_PAYMENT_DATES' is not usable in SQL.

    Does anyone know of a workaround? I'm trying to avoid having to store this function.

    Thank you
    Christine

    Well you can't do this using an sql not stored function.
    What you could do is to increase your sort_area_size which can help you to overcome the performance Bug.

    for example: alter session set sort_area_size = 64000;

    other than that, it seems that you need a stored function

  • A SQL server management studio 2012 error: PERCENTILE_DISC function is not allowed in the current compatibility mode. It can only in mode 110 or higher.

    Our company just upgraded to SQL Server Management Studio 2012 and it has been very useful because I needed to use the percentile for the code I wrote. As a first step, the function did not work because I set the compatibility mode 110 level. After that I did, the function worked. However, now it does not work yet, and I get the same error:

    The PERCENTILE_DISC function is not allowed in the current compatibility mode. It can only in mode 110 or higher.

    I went to the properties of database section, then options and noticed that the compatibility mode has not changed, it is set to "SQL Server 2012 (110). I even used the following code to see if that would help at all even if the compatibility mode is already on this mode:

    ALTER DATABASE Analytics
    SET COMPATIBILITY_LEVEL = 110 
    

    Someone already had this problem or knows if I need to change something in the properties of database for this function work? Is this just a bug in the new version?

    Hello

    I suggest you post this question in the SQL Server 2012 TechNet Forums: http://social.technet.microsoft.com/Forums/en-us/category/sqlserver

    Thank you.

  • SQL takes time to perform in a function

    Database Oracle 10.2.0.4.0 - 64-bit running on Solaris

    I have a few functions Oracle I wrote that running a bunch of SELECT statements.  Function arguments are the parameters that go into the place where the clause of the SELECT statement.

    When I run these exact same SELECT statements in functions outside the functions that they run fast (the return is in milliseconds).

    But when I run the SELECT statements functions they run really slow. Like 10-15 seconds.  Almost as if they do a FTS.

    Any thoughts as to why and how I could debug this function to see why its happening in the service?

    Could there be an Oracle parameter setting that is the cause to be slow?

    Here is an example of one of the functions.

    CREATE OR REPLACE FUNCTION NEWEIS.pty_check_for_lic_appl_status

    (a_pty_uid IN license_applications.pty_uid_primary%TYPE,

    a_license_type IN license_applications.license_type_code%TYPE)

    RETURN VARCHAR2 is v_return VARCHAR2 (25);

    v_count NUMBER;

    BEGIN

    / * Get the number of license type codes.*.

    SELECT COUNT (*) FROM v_count

    OF license_applications

    WHERE license_applications. PTY_UID_PRIMARY = a_pty_uid and

    license_applications.license_type_code = a_license_type and

    license_app_status_code IN (SELECT license_app_status_code

    OF license_app_status_codes

    WHERE complete_flag = ' only);

    / * If there is more than one code type, then return an asterisk.

    IF v_count > 1 THEN

    v_return: = ' *';

    ELSIF v_count <>1 THEN / * if no codes, then return empty cuisine.* String.

    v_return: = ";

    ELSE / * Else return the real code.*.

    La.license_app_status_code SELECT INTO v_return

    OF the license_applications

    The WHERE the. PTY_UID_PRIMARY = a_pty_uid AND

    La.license_type_code = a_license_type and

    La.license_app_status_code IN

    (SELECT license_app_status_code

    OF license_app_status_codes

    WHERE complete_flag = ' n ");"

    END IF;

    RETURN v_return;

    END pty_check_for_lic_appl_status;

    /

    When you test the SQL code outside the function, has replaced the parameters with literals? The sql plan may be different when you use bind variables (which is the case in the service). You need to get the plan used by the function.

  • PL/SQL: Cursor with list filling can do IF EXISTS on Table

    Here's my problem. The DB I work with is a database of events (network events). I have a task to take a list of nodes of 2600 and see whether these nodes exist in a set of events that would be with a certain WHERE clause. On my first pass, I did WHERE AND NŒUD clause in (list of 2600 nodes). Well you can put only 1,000 items in a list so I've divided into 3 reports and served while a UNION all between them. This used 15% of the resources of the db and ran for hours and the Group dba like me to find a better way. They would prefer that I use PL/SQL.

    I am new to pl/sql (but not programming or SQL). So the first thing I've done is just figure out how to get my list in a Varray, which I then went to a table because I couldn't find examples, after hours and hours of searching the Web,.
    referencing a Varray with SQL syntax.

    START CODE sample 1 *.
    DECLARE
    DECLARE
    TYPE NodeList IS TABLE OF VARCHAR2 (255);
    Node NodeList: = NodeList ('node1', node2', [.. .list of 2597 nodes..], 'node2600')

    BEGIN
    dbms_output. Enable (1000000);
    FOR i IN Nodes.FIRST... Nodes.LAST
    LOOP
    DBMS_OUTPUT. Put_line (' relevant points: ' |) Nodes (i));
    END LOOP;
    END
    END CODE Sample 1 *.

    The pseudo-code I'm envisioning goes something like this:

    IF one of these nodes (nodes of 2600 list),
    There are in the nodes for this WHERE clause (which is taken from the event db table).
    then print the records (of the events in the event db table) that contains the nodes (ie the list nodes).

    I think I found an example with 2 sliders, but I can't find this example once again. And anyway, I can't figure out how to get my list in a cursor. I have many examples of how to complete a cursor on a select statement against a database.

    I tried this but it did not work:
    START the CODE sample 2 *.
    DECLARE
    DECLARE
    TYPE NodeList IS TABLE OF VARCHAR2 (255);
    Node NodeList: = NodeList ('node1', node2', [.. .list of 2597 nodes..], 'node2600')

    CURSOR MOM_OVO_NODES IS
    SELECT the node
    OF NodeList
    ORDER BY node;

    BEGIN
    dbms_output. Enable (1000000);

    FOR nodelist_rec IN MOM_OVO_NODES
    LOOP
    dbms_output.put_line (' relevant nodes: ' | nodelist_rec.) Node);
    END LOOP;

    END
    END CODE sample 2 *.

    Is there a way to get this list in a slider? Or I think about this correctly?

    Brad

    Brad Bueche wrote:
    Here's my problem. The DB I work with is a database of events (network events). I have a task to take a list of nodes of 2600 and see whether these nodes exist in a set of events that would be with a certain WHERE clause. On my first pass, I did WHERE AND NŒUD clause in (list of 2600 nodes). Well you can put only 1,000 items in a list so I've divided into 3 reports and served while a UNION all between them. This used 15% of the resources of the db and ran for hours and the Group dba like me to find a better way. They would prefer that I use PL/SQL.

    PL/SQL is probably going to be a slower solution, then SQL. It's almost always.

    Your best bet would be to maintain a table of nodes. You can then use a single SQL query with an IN WHERE clause as:

    WHERE node in (SELECT node FROM node_table)
    

    Or you can use a join (the method preferred honestly, gives Oracle more optimization options).

    If you don't want to maintain a table of node, you can always create a global temporary Table or the external Table that could be loaded prior to running your report.

    If you have tried these methods, and it is still too low or high intensity of resources, then we should look at the SQL and chorus only. See the PL/SQL FAQ's for more information on setting the SQL statements.

  • SQL tuning advisor recommnds to create the function SYS_OP_C2C function index

    I have a large table and an index on it. I use a tool to fill data, this simple tool submits the sql for Oracle DB and it does NOT index to use for requests. When I run the sql tuning advisor, he recommends to create additional indexes and use the SYS_OP_C2C function, which I don't want.

    When I run the query through sql plus picks it up in the index.
    Someone of you came, why its recommend that additional nonsense?

    create index abc.xxxx on this_table (SYS_OP_C2C ("this_column"));

    Thank you

    The internal Oracle SYS_OP_C2C function perform the conversion of a set of characters to another set of characters - C (haracterSet) 2 c (haracterSet). There are situations where you will see this conversion without explicit, as in this case command that should be a sign that the data types are not the same and the implicit conversion takes place and this could also be a problem from the point of view performance because it can disable the use of the index.

    Make sure you the characterset and nls set of all of the database and the tool are the same.
    Make sure that the data type of the column in the index is the same as the database.
    Confirm the ETL vendor for your database support and fixes, etc..

    Optimizer will only advise to use this function when the data type or the character set does not match.

    Thank you
    Kerry

  • Call PL/SQL and Oracle ADF Application reports Open functions

    Hi all

    My company will convert some projects of Oracle forms to Oracle ADF, so we must call the PL/SQL functions and open the Oracle reports (which are already exist) the ADF application.

    Thank you..

    Jack.N

    Hi Jack.N,

    call the functions PL / SQL---> http://sameh-nassar.blogspot.com/2010/01/create-plsql-function-and-call-it-from.html

    Open Oracle reports---> http://radio-weblogs.com/0137094/2008/06/15.html

    There is integration between the ADF and other systems in---> http://wiki.oracle.com/page/ADF+Integration

    Sameh Nassar

  • PL/SQL, used in application of the APEX of unit tests

    question by my client:

    I develop an Oracle Application Express application and work on unit tests for stored procedures in PL/SQL and the packages that are stored in the underlying database and used by the application of the APEX. These unit tests must run in the context of SQL Developer Unit Test.
    The problem is that the PL/SQL code stored in the database using functions such as NV('APPLICATION_ITEM') to access items in the application of the apex. They do return all values when I try to execute the PL/SQL within the unit test framework, that is to say in the backend. While it is good that the NV is not error, NULL haven't really work well in my scenario either (for example when the result of this function is inserted into a column NOT NULL in a table). I can think of a few workarounds, such as the creation of my own function NV within the schema to test return values desirable, but nothing seems a really satisfactory solution. I wonder if there is no recommendation to Oracle for this scenario - how can I run code that uses the APEX via backend-specific features. I found nothing in the documentation of the APEX for this but I would like to know if there is a recommendation how to better deal with this case.

    I use SQL Developer version 4.0.0.13.80

    Hello

    Indeed, you must set your PL/SQL function calls. This would be the cleanest solution.

    There is an alternative. Please see the following article on the creation of an APEX in PL/SQL session: Martin Giffy D'Souza on Oracle APEX: how to create a Session of the APEX in PL/SQL

    This approach allows to set the values of APEX application item before you run your unit tests. I don't know if it's possible in SQL Developer Unit Test, but it might get you further down the road.

    Good luck

    Nick

  • CERTAIN behaviors, NULL values

    I am a little confused about the following situation:

    I have a PL/SQL code with a block similar to this:

    BEGIN
    SELECT MAX (col1)
    IN myVar
    FROM MyTable
    WHERE col1 < (SELECT MAX (col1) FROM MaTable;

    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    myVar: < something > =;
    WHEN OTHERS RAISE.
    END;

    The behavior I expect from this is to assign a value to myVar, which is the next most great. value to the record value of col1.  If there is no record in myTable the NO_DATA_FOUND exception is thrown and myVar is filled with predetermined values.  Everything works fine execpt...

    When there is only one record stored in myTable, there is no exception raised and myVar is assigned to NULL.  I think that since there is only one line in the table there is no trace of return that meets the SELECTION criteria and therefore the NO_DATA_FOUND exception which is not the case here would be raised but myVar is assigned NULL and the program continues to flow from there.

    What is the problem with my way of thinking that the exception must be raised when there is a single record in myTable?

    Thank you.

    Documentation:

    A SELECT INTO statement returns no rows, or your program refers to an element deleted in a nested table or a component not initialized in an index - by table. Aggregate SQL such as AVG and SUM always functions return a value or a null value. As a result, a SELECT INTO statement that calls an aggregate function ever triggers NO_DATA_FOUND.

    That would be your MAX.

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

  • SQL only: WHERE Condition pulled the correct runtime of the Central "SQL" tab

    I have a requirement that seems like it should be easy to solve in SQL, but me seems to be stuck with blinders and can't see the solution.

    The 'problem' that I'm trying to solve is to get several reporting units to any use of the SQL even in their where clause for certain types of metrics reports. So this is the solution I am proposing that we store the sql in a central table, which, in a simplified form, would have two columns as:

    GroupName Varchar2 (2000)
    SQL_Filter Varchar2 (5000)


    What I want to do conceptual, it's allow the user (even if they're using MS - SQL) to


    WHERE FunctionName (GetSQL_ForGroupName)

    But first of all, I would tell them that this can be done in Oracle sql. However, I can't understand how to achieve this end. From what I've read so far that oracle will not do:

    WHERE (subquery that returns SQL)

    or (in SQL)

    WHERE VariableSubstition

    or

    WHERE FunctionName (GetSQL_ForGroupName)

    It seems that these things in the WHERE clause allows Oracle after only

    FieldName [operator]

    as in

    WHERE price > (subquery)

    or

    WHERE ID IN (Value) Function

    Is it possible to do a subquery (or anything else) that allows me to draw the where clause running SQL - using only SQL? I can do this with a stored procedure, but it is to say it seems to me I had start coding select specific instructions for them or code so that they could enter select statements (or joins etc.). I don't want to write a complete dynamic reporting engine. I want to do is be able to pull the sql running. This ensures that everyone is 1) with the good sql for metrics 2) by using the same sql and 3) the core sql parameters can be stored in one place instead of 3000 definitions of the various reports.

    I must be looking at this the wrong way, I think. The solution does NOT seem to do WHERE (pull in the SQL running)... but I was not able to find a different way of thinking. For example, WITH does not resolve as you immediately the requirement WHERE fieldname [operator] [subquery | function]. I was browsing the internet and looking through all the books SQL on Safari of O'reilly but I have not met a solution. However, I think, this issue of 'centralization of base SQL' must have been resolved several, several times previously. Why can't I find anything on it then?

    Brad

    You might use a pipeline function to return a TABLE object. This function accepts a parameter that contains the name of the Group (although "GetSQL_ForGroupName" is supposed to represent). The query that they deliver will then look something like this:

    SELECT column_list
    FROM   TABLE(table_function('GroupName'))
    WHERE  additional_conditions
    

    In the function, you can create the SELECT statement that channels the rows in the table with WHERE conditions pulled a table for the provided group name.

Maybe you are looking for