SOLVED: How can I use or call a function that returns %ROWTYPE?

Hi
edit: you can probably skip all this guff and go straight to the bottom...In the end this is probably just a question of how to use a function that returns a %rowtype.  Thanks.
Currently reading Feuerstein's tome, 5th ed. I've downloaded and run the file genaa.sp, which is a code generator. Specifically, you feed it a table name and it generates code (package header and package body) that will create a cache of the specified table's contents.
So, I ran:
HR@XE> @"C:\Documents and Settings\Jason\My Documents\Work\SQL\OPP5.WEB.CODE\OPP5.WEB.CODE\genaa.sp"
749  /
Procedure created.
HR@XE> exec genaa('EMPLOYEES');which generated a nice bunch of code, viz:
create or replace package EMPLOYEES_cache is
    function onerow ( EMPLOYEE_ID_in IN HR.EMPLOYEES.EMPLOYEE_ID%TYPE) return HR.EMPLOYEES%ROWTYPE;
    function onerow_by_EMP_EMAIL_UK (EMAIL_in IN HR.EMPLOYEES.EMAIL%TYPE) return HR.EMPLOYEES%ROWTYPE;
    procedure test;
end EMPLOYEES_cache;
create or replace package body EMPLOYEES_cache is
    TYPE EMPLOYEES_aat IS TABLE OF HR.EMPLOYEES%ROWTYPE INDEX BY PLS_INTEGER;
    EMP_EMP_ID_PK_aa EMPLOYEES_aat;
    TYPE EMP_EMAIL_UK_aat IS TABLE OF HR.EMPLOYEES.EMPLOYEE_ID%TYPE INDEX BY HR.EMPLOYEES.EMAIL%TYPE;
    EMP_EMAIL_UK_aa EMP_EMAIL_UK_aat;
    function onerow ( EMPLOYEE_ID_in IN HR.EMPLOYEES.EMPLOYEE_ID%TYPE)
        return HR.EMPLOYEES%ROWTYPE is
        begin
            return EMP_EMP_ID_PK_aa (EMPLOYEE_ID_in);
        end;
    function onerow_by_EMP_EMAIL_UK (EMAIL_in IN HR.EMPLOYEES.EMAIL%TYPE)
        return HR.EMPLOYEES%ROWTYPE is
        begin
            return EMP_EMP_ID_PK_aa (EMP_EMAIL_UK_aa (EMAIL_in));
        end;
    procedure load_arrays is
        begin
            FOR rec IN (SELECT * FROM HR.EMPLOYEES)
            LOOP
                EMP_EMP_ID_PK_aa(rec.EMPLOYEE_ID) := rec;
                EMP_EMAIL_UK_aa(rec.EMAIL) := rec.EMPLOYEE_ID;
            end loop;
        END load_arrays;
    procedure test is
        pky_rec HR.EMPLOYEES%ROWTYPE;
        EMP_EMAIL_UK_aa_rec HR.EMPLOYEES%ROWTYPE;
        begin
            for rec in (select * from HR.EMPLOYEES) loop
                pky_rec := onerow (rec.EMPLOYEE_ID);
                EMP_EMAIL_UK_aa_rec := onerow_by_EMP_EMAIL_UK (rec.EMAIL);
                if rec.EMPLOYEE_ID = EMP_EMAIL_UK_aa_rec.EMPLOYEE_ID then
                    dbms_output.put_line ('EMP_EMAIL_UK  lookup OK');
                else
                    dbms_output.put_line ('EMP_EMAIL_UK  lookup NOT OK');
                end if;
            end loop;
        end test;
    BEGIN
        load_arrays;
    end EMPLOYEES_cache;
/which I have run successfully:
HR@XE> @"C:\Documents and Settings\Jason\My Documents\Work\SQL\EMPLOYEES_CACHE.sql"
Package created.
Package body created.I am now trying to use the functionality within the package.
I have figured out that the section
    BEGIN
        load_arrays;
    end EMPLOYEES_cache;
