How to make FUNCTION returns several columns and several outputs line

Hi all

Kindly share your idea; Thanks in advance;

I have the demo of the Table.

DEMO table:

name identity
1 to 10
1-a11
1-a12
2-b10
2-b11
3 ccc

and the function is like:

create or replace function (number of p1) return varchar2 as
number of vid;
VNAME varchar2 (20);
Start
SELECT id, name in vid, vname from demo where id = p1;
return v1;
end;
/

This function returns the output for the id = 3;

BUT,

I need output like (input 1)

VNAME vid
1 to 10
1-a11
1-a12

A function returns a single data type.

This type of data can be a type of atomic data (varchar2, number etc.) or it may be a type of data object to save, or even a type of collection data.

Where will you use this feature? In PL/SQL or SQL?

If you are wanting to use it in SQL, need you a pipeline for example function

SQL> CREATE OR REPLACE TYPE myemp AS OBJECT
  2  ( empno    number,
  3    ename    varchar2(10),
  4    job      varchar2(10),
  5    mgr      number,
  6    hiredate date,
  7    sal      number,
  8    comm     number,
  9    deptno   number
 10  )
 11  /

Type created.

SQL> CREATE OR REPLACE TYPE myrectable AS TABLE OF myemp
  2  /

Type created.

SQL> CREATE OR REPLACE FUNCTION pipedata(p_min_row number, p_max_row number) RETURN myrectable PIPELINED IS
  2    v_obj myemp := myemp(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
  3  BEGIN
  4    FOR e IN (select *
  5              from (
  6                    select e.*
  7                          ,rownum rn
  8                    from (select * from emp order by empno) e
  9                   )
 10              where rn between p_min_row and p_max_row)
 11    LOOP
 12      v_obj.empno    := e.empno;
 13      v_obj.ename    := e.ename;
 14      v_obj.job      := e.job;
 15      v_obj.mgr      := e.mgr;
 16      v_obj.hiredate := e.hiredate;
 17      v_obj.sal      := e.sal;
 18      v_obj.comm     := e.comm;
 19      v_obj.deptno   := e.deptno;
 20      PIPE ROW (v_obj);
 21    END LOOP;
 22    RETURN;
 23  END;
 24  /

Function created.

SQL> select * from table(pipedata(1,5));

     EMPNO ENAME      JOB               MGR HIREDATE                    SAL       COMM     DEPTNO
---------- ---------- ---------- ---------- -------------------- ---------- ---------- ----------
      7369 SMITH      CLERK            7902 17-DEC-1980 00:00:00        800                    20
      7499 ALLEN      SALESMAN         7698 20-FEB-1981 00:00:00       1600        300         30
      7521 WARD       SALESMAN         7698 22-FEB-1981 00:00:00       1250        500         30
      7566 JONES      MANAGER          7839 02-APR-1981 00:00:00       2975                    20
      7654 MARTIN     SALESMAN         7698 28-SEP-1981 00:00:00       1250       1400         30

SQL> select * from table(pipedata(6,10));

     EMPNO ENAME      JOB               MGR HIREDATE                    SAL       COMM     DEPTNO
---------- ---------- ---------- ---------- -------------------- ---------- ---------- ----------
      7698 BLAKE      MANAGER          7839 01-MAY-1981 00:00:00       2850                    30
      7782 CLARK      MANAGER          7839 09-JUN-1981 00:00:00       2450                    10
      7788 SCOTT      ANALYST          7566 19-APR-1987 00:00:00       3000                    20
      7839 KING       PRESIDENT             17-NOV-1981 00:00:00       5000                    10
      7844 TURNER     SALESMAN         7698 08-SEP-1981 00:00:00       1500          0         30

SQL> select * from table(pipedata(11,15));

     EMPNO ENAME      JOB               MGR HIREDATE                    SAL       COMM     DEPTNO
---------- ---------- ---------- ---------- -------------------- ---------- ---------- ----------
      7876 ADAMS      CLERK            7788 23-MAY-1987 00:00:00       1100                    20
      7900 JAMES      CLERK            7698 03-DEC-1981 00:00:00        950                    30
      7902 FORD       ANALYST          7566 03-DEC-1981 00:00:00       3000                    20
      7934 MILLER     CLERK            7782 23-JAN-1982 00:00:00       1300                    10

SQL>

If you use it in PL/SQL and then just filling a data type of collection and return that will make. Although you should question why you want to pass large amounts of data around like that first.

Explain your purpose and what you intend to do and we can recommend the best way.

{message: id = 9360002}

Tags: Database

Similar Questions

  • How to make a form with report and a form of inclusion in the same page?

    Hey, guys:

    I was wondering if you could have any link or examples to show how to make a form with report and a form of inclusion in the same page, these two forms are related to the same table. Our customer wants that a user can add a new row to the table in a form and see all lines created by this user in a report, the report should provide link change as well. the problem is: whenever I inserted a new line or change a line or delete a line, and submitted and return to this page, all hidden elements lost their values, this report is empty, and some display only items also lost their values. Could someone give me any suggestions?

    Thank you very much!

    Sam

    So, the problem is essentially with page elements lose their session state values when re-loading of the page. How do you define values for the elements of the hidden page? You have default values defined for those? They are based on the database column? What is the "Source" parameter for these items on the page? It is set to "Always, replace any value in session state"? You have any process of 'Empty the Cache', which is reset these values to null element?

    What is your version of the Apex?

    I would recommend that you have installed for example in apex.oracle.com. This would help to better understand the issue.

    Published by: jaouad khalifi on 13 December 2012 22:11

  • What is the procedure how to make my system image backup and data through Windows NAS Server?

    I work the iMac with bootcamp for Windows 7 - Home Premium.

    I want to return to the system image and data etc. of the 'Windows Back up and Restore' to my Synology NAS (network attached storage). When I do the setting changes, I could not find the option to connect to the NAS, but have only the offer to connect to the external hard drive.

    (1) the 'Windows Back up and Restore' allows to connect to the NAS for the back of my files, in particular for the iamge system? If not, any other method to make the back upward, especially for the system image?

    (2) what is the procedure how to make my system image backup and data through Windows NAS Server?

    Original title: save the Windows image

    Backup to a network location is not supported by Windows 7 Home Premium. Do you need Windows 7 Professional or ultimate edition.

    http://Windows.Microsoft.com/en-GB/Windows7/where-should-i-save-my-backup

  • How to make the default text size and line spacing in small Sticky Notes?

    How to make the default text size and line spacing in small Sticky Notes

    Hello

    I suggest that you try the method below and check if it helps.

    Method 1: analysis of auditor of file system (CFS)

    System File Checker is a Windows utility that allows users to find corruptions in Windows system files and restore the damaged files. To perform a scan of the SFC, check out the link: https://support.microsoft.com/en-us/kb/929833.

    Note: the steps for Windows 8/8.1, works perfectly with Windows 10.

    Method 2: clean boot

    A clean boot is executed to start Windows by using a minimal set of drivers and startup programs. This will eliminate software conflicts that occur when you install a program, an update or when you run a program in Windows. Follow the link to perform the clean boot: https://support.microsoft.com/en-us/kb/929135.

    Kind regards

    Angelo bar

    Microsoft community

  • I changed a single picture to paint in Windows 7. Now, all my pictures are files of paint. How to make their return to normal JPEG?

    Normally, I use Paint on my photos.  I changed a photo to painting so that I could make a few adjustments.   Now, all my pictures are open as files of the paint.  How to make their return to the normal setting of JPEG file?

    Seems you have to change the program by default JPG/JPEG to everything that you had previously, possibly "Windows Photo Viewer?

    If so, see - http://windows.microsoft.com/en-us/windows/change-default-programs#1TC=windows-7

    Either the "set your default programs or him 'associate a file type with a program" sections. "

  • HOW TO MAKE ICONS FOR ALL FILES AND FOLDERS IN LARGE WINDOW 7

    HOW TO MAKE ICONS FOR ALL FILES AND FOLDERS IN LARGE WINDOW 7

    You can try this: -.

    Start-> Control Panel-> display
    From there, you can select medium or large. This will be the size of everything on the screen.
  • I've renamed the images in a file and now they are all out of control, how to make their return to the original order

    I opened a drive with my camera phone, then renamed the photos with brief descriptions, and now they are all out of order. How to make back in the original order they appeared.

    Dennis

    Renamed files are apparently to be sorted by alphabetical order.
    It is the normal behavior of Windows.

    If you open the folder in question and go to... View / details... and
    Select the column that says: "Date picture taken", she should use
    photos.

    Also you can drag and drop photos to change position.

    Once you have pictures in the order you need... you can re-
    Number them in a batch to maintain order.

    Just go to... Edition / select all... right click on the first file name and choose...
    Rename... Enter the next number...

    .jpg (10001)

    Press Enter and the remaining files will be named in the order.

    You can also add a word if you want to identify the group.

    Summer vacation (10001) .jpg
    (Yes, there is a space between the letter n and the first parenthesis)

  • How to make reference to a column name in the form report

    Hello
    How can I make reference to a column name in the form report. My problem is that "I have a form report that I have the column name when using click on the column name, it must get to the next page with the corresponding values of the column".

    Here, I realized that when I click on the name of the column (in page 1) it brings me to the next page (page 2). but in the next page (P2) I want to display (display only) the corresponding values of the column (page 1) selected, but the values are not editable and shouldn't be in the text box must be in display area.

    So, how can I write a SQL to display single source field. That is to say, how can I consult report form (page 1) in name column.

    Hello

    If you use the link in the column when you click on the need of the column value, you need to navigate to the next page and all the data accordingly select value here.

    Modify the report form and see the top of the page and click on report attribute.

    So now you have the attributes of the columns is to say what are the columns are available in the reports form.

    Click on change column what you need Ie the column when you click on its passage to the next page this column, for example, as mentioned in the previous post "Empname".

    Check the link column and give perspective of values according to your need and click on apply chages.

    Thank you & best regards
    Srikkanth.M

  • How to make a picture of MS and a recovery CD to my HD using Win Pro 7?

    I completely under license from MS Windows 7 Pro and Office Pro 2007.

    I recently went though a Script virus trouble which resulted in my need to blow away (reformat) the HD and install all my programs under license and all the drivers from scratch.

    How to make a disk Image of my drive C and also a bootable CD Windows, in which case I have to do this again?

    You hope that it works?

    The day you have your backup/restore tools to work is not the day to know that they don't.

    Why not make a little test... pretend that your system does not start for some reason unknown and impossible to fix and to do the image you have created to recover.

    With the stuff you have since your last operation (a picture that is stored somewhere and a bootable CD), you can at least run a test to see if you can boot from the CD, and then if you can get there far enough, see if you can at least access the images you created.

    Of course, you don't have to actually restore the image - just make sure that you can boot from the CD you have done, and from there, you can at least navigate to and find the image that you created and do things at the point choose to restore your system from this image.

    Have you checked that you can at least get there?

    I use Macrium Reflect (the free version) and keep my images on an external drive.

    I made a bootable USB drive using Macrium.

    To make me feel better about all of this, I started my system on the USB and from there I could navigate to and view system images stored on my external hard drive and could choose to restore the last picture, if I wanted to.

    Of course I didn't really want to restore that image, but at least I got far enough along to believe that if I ever need to restore from an image at least I had something that I could start now and at least find my backup of images in case I ever need to use.

    Will it really work if I ever need to use it?  The only way to know for sure would be to actually try it and see and I could do it one day, but at least it looks promising.

    If you are using built in tools MS you could do the same kind of test and if you encounter a problem and it does not you can understand what is the problem and see if you can remedy.

    Another thing to consider is that if you have a problem with the MS tools and come to this community help I think that it is extremely unlikely that you will find a lot of help with the exception of the most fundamental aspects.  Microsoft has committed that 'experts' alleged Support Engineer here seem unable to solve even the simplest problems.

    If you need assistance with your backup/restore operation I don't think you're going to get a lot of Microsoft because Microsoft is not in the business of backup/restore.  This isn't what they are doing and is not their area of expertise.  You will probably get the best help in using the tools of the companies working in the areas of backup/restore, that's all they do and that's what they are doing throughout the day.

    In these communities of MS, volunteers are always your most reliable resource for solving problems.

  • How the two function return values

    Dear all,

    Please explain, how the two values of function return?

    give a simple example.

    OK, a few examples...

    First example, using a type of structured on the database object:

    SQL > create or replace type tMyValues as an object (yr number, number, number of dy mn)
    2.

    Type of creation.

    SQL > create or replace function getMyValues return tMyValues is
    2 number of y: = extraction (year sysdate);
    number of 3 m: = extraction (sysdate months);
    number of 4 d: = extract (day of sysdate);
    5. start
    6 return new tMyValues(y,m,d);
    7 end;
    8.

    The function is created.

    SQL > set serverout on

    SQL > declare
    2 myValues tMyValues;
    3. start
    4 myValues: = getMyValues();
    5 dbms_output.put_line (' year: ' | myValues.yr);
    6 dbms_output.put_line (' month: ' | myValues.mn);
    7 dbms_output.put_line (' date: ' | myValues.dy);
    8 end;
    9.
    Year: 2015
    Month: 4
    Day: 1

    PL/SQL procedure successfully completed.

    Second example, using an associative array within PL/SQL:

    SQL > set serverout on
    SQL > declare
    2 type tMyValues is table of the index number to varchar2 (10);
    3 myValues tMyValues;
    4
    5 function getMyValues return tMyValues is
    6 retValues tMyValues;
    7. start
    8 retValues ('Year'): = extraction (year sysdate);
    9 retValues ('Month'): = extraction (sysdate months);
    10 retValues ('Day'): = extract (day of sysdate);
    11 return retValues;
    12 end;
    13. begin
    14 myValues: = getMyValues();
    15 dbms_output.put_line (' year: ' | myValues ('Year'));
    16 dbms_output.put_line (' month: ' | myValues ('Month'));
    17 dbms_output.put_line (' date: ' | myValues ('Day'));
    18 end;
    19.
    Year: 2015
    Month: 4
    Day: 1

    PL/SQL procedure successfully completed.

    For the pipeline functions, see the example I wrote on the link provided by ReemaPuri (answer No. 3) that I don't need to re - write what I did before.

  • How to make reference to a column name in the domain constraint

    When specify us a constraint check (for SQL Server) in a field, we need to enter an expression in the syntax, for example

    Len (Phone) > 7

    Later, the Modeler will exactly this expression in the SQL code. But it would be wrong as a constraint to refer to a column name in the table (which would not be 'phone').
    So, how to make the data name Modeler to a real column in the constraint domain?

    Hello

    Use the % COLUMN as a placeholder column name - len (%COLUMN%) > 7

    Philippe

  • How to create a grid with columns and gutters?

    Can someone tell me the best way to do the above?

    I hoped illustrator would have the same functionaility like inDesign to add columns and specify the width and number and column gutters.  Is it possible to do it, or can someone advise a simple way to do this?

    Way the easiest way is to draw a rectangle the size, you want the grid then it is selected

    Go to object > path > split into grid

    Enter the number of columns leave the lines as 1

    Enter the with of the gutter

    as such

    You can do something like this with text and block Options but think zI it is better to use this and put on the text.

  • Updated Firefox and now I Bing as the start page for Firefox browser. How to make Google return

    Updated Firefox 22 to 23 Firefox and now I Bing as my browser. I want Google as my browser. How to set Google as my browser on Firefox start page.

    I'm back and I solved the problem myself. That's what you have to do... (1) type in the search "topic: config ' and click 'ok' when warning is displayed; (type 2) to the research "browsers.search.selectedEngine" 3) now right-click on "browers.search.selectedEngine" and choose in the menu 'new' and now, choose "string" and just write 'Google' and click on 'ok '. She and your done. Now I have my trusty Google back as well as you. I was a little afraid at the beginning because I know if I make a mistake I would have maybe reinstall Firefox but everything worked very well and is very easy to do. Just make sure that you re - check before you click on 'ok '.

    George
    Humacao, Puerto Rico

  • iTunes started in alphabetical order my albums and playlists.  How to make their return to good order?

    Within the last week so bone, iTunes began alphabetical order my albums and playlists.  It ruins the continuity of the albums, as Dark Side of the Moon, for example.  How can I get it changed?  I don't want my music in alphabetical order.

    In songs or other views of lists sorted on the column of the album. This should albums in the correct order. If this isn't the question could you please provide a few details.

    TT2

  • I lost my music and videos how to make their return on my computer and my zune?

    our computer has a virus and when the computer man restore the computer, music and videos have disappeared how do their back, I can see them but they say I have to buy them back

    Hello

    What do you mean by you can see them, but you can buy them?

    and what do you by what they have restored the computer?

    If they have reinstalled vista read this

    a clean install wipes the hard drive clean of everything

    You cannot undo what you've done

    If you have lost data, you can try this

    http://www.Piriform.com/Recuva

    Read also:

    Since we don't know exactly how you reinstalled it seek a windows.old folder

    How to restore your personal files after you perform a custom Windows Vista or Windows 7 installation

    http://support.Microsoft.com/kb/932912

    or even return to a previous operating system by using the information in file window.old at the link below

    http://support.Microsoft.com/kb/933168

    If the above does not work:

    Try the data recovery experts

    but they are very expensive

Maybe you are looking for

  • d004au

    I use HP laptop laptop 14-d004au and install win7 But I see driver support only for win8 Please provide the driver and software for win7. such that the card NETWORK, Synaptics TouchPad Driver, driver of HP wireless button, other...

  • Not running at the maximum speed

    Hello My profile for my computer notebook (Acer Aspire v5 - 552 G) says that my processor speed is clocked at 3, 5 GHz, how ever all the measures that I took, it wornt spend 2.9 GHz. No idea what this may be due? The processor is a Dual Core of A6 -

  • can I set up my desktop to automatically load on the web site of my brother at the start?

    Is it possible to have easily a web site specific, called automatically when I turn on my computer? Or will it be manipulation with the Autoexec.bat?

  • HP DVD Writer 840b drivers

    Problems with my DVD writer and I want to return to the initial pilot and repeat.  I have hp was last updated, but it has not solved the problem. The writer is not written on the cd, it says it is but nothing sees when I try to view the files later. 

  • Salary of reference GOSI number

    HelloI have a problem with reference GOSI salary...The question is this.The user is to enter the wage GOSI - 6019and run the Express, it is deduced from correct and also correct salary gosithe user, run again the payroll for an employee in payroll ba