Returning a collection of data

Hi all,
Took me ages to finally post this cause the forum server seems to be having problems.
I want to do a query in a function then return a series of results back to the calling process. Can someone tell me what is the best method of doing this?
Nested table? Table of Records? VArray (even though I don't think I could use it due to its inability to dynamically increase in capacity).
Can someone also suggest which method is best for returning a one column series of data and more than one column?
And finally, does such a thing as a Table of Records actually exist as a storage method thats passable by functions/paramaters?
Many many thanks!

I'll answer your original question.
If your return type is know beforehand then you can create a type for each row and for a table of that row.
(Declare these in your package spec so that the calling PL/SQL can reference the types!)
E.g.:
type ty_person is record
( person_id pls_integer
, first_name varchar2(100)
, last_name varchar2(100)
, date_of_birth date
Then create a table type
type ty_person_t is table of ty_person index by binary_integer;
Then you can reference this in your procedure
function f_get_people_older_than(X_age in pls_integer) return ty_person_t;
The calling proc would then be:
declare
X_people mods_people_package.ty_person_t;
begin
X_people := mods_people_package.f_get_people_older_than(30);
end;
Hope this helps..
Chris

Similar Messages

  • Best way to collect periodic data over RS232?

    I'm using Labview 6i to collect data from a device over RS232.  The device manual says that it delivers data digitally by sending 10 bytes every 100ms.  I'm using VISA Write to send an initialization string, and then I step in to a loop containing VISA Read set to read data synchronously, set to read 10 bytes of data.  I have tried a number of things to get this to work:
    Adding a wait to the loop and varying the wait time
    Increasing the bytes read from 10 to 15 and filtering out the specific 10-byte set I want to read
    Taking out the wait completely and letting the loop run untimed, limited by the VISA Read node
    The problem I encounter is that often the VISA Read node returns a set of data that is "shifted".  In hex, my 10-byte set should look like this:
    FFFE 0106 04 FF FF FF 45 D4
    Where the FFFE 0106 04 acts as a header.  Often the 10 byte set I retrieve contains some bytes from one set, and some bytes from the next set; so, the header might lie in the center or at the end of the 10-byte set rather than at the beginning (in which case there is some data lost at the leading and trailing ends)
    One thing I have tried is throwing out "bad" sets, but then I am losing data and not getting the full 10 data points per second that the device is capable of.
    When reading data like this, where a set of bytes is sent periodically, how can you ensure that every set is properly read?

    When working with a device that is essentially streaming data back to the computer you have to take on the responsibility of  parsing the response and breaking it up into individual messages. One good thing in your favor is that you have a well defined header that you can search for in the datastream. The nice thing about the shift register approach is that you can parse as many or as few packest as you want. Moreover at the leasurely rate the device is passing data LV should be able to more than keep up with the flow.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Get entity as return of collection in entity framework

    how to get entity as return of collection in entity framework,,, i dont have any idea...
    when i select entity and then get column information then no column return .....

    The way the Oracle provider works right now requires that you use a cursor, even if you want to map it to an entity. To map it to an entity, that cursor needs to contain the necessary columns to form the entity (ie: it's returning data from the same table).
    Here's an example from one I have mapped:
    CREATE OR REPLACE PROCEDURE ENVMSTR.P_ORG_UNIT_R_BY_STAFF
    STAFF_ID_P IN NUMBER
    , RESULT_CURSOR_P OUT SYS_REFCURSOR
    ) AS
    BEGIN
    OPEN RESULT_CURSOR_P FOR
    select *
    from dept_organizational_unit d
    where deptorgunit_cd = (select deptorgunit_cd from staff where staff_id = STAFF_ID_P)
    or deptorgunit_cd in ( select deptorgunitrel_parent_cd from dept_org_unit_relation
    start with deptorgunitrel_child_cd = (select deptorgunit_cd from staff where staff_id = STAFF_ID_P)
    connect by prior deptorgunitrel_parent_cd = deptorgunitrel_child_cd);
    END P_ORG_UNIT_R_BY_STAFF;
    web.config:
    <add name="ENVMSTR.P_ORG_UNIT_R_BY_STAFF.RefCursor.RESULT_CURSOR_P" value="implicitRefCursor bindinfo='mode=Output'" />
    With those things set up, I'm able to import the function and map it to the entity that represents the dept_organizational_unit table (that entity is called OrgUnit in the model, but it doesn't really matter what you call it). The interesting thing I found is that in this situation I didn't actually have to add config file entries for each column in the cursor, probably because it maps perfectly to the entity. If I was trying to use a complex type instead then I probably would (and the configuration required to do that gets horrific in a hurry).

  • Apex Collections and dates

    Apex Collections and Dates
    I made an earlier posting today on the forum titled “‘ORA-01861: literal does not match format string’ error after my hosting company upgraded to Apex 3.2.” The issue relates to Apex collections and dates. Prior to the hosting company upgrading Apex 3.2 from 3.1 all was working OK. It seemed a reasonable assumption that the issue relates to the upgrade to 3.2. Having tested the code against another Apex 3.2 installation I am satisfied that the issue is not with Apex 3.2. That said, I am still getting the issue on the hosting site.
    To demonstrate the issue to my hosting company and this forum, I put together a simple one page application that demonstrates the issue using the least amount of code.
    I created a page with an ‘On Load – Before header” process that sets up an Apex Collection with a single value of ’20-FEB-2009’ in the c001 element as follows:
    if apex_collection.collection_exists(p_collection_name=>'THEISSUE') then
    apex_collection.delete_collection(p_collection_name=>'THEISSUE');
    end if;
    apex_collection.create_collection(p_collection_name => 'THEISSUE');
    APEX_COLLECTION.ADD_MEMBER(
    p_collection_name => 'THEISSUE',
    p_c001 => '20-FEB-2009');
    I added an SQL REPORT region to the page which uses the Apex Collection as follows:
    select to_date(c001,'DD-MON-YYYY') testdate
    from apex_collections
    where collection_name='THEISSUE'
    and to_date('20-FEB-2009','DD-MON-YYYY')
    = to_date(c001,'DD-MON-YYYY')
    When the page is run I get the ‘ORA-01861: literal does not match format string’ error.
    If I remove the following from the SQL Report Region:
    and to_date('20-FEB-2009','DD-MON-YYYY')
    = to_date(c001,'DD-MON-YYYY')
    and run the page, the date is displayed OK, i.e., c001 is converted to a date OK. This made me wonder whether it does not like the line to_date('20-FEB-2009','DD-MON-YYYY')? So I changed the where code for the report to :
    and to_date(c001,'DD-MON-YYYY')
    = to_date(c001,'DD-MON-YYYY')
    i.e., convert c001 to a date and compare it to itself. The rationale being that if the c001 converts to a date OK, then comparing c001 converted to a date with itself should not give an error. It did it gave the same error ‘ORA-01861’
    It would seem on my hosting site since the upgrade, that Apex and Oracle have problems with Apex Collection elements being converted to dates as part of the where clause.
    Now my understating of Oracle Apex collections in simple terms is that all Apex collections are held in a single Oracle table managed by a series of Apex functions. Given that all Apex collections are in the same table, could the issue be with the Oracle database when it is creating its execution plan for the query? Could Oracle be including the value of c001 from other collections (i.e., when c001 is not in a date format ) in the initial stages of its execution plan?
    I hope the above make sense and thanks in advance.
    Ian

    Scott,
    I believe I have found the answer the statistics on WWV_FLOW_COLLECTIONS$ and WWV_FLOW_COLLECTION_MEMBERS$. are out of date and Oracle is doing a full table scan instead of using the indices to select only the c001 columns that belong to the given collection_id. If I change my simple example to store the date value in c050 it works ok. (In all probability this will be the only collection on the hosted database to use c050).
    I have asked the hosting company to gather stats on all the apex tables.
    Thanks for your help
    Ian

  • How do I perform a trigger that collect the data for every rising edge continuously and then automatically put the data in a .xls file??

    I need to collect the data for every rising edge a trigger perfoms. So far I could collect the data but it seems that it only collect the data in the start of triggering, but not continuously. I also want to put the data in an excel spreadsheet and automatically add new set of data when the next rising edge occur. Please help.
    thanks a lot.

    LabWindows/CVI actually ships with a comprehensive set of examples for just about every area of programming you can use it in, including triggered analog data acquisition and ActiveX control of Microsoft Excel for data logging. Go to the following two directories on your computer to find respective examples for the two areas you are inquiring about:
    1) C:\MeasurementStudio\CVI\samples\DAQ\Ai\DAQsingleBufExtTrig.PRJ
    2) C:\MeasurementStudio\CVI\samples\activex\excel\excel2000dem.prj
    Just make sure to study the examples carefully so that you fully understand the processes followed for triggered analog acquisition and the process of launching an ActiveX automation server for control, and then you should be able to merge the concepts shown in both of the example
    s to make the application you desire.
    Jason F.
    Applications Engineer
    National Instruments
    www.ni.com/ask

  • Mass collection of data sources in Transport request.

    Hi All,
    I want to capture the data sources which are available in RSA5. It is already activated and captured in Transport Request. But the Transport request was deleted by somebody.
    I want to re-capture the activation of data sources which are there in RSA5. I want to collect 90 data sources in one Transport request.
    Can you please guide me a easy way to capture all the data sources in transport request.
    Thanks.

    Hi,
    you might be able to create a new Transport request and add the datasources manually.
    check out the table roosource for the sources. you can find your's by filtering on tstpnm.
    add the sources with object 'R3TR' and subobject 'OSOA'.
    regards
    Siggi

  • I'm doing a scan around a line by sampling data 360 degrees for every value of z(z is the position on the line). So, that mean I have a double for-loop where I collect the data. The problem comes when I try to plot the data. How should I do?

    I'm doing a scan around a line by sampling data 360 degrees for every value of z(z is the position on the line). So, that mean I have a double for-loop where I collect the data. The problem comes when I try to plot the data. How should I do?

    Jonas,
    I think what you want is a 3D plot of a cylinder. I have attached an example using a parametric 3D plot.
    You will probably want to duplicate the points for the first theta value to close the cylinder. I'm not sure what properties of the graph can be manipulated to make it easier to see.
    Bruce
    Bruce Ammons
    Ammons Engineering
    Attachments:
    Cylinder_Plot_3D.vi ‏76 KB

  • How to collect my data from a disk that I suspect to contain a malware

    I have experience several crashes the last 72 hours and I have to buy a new hard drive that I am using as an external drive to work from as a startup disk.
    Once I install all my software back, how can I collect my data from a hard drive that I am suspecting to contain a malware. I previously use Bitdefender for mac and because I do not know which software is causing the problem, I just install Clamxav.
    Please advise.

    BitDefender was likely causing the problem.
    Just plug it in and transfer the data. You'd have to install the malware for it to affect your Mac, but XProtect blocks all known malware from installing.

  • Pipeline Table Function returning a fraction of data

    My current project involves migrating an Oracle database to a new structure based on the new client application requirements. I would like to use pipelined table functions as it seems as though that would provide the best performance.
    The first table has about 65 fields, about 75% of which require some type of recoding for the new app. I have written a function for each transformation and have all of these functions stored in a package. If I do:
    create new_table as select (
    pkg_name.function1(old_field1),
    pkg_name.function2(old_field2),
    pkg_name.function3(old_field3),
    it runs with out any errors but takes about 3 1/2 hours. There are a little more than 10 million rows in the table.
    I wrote a function that is passed the old table as a cursor, runs all the functions for the transformations and then pipes the new row back to the insert statement that called the function. It is incredibly fast but only returns .025% of the data (about 50 rows out of my sample table of 200,000). It does not throw any errors.
    So I am trying to determine what is going on. Perhaps one of my functions has a bug. If there was would cause the row to be kicked out? There are 40 or so functions so tracking this down has been a bit of a bear.
    Any advice as to how I might resolve this would be much appreciated.
    Thanks
    Dan

    . I would like to use pipelined table functions as it seems as though that would provide the best performanceUh huh...
    it runs with out any errors but takes about 3 1/2 hours. There are a little more than 10 million rows in the table.Not the first time a lovely theory has been killed by an ugly fact. Did you do any bench marks to see whether the pipelined functions did offer performance benefits over doing it some other way?
    From the context of your comments I think you are trying to a populate a new table from a single old table. Is this the case? If so I would have thought a straightforward CTAS with normal functions would be more appropriate: pipelined functions are really meant for situations in which one input produced more than one output. Anyway, ifr we are to help you I think you need to give us more details about how this process works and post a sample transformation function.
    There are 40 or so functions so tracking this down has been a bit of a bear.The teaching is: we should code one function and get that working before moving on to the next one. Which might not seem like a helpful thing to say, but the best lesson is often "I'll do it differently next time".
    Cheers, APC

  • How to return a set of data  by using webservice ?

    Hi.
    I am finding how to return a set of data by using java webservice that serves clients written by others such as VB. Net. Please help me !
    Thanks in advance.

    Check the how to on Accessing Oracle9iAS Java Web Service from a .NET Client
    http://otn.oracle.com/sample_code/tech/java/codesnippet/webservices/index.html
    Chandar

  • How to make a function return number(10,0) data type (ORACLE 10g)?

    With 10g, how to make a function return number(10,0) data type?
    here is the function, it returns a number type :
    create or replace FUNCTION Get_portfolio_Id3 (p_HistObjTable In Varchar2,p_LHISTOBJID IN NUMBER) RETURN view_cpu_STD_Asset.LPORTFOLIOITEMID%Type IS
    v_Id view_cpu_STD_Asset.LPORTFOLIOITEMID%Type;
    BEGIN
    If p_HistObjTable ='amPortfolio'
    then v_Id:=p_LHISTOBJID ;
    elsIf p_HistObjTable = 'amComputer' then
    select litemid into v_Id from smcdba.amComputer c where c.LCOMPUTERID=p_LHISTOBJID ;
    else v_Id:=-99;
    End If;
    RETURN v_Id;
    END Get_portfolio_Id3;
    Thanks.
    Message was edited by:
    user631701

    create or replace FUNCTION Get_portfolio_Id3 (p_HistObjTable In Varchar2,p_LHISTOBJID IN NUMBER) RETURN view_cpu_STD_Asset.LPORTFOLIOITEMID%Type IS
    v_Id view_cpu_STD_Asset.LPORTFOLIOITEMID%Type;
    BEGIN
    If p_HistObjTable ='amPortfolio'
    then v_Id:=p_LHISTOBJID ;
    elsIf p_HistObjTable = 'amComputer' then
    select litemid into v_Id from smcdba.amComputer c where c.LCOMPUTERID=p_LHISTOBJID ;
    else v_Id:=-99;
    End If;
    RETURN round(v_Id);
    END Get_portfolio_Id3;

  • How to Rectify Goods Return posted in wrong date

    Dear Expert
    Please guide me how to rectify the Goods return posted in Wrong Date.
    Regards
    Rajani patel

    DEAR GORDAN
    I am talking about Purchase Goods Return based on GRPO then how can i rectify it
    Scenario is like this
    GRPO date:10th April 2010 and client has made Goods Return in 21th Sept 2010 instead of same date of GRPO
    Regards
    Rajani P Patel

  • Simplest approach for creating database for small collection of data - new project design phase

    Hello. I am at the design stage of a VB.NET project, which I hope will help me strengthen some skills I have learnt so far, and learn new ones. I have a couple of questions. Firstly regarding data types, is there a unified, standardised, all-convergent
    data type available I can use? Secondly I've read about numerous avenues to create a database, namely binary serialisation, access-based, excel-based, notepad-based - The project I intend to create, will only require storage of a "relatively" small
    collection of data, which may grow over time, but not significantly - so, taking this into account, which method is advisable for creating my database? (a beginner-friendly option is preferred). I have included a couple of images, with my questions, to give
    a rough idea of what I'm planning to do. Thanks for your advice and suggestions.

    Type would be the type of recording, as in LP (Long Play - standard album), EP (Extended Play) or Compilation. Most would be LP.
    Chris,
    I have a start on this and I want to pause here to post what I have and to discuss it.
    There’s a lot to talk about because you’re going from little knowledge of a class to a lot in a hurry. There is no real hurry
    in any of this; if you don’t understand then let’s stop and talk about it – until you fully have a handle on it, adding more would only fuel the confusion.
    I’ll add this at this juncture: There is no one single right way to do this. There are definitely some
    wrong
    (or maybe just simply ineffectual) ways, but certainly no single right way. A lot of what you’ll see in the following will reflect my preference; nothing more than that.
    Also though, I’m doing some of this to expose you to it. By that I mean that I may or may not have done it this way all along,
    but I decided that I want to open the doors, even though at first it’ll seem like you’re trying to get a drink of water from a fire hydrant. ;-)
    I have it set up with two namespaces: CMJR and Common. The latter one is for use for what I’m considering to be a ‘common’ need
    – things that you may use in several classes. In time, the routines for serialization will be there but no need to even talk about that now so it’s not there.
    The code so far (which I’ll show by the end of this discourse) is about 500 lines. For a class library, that’s puny! Most of
    what I have thus far is just a shell of what will be filled in later. I won’t at all be surprised that by time this is completed, that 500 lines can easily grow to 5000 lines or more.
    Like I said yesterday, the great thing about doing it this way is that it’s done
    your
    way; the drawback is just how much there is to do though, so if nothing else, this will perhaps influence your decision on how you want to handle things like this in the future.
    The namespaces/classes are laid out as:
    CMJR
    Music (a class)
    Film (a class)
    Games (a class)
    Common
    IDataSource (an interface)
    IGenre (an interface)
    Utilities (a class)
    This
    image shows the structure of things thus far. The reason why the enum “GenreType” isn’t expanded in that
    image is because it’s hugely long! In fact I fully expect that you’ll likely delete most of those. I got them from someone else’s class library (about a decade ago) so it was convenient to use.
    Let’s start from the inside and work toward the outside here:
    What is an
    enum?
    An enum (enumeration) is a type all its own. It’s a constant (of integral type) that you define. You can think of it as “an
    integer with a name associated with it” because in code, you’ll use it like a multiple-choice selection and [typically] you’ll use its name.
    Any time there’s a need for some something to be “this or that”, an enum very often is a useful type to use. In what we talked
    about yesterday regarding what the source of the data is (CD or PC), that’s what came to mind; select which of the two from an enum. I always include a “_String” property with these so that it can later be used in whatever will consume the class. Often it’s
    nothing more than use the .ToString method of the enum itself, but remember that then enum is actually an integer, not a string.
    In this library so far, I have three enums defined. Two of those are in each of two interfaces (discussed in a bit) and one
    is specifically related to only the music, so it’s in the class “Music”:
           Public Enum MusicFrom
               LP
               EP
               Compilation
           End Enum
    The “type” that I asked about earlier is encompassed in that enum and you can more or less see how it works without any further
    explanation.
    Do understand that enum is only ‘useful’ for programming. We could use strings for all that it matters, but the problem with
    doing that are many, including things like typos and capitalization. That’s not the case with an enum because you select one of the choices offered. In the one above, that would be either LP, EP, or Compilation. It can’t be anything else.
    So if strings have this issue with typo’s and the like, what about if we just assigned it a number (an integer). Sure that’s
    a better idea but are you really going to remember what 23 means? I doubt it, or not for long.
    BUT – if we had a number that has a string associated with it, yea that’s a good idea!
    Right! Now you know what an enum is. ;-)
    Notice from the
    class
    diagram though – it’s not shown; I’m not using it all and that’s because I question its worth here, at least
    for the current setup. I’ll explain what I mean:
    As it’s currently set up, the basic unit of the class “Music” is a song. Even though there’s a title for the album, the album
    – as a type – doesn’t exist. LP, EP, and Compilation refer to the album, not the song (in my opinion here) so I don’t see how it can be used.
    If, however, we create a new type called “Album”, then I can see how it could be used. In something I worked on a while back
    that’s exactly how I have it set up: An album is a “container for songs” and the album (a class in what I’m referring to from a few months back) has certain properties like a name and cover art, etc..
    I don’t have this set up that way, but give that some thought.
    What is an
    interface?
    Until quite recently I ‘knew of them’ but I never used them. There may or may not be merit in it here either but I wanted to
    expose you to them.
    From that link above:
    “An
    interface defines a set of members, such as properties and procedures, that classes and structures can implement. The interface defines only the signatures of the members and not their internal workings.”
    The interface is a way in which you create a ‘code contract’. You don’t define what the methods, properties and events do in
    the interface – you define that they have to be implemented if a class uses it.
    It’s up to the class to actually put it to use (i.e., the code that’s executed in the member of the interface).
    It’s a lot deeper than I’m discussing here – including a fair amount of ambiguity – so I won’t go any further than that for
    now.
    I have two interfaces set up and I have them in the “Common” namespace. They are “IDataSource” and “IGenre”.
    IDataSource has an enum named “SourceType” and two read-only properties (see it later in the code).
    The interface IGenre is likewise set up the same way and that’s where the long list of elements are in the enum named “GenreType”
    that I talked about earlier.
    I think it’s a good idea with Genre that it’s a “pick one of these” rather than simply a string and here’s why: If we later
    add in a method to choose songs from a collection of them, one of the options might be of a particular genre. That’s not an uncommon request I would think. By using an enum, we don’t have to worry about your users mistyping when they add the data:
    RockAndRoll
    Rock and Roll
    Rock
    …etc., and imagine some of the typos your users might come up with, so by using an enum it’s definitive rather than guessing.
    I said that an enum is ‘only for programming though’ so we’ll need to make it more usable later on. For example, I can also
    build in methods to hand you back a string array of the string equivalent of those enums and then later a method to turn that string back into the actual enum member. By doing this then the method(s) which will use this will filter the data from the collection
    to only include those with that particular genre.
    Other than something simple, I’ve learned that once you get involved in a really long enum – like the genre that I showed above
    – it’s better to create a class which, all on its own, has methods for handing you the string array and then handling the conversion back to an enum, so that’s a possibility too.
    That’s for use in your UI so the blinders will start to come off at that point. ;-)
    Continued in a subsequent post…
    Still lost in code, just at a little higher level.

  • Where does Apple collect their Date & Time Information?

    I'm trying to isolate a problem for why the date and time for Unalaska and Dutch Harbor, AK when set automatically is on Hawaii Time when it should be on Alaska Time.  The islands further west on the Aleutian Island Chain are on Hawaii Time, but not Unalaska Island.  While in Unalaska, I have to set date & time on all my Mac devices to manual, and switch it back to automatic whenever I leave.  As much as I travel, it is a nuisance having to switch back an forth between automatic and manual. This has been an ongoing problem for the past 2 or 3 years, and previously, it worked correctly. 
    I've noticed that some date/time websites have it wrong, but some have it correct.  So, if I can find out where Apple collects their Date & Time information, I should be able to figure out whether it's an "Apple" problem or an "ISP" problem.

    Chris CA wrote:
    OGELTHORPE wrote:
    Terence Devlin wrote:
    Wonder why Ford, General Motors and all those car manufacturers don't do this? Hmmm?
    I thought that they put out recalls for stolen cars.  Am I wrong on that?
    Yes.
    A vehicle recall is to fix issues that the manufacturer feels they need to do something about such as bad parts.
    Or the Government felt they needed to do something about.

  • Need a FM which returns the last modified date& time

    Hi,
    Kindly Suggest me if any Function Module is there which returns the last modified date& time for tables HRP1000 and HRP1001.
    Rgds
    Kishor.C

    just check the following tables..
    CDHDR - Change document header
    CDPOS - Change document items
    you can use this function module..
    BPCT_CHANGEDOCUMENT_DISPLAY
    Edited by: Arunima Rudra on Apr 14, 2009 4:49 PM

Maybe you are looking for