/is the initialization section, and my understanding is that this is supposed to run when any of the package variables or functions are referenced. Is that correct?
With that in mind, I'm trying to call the onerow() function, but it's not working:
HR@XE> select onerow(100) from dual;
select onerow(100) from dual
ERROR at line 1:
ORA-00904: "ONEROW": invalid identifier
HR@XE> select employees_cache.onerow(100) from dual;
select employees_cache.onerow(100) from dual
ERROR at line 1:
ORA-06553: PLS-801: internal error [55018]
HR@XE> select table(employees_cache.onerow(100)) from dual;
select table(employees_cache.onerow(100)) from dual
ERROR at line 1:
ORA-00936: missing expressionHe provides the code genaa.sp, and a very brief description of what it does, but doesn't tell us how to run the generated code!
Now, I have just done some googling, and it seems that what I am trying to do isn't possible. Apparently %ROWTYPE is PL/SQL, and not understood by SQL, so you can't call onerow() from sql. Correct?
So I try wrapping the call in an exec:
HR@XE> exec select employees_cache.onerow(100) from dual;
BEGIN select employees_cache.onerow(100) from dual; END;
ERROR at line 1:
ORA-06550: line 1, column 30:
PLS-00382: expression is of wrong type
ORA-06550: line 1, column 7:
PLS-00428: an INTO clause is expected in this SELECT statement
HR@XE> exec select table(employees_cache.onerow(100)) from dual;
BEGIN select table(employees_cache.onerow(100)) from dual; END;
ERROR at line 1:
ORA-06550: line 1, column 14:
PL/SQL: ORA-00936: missing expression
ORA-06550: line 1, column 7:
PL/SQL: SQL Statement ignored
HR@XE> exec employees_cache.onerow(100)
BEGIN employees_cache.onerow(100); END;
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00221: 'ONEROW' is not a procedure or is undefined
ORA-06550: line 1, column 7:
PL/SQL: Statement ignoredNo joy.
Of course, now that I'm looking at it again, it seems that the way to go is indicated by the first error:
PLS-00428: an INTO clause is expected in this SELECT statement
So am I supposed to create a type of EMPLOYEES%ROWTYPE in a PL/SQL procedure, and the idea of this code, is that the first call to onerow() runs the initialiation code, which populates the cache, and all subsequent calls to onerow() (whether by my session or any other) will use the cache?
I've had a stab at this, but still, no joy:
create or replace procedure testcache is
    emp employees%rowtype;
    begin
        select employees_cache.onerow(100) from dual into emp;
        dbms_output.put_line('Emp id: ' || emp.employee_id);
    end testcache;
show errors
HR@XE> @testcache.sql
Warning: Procedure created with compilation errors.
Errors for PROCEDURE TESTCACHE:
LINE/COL ERROR
4/9      PL/SQL: SQL Statement ignored
4/54     PL/SQL: ORA-00933: SQL command not properly ended
HR@XE>Have a feeling this should be really easy. Can anybody help?
Many thanks in advance.
Jason
Edited by: 942375 on 08-Feb-2013 11:45

>
Ha, figured it out
>
Hopefully you also figured out that the example is just that: a technical example of how to use certain Oracle functionality. Unfortunately it is also an example of what you should NOT do in an actual application.
That code isn't scaleable, uses expensive PGA memory, has no limit on the amount of memory that might be used and, contrary to your belief will result in EVERY SESSION HAVING ITS OWN CACHE of exactly the same data if the session even touches that package.
Mr. Feuerstein is an expert in SQL and PL/SQL and his books cover virtually all of the functionality available. He also does an excellent job of providing examples to illustrate how that functionality can be combined and used. But the bulk of those examples are intended solely to illustrate the 'technical' aspects of the technology. They do not necessarily reflect best practices and they often do not address performance or other issues that need to be considered when actually using those techniques in a particular application. The examples show WHAT can be done but not necessarily WHEN or even IF a given technique should be used.
It is up to the reader to learn the advantages and disadvantages of each technicalogical piece and determine when and how to use them.
>
Now, I have just done some googling, and it seems that what I am trying to do isn't possible. Apparently %ROWTYPE is PL/SQL, and not understood by SQL, so you can't call onerow() from sql. Correct?
>
That is correct. To be used by SQL you would need to create SQL types using the CREATE TYPE syntax. Currently that syntax does not support anything similar to %ROWTYPE.
>
So am I supposed to create a type of EMPLOYEES%ROWTYPE in a PL/SQL procedure, and the idea of this code, is that the first call to onerow() runs the initialiation code, which populates the cache, and all subsequent calls to onerow() (whether by my session or any other) will use the cache?
>
NO! That is a common misconception. Each session has its own set of package variables. Any session that touches that package will cause the entire EMPLOYEES table to be queried and stored in a new associative array specifically for that session.
That duplicates the cache for each session using the package. So while there might be some marginal benefit for a single session to cache data like that the benefit usually disappears if multiple sessions are involved.
The main use case that I am aware of where such caching has benefit is during ETL processing of staged data when the processing of each record is too complex to be done in SQL and the records need to be BULK loaded and the data manipulated in a loop. Then using an associative array as a lookup table to quickly get a small amount of data can be effective. And if the ETL procedure is being processed in parallel (meaning different sessions) then for a small lookup array the additional memory use is tolerable.
Mitigating against that is the fact that:
1. Such frequently used data that you might store in the array is likely to be cached by Oracle in the buffer cache anyway
2. Newer versions of Oracle now have more than one cache
3. The SQL query needed to get the data from the table will use a bind variable that eliminates repeated hard parsing.
4. The cursor and the buffer caches ARE SHARED by multiple sessions globally.
So the short story is that there would rarely be a use case where ARRAYs like that would be preferred over accessing the data from the table.

