How to use Cursor's Fetch to return multiple column Data

Hi ,
This is my Table :
SQL> select * from Login;
USERNAME PASSWORD CONFIRMPASSWORD
RAvi SAI SAI
Kiran Keyboard Keyboard
VARNU JAINA JAINA
This is my stored Procedure , for that Table , this is working fine , where he Cursor's Fetch is returning only a Single column of Data .
CREATE OR REPLACE PROCEDURE getEmpName(EMP_ID IN VARCHAR2)
IS
EMPNAME VARCHAR2(50);
CURSOR MYCUR
IS
SELECT USERNAME from login where USERNAME=EMP_ID;
BEGIN
OPEN MYCUR ;
LOOP
FETCH MYCUR  INTO EMPNAME;
DBMS_OUTPUT.PUT_LINE(EMPNAME);
EXIT WHEN MYCUR%NOTFOUND;
END LOOP;
close MYCUR ;
END;
Now , I have a requirement as , i need to get the Password also along with Username ,
Please tell me how can i use FETCH of Cursor to populate Details into the Declared Variables
FETCH MYCUR  INTO EMPNAME;
CREATE OR REPLACE PROCEDURE getEmpName(EMP_ID IN VARCHAR2)
IS
EMPNAME VARCHAR2(50);
PASSWORD VARCHAR2(50);
CURSOR MYCUR
IS
SELECT USERNAME , PASSWORD from login where USERNAME=EMP_ID;
BEGIN
OPEN MYCUR ;
LOOP
FETCH MYCUR  INTO EMPNAME; // Help needed here**
DBMS_OUTPUT.PUT_LINE(EMPNAME);
EXIT WHEN MYCUR%NOTFOUND;
END LOOP;
close MYCUR ;
END;
Edited by: user10503747 on Oct 14, 2010 11:51 AM
Edited by: user10503747 on Oct 14, 2010 11:52 AM

1) I'm hoping that this is a homework assignment. You would never, in the real world, store a password in clear text. And you would never, from a database design, have separate Password and ConfirmPassword columns.
2) The INTO clause can accept a list of variables. So
FETCH your_cursor_name INTO local_variable1, local_variable2;would be valid.
3) You would generally want to avoid having local variables that share the name of a column-- that leads to some pretty serious confusion related to scoping. One common convention is to prefix local variables with a "l_".
4) You would generally want local variables to inherit the type of the column rather than explicitly declaring the length of a string in your procedure. That way, if you change the table in the future, your code will continue to work.
5) And finally, a procedure that just calls DBMS_OUTPUT would cause all sorts of red flags in reality. It would make far more sense for this to be a function that returns a value than a procedure that tries to write to a buffer that the client application may or may not have created.
Justin

