Question about using objects in SQL query.

I had posted this question in the SQL/PLSQL forum but I guess nobody took the time to understand exactly what I am asking so I decided to try here hoping to get the answer. So here is the thing:
I have created generic object type "tree" - the constructor takes as a parameter sql query which returns "node_id" and "parent_node_id" - this is all we need to have a tree. The object has all related to a tree structure member functions and one of them is "oldest_relative" (the tree may not be fully connected - it may be more like a set of many trees, so it's not necessary all nodes to have the same root).
I also have departments table with the following fields: department_id, parent_department_id, department_name,...
all records in the table w/out parent_departments (parent_department_id is null) are considered divisions.
Now if I run the following query:
SELECT "DEPARTMENT_ID", "PARENT_DEPARTMENT_ID", "DEPARTMENT_NAME", tree('select department_id "node_id", parent_department_id "parent_node_id" from departments').oldest_relative("DEPARTMENT_ID") "DIVISION_ID" FROM departments
my question is: Is the tree object created for every row or does Oracle somehow caches the object since the object itself is not changing but only the parameter for the oldest_relative member function.
The table only has a few hunderd records and I can't see much of a difference in the execution time btw the query above and query like this:
SELECT "DEPARTMENT_ID", "PARENT_DEPARTMENT_ID", "DEPARTMENT_NAME", b.t.oldest_relative("DEPARTMENT_ID") "DIVISION_ID"
FROM departments left join (select tree('select department_id "node_id", parent_department_id "parent_node_id" from departments') t from dual) b on 1 = 1
where the object is clearly created just ones. (there is probably a better way to do it instead of this join)
Pls elaborate
George

Not exactly sure what the question is...
As I understand, you are comparing the following two constructor calls:
+select..  tree('select department_id "node_id", parent_department_id "parent_node_id" from departments').oldest_relative("DEPARTMENT_ID") ... FROM ...+
+select tree('select department_id "node_id", parent_department_id "parent_node_id" from departments') ... FROM dual+
These calls are the same (besides the 1st one doing an immediate implicit call to a method of the object being constructed). The number of times these are being called depends on the number of times this SQL projection is applied - and that is determined by the number of rows being projected by the SELECT.
The latter one is against DUAL which only has a single row. So that constructor is only called once. The former can be against multiple rows. Obviously a single pass through a data set is desirable - which means that the sub-select (use by the constructor) should ideally only be executed once and makes the 2nd method more desirable.
However, I'm having a hard time understanding why the class and constructor are at all needed. Why pull data from a SQL table into PL memory? As that is where the class will need to cache and store the results of that construction parameter SQL SELECT. And once in PL memory, how does the object effectively access, search and use this cached data?
PL memory is expensive. It is not sharable.
PL data structures are primitive - these cannot be compared to SQL structures in the form of tables and columns that can be stored in a number of physical ways (index tables, hash tables, partitioned tables, clustered tables, etc). Cannot be indexed like SQL structures using B+tree, bitmap, function and other indexing methods. Cannot be sorted, grouped, analysed, filtered, etc like SQL structured data.
It makes very little sense to read SQL data into a class and then deal with that data, cached in expensive PL memory, using primitive PL structures.
And the same would be true if Java or C# was used. The best place for data is inside the SQL engine. That is the most superior environment for data. It can processes more data, scale better, perform better and offer more flexibility, than pulling data from it and then crunch that data using PL or Java or C#.

Similar Messages

  • Another question about using objects in SQL queries

    Hi gurus, I need your thoughts on this:
    I have created generic object type "tree" - the constructor takes as a parameter sql query returning "node_id" and "parent_node_id". As a tree - the object has all related to a tree structure member functions and one of them is "oldest_relative" (the tree may not be fully connected - it may be more like a set of many trees, so it's not necessary all nodes to have the same root).
    I also have departments table with the following fields: department_id, parent_department_id, department_name,...
    all records in the table w/out parent_departments (parent_department_id is null) are considered divisions.
    Now if I run the following query:
    SELECT "DEPARTMENT_ID", "PARENT_DEPARTMENT_ID", "DEPARTMENT", tree('select department_id "node_id", parent_department_id "parent_node_id" from departments').oldest_relative("DEPARTMENT_ID") "DIVISION_ID" FROM departments
    my question is: Is the tree object created for every row or does Oracle somehow caches the object since the object itself is not changing but only the parameter for the oldest_relative member function.
    The table only has a few hunderd records and I can't see much of a difference in the execution time btw the query above and query like this:
    SELECT "DEPARTMENT_ID", "PARENT_DEPARTMENT_ID", "DEPARTMENT", b.t.oldest_relative("DEPARTMENT_ID") "DIVISION_ID"
    FROM departments left join (select tree('select department_id "node_id", parent_department_id "parent_node_id" from departments') t from dual) b on 1 = 1
    where the object is clearly created just ones. (there is probably a better way to do it instead of this join)
    Pls elaborate
    George

    Hi, TREE is not a function but PL/SQL object type I have written representing tree structure. The Oracle version is 10g.

  • Question about Using Objects

    Hi Guys,
    Need some help here with understanding the basics. Basically i'm getting a bit confused on how objects are instantiated and used in java. Firstly an object of a class is instantiated with the following piece of code;
    ClassA obj = new ClassA();This would allow you to use the variable and method of ClassA. Say ClassA has the method set(). You could call it via the obj object with the code;
    obj.set();that I understand. You can also declare an annonymous object which is an object that is only really going to be used once for the purposes of the statement. For example, something like;
    System.out.println(new Date());That I understand too. However what is confusing me is this type of object instantiation;
    public static ClassA obj; You cannot not call the set() method of the ClassA in the same way so why use this? Also this code is confusing me;
    obj = new ClassA();Are you saying that a precreated object is now equal to ClassA. Meaning that you can call its set() method in the same way?
    What do they mean? Why are they used? Can anyone give me an example of how they would be used?
    Any help would be appreciated.

    public static ClassA obj;This is a declaration, basically you are telling the
    computer that you intend to make a "ClassA" object
    and the program will allocate enough memory to hold a
    "ClassA" object, although the object "obj" does not
    actually "exist" at this time. This is why you can't
    use the set() method, because obj doesn't have any
    methods at all since it hasn't fully been created
    yet.
    obj = new ClassA();This is what actually creates the object, according
    to the instructions in the object's "ClassA()"
    method, which is known as a constructor.
    ClassA obj = new ClassA();This statement simply combines the two previous ones
    into one line. You are declaring "obj" to be a
    "ClassA" which allocates memory to store it, and then
    immediately executing the "ClassA()" constructor to
    build a new ClassA and store it in the memory space
    referenced by "obj". Does any of that make sense?
    I'm not exactly a teacher, but I think I understand
    your problem enough to explain it.Yes that does make sense. However i have some more questions now if you dont mind answering.
    If the code
        public static ClassA obj;simply allocates the memory (instantiate) and does not name (declare) the object then why cant you do something like this afterwards;
    obj = new ClassC();or this;
    obj1 = new ClassA();The object doesn't yet exist you only putting memory aside for it. Its only at this point that your naming the object and setting the parameters for it.
    Why bother even allocating memory for the object without actually declaring the object? Surely combing the two statements is more efficient and makes more sense than separating them. Why do you need to allocate the memory and then give it a name?
    Also the following piece of code;
    ClassA objA = obj;Since obj is already intialized as being a new ClassA object, then is this simply declaring and instantiating a new object of type ClassA? And what is the difference between this and;
    ClassA objA = new ClassA();Thank You

  • Question about using TVARV in an ABAP program

    Hello gurus, Im sorry about the silly question.
    I have a question about using TVARV in an ABAP program.
    A program is presenting a problem and I think that in this code:
    SELECT SIGN OPTI LOW HIGH
      FROM TVARV
      INTO TABLE R_1_163431035_VELOCIDADE
      WHERE  NAME = '1_163431035_VELOCIDADE'
      AND    TYPE = 'S'.
      IF ZMM001-VELOCIDADE_B   IN R_1_163431035_VELOCIDADE AND
          ZOPERADORAS-OPERADORA = 'ABCD' AND
          ZMM001-MATERIAL       IN R_1_163431035_PRODUTO.
      ELSE.
      ENDIF.
    What happens is that the value "ZMM001-SPEED" B not exist in "R1_163431035_VELOCIDADE" but the program executes commands under the IF and not under the ELSE, as I imagine it would work. Is this correct ?
    I am new to ABAP programming, but I have a lot of XP in other programming languages ​​and this makes no sense to me.
    Anyone know where I can find some documentation of the use of "TVARV" in ABAP programs?
    I search the Internet if other programmers use TVARV this way, but found nothing, which leads me to think that was a quick and dirty solution that used here.
    If this is a bad way to program, what would be the best way?
    Regards
    Ronaldo.

    Hi Ronaldo,
    But in this case, the range is not empty, there are 17 records, in this way.:
    For the column "SING" all values ​​are "E"
    It means that the result is false if ZMM001-VELOCIDADE_B has the same value as one of the 17 records (E = exclude).
    For instance, if it has value 'C' and one of 17 records matches C, then the result is false.
    The "IF" with "IN" using "TVARV" as used in the program of the post above has the same behavior of a selection screen?
    Yes, the same behavior as the selection criterion to be exact. You can press the help key in the complex selection dialog for more info.
    I know it's a silly and very basic question, but other language that I used, only the SQL has the "IN" operator, but I think they work in different ways, so I would like to understand how it works in ABAP.
    Not silly ;-). Yes they work differently.
    More info here:
    - http://help.sap.com/saphelp_nw70/helpdata/en/9f/dba74635c111d1829f0000e829fbfe/frameset.htm
    - http://help.sap.com/saphelp_nw70/helpdata/en/9f/dba71f35c111d1829f0000e829fbfe/frameset.htm
    BR
    Sandra

  • Use a manual SQL query in an interface

    Hello,
    I would like to know if I can use a manual SQL query in an interface.
    Here is what I need.
    I have two tables.
    T1 with 4 fields :
    idT1, LibC, val, lib_val
    An example of a line from T1
    1, field1, 33 , value 33
    2, field2, 44 , value 44
    And table T2 with fields such as:
    idT2, ... , field1, field2
    There is no key to join T1 and T1, but I should retrieve the value of field lin_val from T2 which corresponds to the value of field1.
    In SQL, the query looks like this:
    SELECT t2.lib_val
    FROM t2 , t1
    WHERE T2.LibC = "Column_name"
    AND T2.val = T1.Column_name
    AND t1.idT1 = xyz

    You should go for yellow interface.It will solve your problem. Here you go
    http://odiexperts.com/how-to-create-a-temp-table-in-odi-interface/
    https://blogs.oracle.com/warehousebuilder/entry/odi_11g_simple_flexible_powerful
    Thanks.

  • I have a question about using multiple ipads in our school.  Each of our teachers have a iPad and AppleTV in their classroom.  The issue is, with our classrooms so close in proximity to one another, is there a way to pair teacher

    I have a question about using multiple ipads in our school.  Each of our teachers have a iPad and AppleTV in their classroom.  The issue is, with our classrooms so close in proximity to one another, is there a way to pair teacher #1 iPad to its AppleTV without effecting/projecting onto the adjacent teachers #2 classroom AppleTV?

    Not as such.
    Give the AppleTV units unique names and also enable Airplay password in settings with unique passwords for each teacher.
    AC

  • Hi, I have quick question about use of USEBEAN tag in SP2. When I specify a scope of SESSION for the java bean, it does not keep the values that I set for variable in the bean persistent.Thanks,Sonny

     

    Make sure that your bean is implementing the serializable interface and that
    you are accessing the bean from the session with the same name.
    Bryan
    "Sandeep Suri" <[email protected]> wrote in message
    news:[email protected]..
    Hi, I have quick question about use of USEBEAN tag in SP2. When I
    specify a scope of SESSION for the java bean, it does not keep the
    values that I set for variable in the bean persistent.Thanks,Sonny
    Try our New Web Based Forum at http://softwareforum.sun.com
    Includes Access to our Product Knowledge Base!

  • Question about using new battery in old Powerbook

    I have a pre-intel Powerbook G4, and the battery is pretty much toast (lasts about 15 minutes now). I have ordered a new battery for it, and I have this question about using it:
    Am I smarter to keep the new strong battery out of the PB most days (as I usually work with it plugged in at home) and just pop it in when I know I will be out surfing on batteries? Or is it just as good living in my laptop 24/7 and only occasionally being called upon to do its job?
    Current bad Battery Information below:
    Battery Installed: Yes
    First low level warning: No
    Full Charge Capacity (mAh): 1144
    Remaining Capacity (mAh): 1115
    Amperage (mA): 0
    Voltage (mV): 12387
    Cycle Count: 281
    thanks folks, Shereen

    Hi, Shereen. Every Powerbook battery wants to be used — drained and then recharged — at least every couple of weeks. If you've always used your Powerbook on AC power nearly all the time, and not followed that pattern of discharging and recharging the battery every week or two, it's possible that your use habits have shortened the lifespan and prematurely diminished the capacity of your old battery. Of course it's also possible that your battery is merely old, as a battery's capacity also diminishes with age regardless of how it's used. You didn't say how old the battery is in years, so this may or may not be an issue. I mention it only because it can be an issue.
    For general information on handling a battery for the longest possible lifespan, see this article. My advice on the basis of that article and long experience reading these forums is that it would be OK to do as you propose, but I doubt that you'd derive any significant benefit from it. You would still want to be sure of putting the new battery through a charge/discharge cycle every week or two, even if you didn't have a reason to use the Powerbook away from home or your desk, because sitting unused outside the computer is just as bad for a battery as sitting unused inside it. And you should never remove the battery from your computer when it's completely or almost completely discharged and let it sit that way any longer than a day or two.
    Message was edited by: eww

  • Question about using Macbook in Vietnam.

    I have a question about using Macbook in Vietnam. I bought my mac here in the US, and I'm going to visit Vietnam, but I'm wondering if I can plug in the power directly into the wall or I have to need any convert power modem for my mac. The only thing I know that Vietnam use 220V so, can anyone help me?

    You may need a plug adaptor, but you don't need a power converter.
    (43828)

  • I have a question about using adobe CS files in CS6 edition

    I am a graphic artist . I have a question about using adobe CS files in CS6 edition. when I am gonna open thse adobe CS created files in CS6 Edition i get a color variation than i made with the CS version.Please give me an idea about this issue as soon as possible.If you need i can upload my problem as a screenshot to clearity

    donrulz,
    Are your Edit>Color Settings the same?
    Are you using spot colours, such as Pantone (there have been some changes in CMYK values with new colour books)?

  • Where Would be the best category to ask a question about using dashboard?

    Where Would be the best category to ask a question about using dashboard?

    However, don't ask it in this topic. Create a new topic for the question with a title describing that you are looking for Dashboard help.

  • Question about Using PAPI Web Service in PowerBuilder 9

    Hi, all.
    I Have a simple question about using papiws in power builder 9.
    In pb9, I created a new Web Service Proxy Wizard and I input a url for papiws(ex. http://seraphpernote:7001/papiws/PapiWebService) and click next.
    But I couldn't get any Service List.
    In Eclipse, I used this url for using papiws well.
    Does anybody know about this case??
    help me plz.

    IIRC you must activate PAPI-WS for the engine. In Studio you do it by right-clicking on the project, then "engine preferences". In enterprise/standalone you must activate PAPI-WS in the Admin Center.

  • Question about using 10g/11g and APEX ...

    Hi,
    I just recently learned of Oracle's APEX and have a few questions about using it.
    Can I use APEX with express, standard, and enterprise editions of 10g and 11g?
    Are all of these free to use?

    You might want to read about APEX rather than jumping into questions that are reasonably well documented. Info at http://www.oracle.com/technology/products/database/application_express/index.html
    Your specific questions:
    1) Apex is a package that can be installed into any properly licensed database.
    2) The price for the production license of the database varies by edition.
    The price for Express Edition is $0 for use in production. Part of the cost for that edition is 'no Oracle Support based support, no patches, data volume limitation, etc.'

  • Question about using Runtime.getRuntime();

    hi all
    i have a question about using Runtime.getRuntime(). if i use this to get a runtime reference to run an external program, is it considered as starting a new thread inside the thread that starts it?
    is it safe to do it in the Session EJB? if not, what can you recommand to do it? thanks

    hi all
    i have a question about using Runtime.getRuntime().
    if i use this to get a runtime reference to run an
    external program, is it considered as starting a new
    thread inside the thread that starts it? No. Starting a process, starts a process. Threads have nothing to do with it.
    is it safe to do it in the Session EJB? if not, what
    can you recommand to do it? thanksSo what? Run another process? If you want to run another process in java then your choices are to use Runtime.exec() or use JNI. And using JNI will probably end up doing exactly the same thing as Runtime.exec().
    "Safe" is harder. Typically to correctly use Runtime.exec() you must use threads. And as noted threads ideally should not be used. You can use them but if you do you had better understand why they didn't want you using them in the first place. You had also better be sure that you really want to wait for it to complete.
    Other than that Runtime.exec() is safe because it can't crash the VM like other interfaces can (like JNI.)

  • Simple Question About Using "Group by" Inside the Oracle XE Query Builder

    Hi,
    I am a new user of Oracle 10g XE and I have built and populated some tables. I am trying to create a view (make a query) via using the Query Builder. I have chosen two attributes, say course_section_ID and trainer_ID in the same table. I choose the "COUNT" function for course_section_no and I check the box for "Group By" with trainer_ID. (I would like to count the number course sections each trainer is teaching). Then I "run" the query and the same error message appears:
    fail to parse SQL query:
    ORA-00904: "COURSE_SECTION"."TRAINER_ID": invalid identifier
    Both attribute names should be valid (as shown above).
    If I only choose course_section_ID and do a COUNT on it, it gives the same error message on course_section_no.
    I did try to do the same thing with the demo HR database. There were no problems with counting a field nor with grouping on a field with HR.
    PLEASE HELP!
    Thanks.

    I have got it. When all the attribute names are in the uppercase, then I can do aggregate functions and "group by" with the GUI.

