defining a unique key column in apex - oracle

I am trying to get the distinct records from a table, as many duplicate rows are coming from the following query
select * from sales_details_view;
When I query the following query in pl/sql developer, I am getting correct results
select distinct * from sales_details_view;
But when I use the same query in an interactive report in Oracle APEX 4.1, it is giving me the following error
The report query needs a unique key to identify each row. The supplied
key cannot be used for this query. Please edit the report attributes
to define a unique key column. ORA-01446: cannot select ROWID from, or
sample, a view with DISTINCT, GROUP BY, etc.

You need to set Link Column (in Report Attributes) to something other than "Link to Single Row View". You can set it to either "Exclude Link Column" or "Link to Custom Target".

Related

oracle forms not showing all fields

I have 2 tables: product which has primary key product_id and Review which has product_id which references the product_id of product table;
I created form master-detail for them but when executing I get at the bottom of page:
FRM-40505: ORACLE error: unable to perform query
and when pressing ctrl+shift+e I get:
SELECT ROWID, REVIEW_ID, LIKE, DISLIKE, FIRST_NAME, LAST_NAME, PRODUCT_ID
FROM U1.REVIEW WHERE (PRODUCT_ID=:1)
ORA-00936: missing expression
how to solve this? what is wrong? thank you in advance
Seems you have a field named like in your block with base table named review has Database Item set to Yes in the property palette, and for this reason Oracle treats that field as if a column of the table, but there's no such column, and not possible to have a column named like within a db table, since it's a reserved keyword.

Updating Resultset that points to an Oracle view

Is it possible to do updates via Resultset to an Oracle view? Asking as my code is giving me insufficient priviledge error when it does the rs.updateRow() call. I have checked and I definitely have access to the table/view.
The code looks like:
white (rs.next()) {
int updateStatus = getPSCforAction(status);
rs.updateInt("SPSC", updateStatus);
rs.updateRow;
}
The SELECT statement changes depends on operation but it will always be querying an Oracle view (and in some cases multiple views). My main question is whether updating via resultSet can be done to an Oracle view (or views)?
To answer your question one must see a definition of you view and a SELECT statament that is used to produce the resulset in your Java code. Without looking at this it is hard to give the answer
Anyway, generar rules and limitations are described in the Oracle Database JDBC Developer's guide:
Result Set Limitations
The following limitations are placed on queries for enhanced result
sets. Failure to follow these guidelines results in the JDBC driver
choosing an alternative result set type or concurrency type.
To produce an updatable result set:
A query can select from only a single table and cannot contain any
join operations.
In addition, for inserts to be feasible, the query must select all
non-nullable columns and all columns that do not have a default value.
A query cannot use SELECT * . However, there is a workaround for this.
A query must select table columns only.
It cannot select derived columns or aggregates, such as the SUM or MAX
of a set of columns.
To produce a scroll-sensitive result set:
A query cannot use SELECT *. However, there is a workaround for this.
A query can select from only a single table.
Scrollable and updatable result sets cannot have any column as Stream.
When the server has to fetch a Stream column, it reduces the fetch
size to one and blocks all columns following the Stream column until
the Stream column is read. As a result, columns cannot be fetched in
bulk and scrolled through.
They vaguely write that:
A query can select from only a single table and cannot contain any
join operations.
Could be that they mean "exlusively from tables, but not views", but also they could mean: "from tables and views", nobody knows, one must test this.
Another possible problem - your view may not be updatable, that is it doesn't conform to the following rules:
Notes on Updatable Views The following notes apply to updatable views:
An updatable view is one you can use to insert, update, or delete base
table rows. You can create a view to be inherently updatable, or you
can create an INSTEAD OF trigger on any view to make it updatable.
To learn whether and in what ways the columns of an inherently
updatable view can be modified, query the USER_UPDATABLE_COLUMNS data
dictionary view. The information displayed by this view is meaningful
only for inherently updatable views. For a view to be inherently
updatable, the following conditions must be met:
Each column in the view must map to a column of a single table. For
example, if a view column maps to the output of a TABLE clause (an
unnested collection), then the view is not inherently updatable.
The view must not contain any of the following constructs:
A set operator
A DISTINCT operator
An aggregate or analytic function
A GROUP BY, ORDER BY, MODEL, CONNECT BY, or START WITH clause
A collection expression in a SELECT list
A subquery in a SELECT list
A subquery designated WITH READ ONLY Joins, with some exceptions, as
documented in Oracle Database Administrator's Guide
In addition, if an
inherently updatable view contains pseudocolumns or expressions, then
you cannot update base table rows with an UPDATE statement that refers
to any of these pseudocolumns or expressions.
If you want a join view to be updatable, then all of the following
conditions must be true:
The DML statement must affect only one table underlying the join.
For an INSERT statement, the view must not be created WITH CHECK
OPTION, and all columns into which values are inserted must come from
a key-preserved table. A key-preserved table is one for which every
primary key or unique key value in the base table is also unique in
the join view.
For an UPDATE statement, the view must not be created WITH CHECK
OPTION, and all columns updated must be extracted from a key-preserved
table.
For a DELETE statement, if the join results in more than one
key-preserved table, then Oracle Database deletes from the first table
named in the FROM clause, whether or not the view was created WITH
CHECK OPTION.

