Ajax call ORA-01403: NO DATA FOUND - oracle-apex-19.1

I've found out a lot of similar question about this error on stackoverflow, but no one the same of my problem.
I've build a simple page with two Regions. The first region has two select lists and the second Region has a chart who takes data from the select lists. When I open the page, Apex loads every componts Regions, items...
I know in my case that initially my chart hasn't data from the select lists and the select below return 0 rows and I get the error message:"AJAX call ORA-01403: NO DATA FOUND".
When the page has been loaded, I can use the select lists and show value from the chart.
select MSO_DEVICE, nvl((case when MSO_OEE < 100 then 100 else 100 end),0) max_value, nvl((case when MSO_OEE is null
then 0
when MSO_OEE = 0
then 0
else MSO_OEE
end),0) value
FROM MES_OEE
where MSO_DEVICE = :P2_DEVICE
and MSO_DATE = :P2_DATE
order by 2 desc;
I've tryed to set a server condition on Chart region when P2_DEVICE and P2_DATE are null, but in this case the region not appear. In this case I would like to show the region chart with no value or value "0".

I found out a solution for my problem. I hope it'll be helpful for many people.
select
mso_device
, 100 max_value
, coalesce(mso_oee, 0) value
from
(select
mso_device
, mso_oee
from
mes_oee
where
mso_device = :p5_device
and mso_date = to_date(:p5_date, :APP_NLS_DATE_FORMAT)
union all
select
null
, null
from
dual
where
:p5_device is null
or :p5_date is null)
ORDER BY 2 DESC;

Related

Issue in Jqgrid pagination in Oracle server

We have a code to sort data and paginate the same and render the data to a Jqgrid. The code works fine when it is connected to an SQL server. That is on paginating each page returns distinct data as expected. But on connecting to an oracle server after some point of time the duplicate data are rendered. Both Oracle and SQL server has same data. Parameters in the Jqgrid page and the number of pages are working as expected on the server-side. That is on paging the start point and chunk size is correctly transferred to the server-side. The duplicate values are observed after sorting columns that are of type varchar in the database but hold numeric also. The database status column holds values of 3 and A, after sorting with the status column the duplicate data when the paginating issue is observed. Duplicate data in the sense, that data on page 2 will be the same as data on page 3. Any help will be appreciated. Thanks in advance...
Query One:-
select * from ( select row_.*, rownum rownum_ from ( Select x,y,z,status FROM tablename c WHERE status IN('in condition seperated with status') ORDER BY status asc ) row_ where rownum <= 30 ) where rownum_ > 20;
Query Two:-
select * from ( select row_.*, rownum rownum_ from ( Select x,y,z,status FROM tablename c WHERE status IN('in condition seperated with status') ORDER BY status asc ) row_ where rownum <= 20 ) where rownum_ > 10;
Here the query 1 and 2 always return the same results.
Where two or more values in the column of your ORDER BY clause are the same, you must always provide another secondary column to rank. Otherwise, data return has only a probability of fetching correct result as we expect. The possibility of getting a correct answer will be same as rolling a dice. The secondary column must be unique for accurate results. While you might be able to assume that they will sort themselves based on order entered
select * from( select row_.*, rownum rownum_ from( Select x,y,z,status FROM tablename c WHERE status IN('in condition seperated with status') ORDER BY status,x asc ) row_ where rownum <= 30 ) where rownum_ > 20;
Hoping x is a unique value. DBMS_RANDOM.VALUE can also be used in case if is an oracle specific query other than adding extra order by clause

How to fetch value of checkbox in oracle apex if I used a blank form?

