Fetching next value of a sequence into a variable(TextField)

Hello All,
I have another little issue that i hope someone can resolve.
I need to grab the "nextval" from a sequence, insert it into a text field or variable then read this variable to create a record in two individual tables ( one is for a PK other is the relating FK in another table )
eg:
fetch sequence.nextval into :P1_item1
then
insert into mytable values (:P1_item1, ........ )
insert into myothertable values (somekey, :P1_item1, ........ )
I assume this needs to be in a process somewhere in the application but do not know where or the code to achieve it.
Any help will be much appreciated
Thanks
Robert

Thanks for your reply. Unfortunately i could not find my answer on the link you sent me.
Any other ideas ? or do u know the code i could use to make this work ?

Similar Messages

  • Next value of the sequence is lower than the already used value

    Hello All
    Recently we have done a test migration of a Database from 10.2.0.4 to 11.2.0.2.
    The source database was open during the test migration.
    We used Datapump utility for this, first we have created the dump files using the EXPDP and then imported to the target DB using IMPDP.
    Now we are facing issues with the SEQUENCE as under mentioned
    SELECT Max(RegNr) FROM W23AS.werkProstats;
    2058292SELECT W23AS.werkRegNr.NEXTVAL FROM Dual;
    2058285As you can see the next value of the sequence is lower than the already used value.
    Can anybody point out the reason for this.
    NOTE : This particular sequence is defined with NOCACHE option.
    CREATE SEQUENCE W23AS.werkRegNr START WITH 2000000 NOCACHE;
    Thanks InAdvance
    Cheers Tapas

    Hi Keith
    Please find the details as mentioned below
    i) You did not migrate the sequences
    We migrated the Sequences too.
    ii) you migrated the entire schema but these sequences already existed and therefore were not migrated. (ignore error when object exists ).
    These sequences were not existing before.

  • Putting attribute value from java level into sessionScope variable?

    Hallo,
    is it possible to put an attribute value from java level into a sessionScope variable?
    For example when i'am in prepareSession is it possible to fill a sessionScope variable which i can use in a jspx-Site? And when how i must do it?
    Any help is appreciated.

    At the java level i make this
    private void setUserIdIntoUserDataHashtable() {
    Integer userid = getUserIdForLoggedInUser();
    Integer groupid = getGroupIdForLoggedInUser();
    Hashtable userdata = getDBTransaction().getSession().getUserData();
    if (userdata == null){
    userdata = new Hashtable();
    userdata.put(PBConstants.CURRENT_USER_ID, userid);
    userdata.put(PBConstants.CURRENT_GROUP_ID, groupid);
    And when i at the java level i can use the constants. But i don't have an interaction at this point. Thats why i don't now how to bring the values to a sessionScope variable i need later in a / some sites?

  • All values from associative array into one variable

    Hello! Please:
    I have, for example:
    DECLARE
      TYPE tb1 IS TABLE OF INTEGER INDEX BY PLS_INTEGER;
      v4 tb1;
      variable1 myType; --varray of integers
    BEGIN
      v4(1)   := 34;
      v4(2)   := 46456;
      v4(100) := 54217:
      ...  --shortly -lot of values
    END;
    /How can I get all v4(x) values into variable1?
    something like:
    FOR i IN 1..v4.COUNT
    variable1 :=...don't know
    --to have this in the variable1: variable1:= myType(34, 46456, ..., 54217, ...);
    END LOOP;Thank You for answer!

    Is this you are looking for?
    create or replace type myType is varray(500) of number;
    DECLARE
    TYPE tb1 IS TABLE OF INTEGER INDEX BY PLS_INTEGER;
    v4 tb1;
    variable1 myType:=myType(); --varray of integers
    BEGIN
    v4(1) := 34;
    v4(2) := 46456;
    v4(3) := 54217;
    FOR i IN 1..v4.COUNT loop
    variable1.extend();
    variable1(i) := v4(i);
    END LOOP;
    FOR i IN 1..variable1.COUNT loop
    dbms_output.put_line(variable1(i));
    end loop;
    END;
    /

  • Invalid object name for Next value from sequence  using sqlserver 2012

    Select SequenceName.nextVal into lint from dual ;
    Invalid object name error message is coming when using sqlserver 2012
    Please help

    Hello,
    Create the sequence and a stored procedure which returns the sequence as follows:
    CREATE SEQUENCE mySequence_tinyint AS tinyint
    GO
    CREATE PROCEDURE Central_CreateSequence
       @NextID BIGINT OUTPUT
    AS
    BEGIN
       SET NOCOUNT ON;
       SELECT @NextID = NEXT VALUE FOR mySequence_tinyint;
    END
    GO
    In PowerBuilder, run this script:
    long ll = -10
    DECLARE proc PROCEDURE FOR Central_CreateSequence @NextID = :ll OUTPUT;      
    EXECUTE proc;
    FETCH proc INTO :ll;
    CLOSE proc;
    IF SQLCA.SQLcode <> 0 THEN
    MessageBox("error", SQLCA.sqlerrtext)
    END IF
    MessageBox("", ll)
    I know there can be other ways to return the next value of the sequence...
    HTH
    Jacob

  • How I can transfer data from the database into a variable (or array)?

    I made my application according to the example (http://corlan.org/2009/06/12/working-in-flash-builder-4-with-flex-and-php/). Everything works fine. I changed one function to query the database - add the two parameters and get the value of the table in String format. A test operation shows that all is ok. If I want to display this value in the text area, I simply drag and drop service to this element in the design mode
    (<s:TextArea x="153" y="435" id="nameText" text="{getDataMeanResult.lastResult[0].name}"  width="296" height="89"  />).
    It also works fine, just a warning and encouraged to use ArrayCollection.getItemAt().
    Now I want to send the value to a variable or array, but in both cases I get an error: TypeError: Error #1010: A term is undefined and has no properties..
    How can I pass a value from the database into a variable? Thank you.
    public var nameTemp:String;
    getDataMeanResult.token = authors.getDataMean(arrayOfNumber[0], dir_id);
    nameTemp = getDataMeanResult.lastResult[0].name;
    public var nameArray:Array = new Array();
    for (var i:uint=o; i<3; i++){
    getDataMeanResult.token = authors.getDataMean(arrayOfNumber[i], dir_id);
    nameArray[i] = getDataMeanResult.lastResult[0].name;
    And how i can use syntax highlighting in this forum?

    Astraport2012 wrote:
    I have to go back to the discussion. The above example works fine when i want to get a single value of the database. But i need to pass an array and get an array, because i want to get at once all the values for all pictures tooltips. I rewrote the proposed Matt PHP-script and it works. However, i can not display the resulting array.
    yep, it won't work for Arrays, you'll have to do something slightly more intelligent for them.
    easiest way would be to get your PHP to generate XML, then read that into something like an ArrayList on your HTTPService result event (depends what you're doing with it).
    for example, you could have the PHP generate XML such as:
    <pictures>
         <location>test1.png</location>
         <location>test2.png</location>
         <location>test3.png</location>
         <location>test4.png</location>
         <location>test5.png</location>
         <location>test6.png</location>
    </pictures>
    then you'll read that in as the ResultEvent, and perform something like this on it
    private var tempAC:ArrayList = new ArrayList
    protected function getStuff_resultHandler(event:ResultEvent):void
        for each(var item:Object in event.result.pictures)
           var temp:String = (item.@location).toString();
           tempAC.addItem(temp);
    in my example on cookies
    http://www.mattlefevre.com/viewExample.php?tut=flash4PHP&proj=Using%20Cookies
    you'll see an example of how to format an XML structure containing multiple values:
    if($_COOKIE["firstName"])
            print "<stored>true</stored>";
            print "<userInfo>
                    <firstName>".$_COOKIE["firstName"]."</firstName>
                    <lastName>".$_COOKIE["lastName"]."</lastName>
                    <userAge>".$_COOKIE["userAge"]."</userAge>
                    <gender>".$_COOKIE["gender"]."</gender>
                   </userInfo>";
        else
            print "<stored>false</stored>";
    which i handle like so
    if(event.result.stored == true)
                        entryPanel.title = "Welcome back " + event.result.userInfo.firstName + " " + event.result.userInfo.lastName;
                        firstName.text = event.result.userInfo.firstName;
                        lastName.text = event.result.userInfo.lastName;
                        userAge.value = event.result.userInfo.userAge;
                        userGender.selectedIndex = event.result.userInfo.gender;
    depends on what type of Array you're after
    from the sounds of it (with the mention of picture tooltips) you're trying to create a gallery with an image, and a tooltip.
    so i'd probably adopt something like
    <picture>
         <location>example1.png</location>
         <tooltip>tooltip for picture #1</tooltip>
    </picture>
    <picture>
         <location>example2.png</location>
         <tooltip>tooltip for picture #2</tooltip>
    </picture>
    <picture>
         <location>example3.png</location>
         <tooltip>tooltip for picture #3</tooltip>
    </picture>
    etc...
    or
    <picture location="example1.png" tooltip="tooltip for picture #1"/>
    <picture location="example2.png" tooltip="tooltip for picture #2"/>
    <picture location="example3.png" tooltip="tooltip for picture #3"/>
    etc...

  • Generating next value in a custom 2 character sequence

    I am working on a customer project for creating a web portal that needs to write data back to an ancient legacy backend mainframe system.  I have never used sql server sequences before but I believe that is what I will need to use.  
    Each vendor in this application has a char(3) vendor code field.  Each transaction a vendor does is identified by a char(2) transaction code field.  The char(2) transaction code field for the legacy system is what I am trying to generate.  
    This transaction code field is 2 character alpha-numeric sequence.  I need to create a store proc to give me the next available transaction code for that vendor.  The sequence got numbers 0-9 then letters A-Z as follows:
    00,01,02....0A,0B...0Y,0Z,10,12....ZZ
    In the stored proc to get me the next available transaction code for a vender, I need to take the 3 character vendor code as in input parameter, then check the vendor transactions table to see which transaction codes exist and return the next one from the
    sequence to use next.
    Here is a very basic table def. and some sample data:
    CREATE TABLE vendor_trans
    vendor_cd char(3),
    trans_cd char(2)
    INSERT INTO [dbo].[vendor_trans]     ([vendor_cd]     ,[trans_cd])     VALUES     ( 'ABC' ,'00' )
    GO
    INSERT INTO [dbo].[vendor_trans]     ([vendor_cd]     ,[trans_cd])     VALUES     ( 'ABC' ,'01' )
    GO
    INSERT INTO [dbo].[vendor_trans]     ([vendor_cd]     ,[trans_cd])     VALUES     ( 'ABC' ,'02' )
    GO
    INSERT INTO [dbo].[vendor_trans]     ([vendor_cd]     ,[trans_cd])     VALUES     ( 'ABC' ,'04' )
    GO
    INSERT INTO [dbo].[vendor_trans]     ([vendor_cd]     ,[trans_cd])     VALUES     ( 'ABC' ,'0A' )
    GO
    INSERT INTO [dbo].[vendor_trans]     ([vendor_cd]     ,[trans_cd])     VALUES     ( 'ABC' ,'0C' )
    GO

    Just create a scalar function that will give you the next character sequence.
    Then use it on the max transaction code for the given vendor, to get their next code.
    IF EXISTS (SELECT * FROM dbo.sysobjects WHERE ID = OBJECT_ID('dbo.funNextCode') AND XTYPE IN ('FN', 'IF', 'TF'))
    DROP FUNCTION dbo.funNextCode
    GO
    CREATE FUNCTION dbo.funNextCode (@Code char(2))
    RETURNS char(2)
    AS
    BEGIN
    DECLARE @NewCode char(2)
    SELECT @NewCode = CASE WHEN RIGHT(@Code,1) != 'Z'
    THEN LEFT(@Code,1)
    ELSE CHAR(CASE LEFT(@Code,1) WHEN '9' THEN 64
    WHEN 'Z' THEN 47
    ELSE ASCII(LEFT(@Code,1))
    END + 1)
    END
    + CHAR(CASE RIGHT(@Code,1) WHEN '9' THEN 64
    WHEN 'Z' THEN 47
    ELSE ASCII(RIGHT(@Code,1))
    END + 1)
    RETURN @NewCode
    END
    GO
    -- UNIT TEST funNextCode
    DECLARE @TableOfCodes TABLE (idx int IDENTITY(1,1), Code char(2))
    DECLARE @Code char(2) = 'ZZ'
    ,@Count int = 0
    WHILE @Count < ((36 * 36) + 1)
    BEGIN
    SELECT @Code = dbo.funNextCode(@Code)
    INSERT @TableOfCodes SELECT @Code
    SELECT @Count = @Count + 1
    END
    SELECT * FROM @TableOfCodes ORDER BY idx
    --SELECT * FROM @TableOfCodes ORDER BY Code
    -- Using funNextCode with vendors
    DECLARE @VendorTransactions TABLE (VendorCode char(3), TransCode char(2))
    INSERT @VendorTransactions VALUES ('ABC', '00'), ('ABC', '01'), ('ABC', '02')
    ,('ABC', '04'), ('ABC', '0A'), ('ABC', '0C')
    DECLARE @VendorCode char(3)
    ,@LastCode char(2)
    SELECT @VendorCode = 'ABC'
    -- Get the last code for the given vendor
    SELECT @LastCode = MAX(TransCode)
    FROM @VendorTransactions
    WHERE VendorCode = @VendorCode
    -- If no code exists, then set it so funNextCode will generate the starting code as '00'
    SELECT @LastCode = ISNULL(@LastCode, 'ZZ')
    SELECT dbo.funNextCode(@LastCode) as [NextCode]

  • Best way to get sequence.next value in pl-sql/triggers

    Hi,
    I want to know the best practice about to get the sequence.next value in pl-sql procedures / triggers from the below two methods.
    1. SELECT PRINT_BATCH_SEQ.NextVal INTO PSQNO FROM DUAL;
    INSERT INTO TABLE R1TMP VALUES (PSQNO, '12-MAR-06');
    2. INSERT INTO TABLE R1TMP VALUES (PRINT_BATCH_SEQ.NextVal, '12-MAR-06');
    From the above two statements which one is best with respect to performance / parsing /memory usage.
    Kindly give your suggession please.
    Thanks,
    Riaz.

    Hi,
    Thanks for your immediate reply.
    My thought was
    1. when we do like this, at the time of insert the cost of the operation will be more and this will lead some performance issue as bulk insert.
    2. If we get it from dual and send the value as bind variable, then we can avoid the parsing of the sql.
    Please correct me if i am wrong.
    thanks,
    riaz.

  • Fetches more values into one variable

    Hi, inside a cursor loop I'd like to assign, each fetch, a value to a variable, in order, at the end to have a collection of all the values fetched into the same variable.
    The code is the following:
    CREATE OR REPLACE procedure APPS.AAA as
    v_pino varchar2(64);
    CURSOR tks_opened_range IS
    SELECT incident_number AS YP_TKS_OPENED_WITHIN_RANGE FROM cs.cs_incidents_all_b a, cs_incident_statuses_b b, Cs_Incident_Statuses_Tl c
    WHERE b.incident_status_id = c.incident_status_id
    AND a.incident_status_id = b.incident_status_id
    AND (b.attribute1 <> '3' OR b.attribute1 IS NULL)
    AND c.language = 'EL'
    AND ((sysdate - to_date(incident_attribute_6, 'dd-mm-yyyy hh24:mi'))*1440) BETWEEN 1 AND 11111111111
    AND incident_attribute_2 IN ('ΓΕΝΙΚΗ ΔΙΕΥΘΥΝΣΗ ΤΕΧΝΟΛΟΓΙΑΣ')
    ORDER BY incident_number;
    rec_tks_opened_range tks_opened_range%ROWTYPE;
    begin
    FOR rec_tks_opened_range IN tks_opened_range
    LOOP
    v_pino := rec_tks_opened_range.YP_TKS_OPENED_WITHIN_RANGE;
    DBMS_OUTPUT.PUT_LINE('v_pino: ' || v_pino);
    end loop;
    end AAA;
    This works with the variable v_pino!....but at the end, the value of the variable v_pino is ONLY the last fetched by the cursor.
    Is there a way to declare a variable (or better a collection) or a new type in order to have all the data fetched into this variable and the end of the fetching ?
    I need to know this trick because, after, I have to assign this variable to a pipelined table function.
    Thanks in advance
    Alex
    /

    Great Devang !! Thanks a lot ! It works ! Now I am able to retrieve all the values I need and store them into my variable gino
    I searched on the note you mentioned in your mail in order to pass an array as a variable to a table function (PIPE ROW call), but I didn't find nothing about it.
    Now I explain to you my situation.
    I already implemented a table function that works perfectly. I have 2 cursors declared and 2 PIPE ROW calls.
    FUNCTION statistic_report_2_1 (p_resolv_time_ll varchar2, p_resolv_time_ul varchar2, p_ypiresia varchar2)
    RETURN xxi_statistic_rep_2_1_tab PIPELINED
    IS
    -- CURSORS FOR THE FIRST SHEET - Tickets opened per group and per duration
    -- Cursor for tickets opened within 1 hour --
    CURSOR tks_opened_1_h IS
    SELECT incident_number AS YP_TKS_OPENED_WITHIN_1_HOUR
    FROM cs.cs_incidents_all_b a, cs_incident_statuses_b b, Cs_Incident_Statuses_Tl c
    WHERE b.incident_status_id = c.incident_status_id
    AND a.incident_status_id = b.incident_status_id
    AND (b.attribute1 <> '3' OR b.attribute1 IS NULL)
    AND c.language = 'EL'
    AND ((sysdate - to_date(incident_attribute_6, 'dd-mm-yyyy hh24:mi'))*1440) < 60
    AND incident_attribute_2 IN (SELECT * FROM TABLE(CAST(xxi_szf_discoverer.ypiresia_values(p_ypiresia) AS xxi_ypiresia_list_tab)))
    ORDER BY incident_number;
    rec_tks_opened_1_h tks_opened_1_h%ROWTYPE;
    -- Cursor for tickets opened between 1 hour and 3 hours --
    CURSOR tks_opened_1_3_h IS
    SELECT incident_number AS YP_TKS_OPENED_BE_1_3_HOURS FROM cs.cs_incidents_all_b a, cs_incident_statuses_b b, Cs_Incident_Statuses_Tl c
    WHERE b.incident_status_id = c.incident_status_id
    AND a.incident_status_id = b.incident_status_id
    AND (b.attribute1 <> '3' OR b.attribute1 IS NULL)
    AND c.language = 'EL'
    AND ((sysdate - to_date(incident_attribute_6, 'dd-mm-yyyy hh24:mi'))*1440) BETWEEN 60 AND 179
    AND incident_attribute_2 IN (SELECT * FROM TABLE(CAST(xxi_szf_discoverer.ypiresia_values(p_ypiresia) AS xxi_ypiresia_list_tab)))
    ORDER BY incident_number;
    rec_tks_opened_1_3_h tks_opened_1_3_h%ROWTYPE;
    PRAGMA AUTONOMOUS_TRANSACTION;
    BEGIN
    -- FIRST SHEET OPEN CURSORS --
    TICKETS NUMBER OPENED WITHIN 1 HOUR
    FOR rec_tks_opened_1_h IN tks_opened_1_h
    LOOP
    PIPE ROW(stat_rep_2_1_type(
    rec_tks_opened_1_h.YP_TKS_OPENED_WITHIN_1_HOUR
    END LOOP;
    -- TICKETS NUMBER OPENED BETWEEN 1 HOUR AND 3 HOURS --
    FOR rec_tks_opened_1_3_h IN tks_opened_1_3_h
    LOOP
    PIPE ROW(stat_rep_2_1_type(
    ,rec_tks_opened_1_3_h.YP_TKS_OPENED_BE_1_3_HOURS));
    END LOOP;
    RETURN;
    END statistic_report_2_1;
    But, in this way and with this syntax, I obtain for each PIPE ROW call only one field filled each time, because I can’t call 2 cursors in a nested loop together (data duplication);
    For example:
    1st PIPE ROW call : only the first field is filled and into the second I have to put ‘’
    2nd PIPE ROW call : only the second field is filled and into the first I have to put ‘’
    ….and I cant’ call with a single PIPE ROW call two cursor variables…..
    Into a Discoverer report this data layout is really bad (you can imagine with thousand
    of records).
    For this reason I thought to use an array variable (gino) to pass to a single PIPE ROW call outside the cursor loop……but it doesn’t work !!!
    Can you suggest me how to resolve this problem….if it possible ?
    Did I have to declare other TYPE or collection ?
    Thanks you so much
    Alex

  • Need to fetch function code value of push button into BUS

    He expert,
                       I have created one custom screen in standard transaction IQ02.where I am populating some values into screen and one push button is there.I want to trigger the workflow only when user press this push button.I am using BUS DEVICE for that.
    Is it possible to fetch function code value of push button into the BUS object by creating custom attributes.So i can put the function code value as a condition before triggering workflow.or is there any other way to  to implement the above functionality.
    Please suggest.

    Hi,
    I'd say you need to delegate the std DEVICE object to your own ZDEVICE, where you define a custom event. Then generate the DEVICE.CUSTOMEVENT event when the user clicks on your pushbutton (eg. with SAP_WAPI... function module).
    In your workflow remove the standard triggering event and use your custom event instead.
    Cheers,
    Patrick

  • Using a single sequence value over multiple scripts (in a variable?)

    Hi all...
    I'm writing a number of scripts that insert rows into tables.
    To better explain my point, I'll paste a simple breakdown of the scripts here as that will be easier to understand...
    Script 1:
    INSERT INTO WORKGROUP_DEPARTMENTS(ID, DEPT_NAME, DEPT_TYPE)
    VALUES (SEQ_WGDPT.NEXTVAL, 'Staff', 3);
    Script 2:
    INSERT INTO WORKGROUP_SECTIONS(ID, SECT_NAME, WGDPT_ID)
    VALUES (SEQ_WGSEC.NEXTVAL, 'Staff 1',
    (SELECT ID FROM WORKGROUP_DEPARTMENTS
    WHERE DEPT_NAME = 'Staff'
    AND DEPT_TYPE = '3')
    Script 3:
    INSERT INTO WORKGROUPS(NAME, UNIT_TYPE, WGSEC_ID)
    VALUES ('Staff Room', 3,
    (SELECT ID FROM WORKGROUP_SECTIONS
    WHERE SECT_NAME = 'Staff 1')
    As you can see, in scripts 1 and 2 a new value is produced from a sequence (SEQ_WGDPT & SEQ_WGSEC respectively). Then, in scripts 2 & 3 (respectively) these values are inserted into another table.
    What I'm trying to figure out is: can I do the same thing here without having to include the horrible SELECT statements in scripts 2 & 3 in order to find the ID, which was produced by the sequence in the previous script?
    Unfortunately they do have to be separate scripts, and as such I can't call Sequence.CurrVal from a different script as other users may have used the sequence since it was used initially in the previous script. I could call it from the original calling script, and save it intop a variable, but I have no idea how to - even if it is the right idea!
    I tried to insert the sequence value into a variable a la PL/SQL so that I could call this variable from the next script, but failed miserably as I'm rubbish!
    Any help would be great. Thanks.

    You can use PL/SQL, for example:
    SQL> desc t
    Name                                      Null?    Type
    ID                                                 NUMBER
    NAME                                               VARCHAR2(10)
    SQL> desc t1
    Name                                      Null?    Type
    ID                                                 NUMBER
    NAME                                               VARCHAR2(10)
    ID1                                                NUMBER
    SQL> desc t2
    Name                                      Null?    Type
    ID                                                 NUMBER
    NAME                                               VARCHAR2(10)
    ID2                                                NUMBER
    SQL> create sequence seq_1;
    Sequence created.
    SQL> declare
      2   prev_id number;
      3  begin
      4   insert into t values(seq_1.nextval,'A')
      5   returning id into prev_id;
      6   insert into t1 values(seq_1.nextval,'B',prev_id)
      7   returning id into prev_id;
      8   insert into t2 values(seq_1.nextval,'C',prev_id);
      9  end;
    10  /
    PL/SQL procedure successfully completed.
    SQL> select * from t;
            ID NAME
             1 A
    SQL> select * from t1;
            ID NAME              ID1
             2 B                   1
    SQL> select * from t2;
            ID NAME              ID2
             3 C                   2
    Rgds

  • How to fetch n records at a time from a FM and then fetch next n records

    I have a report program which is calling a function module . This function module returns all the records from a table. As the table has millions of records, it cant be returned at a time. How can we return N records from a function module and then return Next n records .The Function module and the report program are in different system .
    Thanks in Advance.

    Use open cursor and fetch cursor.
    Check the program as in SAP Help.
    DATA: BEGIN OF count_line,
            carrid TYPE spfli-carrid,
            count  TYPE i,
          END OF count_line,
          spfli_tab TYPE TABLE OF spfli.
    DATA: dbcur1 TYPE cursor,
          dbcur2 TYPE cursor.
    OPEN CURSOR dbcur1 FOR
      SELECT carrid count(*) AS count
             FROM spfli
             GROUP BY carrid
             ORDER BY carrid.
    OPEN CURSOR dbcur2 FOR
      SELECT *
             FROM spfli
             ORDER BY carrid.
    DO.
      FETCH NEXT CURSOR dbcur1 INTO count_line.
      IF sy-subrc <> 0.
        EXIT.
      ENDIF.
      FETCH NEXT CURSOR dbcur2
        INTO TABLE spfli_tab PACKAGE SIZE count_line-count.
    ENDDO.
    CLOSE CURSOR: dbcur1,
                  dbcur2.
    Regards
    Kannaiah

  • Store multiple values into a variable

    I was wondering if it was possible to store multiple values into one varaible. Something along the lines of...
    Oracle: 10g
    --Table xSample (this is obviously a dumbed down version of the table for the sake of showing what I want to accomplish
    S_ID   YEAR
    1         2009
    2         2009
    3         2009
    4         2009
    --Query
    select     s_id
    into       pID
    from      xSample
    where    year = 2009;Basically the reason I was trying to figure out how to store multiple values into a variable is b/c I was going to use that variable (pID) as a parameter and have it's values passed dynamically when the proc was called. The values would go into a query that would look something like:
    select *
    from cust_data
    where person_id in (pID)
    aka
    select *
    from cust_data
    where person_id in (1,2,3,4)Not sure if this is possible, but if anyone knows of a way I could accomplish this that would be great.
    Edited by: user652714 on Dec 23, 2009 9:37 AM

    Here's a basic idea building a comma seperated list, then consuming it in another query (taking the in list approach from Tom's post, linked earlier).
    create table xsample (s_id number not null, year number);
    insert into xsample select level, 2009 from dual connect by level <=4;
    commit;
    declare
       --4000 should be lots ... hopefully?
       v_parameter_list varchar2(4000);
    begin
      --create the comma seperated list
      select
        substr(max(sys_connect_by_path(s_id, ',') ), 2, 4000)
      into
        v_parameter_list
      from
        select s_id, row_number() over(order by 1) as rn
        from xsample
        where year = 2009
      start with rn = 1
      connect by prior rn = rn - 1;
      --consume the comma seperated list
      for x in
        with data as
          select
            trim( substr (txt,
            instr (txt, ',', 1, level  ) + 1,
            instr (txt, ',', 1, level+1)
            - instr (txt, ',', 1, level) -1 ) ) as token
          from
            select ','||v_parameter_list||',' txt
            from dual
          connect by level <= length(v_parameter_list)-length(replace(v_parameter_list,',',''))+1
        select *
        from xsample
        where s_id in (select * from data) 
      loop
        dbms_output.put_line('next item = ' || x.s_id);
      end loop;
    end;
    /

  • Please help..it's Urgent..How to fetch the value from table row from Page

    Hi,
    I have created a table with 2 LOV's , LOV2 is dependent on LOV2.
    Here I can not use the general Dependent LOV concept, as these values are coming from 2 different LookUps.
    I am not able to fetch the user input for LOV1 (from page) .that is why not able to set the where cluse fro 2nd LOVVO.
    I have used this code:
    if ("ViolationCat".equals(lovInputSourceId)) {
    OAMessageLovInputBean msglov =
    (OAMessageLovInputBean)webBean.findChildRecursive("ViolationCat");
    // String p_violation_category = "'"+(String)msglov.getValue(pageContext)+"'";
    String p_violation_category =
    (String)msglov.getValue(pageContext);
    // System.out.println(" p_violation_category =" +
    // p_violation_category);
    String v_violation_category = "";
    //System.out.println("vcat=" + vCat);
    OAViewObject violationVO =
    (OAViewObject)am.findViewObject("SNI_Violation_DtlsVO2");
    Number vcatViolationIdnum =
    (Number)violationVO.getCurrentRow().getAttribute("ViolationId");
    String vcatViolationId = "" + vcatViolationIdnum;
    pageContext.putTransactionValue("vcatViolationId",
    vcatViolationId);
    pageContext.putTransactionValue("p_violation_category",
    p_violation_category);
    String query =
    " SELECT LOOKUP_CODE, \n" + " MEANING, \n" +
    " LOOKUP_TYPE \n" +
    " FROM apps.fnd_lookup_values \n" +
    " WHERE LOOKUP_TYPE ='SNI_VIOLATION_CATEGORY' AND MEANING=?";
    PreparedStatement ps = txn.createPreparedStatement(query, 1);
    try {
    ps.setString(1, p_violation_category);
    ResultSet rs = ps.executeQuery();
    //System.out.println("before while,");
    // rs.next();
    // v_violation_category = rs.getString("LOOKUP_CODE");
    // System.out.println("v_violation_category="+v_violation_category);
    while (rs.next()) {
    //System.out.println("inside while");
    v_violation_category = rs.getString("LOOKUP_CODE");
    // System.out.println("v_violation_category=" +
    // v_violation_category);
    ps.close();
    } //try ends
    catch (Exception e) {
    e.getMessage();
    //System.out.println("in catch.." + e.getMessage());
    OAViewObject subCatVO =
    (OAViewObject)am.findViewObject("SNI_ViolationSubCategoryVO1");
    //System.out.println("get VO before where clause: subCatVO::"+subCatVO.getQuery());
    subCatVO.setWhereClause("LOOKUP_TYPE like '%SNI_VIOL_SUB_CAT_" +
    v_violation_category + "'");
    System.out.println("after set where clause VO: subCat VO::" +
    subCatVO.getQuery());
    subCatVO.executeQuery();
    // System.out.println("query of subCat VO::" +
    // subCatVO.getQuery());
    //End of sub category Validation
    It is working fine only for the 1st row of teh table.
    I have tried to fetch the value using :
    String violationCategory = (String)violationVO.getCurrentRow().getAttribute("ViolationCategory");
    String violationSubcategory = (String)violationVO.getCurrentRow().getAttribute("ViolationSubcategory");
    But it is fetching null value.
    Please tell me how can I able to fetch the values.

    Hi
    in your scenarion,first u have to identify the particular row of table where the changes is being made ,u have to use this code .when u select the lov ,first it will give the row refernce and then u have to catch the lov event
    OAApplicationModule am =
    (OAApplicationModule)pageContext.getApplicationModule(webBean);
    String event = pageContext.getParameter("event");
    if ("<ItemPPREventName>").equals(event))
    // Get the identifier of the PPR event source row
    String rowReference =
    262
    pageContext.getParameter(OAWebBeanConstants.EVENT_SOURCE_ROW_REFERENCE);
    Serializable[] parameters = { rowReference };
    // Pass the rowReference to a "handler" method in the application module.
    am.invokeMethod("<handleSomeEvent>", parameters);
    In your application module's "handler" method, add the following code to access the source row:
    OARow row = (OARow)findRowByRef(rowReference);
    if (row != null)
    thanx
    Pratap

  • Reg: Fetching default value -

    Hi Experts,
    Need some help in writing a query.
    Table 'Tab_2' has column 'c3' which checks for its value from 'tab_1' column 'c1' values, and accordingly fetches value from column 'c2'.
    But if a value from c3 is not present in tab_1 column 'c1', it should default 'c2' value as 'dx'.
    Please find below the Create & Insert scripts:
    create table tab_1(
        c1 varchar2(200Char),
        c2 varchar2(200Char)
    create table tab_2(
        c3 varchar2(200Char),
        c4 varchar2(200Char)
    insert into tab_1 values('104,113,146,165','1x');
    insert into tab_1 values('204,213,246,265','2x');
    insert into tab_1 values('304,313,346,365','3x');
    insert into tab_1 values('default','dx');
    commit;
    insert into tab_2 values('146',null);
    insert into tab_2 values('265',null);
    insert into tab_2 values('333',null);
    commit;Here's query where I'm stuck:
    SQL> with x1 as
      2  (
      3      select
      4          REGEXP_SUBSTR(c1,'[^,]+',1,level) id1,
      5          c2
      6      from tab_1
      7          connect by level <= length(translate(c1,'~0123456789','~'))+1
      8          and prior c1 = c1
      9          and prior sys_guid() is not null
    10          and c1 != 'default'
    11  )
    12  select
    13      id1, c2, c3
    14  from x1 RIGHT OUTER JOIN tab_2
    15      on (x1.id1 = tab_2.c3);
    ID1        C2         C3
    146        1x         146
    265        2x         265
                          333Please let me know if any further clarification is needed.
    - Ranit

    The data model looks flawed. So not sure the following solution will satisfy all the issues with respect to your problem.
    with t
    as
    select regexp_substr(c1, '[^,]+', 1, level) c1
          , c2
       from tab_1
    connect
         by level <= length(c1) - length(replace(c1, ',')) + 1
        and c1 = prior c1
        and prior dbms_random.value() is not null
    select t1.c3, t2.c1, nvl2(t2.c1, t2.c2, (select c2 from tab_1 where c1 = 'default')) c2
      from tab_2 t1
      left join t t2
        on t1.c3 = t2.c1;Edited by: Karthick_Arp on May 22, 2013 12:39 AM
    Changed NVL to NVL2

Maybe you are looking for

  • After 6 months of no trouble, "this disk cannot be mounted"

    I've had a time capsule connected and working with my white MacBook for over 6 months. I'm at college, and when I disconnect my MacBook to go home and then come back, there has been no trouble getting the Time Capsule to work again. However, yesterda

  • Error In MySQL Query With DATE_FORMAT

    this produses an empty query when it shouldn't. I've made some error when using DATE_FORMAT and filtering by MONTH and YEAR but not sure how to fix it: mysql_select_db($database_VALUATIONS, $VALUATIONS); $query_valuations = sprintf("SELECT val_Trans_

  • Service 'ipod service' Error

    I had recently had to reinstall windows on my computer and I know that I am regretably using older software for installation but before doing so I did have itunes on my computer and now tryin to install it I keep geting the same problem at the point

  • Question on an error message in Event Viewer.

    Hi, I had a question on a error message in event viewer for BO 3.0 Error Message: Tried to allocate 20 windows desktop but only able to allocate 17 of them.The system may have reached its windows desktop limit.Please contact your system administrator

  • Design of data-flow

    Hello experts! We want to design our data-flow in a new way and I want to know from some experts, if this is a good way of if there maybe is a better way. At the moment we extract over the following InfoSources: 0CO_OM_WBS_1 0CO_OM_WBS_6 0CO_OM_OPA_1