How to set session oracle apex? - oracle-apex

SUPPOSE If i run any form in apex and then I will update any record then they get capture "APEX_PUBLIC_USER".
I want to capture my login user id by default using login URL
how to solve this ??

I'm not sure I understand what
I want to capture my login user id by default using login URL
means, but - user who is currently logged in is contained in :APP_USER so I suggest you use it.

The best practice in APEX to capture the audit fields (created_by, created, updated_by, update) is to use a trigger on the table. That way no coding is needed in apex itself.
Suppose you have a table rahul with a column "name" that you want to add records to via apex. Then you'd just create a form with the page item P1_NAME and let the database handle the other columns for you with the trigger.
create table rahul (
id number generated by default on null as identity
constraint koen_id_pk primary key,
name varchar2(255 char),
created date not null,
created_by varchar2(255 char) not null,
updated date not null,
updated_by varchar2(255 char) not null
)
;
-- triggers
create or replace trigger rahul_biu
before insert or update
on rahul
for each row
begin
if inserting then
:new.created := sysdate;
:new.created_by := coalesce(sys_context('APEX$SESSION','APP_USER'),user);
end if;
:new.updated := sysdate;
:new.updated_by := coalesce(sys_context('APEX$SESSION','APP_USER'),user);
end rahul_biu;
/

Related

Set column value from Application Item by using JavaScript in Oracle APEX interactive grid

i want to set column value in IG when user press Save. i have 2 columns 'created_by' and 'updated_by', now when my primary key column :P8_ID is null then should set 'created_by' column value using application item :SESSION_USER_ID which was set at login and 'updated_by' when :P8_ID is not null.
i can set using process on a Form where 'Page Items' are available but how to do the same for IG columns? please guide. --using Apex 21.1--
A common practice in apex applications is to have the audit columns on a table (created (date), created_by, updated (date) and updated_by) set by a trigger. The advantage of this approach is that this is transparent in your application. You don't have to worry about the audit columns anywhere in the application where insert/updates are done.
Example on a dummy table:
create or replace trigger test_table_biu
before insert or update
on test_table
for each row
begin
if inserting then
:new.created := sysdate;
:new.created_by := coalesce(sys_context('APEX$SESSION','APP_USER'),user);
end if;
:new.updated := sysdate;
:new.updated_by := coalesce(sys_context('APEX$SESSION','APP_USER'),user);
end test_table_biu;
/

wwv_flow_files no longer available to use its fields in Apex19.1

We are migrating applications from Apex4.2 to Apex19.1 and used Temp table (wwv_flow_files) in our one page to upload spreadsheet and then perform PLSQL process on the page. But as wwv_flow_files is now deprecated and we have to use APEX_APPLICATION_TEMP_FILES temp table but unfortunately the fields that we used don't exit in new Temp table in Apex19.1
select blob_content into v_blob_data from wwv_flow_files where last_updated = (select max(last_updated) from wwv_flow_files where upper(UPDATED_BY) = upper(:APP_USER)) and id = (select max(id) from wwv_flow_files where upper(updated_by) = upper(:APP_USER));
Little brief about PLSQL process: Above PLSQL is part of one block where Spreadsheet will be uploaded and then on multiple validations it gets values into Physical table of Oracle.
We are performing migration and have to make sure will minimal effort functionality should work as is.
Please help. Thanks in advance.
In the where clause you only need the column "name" from apex_application_temp_files!
https://docs.oracle.com/cd/E11882_01/appdev.112/e11945/up_dn_files.htm#CIHDDJGF
Example:
IF ( :P1_FILE_NAME is not null ) THEN
INSERT INTO oehr_file_subject(id,NAME, SUBJECT, BLOB_CONTENT, MIME_TYPE)
SELECT ID,:P1_FILE_NAME,:P1_SUBJECT,blob_content,mime_type
FROM APEX_APPLICATION_TEMP_FILES
WHERE name = :P1_FILE_NAME;
END IF;