Maybe you are looking for

  • Photo editor app now available but doesn't work, after latest What's New update

    hi all odd experience what I wanted to highlight with you all. I've just had an updated (this morning) to What's New build 3.0.A.0.2 After installing this patch / update, I was then told that "Photo Editor" was available to download. Build is 5.0.A.0

  • WLC 7.4.100.60 and roaming problems on 8500

    Hello, After installing an 8500 controller on 7.4.100.60 and migrating 1000 APs do this controller, we have the following problems: [1] clients get disconnected and loose sessions (note: client is mobile gun and is heavily mobile). I have the impress

  • When to use Apple Intermediate Codec -v- NTSC  ???

    OK, After successfully creating two projects - one for YouTube and another on DVD - I found myself in a slump when 3 succeeding projects wouldn’t upload properly to YouTube. After doing some troubleshooting with people who “might” know what the probl

  • Deletion of Vendor

    Hi Friends, I have deleted few vendors by using T-code XK06. Can anybody tell me after how many days it will be completely deleted from database????Because I can remove the flag for deletion in T-code XK06 also. In that case what is the difference be

  • Organizer 8 terminates when downloading/importing MTS file

    I am in Organizer trying to download a video file (MTS) from a memory card. The file shows up for me to select when I do the File > Get Photos & Videos > From Camera or Card Reader. I select it and click done. Then I get the message "Files Successful