Similar Messages

  • How to use one dynamic connection managers for multiple parallel data flow tasks

    hi there:
       I have 6 databases residing on the same server. What I want to do is  call a store procedure with identical name on each database dbo schema and transport results to a centralized place. The key is to have those SPs run in parallel instead
    of in sequence as each SP may take around 10 mins to finish. 
    The simplest way is to create 6 OLE DB connection managers and create 6 DFT tasks. However, I do not want to maintain 6 OLE DB connection managers as there is a chance to have more connection  managers.
     What I did so far is to create a OLD DB connection manager and use expression to set up connectionString properties so that it will get populated by variables at run time. It is fine when running all SPs in a Foreach Loop Container. However, it takes
    around 60 mins to finish.
      When I try to run it in parallel ( basically created 6 DFTs but use only one Dynamic Connection Manager), the connection string gets confused therefore all DFT tasks failed.
       Does anyone here have some experience on this topic?
    Thanks
     hui
    --Currently using Reporting Service 2000; Visual Studio .NET 2003; Visual Source Safe SSIS 2008 SSAS 2008, SVN --

    Yes, basically, on the connectionString property of ONE OLEDB, you are using an expression to supply value and this expression is pointing to a variable. 
    In this case , you can update this variable from a table which contains many connection strings. It's good if you want to execute Store procedures in a sequential order. When in parallel mode, this will cause issues as connectionString gets overwritten. 
     I am thinking about using script task to exec sp.
     The whole idea is that I do not want to maintain a large number of Connection Managers. 
    Hope it helps
    --Currently using Reporting Service 2000; Visual Studio .NET 2003; Visual Source Safe SSIS 2008 SSAS 2008, SVN --
    So you are not able to run parallel executions using same conn mgmr, even with dynamic connectionstring, is that correct? Yes, script task will be a way to go if you wish to execute it in parallel, you may connect to SS and query the proper conn string with
    SELECT/WHERE clause in each script > pass it to a script variable > use that script variable and execute the proc. This will require only two things to change in each script, the WHERE condition to get the conn string and the proc name (you may even
    get the proc names the same way you get conn string) and everything else will be same. Let us know how that goes. 
    Hope no two or more procs doing insert/update/delete on the same tables.

  • How to use cursors in abap

    Hi,
        How to use cursor(sql Cursor) in abap program  could any one help me..
    Advance Thanks
    Regards
    Guhapriyan

    Hi Guhapriyan,
    Have a look at demo programs DEMO_SELECT_CURSOR_1, DEMO_SELECT_CURSOR_2 and DEMO_SELECT_CURSOR_3.
    Thanks
    Lakshman

  • How to use the same POWL query for multiple users

    Hello,
    I have defined a POWL query which executes properly. But if I map the same POWL query to 2 portal users and the 2 portal users try to access the same page simultaneously then it gives an error message to one of the users that
    "Query 'ABC' is already open in another session."
    where 'ABC' is the query name.
    Can you please tell me how to use the same POWL query for multiple users ?
    A fast reply would be highly appreciated.
    Thanks and Regards,
    Sandhya

    Batch processing usually involves using actions you have recorded.  In Action you can insert Path that can be used during processing documents.  Path have some size so you may want to only process document that have the same size.  Look in the Actions Palette fly-out menu for insert path.  It inserts|records the current document work path into the action being worked on and when the action is played it inserts the path into the document as the current work path..

  • How to use C:when test... inside column in ADF table

    I am using ADF table with below two columns
    in First column i have to check the Type of document if it is doc type then i have to use commondlink to download that file ,Otherwise i need to show only text.
    for that i added
    *<c:when test="{boolean($favoriteType eq 'doc')}">*
    which is not working .
    please let me know how to use <C:when test... inside column in ADF table
    <tr:column sortProperty="favoriteName" sortable="true"
    headerText="#{res['favorite.favoritename']}"
    width="500" noWrap="false">
    <c:choose>
    *<c:when test="{boolean($favoriteType eq 'doc')}">*
    <tr:commandLink actionListener="#{bindings.downloadFile.execute}"
    text="#{row.favoriteName}"
    disabled="#{!bindings.downloadFile.enabled}"/>
    </c:when>
    <c:otherwise>
    <af:outputText value="#{row.favoriteName}"/>
    </c:otherwise>
    </c:choose>
    </tr:column>
    <tr:column sortProperty="favoriteType" sortable="true"
    headerText="#{res['favorite.favoriteType']}" rendered="true">
    <af:outputText value="#{row.favoriteType}" id="favoriteType"/>
    </tr:column>

    Hi Frank,
    Thanks it is working like cham..
    related to same page i am facing new problem which i posted at below thread
    How to get row data runtime @ trinidad table , set rowSelection="multiple"
    can u reply on same.
    Thanks for all help.
    Jaydeep

  • How to use ni-6008 and build a four channel data acquisition at a rate of 250 samples per channel and display all the data in a waveform chart

    how to use ni-6008 and build a four channel data acquisition at a rate of 250 samples per channel and display all the data in a waveform chart 

    Hi kdm,
    please stick in one thread for the same topic!
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Select function that returns multiple columns.

    Currently I have a function that will return 1 column and I can use that in a select statement. What I need is to return multiple columns from a table. In the function I have I return the street address from a table that holds information about dealers, I need to be able to also return the columns that contain the city, state, and zip code so it can be used in an sql select statement. How would I do this?
    My function:
    FUNCTION GET_ADDRESS(dealer_id IN number)
    RETURN tbl_dealer_info.c_street%TYPE AS
    v_rc tbl_dealer_info.c_street%TYPE;
    CURSOR get_dealer_cur IS
    SELECT c_street
    FROM tbl_dealer_info
    WHERE n_dealer_id = dealer_id;
    BEGIN
    v_rc := NULL;
    OPEN get_dealer_cur;
    FETCH get_dealer_cur INTO v_rc;
    IF get_dealer_cur%NOTFOUND THEN
    NULL;
    END IF;
    CLOSE get_dealer_cur;
    RETURN v_rc;
    EXCEPTION
    WHEN OTHERS THEN
    RETURN NULL;
    END GET_ADDRESS;
    My select statement:
    select GET_ADDRESS(1205) Street, DI.n_inactive_flag, DI.n_onhold_flag
    from tbl_dealer_info DI
    where DI.n_dealer_id = 1205;
    I would like to be able to select the street, city, state, and zip all in this select statement from the GET_ADDRESS function.
    Thanks,
    Lori Neirynck

    "The reality is you've probably already put your blinders on and you won't learn the best approach to solving your problem because you insist on asking a courtroom style question (just "yes" or "no" please)."
    Actually, I asked this question because I was looking for the best approach to my problem. I have an SQL statement that correctly selects everything it needs to from all 15 tables. The thing of it is it is very long and difficult to read. I wanted to try using functions so that I could change 12 AND/OR statements into 3 IF statements so everything is easier to read. I have received a couple of different ways to do this from other forums that assumed I knew what I was doing. I have gotten one to work, the other I'm still working on. I'll post the one that worked for others that want to know.
    SQL> insert into dealer_info values (1,'Me','13 success street', 'Wonder Town','Wonderland','1313');
    SQL> commit;
    SQL> create type t_address as object (
    2 street varchar2(100),
    3 city varchar2(30),
    4 state varchar2(30),
    5 zip varchar2(10));
    6 /
    Type created.
    SQL> create or replace function get_address (p_id number) return t_address
    2 is
    3 ret t_address := t_address(null,null,null,null);
    4 rec dealer_info%rowtype;
    5 begin
    6 select * into rec from dealer_info where id=p_id;
    7 ret.street := rec.street;
    8 ret.city := rec.city;
    9 ret.state := rec.state;
    10 ret.zip := rec.zip;
    11 return ret;
    12 end;
    13 /
    Function created.
    SQL> col name format a10
    SQL> col address format a70
    SQL> select name, get_address(id) address from dealer_info;
    NAME ADDRESS(STREET, CITY, STATE, ZIP)
    Me T_ADDRESS('13 success street', 'Wonder Town', 'Wonderland', '1313')
    1 row selected.
    -Lori

  • SELECT in SELECT returning multiple columns ?

    10.2.0.3 version.
    I am trying to tune this query
    SELECT A.EMPLID, A.EFFDT, A.ACAD_PROG,
    (SELECT A1.DESCR FROM PS_ACAD_PROG_TBL A1
    WHERE A1.INSTITUTION = 'AUAO1' AND A1.ACAD_PROG = A.ACAD_PROG AND A1.EFFDT = (SELECT MAX (EFFDT) FROM PS_ACAD_PROG_TBL WHERE INSTITUTION = A1.INSTITUTION AND ACAD_PROG = A1.ACAD_PROG),
    (SELECT A2.DESCRSHORT FROM PS_ACAD_PROG_TBL A2
    WHERE A2.INSTITUTION = 'AUAO1' AND A2.ACAD_PROG = A.ACAD_PROG AND A2.EFFDT = (SELECT MAX (EFFDT) FROM PS_ACAD_PROG_TBL WHERE INSTITUTION = A2.INSTITUTION AND ACAD_PROG = A2.ACAD_PROG),
    as you can see it reading the table PS_ACAD_PROG_TBL two time to get two cloumns DESCR (alias A1) and DESCRSHORT (alias A2) exactly with the same where condition.
    I am trying to replace it with just one select returning multiple columns like this
    SELECT A.EMPLID, A.EFFDT, A.ACAD_PROG,
    (SELECT A1.DESCR, A1.DESCRSHORT FROM PS_ACAD_PROG_TBL A1
    WHERE A1.INSTITUTION = 'AUAO1' AND A1.ACAD_PROG = A.ACAD_PROG AND A1.EFFDT = (SELECT MAX (EFFDT) FROM PS_ACAD_PROG_TBL WHERE INSTITUTION = A1.INSTITUTION AND ACAD_PROG = A1.ACAD_PROG),
    but I am getting ORA-00913: too many values.
    Please help on how to get around this. Thanks in advance.

    William,
    On similar lines I am struggling with the below query based on your suggestions.
    SQL*Plus: Release 9.2.0.1.0 - Production on Wed Aug 5 14:17:21 2009
    Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> WITH arch_dup AS
      2       (SELECT   a.file_id,
      3                 a.sale_start,
      4                 a.activity_start,
      5                 a.activity_end,
      6                 a.item_code_cust,
      7                 a.division,
      8                 (SELECT MAX (DISTINCT (NVL (b.advertised, 'No')))
      9                    FROM ah_cust_gis_arch_stg b
    10                   WHERE b.file_id = a.file_id
    11                     AND NVL (b.sale_start, 'NULL') = NVL (a.sale_start, 'NULL')
    12                     AND NVL (b.activity_start, 'NULL') = NVL (a.activity_start, 'NULL')
    13                     AND NVL (b.activity_end, 'NULL') = NVL (a.activity_end, 'NULL')
    14                     AND b.item_code_cust = a.item_code_cust
    15                     AND b.division = a.division) advertised,
    16                 COUNT (*)
    17            FROM ah_cust_gis_arch_stg a
    18           WHERE a.file_id = 209
    19             AND a.status_id = 21
    20        GROUP BY a.file_id, a.sale_start, a.activity_start, a.activity_end, a.item_code_cust, a.d
    ivision
    21          HAVING COUNT (*) > 1)
    22  SELECT dup.*,
    23         (SELECT activity_id
    24            FROM (SELECT activity_id,
    25                         ROW_NUMBER () OVER (ORDER BY (activity_retail / activity_mult)) rnk
    26                    FROM ah_cust_gis_arch_stg
    27                   WHERE status_id = 21
    28                     AND NVL (sale_start, 'NULL') = NVL (dup.sale_start, 'NULL')
    29                     AND NVL (activity_start, 'NULL') = NVL (dup.activity_start, 'NULL')
    30                     AND NVL (activity_end, 'NULL') = NVL (dup.activity_end, 'NULL')
    31                     AND item_code_cust = dup.item_code_cust
    32                     AND division = dup.division
    33                     AND file_id = 209
    34                     AND UPPER (NVL (advertised, 'N')) = dup.advertised)
    35           WHERE rnk = 1) activity_id
    36    FROM arch_dup dup;
                       AND UPPER (NVL (advertised, 'N')) = dup.advertised)
    ERROR at line 34:
    ORA-00904: "DUP"."ADVERTISED": invalid identifierCan you throw some light on what to do to make the outer query columns available to inner query?
    Thanks,
    Raj.

  • How to change the year in a range of column dates to the new year?

    How to change the year in a range of column dates to the new year?

    Depends on the pattern of the dates. The last procedure will work for any pattern, or no pattern at all.
    For examples.the dates are assumed to be in column A, starting at A2
    Sequential dates?
    Enter first updated date in the first cell.
    Enter =A2+1 in cell A3. Copy the cell.
    Select A3 to the end of the list. Paste.
    With the cells still selected, Copy, then go Edit > Paste Values.
    Evenly spaced dates?
    Same procedure as above, but replace +1 in the formula with + and the number of days between dates in the list.
    Randomly spaced dates?
    Select cell B2. Press option-left arrow to insert a (temporary) column to the left of column B.
    Click on the empty cell B2 in the new column. Enter the formula below:
    =DATE(YEAR(A)+1,MONTH(A),DAY(A))
    Copy the cell, then select B2 - Bn where n is the last ow containing a date to be converted. Paste,
    With the cells still selected, Copy.
    Click on A2, then go Edit > Paste values.
    Click on the column B reference tab to select all of column B.
    Hover the mouse over the right end of the reference tab, and click the black triangle when it appears.
    Choose Delete Column from the menu that appears.
    Regards,
    Barry

  • Stored procedure in  package return multiple columns from multiple tables

    Hi ,
    Can a single stored procedure return multiple column values from different tables.
    example:
    tabA: col2, tabB:col3,tabC:col4 etc.
    one more question:
    if a stored procedure like to return 10 columns for a particular record from a single table do i need to define a TYPE statement for each colum like
    TYPE col1 is TABLE of varchar
    TYPE col2 is TABLE of varchar
    here i want to return only one row, not many rows.
    thanks

    You can try one procedure with OUT or IN/OUT parameters that collect the values from one or more sql statements.
    CREATE OR REPLACE PROCEDURE P1
    (P_COD IN TABLE.COD%TYPE,
    P_DESC1 OUT TABLE1.DESC1%TYPE,
    P_DESC2 OUT TABLE2.DESC2%TYPE)
    IS
    BEGIN
    SELECT table1.DESC1, table2.DESC2
    INTO P_DESC1, P_DESC2
    FROM TABLE1, table2 WHERE
    table1.COD = P_COD and
    table1.cod = table2.cod ;
    END P1;
    JP

  • How to use cursor in php?

    for example:
    CURSOR CUR_ORDER IS
    select distinct a.sales_branch segment2,a.order_number,
    a.delivery_id,
    a.sold_to_customer_id customer_id,
    a.bill_to_customer_id,
    a.ship_to_customer_id,
    a.purchase_order,to_char(a.ordered_date,'yyyy-mm-dd') order_date
    from vv_ar_temp_tl a;
    how to use it in php program?

    Hi,
    I do not know what exactly is Your question about. I'll try to give an overview:
    1. "CURSOR CUR_ORDER IS" is PL/SQL syntax, not PHP
    2. result of oci_parse call is in fact a CURSOR, so I think You already know how to use it.
    3. if Your question is on how to pass cursor between PL/SQL and PHP, I use:
    a) PL/SQL procedure:
    CREATE OR REPLACE
    PROCEDURE TEST_P (PO_REF_CURSOR OUT SYS_REFCURSOR) AS
    BEGIN
    OPEN PO_REF_CURSOR FOR -- Opens ref cursor for query
    SELECT OBJECT_NAME, OBJECT_TYPE FROM USER_OBJECTS WHERE ROWNUM <= 5;
    END;
    b) in PHP:
    $conn = ocinlogon($database_user, $database_passwd, $database); // connect database
    $outrefc = ocinewcursor($conn); //Declare cursor variable
    $mycursor = ociparse ($conn, 'begin test_p(:curs); end;'); // prepare procedure call
    ocibindbyname($mycursor, ':curs', $outrefc, -1, OCI_B_CURSOR); // bind procedure parameters
    $ret = ociexecute($mycursor); // Execute function
    $ret = ociexecute($outrefc); // Execute cursor
    $nrows = ocifetchstatement($outrefc, $data); // fetch data from cursor
    ocifreestatement($mycursor); // close procedure call
    ocifreestatement($outrefc); // close cursor
    ocilogoff($conn); // close database connection
    var_dump($data); // show content fo $data variable
    Now $data contains arrays of columns with arrays of rows from query.
    Hope it helps You,
    Regards,
    Pawel

  • How to use standard Search Input Help (return 2 data code and desc) ?

    Hi,
    Please advise how to use standard Input Help provided by SAP and return 2 data (code and description) ? because the standard Input Help only return the code only ?
    Thank You and Best Regards
    Fernand

    >
    Saket  Abhyankar wrote:
    > Hi,
    >
    > I think you need to go for 'Search Help Exit' or OVS.
    >
    > Regards,
    >
    > Saket.
    That is not true that this is the only way.  The standard Data Dictory based search help can return more than one value as long as there are multiple exporting values defined in the search help, the search help is attached to a Data Dictionary Structure, and this same data dictionary structure is used as the source of the context node. You can read more about this in the online help:
    http://help.sap.com/saphelp_nw70ehp1/helpdata/en/47/9f724642314aabe10000000a42189b/frameset.htm
    The Note section under Integration:
    If an input help structure is stored in a field in the ABAP Dictionary, and if you want to use the field mapping of search help parameters stored in the ABAP Dictionary as the field name for the structure for your Web Dynpro input help, then map your context nodes to this structure. This ensures that all components of the structure are available dynamically at runtime as attributes of the node.
    If the context node is not mapped to the structure, the data element's input help can be used if there is one.

  • How to use cursor function for nested xml

    Hi,
    i have a query for XMLQuery like
    select * from bills where bill_id=????
    it results in something like
    <bills>
    <bill>
    <city>london</city>
    <amount>44</amount>
    </bill>
    <bill>
    <city>london</city>
    <amount>988</amount>
    </bill>
    <bill>
    <city>new york</city> <amount>59</amount> </bill>
    </bills>
    but i want xml output to be sorted for city names adding one more level location like
    <bills>
    <location city="london">
    <bill>
    <amount>44</amount>
    </bill>
    <bill>
    <amount>988</amount> </bill>
    </location>
    <location city="new york">
    <bill>
    <amount>59</amount> </bill>
    </location>
    </bills>
    it should be possible to iterate through the same table to gather informaton with the help of cursor function, but never used CURSOR before.
    any idea?

    sreese wrote:
    p_desig works as a comma delimited string without the NVL function, that's not the issue.
    It IS the issue .. you need to provide  a SAMPLE so we can see what you're doing ..
    How are you "passing it in" ?
    option A:
    procedure ( in_var  in  VARCHAR2 )
    AS
    and nvl(sn.c_attribute1,'x@#$%') in nvl(in_var,'x@#$%')
    option B:
    and nvl(sn.c_attribute1,'x@#$%') in nvl(&1,'x@#$%')
    .. or some other method?

  • How to use Cursor Paramter

    Hi all,
    My query will written values by passing 5 parameter values.
    Now i want to use this query in plsql cursor, For that i need to use cursor parameter concepts and its very new to me. so pls any one help me how to use this cursor parameter to pass the values when i run my procedure.
    Regards
    Ajantha

    If you mean writing cursor with parameters you could try this way.
    CURSOR c1 (name VARCHAR2, salary NUMBER) IS SELECT ...
    --- open the cursor:
    OPEN c1(emp_name, 3000);
    Link for more info
    http://download-uk.oracle.com/docs/cd/B10501_01/appdev.920/a96624/06_ora.htm#36656
    Thanks

  • How to use Automatic Row Fetch programmatically ?

    Hi
    I like to use Automatic Row Fetch (AFR) of APEX to populate data into a DML form page by clicking a button with a defined where_clause, and like to update the record accordingly as we did in Oracle forms execute_query procedure. I prefer Oracle provided facilities, don't want to do it manually. Any help ?....
    Hasan Al Mamun

    You will probably get a better answer if you ask this in the Apex - Oracle Application Express- forum.
    Sorry, I don't have an immediate answer for your question ;(