How to search through rows and assign column value based on search in Postgres?

I'm creating an application similar to Twitter. In that I'm writing a query for the profile page. So when the user visits someone other users profile, he/she can view the tweets liked by that particular user. So for that my query is retrieving all such tweets liked by that user, along with total likes and comments on that tweet.
But an additional parameter I require is whether the current user has liked any of those tweets, and if yes, I want it to retrieve it as boolean True in my query so I can display it as liked in UI.
But I don't know how to achieve this part. Following is a sub-query from my main query
select l.tweet_id, count(*) as total_likes,
<insert here> as current_user_liked
from api_likes as l
INNER JOIN accounts_user ON l.liked_by_id = accounts_user.id
group by tweet_id
Is there an inbuilt function in postgres that can scan through the filtered rows and check whether current user id is present in liked_by_id. If so mark current_user_liked as True, else False.
You want to left outer join back into the api_likes table.
select l.tweet_id, count(*) as total_likes,
case
when lu.twee_id is null then false
else true
end as current_user_liked
from api_likes as l
INNER JOIN accounts_user ON l.liked_by_id = accounts_user.id
left join api_likes as lu on lu.tweet_id = l.tweet_id
and lu.liked_by_id = <current user id>
group by tweet_id
This will continue to bring in the rows you are seeing and will add a row for the lu alias on api_likes. If no such row exists matching the l.tweet_id and the current user's id, then the columns from the lu alias will be null.

Pass Mapping value to Session Email Task

I have 2 source. Oracle and SQL Server. I need to extract CustomerID from both and match. I need 2 outputs.
Number of CustomerID from Oracle
Number of CustomerID matching between Oracle and SQL Server.
Then, generate report and send it through mail to user.
Source - Oracle
Source - MS SQL
Joiner (Detail outer join with oracle)
Router
Group 1: CustomerID(Oracle) is not null and CustomerID(SQL Server) is null
Group 2: CustomerID from both not null
AGG transformation after both group to get count
Union to merge it
Load into target file
Now I will have to use Shell script to prepare mail and send it to user.
Is there way we can do it simple? like assigning count to workflow variable and then use it in Email task?
goto workflow:
open the session task and navigate to components tab
edit on sucess email and set type t0 non-reusable
click on edit button in value
click on edit button next to email text
enter "%l" . this will get the count of records and send to you in the email body.

Understanding Secondary Indexes

if i have Table
Table
CREATE TABLE Users (
userId STRING(36) NOT NULL,
contactName STRING(300) NOT NULL,
eMail STRING(100) NOT NULL,
....
) PRIMARY KEY (userId)
and secondary index
CREATE NULL_FILTERED INDEX ActiveUsersByEMail
ON Users (
eMail,
isActive,
)
and i select record by:
SELECT * FROM Users WHERE eMail = 'test#test.com' AND isActive = TRUE
spanner will automatically look at index, take userId and give me a record ?.
or i need to create
CREATE NULL_FILTERED INDEX ActiveUsersByEMail_01
ON Users (
eMail,
isActive,
userId
)
and first take userId by:
SELECT userId from Users#{FORCE_INDEX=ActiveUsersByEMail_01} WHERE eMail = 'test#test.com' AND isActive = TRUE
and then i take a record by:
`SELECT * FROM Users WHERE userId = '${userId}'``
Question is automatically use or not spanner secondary indices for standard select if condition match secondary index keys?
You should use FORCE_INDEX as Cloud Spanner will only choose an index in rare circumstances as stated here. You can use the STORING clause to add data directly to the index, allowing you to read the data directly from the index to avoid the second call. This is suggested for common query patterns in your application.
In github i ask same question and It turned out that this is easily done (without creating additional index) by:
SELECT * from Users#{FORCE_INDEX=ActiveUsersByEMail} WHERE eMail = 'test#test.com' AND isActive = TRUE
At this time the search is going on index and row come with all fields