Similar Messages

  • How can I use system call in kernel loadable module?

    Hi,
    I want to use system call (shmat, mmap,...) in kernel module.
    When kernel module is loaded, it cause system error (undefined symbol name 'shmat', 'mmap').
    How can I use system call in kernel module ?
    Thanks in advance.
    david joo

    You cannot use system calls in the kernel modules.
    Read 'Writing Device Drivers' answerbook - it lists the set of interfaces (known as DDI/DDK) that are supposed to be used instead.
    Hope this helps...
    --I.

  • How can i use talking caller id without jailbreak and those wacky apps

    how can i use talking caller id without jailbreak and those wacky apps

    Talking caller ID is not a feature of the iPhone. If by "wacky apps" you mean the ones that make custom ring tones for each contact from their name, that's your best bet.

  • How can I use the color adjustments interface that shows up for camera RAW on jpeg files?

    How can I use the color adjustments interface that shows up for camera raw on other files types? The HLS controls had the secondary color adjustments (6 colors instead of the 3). Plus, it had same vibrancy and a better Curves interface. Yesterday was the first time I imported raw into Photoshop CS5 and I got that really cool interface. What is that? Can I use that on other file formats?

    Actually I am using the Tradional Chinese Version, when I try to edit the jpg file with camera raw, the system shows that there is no camera raw plug-in. The cmaera raw never work.

  • How can I use User-Defined Aggregate Functions in Timesten 11? such as ODCI

    Hi
    we are using Timesten 11 version and as per the documentation, it doesn't support User-Defined Aggregate Functions.
    So we are looking for alternatives to do it. Could you please provide your expert voice on this.
    Thanks a lot.
    As the following:
    create or replace type strcat_type as object (
    cat_string varchar2(32767),
    static function ODCIAggregateInitialize(cs_ctx In Out strcat_type) return number,
    member function ODCIAggregateIterate(self In Out strcat_type,value in varchar2) return number,
    member function ODCIAggregateMerge(self In Out strcat_type,ctx2 In Out strcat_type) return number,
    member function ODCIAggregateTerminate(self In Out strcat_type,returnValue Out varchar2,flags in number) return
    number
    How can I use User-Defined Aggregate Functions in Timesten 11? such as ODCIAggregateInitialize ?

    Dear user6258915,
    You absolutely right, TimesTen doesnt support object types (http://docs.oracle.com/cd/E13085_01/doc/timesten.1121/e13076/plsqldiffs.htm) and User-Defined Aggregate Functions.
    Is it crucial for your application? Could you rewrite this functionality by using standart SQL or PL/SQL?
    Best regards,
    Gennady

  • Can a loaded SWF call a function that lives in the parent?

    I'm building a pretty simple Flash site in AS3. There is a
    main movie (main.swf) that simply loads different swfs via buttons
    on a main nav bar. The user clicks on a MC in "main.swf" and a
    function is called, loadMyContent("section1.swf"), is called and it
    animates in nicely. Other buttons use the same function, loading
    section2.swf, section3.swf, etc.
    I've defined how "loadMyContent()" works in the the main
    movie's document class file. It's all working fine when I just need
    to load content from a user action from the buttons that live in
    "main.swf". I want to call that same "loadContent" function from
    within "section1.swf" and have "main.swf" run it's "loadContent"
    fuction, but I can't seem to figure out how to make a child call a
    function that lives in the parent.
    Is there any way of having my child do this?
    I have a suspicion I may have to define that "loadContent"
    somewhere else, but I'm a little stumped now. I'm not really
    familiar with design patterns yet, although I want to get an
    understanding of them sometime soon. Can anyone offer some help
    with my immediate need or suggest a route to a solution?
    Thanks.

    kglad,
    Thank you very much! That worked perfectly. My section1 FLA
    is now compiling it's SWF without complaint.
    In case someone else is following this, the exact code I
    ended up using to cast "this.parent.parent" as a MovieClip is:
    MovieClip(this.parent.parent).loadMyContent("section2.swf");
    The discussion I think kglad is referencing is
    this
    discussion. If that's not it, just let me know. Again, kglad,
    thank you!

  • How can i use video call

    Syed Shahzad

    Hi and welcome to the Skype Community,
    Please take a look at the instructions here on how to perform a video call using Skype for Windows Phone: https://support.skype.com/en/faq/FA12181/making-a-video-call-windows-phone-8
    Follow the latest Skype Community News
    ↓ Did my reply answer your question? Accept it as a solution to help others, Thanks. ↓

  • How can I use the procedures and functions in my library

    hello, all
    I have a pl/sql library MYLIB.pld, MYLIB.pll and MYLIB.plx.
    How can I invoke procedures and functions there in JDeveloper?
    Thanks.
    Damon

    I am indeed using ADF BC to re-develop the oracle application.
    Here is my situation:
    We have an oracle form application.
    Our objective is to try to re-use the existing sources in the form application as much as possible:
    1. tons of procedures and functions in a pl/sql library(a file with extension name portfolioLib.pll or portfolioLib.plx);
    2. tons of form-level triggers, data-block triggers and item-triggers;
    3. tons of database stored procedures and triggers;
    After doing a research on JDeveloper, we decide to use ADF Swing+ADF BC to re-develop the application.
    My opinion for the above three kinds of sources in our form application is:
    for 1: we try to move most of procedures and functions into database(except Form build-in);
    for 2: we try to wrap those triggers in a SQLJ class;
    for 3: we try to call database procedures and functions with PreparedStatment or CallableStatement;
    I just do a test on a post-query trigger on a data-block:
    I created a sqlj file, named testSQLJ.sqlj in the test.view package;
    I tried to call it in createInstanceFromResultSet of testDeptVOImpl.java which is test.model package,
    I was told that testSQLJ cannot be found there. why?
    How can I call some classes from test.view package in some classes of test.model?
    I read some documents about how to deal with post-query trigger in JDeveloper: create a view with SQL statement, but it seems that it does not support pl/sql statement there.
    Can you give me some opinion about the above stuff?
    I really appreciate your help.
    Damon

  • How can a custom class call a function in "parent" class?

    Say I have an application (ultrasimplified):
    public class myApp {
    myClass mc;
    boolean foo=false;
    public static void main(String[] args) {
    mc = new myClass();
    public static void myFunc(boolean blah) {
    foo=blah;
    in a separate .java file where my questions lie:
    public class myClass {
    boolean bar=true;
    public void myClass() {
    // this is wrong, but how would I do this:
    foo = bar; // foo in myApp set to true
    // or how would I call "myFunc()" in myApp from this class:
    myFunc(bar);
    my problem is that I've created a new class that I share between two applications so I could share the code. However, I want this class I created to call a function in the application class that instanciated it. Or alternatively, I would like to set a variable in the class that instanciated myClass.
    How would go about this? I've used the "this" parameter in applets to pass the parent class to an inner class, but main() in applications doesn't allow the non-static "this":
    myClass my = new myClass(this);
    Is there something similar I can do?

    You can let MyApp implement an interface and refer to that object in MyClass:
    class MyApp implements Something {
    main() {
    MyApp app = new MyApp();
    MyClass mc = new MyClass(app);
    public void foo() { }
    class MyClass {
    Something app;
    MyClass(Something app) {
    this.app = app;
    app.foo();
    interface Something {
    public void foo();
    Better yet, you can let MyApp extend an abstract class that defines foo(). Then MyApp can override the foo() method. If later on, the abstract class needs to add a bar() method then default implementation can be done in the abstract class. If you make it an interface then all implementing classes will have to be updated to implement the new method.

  • How can I debug the Call Library Function at run-time

    I've written a VI using the CLF to call a DLL which was compiled off-site by another engineer using MSVC. Even though the VI runs without flagging any errors, the VI is not doing what I expect. Is there any way of finding out if the DLL is been called correctly? The first function that is called doesn't return any value, but I think that it should. Does this mean that the DLL is not being called correctly? Note also that the DLL works fine with a JAVA GUI.

    Make sure that you are specifying the proper function prototype in the call library function. If you are slightly off the call will not work properly. Ask the offsite engineer to provide you with this data. Another tip is to build the dll with the option to show front panel when called. You can actually popup the dll like you would a subvi. If you design it with test indicators showing on the front panel that is a great way to determine if it is working. Hope this helps.
    BJD1613
    Lead Test Tools Development Engineer
    Philips Respironics
    Certified LV Architect / Instructor

  • How can I use equalsIgnoreCase in JDBC Application to return database value

    How can I ensure that the code will return a name from the database by using equalsIgnoreCase().
    Please see below code .
    public class RetrievEmp {
    final static String FILE_NAME "c:\\project\\test.txt";
    /** Retrieves data from Employee table with the specified column
    * and employee's name.
    public String getDataFromEmpTable(String empname, String column) throws Exception {
    java.sql.Connection con = null;
    String query = "select " + column + " from owner.Employee where NAME = ?";
    ConnectionPool conPool = ConnectionPool.getPool();
    ResultSet rs = null;
    con = conPool.getConnection();
    PreparedStatement ps = con.prepareStatement(query);
         try {
              ps.setString(1, name);
         rs = ps.executeQuery();
              if(rs.next()) {
    rs.getString(1).equalsIgnoreCase(column);
         return rs.getString(1);
              else {
                   return null;
              finally {
                   try {
                        if(rs != null) {
                             rs.close();
                        if(con != null) {
                             con.close();
                        if(ps != null) {
                             ps.close();
                   }catch(Exception e){
         log.debug("Exception while closing connection");

    Thank you for your posting - The Member Feedback forum is not monitored by Oracle support or product teams and so Oracle product and technology related questions cannot be answered. However we recommend that you post this thread to the "Database - General" forum.
    The URL is: General Database Discussions
    Thanks - The OTN team

  • How can I use the same iCloud email that's on my iPad on my Iphone?

    How come my iPhone 4 will not let me use my iCloud email address that's on my iPad?

    What happens when you try to use it?  Any error message?

  • How can I use an iTunes gift card that was sent to me from someone in another country?

    Hi, My son got some iTunes gift cards for Christmas, the problem is that the sender lives in another country and we cannot use the gift cards here in Sweden. Can anyone help us? Thanks in advance.

    You can't use those cards. Sorry.
    (96020)

  • How can I use the message protection function ???

    hello,everyone! I am a programmer working on the iphone,and I have a trouble in message filtering.How can I do it when I want to refuse the message which is sended from the specific people?? thank you

    Why not ask over at the registered developers forum?

  • HELP NEEDED!!HOW CAN I USE ORACLE TO GIVE FUNCTIONALITY TO OTHER DATABASES

    We presently use a transactional System based on Pervasive.SQL Database Manager (it has ODBC capabilities). However, we need to give our Transactional system a WAN capability (So we can use it in more than one site).
    Do you have any ORACLE product that can be used for this?
    one way is to use the Oracle Product like a Data Warehouse and Replicate the Database with other Servers, but we would like to know the feasibility of this?
    An urgent response would be appreciated.

    Femi,
    Is it possible to just convert the other databases so you have a standard platform and all your data management and replication issues could be handled with just a knowledge of knowing one tool inside and out - Oracle!
    Let me know. email me directly and we can further discuss. [email protected]
    null

Maybe you are looking for

  • Error--Control indicators not assigned to company code

    While creating PO in IDEAS following error is coming. "Control indicators not assigned to company code" Pl . suggest the remedy, Thanks a ton, Regards, NB

  • Sales AR Item Type Invoice Print Layout Design "Sub Total" per Page

    Dear Forum Team We need some advice on how to modify, fomulate(?) [Sub Total] for each page's 'amount' on the Sales AR Item Type Invoice. Currently the 'sub total amount' on each page is showing Grand Total instead of sub total. Thanks

  • Microphone problem win 8.1

    Msi gt70 The only microphone that works is the internal one. When i change to the one i want to use in recording devices, it still use internal microphone. If i use a usb microphone it works An yes i tried different headsets and microphones.

  • [HELP] Enabling field in F-47

    Hello Gurus, I'm trying to enable the PO number ( purchase order ) and PO item in F-47, i've already checked the transactions OB41 for posting key and OBC4 for G/L account group. I have two enviroments 210 and 220, on 210 i have the purchase order fi

  • QA32/QA11 user decision should pop up LT06 screen

    Hi, When we distribute the quality stock from inspection lot to unrestricted and blocked, we want the LT06 popup to distribute the palletized qty. Palletization is already done during CORK and is in Q stock. Because distribution to UR and blocked is