How can I load images dynamically in place of cell data in a report in Oracle Application Express?
E.g.
A table has 'Y' and 'N' entries. When I display it as a report, I want to use certain images according to the data in the table. If it's a 'Y', display one image and if it's a 'N', display another image.
You can do this:
select id,
htf.img (case when flag='Y' then 'yesicon.png'
else 'noicon.png' end) flag_icon
from mytable
where ...
You probably need to add a path for the filenames e.g. '#WORKSPACE_IMAGES#yesicon.png' etc.
If you will be using this a lot it would be worth building a function to simplify it:
select id,
mypkg.yesno_icon (flag) flag_icon
from mytable
where ...
Related
I do voluntary work at an animal shelter. We have an application which uses a SQL Server 2019 database. I have created a view that includes a varbinary(max) column. The value in this column is a picture, stored in hexadecimal-format. I would like to convert this Hex-value to a base64-binary file and add these to the view as an extra column.
I found the perfect solution for my situation in SQL Server : hex to base64. The example provided converts 1 single hex-value into 1 base64-value. I now need to add this solution to my view, but I'm not having any success.
The offered solution:
DECLARE #TestBinHex varchar(max), #TestBinary varbinary(max), #Statement nvarchar(max);
SELECT #TestBinHex = '0x012345';
SELECT #Statement = N'SELECT #binaryResult = ' + #TestBinHex;
EXECUTE sp_executesql #Statement, N'#binaryResult varbinary(max) OUTPUT', #binaryResult=#TestBinary OUTPUT;
SELECT
CAST(N'' AS XML).value(
'xs:base64Binary(xs:hexBinary(sql:column("bin")))'
, 'VARCHAR(MAX)'
) Base64Encoding
FROM
(SELECT #TestBinary AS bin) AS bin_sql_server_temp;
A simplified version of my view:
SELECT
a.cat_id, a.catname, s.cat_id,
s.stay_id, s.shelter_handler, s.shelter_kennel, s.picture
FROM
dbo.animal AS a
OUTER APPLY
(SELECT TOP 1 *
FROM dbo.shelterdata
WHERE a.cat_id = s.cat_id
ORDER BY s.stay_id DESC) AS S
WHERE
(a.cat_id IS NOT NULL) AND (s.leave_date IS NULL)
The view shows an overview of all cats currently present in the shelter (leave_date is NULL). The reason for the TOP 1 is that sometimes shelter animals get returned, and the application then assigns a new stay_id. To prevent duplicate values from the join, I only return the value of the most recent stay_id.
What I am trying to achieve: the second table (dbo.shelterdata) includes the picture, stored in hex value. I'd like to add a column Base64Encoding to the view which includes the converted value.
My attempts
I was successful in replacing the static value '0x012345' by a SELECT statement. But the way the solution is formatted, it only allows for one input value. So I had to restrict it with a WHERE clause. It is obvious to me that I need to make a subquery which inputs the hex value based on the unique cat_id. However, it has been many years since I worked with variable, so I'm struggling with the formatting of the statement.
My request
Does anyone have a suggestion how to build the conversion into the view?
Any assistance would be greatly appreciated.
After searching for a few more hours, I stumbled onto the solution. Maybe it will help someone else in the future. The solution is remarkably simple, as is often the case.
My view, mentioned above, is called dbo.shelter_view
select sv.picture,sv.cat_id,
cast('' as xml).value(
'xs:base64Binary(sql:column("sv.picture"))', 'varchar(max)'
) as Base64Encoding
from dbo.shelter_view as SV
I have a checkbox with list of values from table a. I need them to be checked if are present in a column of table b. Do you have any ready solution please colleagues ?
Thx
Adam
See this similar question for some background info.
When you're working with a multi-value checkbox item, you want your Source Query to select a colon-delimited list of the values that you want to be checked in your checkbox. (This is true for multi-value Application Express page items in general.) E.g.
select listagg(my_column, ':') within group (order by my_column)
from TableB
where my_column is the name of the column in TableB that your values are stored in.
If you have a lot of values in TableB (enough that the listagg() above returns more than 4000 characters), you'll need a fancier query, but for most cases it'll work fine.
I've been browsing and to no avail, I can't find any information on how to select/show only the column header. My objective is to select only column header . I've uploaded a picture for better illustration on my objective. In the picture shown, I'm trying to only select and display the one ive highlighted in the red box.
Oracle table:
The only information I found from the net is selecting an individual column, and with that. It will display the data as well which is not my objective. my main objective is to only select column headings.
In Oracle APEX SQL Workshop you can describe a table with this command:
desc table_name
If you're using a query, you can click on the "Describe" tab below the query and above the result grid.
I had a similar requirement, so in page designer I plugged in a "Where Clause = Sysdate-1"
you can use select and null to pick columns and use alias to name them
select null AS column_name,null AS column_name
from TABLE_NAME
Problem:
I want to provide my users with an Excel-Grid-like Client-Side Application. That client accesses the PostgreSQL-Server over a Network-Connection.
The client offers a "Find"-Functionality. Instead of filtering and showing only the matching results, the "Find"-function just jumps to the first matching Row in the Grid. (Like the "Find"-Function in Excel)
To reduce the bandwidth-usage and prevent lame LIMIT/OFFSET-Selects, I am using PostgreSQL with server-side cursors to allow scrolling over the sorted Table:
BEGIN WORK;
DECLARE mCursor SCROLL CURSOR FOR
SELECT *
FROM table
ORDER BY xyz
Scrolling and retrieval of the result-data is handled by calling Move/Fetch each time the client scrolls within the grid:
MOVE FORWARD/BACKWARD <offset> IN mCursor; FETCH 40 FROM mCursor;
Now i want to add the "Find"-Functionality witch uses an Index to find the first matching Result-Offset. The only way i know to integrate this functionality is to open a new connection and run the following query and then move the cursor to the returned rowNo:
SELECT t.rowNo
FROM (
SELECT ROW_NUMBER() OVER (ORDER BY ColumnName ASC) AS rowNo
FROM table
) t
WHERE t.ColumnName LIKE 'xyz%'
LIMIT 1
Problem: This query is extremely slow because it can't use an index (2-3 Seconds for ~300k Rows).
Is there an other way to integrate this task more efficient?
Maybe by reading the offset directly from the index-data? Or by starting a query within the Cursor? Or is there a database-system allowing this functionality?
It would not be possible to use an index only if the pattern started with a %.
I guess the problem is not that it can't use an index but that it has to scan the whole index to enumerate all table rows. Show the explain.
This will limit the index scan up to the searched pattern
SELECT min(t.rowNo)
FROM (
SELECT
ROW_NUMBER() OVER (ORDER BY ColumnName ASC) AS rowNo,
ColumnName
FROM table
where ColumnName <= 'xyz' || repeat('z', 100) -- Get all possible like 'xyz%'
) t
WHERE t.ColumnName LIKE 'xyz%'
in my oracle database contained the following data
http://i1207.photobucket.com/albums/bb476/daniwarrior/data-awal.jpg
I want to display the data as shown below
http://i1207.photobucket.com/albums/bb476/daniwarrior/data-aKHIR.jpg
Whitelist column are merging whitelist_pembayaran column, whitelist_pemasan, and whitelist_jenis_iklan
Blacklist column are merging blacklist_pembayaran column, blacklist_pemasang, and blacklist_jenis_iklan
whether the query in oracle can do? if you can how to query to display data like the picture above
*)sorry I can not show pictures because my reputation is less to be able to display the image, so I provide a link to the picture
This is string aggregation within group and string concatenation.
In Oracle 11g you can:
select
id_pegawai,
listagg(whitelist_pembayaran||whitelist_pemasan||whitelist_jenis_iklan,',') within group (order by id_pegawai) as whitelist,
listagg(blacklist_pembayaran||blacklist_pemasang||blacklist_jenis_iklan,',') within group (order by id_pegawai) as blacklist
from table
group by id_pegawai;
(in Oracle <= 10g you may use wm_concat function)
But you have to deal with commas.
Below a try for withelist(for blacklist is the same code):
select
id_pegawai,
listagg(whitelist_pembayaran||decode(whitelist_pembayaran,null,null,',')||
whitelist_pemasan||decode(whitelist_pemasan,null, null, ',')||
whitelist_jenis_iklan,',')
within group (order by id_pegawai) as whitelist
from table
group by id_pegawai;
As explanation: the decode will put a comma after a field only if the field is not null. After whitelist_jenis_iklan is not needed a coma and listagg knows to deal with its comma.