Maybe you are looking for

  • Satellite 2410-413: USB2 PCMCIA card doesn't work

    Good morning. It is my first time on a forum, and my English is poor. I have tried to install a PCMCIA card with 4 USB-2 ports (hw & sw) on my Satellite 2410-413 in order to use a DTV dongle (hw & sw). It will not work: The ports seem to be declared

  • Scroll Bar problem - BI Iview

    Hi, I've created a BW iView and added it to a Page which is attached to a Role.  When I execute the page on the portal , I get get a 2 vertical scroll bars one for the ivew and one for the external page. But the Horizontal scroll bar is hidden below.

  • Database design vs Application/UI  design, pls help..

    Hi All, I have to define a discoun that can be given on the combinations of the folllowing attributes : CustomerGroup, CustomerType, Customer, Region, District, Area, ProductGroup, ProductBrand, Product. From the dba I get this table : CREATE TABLE P

  • Dynamic Routing in OSB11g.

    I have 3 Proxy services (TestSbServices1,TestSbServices2,TestSbServices3) with protocol as sb and service type as Any XML. I am try to use Dynamic routing to route the input message to one of the above 3 proxy services. My dynamic route action has be

  • Why won't my podcasts play in iTunes?

    https://itunes.apple.com/ca/podcast/den-andre-podcasten/id670277522?mt=2 I got this submitted some days ago. It runs through feedburner from soundcloud and blogger. The RSS-feed seems to work fine in other software. And I am able to download it perfe