How to calculate multiple records using post-query in oracle forms - oracleforms

I have multiple number datatype records sorted in Oracle database. I am trying to calculate them to get the result, where I want to display it on DISPLAY_ITEM.
I did database item property: no; and datatype: number
I tried post-query trigger on datablock, then i wrote the trigger:
BEGIN
SELECT sal + allow1 + allow2
INTO :display_item1
FROM employees
EXCEPTION
WHEN no_data_found THEN
:all_allow := 0;;
END;
I got the error
frm-40735; POST-QUERY trigger raised unhandled exception ORA-01422

You can only select 1 row into items. In this case ora-01422 means you got more then 1 row.
The trigger post-query fires for every row, so if you want this to happen for every row just do the count for that row only instead of all rows together.
If you really need to make the count for all those rows you could use the SUM function or so.

If I'm understand you correctly and you want to have one item displaying the total of three different columns in the table this is what I should do. Create three hidden items for columns sal, allow1 and allow2. With hidden items I mean database items that have no canvas specified (a.k.a. NULL canvas items). Then I create a none database item to be be displayed to the user. For this item I then set Calculation Mode property to Formula and the Formula property to ':my_block.sal + :my_block.allow1 and my_block.allow2'.
Alternatively you can use the Post-Query trigger to populate the if we can call it 'formula' item but still you need to return all three columns into separate items. I don't like the use of summary items because that has a slightly different meaning inside forms.
If you don't want to do that and you could possible also built your block on a from clause and there directly in the sql do the computation.
Yet another solution should be to create a database side view to do the computation and create the form block based on the view instead of the table. This is by the way not a bad way of creating forms to separate the form itself from the underlying tables. This giving you freedom to change database structure without invalidating the form.
Many possibilities depending what your needs are but personally I should go for the formula item.

Related

Find out the specific row that was selected in Dash DataTable

I have a Dash DataTable with row_selectable set to "multi". Therefore, the user can select multiple rows via a checkbox that will appear next to each row of the DataTable.
I also have a callback that has as input Input("datatable-id", "selected_rows"). Therefore, each time the user selects a row, I get ALL the rows that are selected.
What I want to do is to update my database column is_selected based on the row that the user just selected. To get the row that the user just selected I can either:
Read my entire is_selected column of my database and find the difference between that and selected_rows.
Use selected_rows to update ALL the rows in my database.
I wonder, is there another better way to find out which specific row the user selected? So that I can simply update my single row in my database accordingly?
So, you can use a dcc.Store as a way to get access to the previous state.
If I'm not wrong, your problem is a comparison between two states: the state_0, the one before the interaction; and the state_1, the one after the interaction.
In that case, using only DashTable attributes, it is hard (at least I don't know how) to get the previous state of selected rows. With that in mind you can create a dcc.Store to store the last state of selected_rows to get access every time the callback is triggered. In other words, put the data as the Output off the callback and a State to get the access to state_0. Update the data with the current selected_rows after making a simple set difference between the current selected_rows and the previous one.

Web Intelligence : limit row number in a block

I have a list of events with a number of orders. I want to only display the first five biggest amount of orders in my report. I created a variable with the rank of each event :
=Rank([Total orders])
Then I created a variable with the five event depending rank but I get this :
=[Event] Where ([Rank]<=5)
I have an empty cell equal to all non displayed results and the sum of commands amounts.
Is there a way to fix that ? If it's not possible how can I rename the empty cell with "Others" label ?
I work on WebI 4.2 Support Pack 4 Compilation : 14.2.4.2410.
I see three different ways to do this. As an example I created a query using the eFashion universe.
You could create a variable like you had and add a filter where MyRank <= 5.
MyRank=Rank([Query 1].[Quantity sold])
You could right-click on your Orders column, choose Ranking > Add Ranking..., and change the value for Top to 5. Leave everything else alone and click OK.
You could database ranking within your query. This option only brings back the data you want. The previous two option bring back more data than you want from the database and then filter it out in the report. This link has some further detail on how to set this up.
Each option has its place. The first one is most like what you have tried. I think the second one is the simplest. And the last one is the most efficient. You choose what is best for you.
Here are my results for each of the three approaches I described in order.

SSRS column group displays data on unique rows

I have a data set where i'm using a table to display Name, Radio #, and Unit # information in SSRS tablix. As some of the groups have 60+ members, i thought it would be better to expand the tables into 4 columns repeating those detail fields instead of displaying a 3 page long skinny table. In the SQL i used a row count%4 function to assign a "position" number 0-3 for each name. If i create a table with the detail members above and then add a parent column group on position, i get the tables repeated as i want but each name/radio/unit appears on a unique row. I've tried several different ways of grouping rows/columns but always seem to get this staggered table (with only name/radio to make it easier to digest): sample_pic
Sorry if this is a duplicate. I've really searched quite a bit before putting this in but it's probably the case that if i knew what to search, i wouldn't be putting this question in. So if you'd rather tell me what to search i can do that too. :)
SSRS will display a row in the table for each row returned from the dataset, this is normal behaviour for data to display.
One way to get what you want is to create a query which has all the information form your column headings in one row, probably with a pivot or similar.
Or you could just display your columns in separate tables.

Create ordering in a MySQL table without using a number (because then it's hard to put something in between)

I have a long list of items (say, a few million items) in a mysql table, let's call it mytable and it has the field mytable.itemid.
The items are given an order, and can be re=ordered by the user by drag and drop. If I add a field called mytable.order and just put numbers in them, it creates problems: what if I want to move an item between 2 other items? Then all the order fields have to be updated? That seems like a nightmare.
Is there a (scalable) way to add order to a table that is different from just giving every item a number, order by that, and do loads of SQL queries everytime the order is changed?
You can either create a trigger or stored procedure to resequence the order values appropriately, or drop all the associated records and insert new ones in the new order.
You can use fractions (two integers, i.e. a/b). Always there is at least one rational between two other.

Save and get arbitrary sort order in SQL Server

My client wants to sort products by drag & drop. The drag & drop part is easy with javascript.
My problem is how do I save and get the sort order?
I'm using .net c# and SQL Server 2008.
When I move a product and drop it in a new position I get the id of the product that's moved, product in front and product behind. With this data I want to update the sort order of products.
I was thinking of adding a field with position, but then I guess I have to update every item when position changes.
In general adding an additional position field is the only thing you can do, to get truly arbitrary ordering.
But you can implement it in several ways. Here are two ways I've implemented myself some time ago.
1. Method: Update all position values, by looping over your items and performing an UPDATE statement for every position.
This is easy to implement, but because of the many updates, it's not good for many items and/or large tables. Especially if you do it via Ajax and perform a complete re-ordering on every change in the list.
2. Method: Do a smart update of only the affected rows.
SELECT all items in the current sort order (The "old list") (Usually fast compared to an UPDATE statement)
Iterate over all items from the "new list" and compare each item to the item from the old list at the same position/index. If the items are the same, don't do anything
If the items are different find that item from the old list, which should actually be at that position and update its position value accordingly (Some lookup data structure might be useful here)
That way you only have to perform minimal database updates, but you'll have more complex code.
Personally I'd go with the first way, until the database updates actually become a performance problem.
We have a sort column but yes we have to re-index all rows as things change. You could mitigate this by assigning sort's in large enough increments to allow some level of movability before you have to do this, such as in 10's or 100's but that's not the best solution and I'd be interested to see what other ideas people have.
If you can capture each move programatically (with up and down buttons for example) then you can just swap the position numbers of the row moving and the row being moved. Make sure that you add new rows at the max position + 1.