I want to put the value of checked name from a checkbox in oracle apex into a table, but unable to do that.
I tried taking help from google but the steps mentioned didn't work too.
Could you please advise how to do that if I have taken a blank form and then added a checkbox to it, also I fetched the checkbox value from LOV.
As I understand, you are using a List of Values as a source of your checkboxes. Let's say you have following values there:
return value display value
----------------------------
123 andAND
456 Dibya
789 Anshul
321 aafirst
555 Anuj
When you select several values, APEX puts their return values into a string and separate them with :. So for the case in your screenshot the value in item P12_NEW will be 123:555. To split this values you can use the following query:
select regexp_substr(:P12_NEW, '[^:]+', 1, level) values
from dual
connect by regexp_substr(:P12_NEW, '[^:]+', 1, level) is not null
The result will be:
values
------
123
555
Next, you need to put these values into table usr_amt (let's say with columns user_id and amount, and the amount is entered into item P12_AMOUNT):
merge into usr_amt t
using (select regexp_substr(:P12_NEW, '[^:]+', 1, level) user_id
from dual
connect by regexp_substr(:P12_NEW, '[^:]+', 1, level) is not null
) n on (n.user_id = t.user_id)
when matched then update
set t.amount = :P12_AMOUNT
when not matched then insert (user_id, amount)
values (n.user_id, :P12_AMOUNT)
This query will search for the each user_id selected in the table, and if the user presents there, updates the corresponding value to the value of item :P12_AMOUNT, if not present - inserts a row with user_id and the value.

Consolidate rows

I'm trying to cut down on rows a report has. There are 2 assets that return on this query but I want them to show up on one row.
Basically if dc.name LIKE '%CT/PT%' then I want it to be same row as the asset. The SP.SVC_PT_ID is the common field to join them.
There will be times when there is no dc.name LIKE '%CT/PT%' however I still want the DV.MFG_SERIAL_NUM to populated just with a Null to the right.
Select SP.SVC_PT_ID, SP.DEVICE_ID, DV.MFG_SERIAL_NUM, dc.name,
substr(dc.name,26)
From EIP.SVC_PT_DEVICE_REL SP,
eip.device_class dc,
EIP.DEVICE DV
Where SP.EFF_START_TIME < To_date('20170930', 'YYYYMMDD') + 1
and SP.EFF_END_TIME is null
and dc.id = DV.device_class_id
and DV.ID = SP.device_id
ORDER BY SP.SVC_PT_ID, DV.MFG_SERIAL_NUM;
I'm not sure I understand what you are saying; test case would certainly help. You said that query you posted returns two rows (only if we saw which ones ...) but you want them to be displayed as the image you attached to the message.
Generally speaking, you can do that using an aggregate function (such as MAX) on certain column(s), along with the GROUP BY clause that contains the rest of them.
Just for example:
select svc_pt_id, max(ctpt_name) ctpt_name, sum(ctpt_multipler) ctpt_multipler
from ...
group by svc_pt_id
As I said: a test case would help people who'd want to answer the question. True - someone might have understood it far better than I did and will provide assistance nevertheless.
EDIT: after you posted sample data (which, by the way, don't match screenshot you posted previously), maybe something like this might do the job: use analytic function to check whether name contains CT/PT; if so, take its data. Otherwise, display both rows.
SQL> with test as (
2 select 14 svc_pt_id, 446733 device_id, 'Generic Electric' name from dual union
3 select 14, 456517, 'Generic CT/PT, Multiplier' from dual
4 ),
5 podaci as
6 (select svc_pt_id, device_id, name,
7 rank() over (partition by svc_pt_id
8 order by case when instr(name, 'CT/PT') > 1 then 1
9 else 2
10 end) rnk
11 from test
12 )
13 select svc_pt_id, device_id, name
14 from podaci
15 where rnk = 1;
SVC_PT_ID DEVICE_ID NAME
---------- ---------- -------------------------
14 456517 Generic CT/PT, Multiplier
SQL>
My TEST table (created by WITH factoring clause) would be the result of your current query.

find rows with same value using LINQ

The issue with the image above is that
I want to apply a bonus share to the shareholders based on the TransLog_Date
Because the shareholder in row 1 has already transferred a portion of his shares to the holder in row 3, his new share value is what shows in row 2 column 5 as 100000
I want the bonus share to be calculated based on the value in row 2, column 5 but not on row 1, column 5.
I have tried several codes in LINQ but getting it wrong as the value is multiplied on all the 3 records which is totally wrong.
var transQuery = (from tq in db.TransactionsLogDbSet
where (tq.TransactionType == TransactionType.PurchaseOfShares)
|| (tq.TransactionType == TransactionType.TransferOfShares)
|| (tq.TransactionType == TransactionType.BonusSharesDeclared)
select tq);
var query = from row in db.TransactionsLogDbSet
group row by row.Transholder_ID into g
select new { Count = g.Count() };
OK, i think I finally got what you want.
Is that right?: Group all rows of some TransactionTypes by the Transholder_ID, then from each group select the row with the maximum Translog_Date, giving you the most recent row per Transholder_ID. Once you have the result of that, you can iterate over it to calculate whatever you need.
from t in db.TransactionLogDbSet
where where tq.TransactionType == TransactionType.PurchaseOfShares || tq.TransactionType == TransactionType.TransferOfShares || tq.TransactionType == TransactionType.BonusSharesDeclared
group t by t.Transholder_ID into g
select (from t1 in g orderby t1.Translog_Date descending select t1).First();
EDIT: I'll continue to edit the following part of my answer as long as we finally arrive at the correct query.
From you last comment so far it follows that you just want to select all rows with a TransLog_Date <= a given DateTime qualifiedDate.
from t in db.TransactionLogDbSet
where t.TransactionLog_Date <= qualifiedDate
select t
Is that it?

Google SQL Pivot make 0 show NULL

I have a pivot table that I need to have return NULL whenever there is not a value in the database. This seems pretty simple when you look at the Google API for their query language:
http://code.google.com/apis/visualization/documentation/querylanguage.html#Pivot
(source: cjweed.com)
(source: descentcampaign.com)
The Google example is the first image. Notice how it contains null, these null values are from data that does not exist in the original table. When I run the sum(vals) for the pivot to work, it always returns 0, even if it doesn't exist.
Also, my sql statement is:
SELECT weekNumber, sum(value) FROM allval
WHERE weekNumber != 0 AND custId != 28
GROUP BY weekNumber
PIVOT custId
ORDER BY weekNumber
Notice the custId != 28. It still appears in my result table, except everything is set to 0.
Anyone know how the Google example in the link was able to maintain the NULL values even through the aggregate function sum?

Resources