For Each Combination of Two Cols Create a Record

How do I PL/SQL creating a new record in table B for each combination of two columns in table A? Do I need to create a cursor?
my_cursor IS
SELECT col1, col2 FROM tableA
and then with a FOR loop somehow write SELECT FROM INSERT INTO?
Thanks,

For unique combination you have to do more than just distinct:
SQL> ed
Wrote file afiedt.buf
  1  select distinct least(x.id1, y.id2) as num1, greatest(x.id1, y.id2) as num2
  2  from t x, t y
  3* order by 1
SQL> /
      NUM1       NUM2
         1          2
         1          3
         1          4
         2          2
         2          3
         2          4
         3          3
         3          4
8 rows selected.
SQL>Which, as you can see strips out the 3,2 because we already have a 2,3
We have to use the greatest and least functions here so that the 3,2 combination was turned around to become 2,3 thus causing a duplicate which was stipped out using the distinct. There are other techniques too, but it depends on your data and what you want to achieve.

Similar Messages

  • Do I need a css file for each fluid layout page I create

    DO I need a different css file for each fluid page page I create?
    THanks!

    The short answer is No!
    When you create a second or subsequent document, you need to ensure that the original style sheet has been attached as shown

  • Onlive TV listing does not show HD listing for series when I try to create a recording

    It happened now already several times the the "Online TV Listing" does not show HD listing for series when I try to create a recording. Instead, it will show two series options in SD. Is this to make people use less bandwidth?
    Here is what I am doing:
    I go to this link  https://www.verizon.com/fiostv/myservices/members/fiostv.aspx
    Then to ...........DVR Manger
    select  ...........Record A Show
    I type search e.g. Nathan for You
    I click on ........Search
    and I select ......Click here to Show Details
    Then I get to chose from 2 (the same) SD channels.
    Nathan for You
    190 Comedy Central
    Tue, Jul 29 10:30 PM
    Record Show Record Series
    Nathan for You
    190 Comedy Central
    Tue, Aug 05 10:30 PM
    Record Show Record Series
    But there is the same on channel 690 HD!
    This happens not only to this particular channel!
    I remember it used to show also the HD channels.
    The only way to schedule in HD is to find the listing in the TV schedule, at the right time and there you will get the
    correct choices for both SD & HD.
    Can this be fixed?
    Thanks!

    On the right click on HD under video quality to filter it. 

  • Using pl/sql function for each day between two dates.

    Hi,
    create TABLE EMP(
    ID_EMP NUMBER,
    DT_FROM DATE,
    DT_TO DATE,
    CREATE_DATE DATE);
    into EMP(ID_EMP, DT_FROM, DT_TO, CREATE_DATE)
    Values(100, TO_DATE('07/01/2008 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('04/30/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),TO_DATE('05/08/2009 14:11:21', 'MM/DD/YYYY HH24:MI:SS'));
    I have a function called  elig_pay_dates(date p_date), which returns the code for  person payment eligibility for a particular date. For paid dates it's 'P' and for unpaid dates it's 'N'.
    How can I check this function between two dates for each day. Example : 07/01/2008 to 04/30/2010.
    By using this function with select I needs to display the dates when there is a change in status.
    I am expecting data in following manner from above logic(this is example):
    07/01/2008 --- 07/01/2009 ---'P'
    07/02/2009 -- 07/25/2009 ----'N'
    07/26/2009 -- 01/01/2010 ---'P'
    01/02/2010 -- 01/13/2010 --'N'
    01/14/2010 -- 01/18/2010 --'P'
    01/19/2010 -- 04/30/2010 -- 'N'
    I thought of looping for each day date but that seems to be expensive for online application. Is there any way that I can achieve this requirement with sql query ?
    Thanks for your help,

    Certainly not the best way to code the requirement, but it does achieve the result you are looking for in a fairly quick time
    create or replace
    function test_ret_paid_unpaid (p_date in date)
    return varchar2
    is
      v_ret     varchar2(1);
    begin
      if ( (p_date between to_date('07/02/2009', 'MM/DD/YYYY') and to_date('07/25/2009', 'MM/DD/YYYY') ) or
           (p_date between to_date('01/02/2010', 'MM/DD/YYYY') and to_date('01/13/2010', 'MM/DD/YYYY') ) or
           (p_date between to_date('01/19/2010', 'MM/DD/YYYY') and to_date('04/30/2010', 'MM/DD/YYYY') )
        then v_ret := 'N';
      else
        v_ret := 'Y';
      end if;
      return v_ret;
    end;
    Wrote file afiedt.buf
      1  with get_paid_unpaid as
      2  (
      3    select dt_from start_date, dt_to end_date, dt_from + level - 1 curr_date, test_ret_paid_unpaid(dt_from + level - 1) paid_unpaid,
      4           row_number() over (order by dt_from + level - 1) rn_start,
      5           row_number() over (order by dt_from + level - 1 desc) rn_end
      6      from test_emp
      7    connect by level <= dt_to - dt_from + 1
      8  ),
      9  get_stop_date as
    10  (
    11  select start_date init_date, end_date, curr_date, paid_unpaid,
    12         case when paid_unpaid != lag(paid_unpaid) over (order by curr_date) or rn_start = 1 or rn_end = 1
    13          then curr_date
    14          else null
    15         end start_date,
    16         case when paid_unpaid != lead(paid_unpaid) over (order by curr_date) or rn_start = 1 or rn_end = 1
    17          then curr_date
    18          else null
    19         end stop_date
    20    from get_paid_unpaid
    21  )
    22  select period, paid_unpaid
    23    from (
    24  select init_date, curr_date, start_date, end_date, stop_date,
    25         case when paid_unpaid = lead(paid_unpaid) over (order by curr_date)
    26                then nvl(start_date, init_date) || ' - ' || lead(stop_date, 1, end_date) over (order by curr_date)
    27              else null
    28         end period,
    29         paid_unpaid
    30    from get_stop_date
    31   where stop_date is not null or start_date is not null
    32         )
    33*  where period is not null
    12:06:10 SQL> /
    PERIOD                                             PAID_UNPAID
    01-JUL-08 - 01-JUL-09                              Y
    02-JUL-09 - 25-JUL-09                              N
    26-JUL-09 - 01-JAN-10                              Y
    02-JAN-10 - 13-JAN-10                              N
    14-JAN-10 - 18-JAN-10                              Y
    19-JAN-10 - 30-APR-10                              N
    6 rows selected.
    Elapsed: 00:00:00.35

  • ** Is it possible to create new BPM instance for each record (Multiline)

    Hi friends,
    In my scenario, JDBC adapter (sender) polls the open purchase order items from the table at the specified interval and send to BPM. In BPM, we used transformation step to split the messages to process each PO . The scenario is working fine. The problem is assume that if we process 10 PO, the error is in  4th PO while process, the BPM will be stopped in 4th PO. Once we correct the error, we are able to restart.
    In this case, we are not able to skip the 4th PO and process from 5th PO onwards. ie. the processing is sequential. Instead, we want to start new BPM instance for every PO. Advantage is that if 4th PO is error, only that BPM instance (work item) will be stopped. Remaining 9 POs will be completed.
    So, how do we start new BPM instance for every PO ?
    Kindly tell me, friends.
    Thank you.
    Kind Regards,
    Jeg P.

    Hi,
    There are two ways to achieve this.  In BPM and before BPM.
    Before BPM:
    Use 1 to unbounded mapping and 1 to unbounded interface mapping.
    In your mapping, make sure you create a seperate message for each PO.
    In BPM:
    Create a multiline container with you POs using a 1 to n mapping.
    Now add a ForEach block to loop through the multiline container and send each PO.
    Important:  Add an exception branch to catch any exception for each send so that the exception does not make the BPM fail.
    Regards,
    Yaghya

  • SharePoint: Workflow to retrieve all users and Create list item record for each user

    Hi all,
    My share point site have two Lists as Holidays and MyCalender.
    Actually Holiday is simple non-Calender list with field as Holiday Date, Reason. MyCalender List Calender type list with Person Look-up column and user can see his own record. User of Manager group will declare holiday. This Holiday should get reflected
    on each user 's MyCalender List.[One listitem as holiday date and reason for each user] so everyone can view that record.
    I have requirement as Manager will create one Holiday record and then run single workflow so for all users present in SharePoint Site, one MyCalender List Item record should get created. Is it possible to do using Workflow?? Please help as I didn't get any
    solution for this.. Thanks in advance!

    You don't need one workflow per user when a filtered view can do this for you.  If the manager's list is the parent calendar, I'm assuming that he'll be at least using the person look-up column.
    Whether this feeds through the MyCalendar or stays where it is, you can use the [Me] parameter within the filter on a new view.  This will then return the assigned holiday filtering against the account that is logged in.
    Steven Andrews
    SharePoint Business Analyst: LiveNation Entertainment
    Blog: baron72.wordpress.com
    Twitter: Follow @backpackerd00d
    My Wiki Articles:
    CodePlex Corner Series
    Please remember to mark your question as "answered" if this solves (or helps) your problem.

  • Why does Labview create a .vi for each global variables?

    Hello,
    I wrote an Labview application which use several global variables (almost 30 variables). All the variables are of variable type "single process". For each of these variables, Labview creates a vi.
    For example, for the variable "_TS.Measures.channes", Labview creates a vi named "TS_'_TS.Measures.channels'.vi". Which means, I have almost 30 "name of variable".vi files: this is confusing!
    All my VI are inside library (.llb). When I try to put the VI of a global variable in a library, Labview can't find them anymore.
    May be can somebody explain me, why LabVIEW does create these VI and how is it possible to put them in a library.
    Cheers,
    Risotto

    Hi everybody,
    Thank you for your answers, I get a lot of informations.
    Yes, I use the new shared variables in LabVIEW8, which I am using like sort of global constants. Now I am understanding what guys are telling me all this about global variables in LabVIEW7.1. Sorry, I forgot to say I was using LabvVIEW8.
    I will have a look on the tutorial too.
    But yet one point about the library collecting all the shared variables in the windows explorer and in the project explorer: When I create a shared variable in my LabVIEW project - for example "test1" as double/single process - the variable doesn't appear in my file directory, but it appears in the project explorer in a library (.lvlib).
    When I drag/paste my shared variable on the block diagramm of my VI, then a file "Math_test1.vi" appears in my file directory. There is no extra .llb created to contain my shared variable vi.
    If I drag/paste the file "Math_test1.vi" in the Math.llb (see picture), then the file is moved in the llb and disapeared from the directory.
    If I created another shared variable "test2" as double/single process and put it on the VI, then LabVIEW creates2 files in the directory: "Math_test1.vi" and "Math_test2.vi". So that I get 2 vi for the "test1" variable now (one in the llb and one in the directory).
    I use several library in the project explorer. But the  library in the project explorer seems to create file with other extension (.lvlib) than the sdtandard LabVIEW library (.llb).
    Cheers,
    Risotto
    Attachments:
    picture.jpg ‏223 KB

  • Need a multi-level control break report displaying a cross-tab for each ...

    I need a multi-level control break report that displays a cross-tab report for each
    detail and subtotal. The individual cross-tabs are no problem. There are two issues:
    1) How to get many cross-tabs (thousands) to appear in one report.
    2) How to provide cross-tabs in-line on the multi-level subtotal lines.
    Here is a concrete example.
    Suppose the data base contains this table:
    road (
    id_number number, -- this is an artificial PK
    city varchar2,
    county varchar2,
    state varchar2,
    length number,
    owner varchar2, -- roads may be owned by cities, counties, states, and others
    surface_type varchar2 -- the surface type may be gravel, asphalt, concrete, and others
    The table is populated with several million records that include every
    length of road in a US city.
    It is OK to suppose that all the attributes in all the records are not null.
    Without the PK, there would be millions of duplicates,
    which should all contribute to the summed lengths.
    The report I need is like a control break report with a detail line for each
    city together with subtotals for each county and state and
    a grand total for the US at the end.
    However, each detail and total line needs to be a cross-tab report
    summing the length over the city, county, state or US
    (whichever is called for at that location)
    for each combination of owner and surface_type.
    so the report would have the following structure:
    a city cross-tab for the first city in county 1/state 1
    a city cross tab for the last city in county 1/state 1
    a cross-tab for count 1
    a city cross tab for the first city in county 2/state 1
    a city cross tab for the last city in county 2/state 1
    a cross tab for state 1
    a cross-tab for the US
    Any suggestions will be appreciated.
    This problem comes up because my client's legacy system,
    which is being replaced,
    already has such a report (in COBOL).
    Thanks!!!
    Steve
    PS, I know one ugly way to do it. Namely, make a variable for each
    possible combination of owner and surface. Then code an ordinary control
    break report. However, I am looking for something better.

    Hi Jenna_Fire,
    According to your description, you have a matrix contains total for each group on each level. Now your requirement is, when you click on any number (data field or total), it will go to the detail report which returns all the detail information of the people
    within the group scope. For example, if you click on the total of Active users in United States, it will return the detail information of Active users in New York and Texas. Right?
    In this scenario, we should set the parameter (@Country, @State, @City) allow multiple values in both main and detail report. And in Default Value (@Country, @State, @City), query out all distinct values. In the textbox which contains
    those total values, when set use these parameters to run the report, we only need to pass the parameters of parent groups. For example, if we click on the total of Active users in New York, we only need to pass Country, State, Status to detail report, and
    in the detail report, the City parameter will use all distinct values (Default Values) because we don't pass the City parameter. We have tested this case with sample data in our local environment. Here are steps and screenshots for your reference:
    1. Create parameter Country, State, City and Status in both main report and detail report. Set both Available Value and Default Value get values from query (Create a dataset for each parameter, use "select distinct [column] from [table]" as query). Set allow
    multiple values for parameter Country, State and City in both reports.
    2. In corresponding textbox, pass appropriate parameters in go to report Action.
    4. Filter data in detail report (in where clause or using filters).
    5. Save and preview. It looks like below:
    Reference:
    Using Parameters to Connect to Other Reports
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

  • Limit of for each conditions in rtf templates

    Hi Everyone,
    I have a use case where i need to genereate a report by using values from two data sets. data sales, cost.
    Data set sales have four columns product1, product 2, product 3, product 4
    Cost has cost1,cost 2, cost 3, cost 4.
    I need to display in below format
    product 1| product 2| cost 1|cost 2| product 3| product 4| cost 3| cost 4|
    To get above format i am using four for each condition groupings two for each data set
    <?for-each:/data/sales?><?product1?>|<?product2?><?end for-each?>|<?for-each:/data/cost?><?cost1?>|<?cost2?><?end for-each?>|<?for_each:/data/sales?><?product3?>|<?product 4?><?end for-each?>|<?for-each:/data/cost?><?cost3?>|<?cost4?><?end for-each?>
    If i use first two for each conditions i am able to see values in template but if i use four line is missing in the template.
    I did not understand where lies the problem.
    Please let me know if you need more info.
    Regards
    Sandeep

    If you have product ID or key in the cost data set, then you can follow the method in this post to display data:
    http://blogs.oracle.com/xmlpublisher/2009/09/formatting_concatenated_dataso.html

  • How to get top 10 records for each option in table prompt?

    Hi,
    I have created one report in which my requirement is to get top 10 highest salaries for each departments. I have created one table prompt which contains the names of all departments. On the salary column I have applied one filter i.e. TOP 10. Currently I am having 3 departments. I want to show the top 10 salaries for each department, but I am getting top 3 from first, 4 from second and 3 from third.They are calculating top 10 salaries based on all departments, not on individual department. How can I get top 10 salaries for each department?

    Hi,
    Use TopN function in your column formula.
    Ex: TOPN("Sales ,5 BY department)
    Thanks,
    Satya

  • IDOC to file: Increase sequence number for each item in a segment

    Dear All,
    I am having one scenario IDOC to file, where one IDoc with multiple items for an header in it will be sent.
    In Destination structure, for each iitem segment I am creating multiple rows. I have a field(INC_NUM) in target structure where in I have to start line number from 1 for each item.
    Also I have a condition - for item x or y I should only have the same line number.
    TinAdvance
    Swarna.
    Edited by: Swarna on Oct 24, 2011 8:15 AM

    Hello,
    You can use the statistic function called index for your requirement. Can you give sample input/output so that we can visualize further?
    Hope this helps,
    Mark

  • Approval for each phase in task

    Hi Everyone
    I am using task list to create Projects. I have field named - "Phases" with values of Planning, Monitoring, Executing, Closing.
    I want to have approval for each phase from approver. Need suggestions on how do I show each approval for each phase for project? Should I create different fields for each approval? I can create approval workflow so that when user change phases it will send
    out an e-mail to approver, but how user will know which approval is for which phase while looking at project item in the list.
    Your suggestions are appreciated.
    Thanks

    Hi Swetha,
    For your situation, once any phase is approved, you could send an email to notify task creator the certain phase is approved.
    If you need to let users who can access the item know the approved phases, you might add some other fields in the list. For example, add the multiple choices that has:
    Request Initiation
    Initiation approved
    Request Plan
    Planning phase approved
    Request Closure
    Closing phase approved
    And add an extra action in workflow to change the field's value per the approve status.
    Regards,
    Rebecca Tu
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Roles for each Product in Oracle Apps 11i

    Hi,
    I have one requirement to create role for each product...
    For example:
    Inventory (INV)... I need to create a role, which will have select privileges on all tables of Inventory...like that for each production, I need to create...
    I have one procedure:
    (a) create role inv_read_role;
    (b) spool the following statement
    sql> spool inv_read.lst
    sql> select 'grant select on INV.'||object_name||' '||'to INV_READ_ROLE;' from dba_objects where owner='INV' and object_type='TABLE';
    sql> spool off
    (c) Run the above spool file
    Here we are done...
    But, If I want to do this for all products in oracle apps 11.5.10.2..
    is there any smarter way to do this????? any stored procedure???

    I want to give readonly access to AP Tables to one database user or more no of database users.....how can we give...for that , we are going to create seperate role for each module in database..assign that role to database user...then he will be able to select only on that module tables......

  • PXI 5114 - Seperate Triggers for Each Channel

    We are using a PXI-5114 High Speed Digitizer.  We were wondering if it was possible to set different triggers for each of the two channels.  We are analyzing a NTSC composite video signal and would like to observe two different lines of video in a LabVIEW VI.

    I would like to clarify a little bit about what you are trying to accomplish.  Do you have one or two separate video sources you wish to hook up to your digitizer?  When you refer to "lines" are you referring to the individual horizontal lines that make up a single video frame?
    The amount of time it takes to reconfigure the digitizer for a new acquisition is not deterministic and will depend upon the speed of your machine as well as any other activity you have going on over the PXI bus.  As a result, reconfiguring in between an event may not be fast enough depending on how quickly you expect the image to be moving.  I am also not quite sure how setting up a trigger for the top horizontal line and then another one for the bottom horizontal line will get the measurement you are looking for because each line will be refreshed at a periodic rate by the video source.  Triggering on a specific line will give you a record with the digitized data for that line but it seems like you will need to do some kind of processing on that data to tell if the data contains this line of the digitized image contains is object you were looking for or not.
    Please let me know if it does not sound like I am envisioning the application correctly.
    -Matt

  • Create new records manually

    Dear friends
    I have 2 tables, the header has two columns "ID" and "Date" and both columns fill with
    database layer trigger and the detail has three columns "Id" and "HeaderID" and "RequestType"
    the "Id" column as like as header fill with trigger in database layer and "HeaderID" is related to the header table and "requestType" fill with Lov,
    Now let me know how can I manage this sample with one key for inset new record and for each header can insert more than one record.
    Thanks for your help.

    Hi
    Thanks a lot for your reply,
    At first I try your suggestion on my header table, then when I create the second record I get the "java.lang.NullPointerException" error!!!! why???
    Thanks

Maybe you are looking for

  • Plsql webservices deploy error in weblogic.... Can anybody help me.. Urgent

    Could any body look into this exception.... I am stuggling with this for the last one week........ I have generated the webservices from PLSql procedure, deployed and tested in oc4j which is successfull running and I can access the webservice too....

  • Problem in Activating a Heirarchy

    I was able to create the heirarchy but i wasnt able to activate it.I will explain in detail IO8_SREP(sales representative ID)is a characteristic InfoObject, it has an attribute IO8_SREPN(sales representative name). For IO8_SREP I tried to create a Ti

  • Any documents for web interface builder?

    any documents for web interface builder?

  • All of a sudden...mail broke!

    A few days ago, mail started hanging (judging from the Activity window) on the "Fetching new mail" window. If I hit the stop sign, it then hangs on "stopping." If I try to quit, it doesn't -- I have to forcibly quit it. This happens with multiple acc

  • Crash to desktop when loading embedded swf

    I have a swf that loads two other embedded swfs. The need for an air native extension came up so I've wrapped this swf inside of an AIR app. I install my app as a native installer. (on Windows 7) My app has a main menu screen and two buttons that wil