How to query Receipt attachment in Purchase Order in Oracle Procurement Cloud - oracle

I am trying to write an SQL query in Oracle Procurement.
I am trying to add a field like 'If a purchase order has an attachment like receipts, it should show the attachment status as 'Y', if no attachment, it should show as 'N' if purchase order receipt is present.
I need to add a column for the above.
ATTACHMENT PRESENT = 'Y'
NO ATTACHMENT = 'N'
Purchase Order Number ATTACHMENT (PO receipt availability)
123456 'Y' (There is receipt)
234567 'N' (no receipt)
How can I make this possible?

Related

How to solve "Warning: triggers are created with compilation errors"?

Hi sorry for the inconvenience of posting a bad question. So below is the edit version of the question:
Purpose of this task:
In this task, I am trying to apply the company’s top client is the one who has purchased the most a discount with 15% discount. One of the requirement before creating this trigger is that - should not hardcode the top client since the top client could change when more purchases are made by other clients. I have created a trigger called TOP_CLIENT and edited the code as below:
AFTER UPDATE ON PURCHASE
BEGIN
SELECT PURCHASENO FROM PURCHASE
WHERE (SELECT MAX(AMOUNT) FROM PURCHASE P
JOIN CLIENT C ON P.PURCHASENO = C.CLIENTNO);
UPDATE PURCHASE
SET AMOUNT = (AMOUNT * 0.85)
END;
/
NOTE THAT:
The table CLIENT and PURCHASE are already created and existed in the database.
Shown errors within this code:
enter image description here
Please comment if any of the above doesn't make sense or have any questions related! Thank you!
First, I suggest adding a numeric DiscountRate column to the Client discount and populating it the applicable rate for any clients who get a discount.
Next, I suggest adding a numeric column called the same DiscountRate to the Purchase table.
With those in place, you can update any purchase row AFTER INSERT OR UPDATE only if the DiscountRate has not yet been applied to the purchase or is not equal to the current client discountrate, depending on your business logic;
DROP TRIGGER TOP_DOSCOUNT;
/
CREATE TRIGGER TOP_DOSCOUNT
AFTER INSERT OR UPDATE ON PURCHASE
FOR EACH ROW
WHEN DiscountRate IS NULL
DECLARE dr PURCHASE.DiscountRate%type;
SELECT nvl(C.DiscountRate,0.0) INTO dr FROM CLIENT C
WHERE PurchaseNo = C.ClientNo;
UPDATE PURCHASE
SET Amount = Amount * (1 - dr), DiscountRate = dr;
END;
/
I am unsure if you want to constantly be updating all your prior purchase records with new discount rates. If not, then I suggest this should Only be an insert trigger...but only you know your business logic to be implemented!

Check oracle table for an expiry date and send mail

I have a table pro where I have following fields
id, product name, email and expiry
I am trying to send an email from oracle when expiry date match with system date.
Is it possible through oracle jobs/scheduler or any other way?
You can use the query below to find a list of users. In my example, I have 120 days so modify it to fit your needs.
In addition, you will need a place to store the email address for each user than JOIN the tables and you can write some code to loop through the list and send mail.
Depending on your platform you can use utilities like mail or setup an Oracle mail server, which is a bit involved.
select username as “USER NAME”, expiry_date as “EXPIRE DATE”, account_status
from dba_users
where expiry_date < sysdate+120
and account_status IN ( ‘OPEN’, ‘EXPIRED(GRACE)’ )
order by account_status, expiry_date, username;

How can i create a pop up list of values in oracle apex that validates logged in user?

I want to show the employee name/id of only the logged in user so that he can put his own id/name in the insert sale record. is that possible and if so how will i be able to do it in that specific field in the form. in my example i want only zhr123 to appear in the pop up list of values. Please refer to this image
Once you're logged in, :APP_USER contains your username.
Therefore, if it has to be a select list item (though, I don't know why as there won't be anything to choose among), include such a condition into its where clause:
select name
from your_table
where name = :APP_USER --> this
Perhaps you'd just rather use it (i.e. the :APP_USER) as item's default value.