Delete columns from BIRT report

I have a BIRT Excel Report with 10 columns. I have a query which executes and brings the data for all the 10 columns.
However, based on one of the input parameters, i need to display just 8 columns. I am able to hide the remaining 2 columns but i would like to delete those 2 columns from the report so that user does not see the hidden columns.
I tried to change the query but i am unable to dynamically set the select parameters.
Is there a way either in Query or in BIRT to remove few columns based on an input condition.
You cannot delete the columns, but it's sufficient to hide them dynamically using the column's visibility expression. You can add an aggregation to the table, using the MAX function for the column data (let's call it max_name).
E.g. if your table column shows the DS column NAME and you want to hide the column if NAME is empty for all rows:
Add an aggration (let's call it MAX_NAME) to the table, with the aggregation function MAX and the expression NAME. Then in the visibility expression of the table column, use !row["MAX_NAME"] as the expression.
After drag and drop the dataset. Right click on column header and select the delete column option.

How to rebuild data combination Power Query

In Power Query, I want to use a list of distinct values from one query (e.g. list of customers present on "Sales" table), to inject it on a SQL statement on another query (e.g. "Customer" dimensional table).
To pull the list of distinct values I have a function, getDistinct() that:
Retrieves one column from a query choice,
Only keep distinct values present on that column, and
Return these distinct values separated by commas so they can be injected within an SQL statement.
This function works fine on a standalone query. However, when I try to use it on my "Customer" query it throws an error (see code and error below):
let
Source = Oracle.Database("myServer", [Query="select * from db_customer where customer_id in (" & getDistinct(Sales,"CustomerID") & ")"])
in
Source
And the error:
Formula.Firewall: Query 'Customer' (step 'Source') references
other queries or steps, so it may not directly access a data source.
Please rebuild this data combination.
I've tried creating a different query that executes the function and then referencing it on my "Customer" query, but this doesn't seem to work. I know I can "Ignore Privacy Levels" (which by the way, I've checked and works), but since I don't know the implications of it, I'm afraid of leaked data.
I don't see why a function or any hand-written code is necessary for this requirement.
I would create a Query to get the Sales table and then Group by CustomerID. I would set that to: Load To / Only Create Connection.
Then the Customers Query would just be:
Source is Oracle Customers table
Merge to Sales Query on CustomerID, with Join Kind = Inner

Delphi XE7 TFDTable View RowID error

I'm converting a Delphi 5 / BDE application to Delphi XE7 / FireDAC. One of my forms has a TFDTable component that points to an Oracle view containing a group by clause in its create statement.
This used to work fine in the BDE application, but with FireDAC I'm getting this error.
ORA-01446: cannot select ROWID from, or sample, a view with DISTINCT,
GROUP BY, etc.
I understand the error I'm getting from Oracle, but I'm not selecting ROWID, FireDAC is! Is there a property in the TFDTable that I can set to prevent it from adding ROWID to the query? If not, how am I supposed to use this view?
FireDAC fetches ROWID because it tries to identify tuples in the resultset for possible updates. For stopping that just enable the ReadOnly option which will properly make the grouped view resultset read only (properly as one cannot just identify particular tuples if they are grouped in a resultset for updating).
The SQL command is generated in TFDPhysCommandGenerator.GenerateSelectTable method, if you wanted to know the source of this problem. There is appended generic unique tuple identifier to the select list according to the ReadOnly property setting (which is ROWID for Oracle DBMS).
Include fiMeta in FetchOptions.Items.
TFDQuery, TFDTable, TFDMemTable, and TFDCommand automatically retrieve
the unique identifying columns (mkPrimaryKeyFields) for the main
(first) table in the SELECT ... FROM ... statements, when fiMeta is
included in FetchOptions.Items. Note:
mkPrimaryKeyFields querying may be time consuming;
the application may need to explicitly specify unique identifying columns, when FireDAC fails to determine them correctly.
To explicitly specify columns, exclude fiMeta from FetchOptions.Items,
and use one of the following options:
set UpdateOptions.KeyFields to a ';' separated list of column names;
include pfInKey into the corresponding TField.ProviderFlags property.
When the application creates persistent fields, then initially
TField.ProviderFlags will be set correctly. After that, automatic
field setup will not happen, when the DB structure or query is
changed. You should manually update ProviderFlags to adjust the column
list. Also, if the primary key consists of several fields, then all of
them must be included into persistent fields. Row Identifying Columns
Alternatively, a row identifying column may be included into the
SELECT list. When FireDAC founds such columns, it will not retrieve
mkPrimaryKeyFields metadata and it will use this column. The supported
DBMSs are the following:
DBMS Row identifying column
Firebird DB_KEY
Informix ROWID
Interbase DB_KEY / RDB$DB_KEY
Oracle ROWID
PostgreSQL OID. The table must be created with OIDs.
SQLite ROWID
Source : http://docwiki.embarcadero.com/RADStudio/XE8/en/Unique_Identifying_Fields_%28FireDAC%29

Resources