SQL & PL/SQL :: Conditional Predicates Is Not Working With MERGE
Aug 6, 2012
I realized that in statement level trigger conditional predicates(INSERTING, UPDATING & DELETING ) are not working.
For example please run below sql:
create table merge_test(col1 number, col2 number);
create or replace trigger merge_test_tr_stat
after INSERT OR UPDATE OR DELETE on merge_test
begin
if inserting or updating or deleting then
dbms_output.put_line('conditional predicates is working ');
else
dbms_output.put_line('conditional predicates is not working ');
end if;
end;
set serveroutput on;
insert into merge_test values (1,1);
Output
------
1 rows inserted.
conditional predicates is working
conditional predicates is working
set serveroutput on;
merge into merge_test mt using ( select 1 col1 from dual ) tab
on ( mt.col1 = tab.col1 )
when matched then
update set col2 = 2
when not matched then
insert values (1,1);
Output
------
1 rows merged.
conditional predicates is not working
conditional predicates is not working
How to use those conditional predicates in statement level trigger.
I am using the following merge statement it's not working properly. If I tried to insert (or) update the existed record. I am getting unique key constraint violated error.
Below is the sample code working fine in 10g and not working now in 11g.
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "PSTest" AS import java.sql.SQLData; import java.sql.SQLException; import java.sql.SQLInput; import java.sql.SQLOutput; import java.util.List; [code]....
we got the below error: ORA-00932: inconsistent datatypes: expected an IN argument at position 1 that is an instance of an Oracle type convertible to an instance of a user defined Java class got an Oracle type that could not be converted to a java class
Current Oracle version is Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit and the version we are upgrading is Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit
how to do a conditional range in a query. For example, I have two tables:
table A: a1 char(1) a2 char(1)
table B: b1 char(1) b2 int
In my query I want to range on a different value in the b2 field depending on what is in the fields in the A table. For example, if the a1 field is Y, I want to look up the record in B with a b2=20. If a2 is Y, I want to look up b2=5. Otherwise I want to look up b2=1. I attempted the following:
select b1 from b, a where b2=(if a1='Y' then 20; elsif a2='Y' then 5; else 1)
I'd like to select one of two fields from a table, based on which of them is greater for that row.
e.g. For every row in JOINING_TBL, I'd like to select either JOINING_DATE or REJOINING_DATE, whichever is greater. I do dream about being able to use a Java-like ternary operator in here, something like this:-
SELECT (JOINING_DATE>REJOINING_DATE?JOINING_DATE:REJOINING_DATE) FROM JOINING_TBL
However, I understand(through other fora) that this can't be used in here.
I'd like to have a conditional that only gets the next value from a sequence is the current (or supplied) value is null.
Here are some trivial examples:
CREATE SEQUENCE ts MINVALUE 1 START WITH 1 INCREMENT BY 1; SELECT ts.NEXTVAL FROM DUAL; SELECT COALESCE(ts.CURRVAL, ts.NEXTVAL) FROM DUAL; SELECT NVL(ts.CURRVAL, ts.NEXTVAL) FROM DUAL; SELECT CASE WHEN ts.CURRVAL IS NOT NULL THEN ts.CURRVAL ELSE ts.NEXTVAL END FROM DUAL;
Ideally multiple executions of any of these (or a better one of your design) should return the same value from the sequence, but mine do not.
The conditional statements should not only be executed in sequence, but also if any of them are true they should not be overridden by any subsequent conditional statements being true.
When actual effort Accepted or Rejected for AST proposals and calculate a flag for "enhance to AST guideline" = Y/N as follows for each employee and display at the employee level
1)If AST eligibility = N AND proposed AST % >0, then "N" 2)Else If AST eligibility = N AND proposed AST % = 0 then "n/a" 3)Else If AST eligibility = Y AND Act Rank = 3 AND proposed AST = 0 then "Y" 4)Else If AST eligibility = Y AND Act Rank = 3 AND proposed AST >0 then "N" 5)Else If AST eligibility = Y AND Act Rank = 2 AND proposed AST = 0 then "Y" 6)Else If AST eligibility = Y AND AST % is greater than or equal to the AST guideline minimum AND less than or equal to the AST guideline maximum, then "Y" 7)Else If AST eligibility = Y AND AST % is less than the minimum guideline OR greater than the maximum guideline, then "N"
I tried the following code but I am not getting the expected result .
if (upper(P_stat)='ACCEPTED' or upper(P_stat) like 'REJECTED%') then else if NVL(P_elgi,'N') <> 'Y' AND P_prop > '0' then P_flag := 'N'; else if(NVL(P_elgi,'N') <> 'Y' AND P_prop = '0') then [code]........
I am trying to create procedure to delete data from audit table but don't know where to start with..
1. Procedure will run on first Saturday of the month (not sure is it possible via pl/sql or have to create separate job) 2. Delete data older than 2 months from Mon - Sat and date shouldn't be 1st of the month. (i.e. leave Sunday & 1st of the month data older than 2 months) e.g.{code}
Procedure delete_log IS BEGIN delete from audit_logs where created >= trunc(sysdate - 60) and created < trunc(sysdate) and created != (Sunday) and created != (First of the month);
I have two tables : oa_membership_dtl(in this created_by field is varchar2(200 byte) ,oa_partner_usr_dtl(in this table partner_userid is number(8,0) i need to do join on above fields.
I am using following two queries:
select * from oa_membership_dtl membership join oa_partner_usr_dtl partner_user on to_char(partner_user.partner_userid,'9999')=membership.created_by select * from oa_membership_dtl membership join oa_partner_usr_dtl partner_user on rtrim(ltrim(partner_user.partner_userid||' '))=rtrim(ltrim(membership.created_by))
by using first data is not fetched but 2nd is working fine , i am getting the matched records using 2nd query.
We have multiple environments and our dev and UAT ones are now different from staging and live (I know, but I am not in a position to get this fixed). I have a set of updates that need to go through to live and in some cases they reference rows that do not exist in the UAT environment, and yet they have to (rigid, dumb process) go through that environment.
Basically, the insert I need to do takes info from two tables and does an insert into a third. That target table has a not null constraint on the affected fields, so the insert fails, quite rightly.
There's lots of info available on how to do conditional inserts with single sub-queries, using DUAL and EXISTS (or rather NOT EXISTS, but that's easy to swap), but those don't seem to easily translate for this one.
The sql that works when everything exists is:
insert into wmcontent.wm_manda_corpserv_companies (wm_manda_company_code, wm_corp_company_code) values ( (select wm_company_code from wmcontent.wm_m_and_a_company where wm_company = 'SW'), (select min(oid) from wmcontent.wx_category where content_type = 2 and name = 'SW') );
In desperation I even tried using "log errors reject limit unlimited" but, no doubt due to my misunderstanding of how that works, I ended up getting the error "ORA-06550: line 38, column 1: PL/SQL: ORA-00972: identifier is too long" as a result.
I want to write a sql qeuery to get result similar to expected average column as shown in sheet.
Record can be uniquely identified by columns ID, PRODUCT and OFFICE. I want to calculate average for each date considering the same record does not exists earlier i.e. I want to consider the latest vote while calculating average. E.g.
Average till date 1/1/2011 is Avg (2, 4, 3) = 3 (as no repeating vote value exists) Average till date 2/1/2011 is Avg (4, 3, 5, 3) = 3.75 (excluding vote value 2 as 122_UK_LONDON was provided his vote earlier, so considered latest vote value i.e. 5) Average till date 3/1/2011 is Avg (3, 5, 3, 6, 5, 8 ) = 5 (excluding vote value 2 for 122_UK_LONDON and vote value 4 for 967_Europe_London)
I'm using the Oracle Emp,Dept tables as my sample. I want to display certain table column values based on some criteria. If met, display those values otherwise display other column values
For example:
So when dept.deptno=10, I want to display these 2 columns values 1. dept.deptno 2. dept.dname
otherwise, display these 2 columns values 1. dept.loc 2. null
Can this be done with one case, decode or "other" type of structure going thru the table one time??
SELECT emp.empno, emp.ename, CASE WHEN dept.deptno = 10 THEN to_char(dept.deptno) [code].......
Let's say there are two almost identical window and some specific functions associated: W1 and W2.
Depending upon the login profile into the application only one window and associated functions will be appeared. This time the other window will be disabled.
I am using Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production versionI have following table - drop table t2;
create table t2(BATot,Ly_BATot,LLy_BATot,BScTot,Ly_BScTot,LLy_BScTot,BAMSTot,Ly_BAMSTot,LLy_BAMSTot) as select 5000,2000,12600,20000,45600,35000,45000,56000,65000 from dual ;
select null class, batot,ly_batot,lly_batot,bsctot,ly_bsctot,lly_bsctot,bamstot,ly_bamstot,lly_bamstot from t2; Simple DML I am using - SELECT * FROM T2;
Is it possible within a CASE statement to put conditions on the date range that I want to pull? IE: am versus pm. The query has to pull specific time ranges for an AM run versus a PM run. ..... FROM table WHERE CASE WHEN TO_CHAR(SYSDATE,'AM') = 'AM' THEN table.date BETWEEN TRUNC(SYSDATE) AND SYSDATE ELSE table.date BETWEEN TRUNC(SYSDATE+12/24) AND SYSDATE
Is there a way to make a button conditional on the existence of another app in the same workspace. What I am trying to do is have a MAIN app and several other MODULE apps in the same workspace. Then a button on a form in the MAIN app that will redirect to a specific page in one of the MODULE apps. If the MODULE app does not exist, meaning not installed, then the button would be invisible.
I implemented the re Captcha plugin and it works ok. What I want to do is, on the same page where the captcha is displayed, to have a report region that is displayed conditionally based on the captcha result.
More specifically, the page has two items for user input (the captcha and a text item) and a Submit button. If the captcha is successful, then the text item will be submitted and the region displayed. The problem I'm running into is that the text item is always submitted regardless of the captcha.
I have an item that does not save to the database.it is conditional read only based on the value in another column, when it is not read only it displays as a Select list.. then whatever is chosen triggers a dynamic action that sets other items.so setting it as a display only is not an option.
after upgrading from 4.0 to apex 4.2 this gives error: Session state protection violation: This may be caused by manual alteration of protected page...
the only workaround I have found is to set the Read Only to none, then create a dynamic action that conditionally sets the field to disabled..This works, but my problem with it is that it looks different than the read only..read only was Black Text and no textbox..disabled is a text box with greyed out text that is hard to read for some of the users..
Apex 4.2I currently have a report column in a classic report that has a Column Formatting Attribute as below. This works fine it shows a map icon that when you click on it goes off to google maps and put 2 geo points on a map. However I need to change this report column so that the HTML expression will be different dependent on the value returned so if the column returns 1 then the HTML Expression will be slightly different.
I think I can do this in the report source directly with a case statement and include the HTML in that for the column but how do you handle all the quotes within the SQL statement. e.g.
Original Query SELECT parcel_id ,status ,LOCATION ,scan_date ,scan_id ,driver_comments ,card_id ,valid_geo_codes -- this is my html column ,property_geo_lat ,property_geo_long ,scan_geo_lat ,scan_geo_long ,broke_geo ,line_1 ,post_code FROM vw_parcel_history_details WHERE parcel_id = :p341_parcel_id ORDER BY scan_date New Query SELECT parcel_id ,status ,LOCATION [code].....
various iterations of that large html string but I do not know how to format it because off all the quotes?
For our customer we have build a custom login page. The form we currently made has de following items:
- Username - Password - Select list for selecting the task type
When the customer enters his username, automatically the select list of the task type will be refreshed to get only the task type where the customer has the rights to do it. This part works...It can occur that a customer has only one task type (which is default) then we want to hide the select list. This part doesn't work
We used APEX version 4.1.1.What we did is:
- One action item to refresh the selection list (works) - One action item to hide the selection list by starting the application (works) - One action item to show the selection list only when the selection list has more than one result. For this part we used the conditional part of the action item (Function returning a boolean).
In the query (inside the function) we want to use the entered username, looking into the application in the session state I saw the correct username, but for some reason the function cannot use this entered username, it becomes empty. When I use a hardcoded username the code works.
Why I cannot use a username into the conditional part of the Action Item.
I had a few regions on my page, the 2nd did not start a new row so it appeared horizontally where possible.During some experimentation, I created a new region with a sequence in between that started new row, but even when that region was conditionally never, my original 2nd region started on new row.
Original: Region 1 - Region 2(empty) - Region 3 (new row/col no)> New region added: Region 1Region 1.5 (added, new row) Region 2 Region 3> Region 1.5 not shown: Region 1Region 2 Region 3>
Let me know if you would like a test case for better visualisation.
Id Country city 1 US 2 US Boston 3 Boston 4 US Newyork 5 London 6 Japan Tokyo
Im looking for a query which returns results based on both city and country passed.
If i pass country US and city Boston it should return row2 with US and Boston row If i pass country null and city Boston it should return row3 If i pass country UK and city Boston it should return row3 If i pass country UK and city London it should return row5
i.e. If country/city combination exists in DB return that row Else city row should be returned.
We have an issue after migrating to apex 4.2.1. We have a select list and use another couple of dummy items to be used as its label instead of giving the text value to the LABEL control. Only one of the dummy items is shown as a label for the select list conditionally based on another value. It was working fine with the earlier versions upto 4.1, but with the introduction of grid in 4.2, its now displaying the select list on a new row (ie the lable in one row and the select list on the next row).
However, we really would like to solve this by having a way to display the label of the select list either in "required format style" or as an "optional style". The display style should be determined only at runtime.
Example. Say P100_MY_SELECT_LIST is the select list
The label for this item is "My Select List Label"
I have another dummy item P100_DUMMY
if P100_dummy = 1 then the label "My Select List Label" should be displayed in red and with an * *My Select List LabelOtherwise it should be in black and without * My Select List Label.
run down of the implications of MERGE by ROWID in such a fashion:
CODE MERGE INTO XXWT_AP_ACCRUALS_RECEIPT_F EXT USING ( SELECT PO_DISTRIBUTION_ID,
[code]...
Can this lead to an "Unstable Set of Rows?". Is it possible for the ROWID's to change during the execution of this statement - meaning certain ROWIDs identified in the SELECT will not actually be updated when it comes to the MERGE operation?
Basically, is it sound practice to use ROWID to merge on - in cases where you dont have a WHEN NOT MATCHED condition?