How to arrange data in SQL?

I am using Oracle SQL Plus.
Please refer to screenshot for reference.
After deletion of data of column sno=4, I want the output of sno to be displayed in serial order ie 1,2,3,4 instead of 1,2,3,5.
Please suggest the SQL query to achieve same.
try:
select ROWNUM as SNO, NAME,DOJ from company order by SNO
If you want the numbering to be persistent, you will need to update the SNO for all the remaining records in the table.
What you have done, by deleting the row is say that "row number 4 no longer exists". If you want to shuffle the remaining rows up, you will need to perform the following:
DELETE FROM company WHERE name='Flipkart';
UPDATE company SET sno=sno-1 WHERE sno>=4;
An alternative, if you don't want to alter the contents of the table itself.. But you want it to display correctly (specifically for this example)
SELECT
CASE
WHEN sno <= 4 THEN sno
ELSE sno-1
END AS sno,
name,
doj
FROM company
ORDER BY sno;

Trying to create a trigger that updates a table when a value in another table is changed (oracle apex)

So I have two tables, one is called "device" the other is "devicerequest"
The "device" table has columns including id (primary key), name, quantity and basically has data like "(1, iPhone, 3), (2, iPad, 1), which is saying: id=1 name=iPhone quantity=3.
The "devicerequest" table has columns including requestid(primary key), deviceid, devicequantity, and has data like (22, 1, 2) which means that it is requesting 2 of the iPhones.
So basically I am trying to create a trigger when the admin confirms the request (their is an approval column in "devicerequest" (which is NULL when a projectrequest is made) and sets it to 'Y' which means yes to the request, it should change the quantity column in device by subtracting the number that was requested (their is a constraint in place to make sure you do not request devicequantity > quantity).
So I have tried a ton of different variants of this, but still keep getting errors, this is what I currently have:
create or replace trigger "DEVICEREQUEST_T1"
before update on "DEVICEREQUEST"
for each row
begin
if(:NEW.approval = 'Y')
then
update device set device.quantity = device.quantity - devicerequest.devicequantity
where device.id = devicerequest.deviceid;
end if;
end;
I get these errors for this:
6 23 PL/SQL: ORA-00904: "DEVICEREQUEST"."DEVICEID": invalid identifier
5 5 PL/SQL: SQL Statement ignored
I have also tried this:
create or replace trigger "DEVICEREQUEST_QUANTITY"
BEFORE
update of "APPROVAL" on "DEVICEREQUEST"
for each row
when (NEW.approval = 'Y')
begin
update device set quantity = quantity - devicequantity where id = deviceid;
end;​
I get these errors for this:
2 67 PL/SQL: ORA-00904: "DEVICEID": invalid identifier
2 1 PL/SQL: SQL Statement ignored
I am using Oracle Application Express 4.2.5, thanks for any sort of help I have been working on this for a while and cannot figure out what is wrong.
Your UPDATE statement would be something like
update device
set device.quantity = device.quantity - :new.devicequantity
where device.id = :new.deviceid;
Of course, in a real system, if admins can be approving requests in parallel, you can easily come up with cases where this would cause the quantity to drop below 0.
You say that you have a constraint that prevents the devicequantity from exceeding the quantity but you can't have a constraint that compares data across tables. You could have a trigger that performs that validation. If so, it is highly likely that your trigger is not sufficient in a multiuser environment to enforce the constraint you expect it to be enforcing.
You could issue an update removing the requested amount at the time of the request rather than approval. If the update would cause the qty to drop below zero, you get an error, otherwise you have "reserved" that number for sale and you don't have to worry about requests coming in very close afterwards. When the request is approved, you have that amount locked in, if disapproved, update the qty to "return" the reserved amount.
You might want to adjust the process depending on the length of time between request and approval and/or if there is some way to determine the probability of approval/disapproval. You could reserve, say, 50% of the requested amount rather than all of it for lower probability requests.

Resources