dynamic logic in SQL WHERE clause based on the value of the ELEMENT
HelloI have a report based on the following SQL query.
select dept_no,
dept_name,
dept_loc
from dept
where dept_loc = :P1_DEPT_LOC
// If P1_DEPT_LOC is not null, I want the WHERE clause and IF P1_DEPT_LOC is null, then I don't need the WHERE clause.
// how can I build this logic in same SQL
Thank youDeepak
Published by: Deepak_J on March 11, 2010 16:37
where: P1_DEPT_LOC IS NULL or dept_loc =: P1_DEPT_LOC
If dept_loc is not null better would be
where dept_loc = coalesce(:P1_DEPT_LOC,dept_loc)
Tags: Database
Similar Questions
-
Conditional WHERE clause based on the input of parameter
When the restriction of data based on a parameter I generally use the following syntax:
AND p.start_date = NVL (p_start_date, p.start_date)
so IF the parameter is null, THEN I join only on itself, OTHERWISE we filter on parameter.
New requirement means greater than or equal to, so I tried this:
AND THE CASE
WHERE (p_start_date = NULL) THEN
p.start_date = p.start_date
ON THE OTHER
p.start_date > = p_start_date
END;
but, at least, is syntactically incorrect.
Any suggestions?
Thank you!Do not use = with NULL - change IS null
-
Setting of outsourcing work is not for a SQL Where clause
Im trying to outsource the WHERE SQL clause of a snapshot data (connecting to Siebel DB) and specify where clause in the run profile that does not work.
Snapshot of research: Select the name of siebel.s_org_ext
Parameter of outsourcing: where_clause_sql
Run the content of the profile:
phase. Phase1.snapshot.clt.where_clause_sql = name = "ABC0009".
#phase. Phase1.snapshot.clt.snapshot_sql = select name from siebel.s_org_ext where name = 'ABC0009 '.
The above parameter retrieves all the records in the table. Below the profile execution retrieves just this record that seems to work fine.
Run the content of the profile:
phase. Phase1.snapshot.clt.snapshot_sql = select name from siebel.s_org_ext where name = 'ABC0009 '.
I want to outsource only where clause as there are many SQL and they are huge to maintain in the run profile.
I have attached a doco with screenshots that will help to understand more.
Hello
You must BE
-Choose "Select table or view" in the table of the snapshot Wizard selection page
&
-Use outsourced where clause
OR
-Choose "SQL" in the snapshot table selection wizard page.
&
-Outsourced use SQL snapshot
You can't mix and match options.
Kind regards
Nick
-
Exclude duplicates on SQL where clause statement
Hello!
Are a few posibilities to exclude duplicates do not using aggregate sql in a main select functions?
Priview SQL statement
SELECT * FROM ( select id,hin_id,name,code,valid_date_from,valid_date_to from diaries ) QRSLT WHERE (hin_id = (SELECT NVL(historic_id,id)FROM tutions where id=/*???*/ 59615)) AND NVL(valid_date_to,to_date('22.12.2999','dd.mm.yyyy')) <= (SELECT NVL(valid_date_to,to_date('22.12.2999','dd.mm.yyyy'))FROM tutions where id= /*???*/ 59615) AND trunc(valid_date_from) >=(SELECT trunc(valid_date_from)FROM tutions where id= /*???*/ 59615) ;
The result
ID HIN_ID NAME CODE VALID_DATE_TO VALID_DATE
50512 59564 RE YOU 01 07.06.2013 16:32:15 07.06.2013 16:33:28 50513 59564 TT2 02 07.06.2013 16:33:23 07.06.2013 16:33:28 50515 59564 TT2 02 07.06.2013 16:33:28 07.06.2013 16:34:42 50516 59564 STEM 03 07.06.2013 16:34:37 07.06.2013 16:34:42 VALID_DATE_TO & VALID_DATE_FROM information AND
07.06.2013 16:34:42 15.07.2013 10:33:23 In this case, I had doubles of the TT2 50513 entry in a statement identifier select main cant use agregate functions are still possible to exclude this result value by changing only the QLRST a WHERE clause (TRUNC must be here)
THANKS FOR ANY ADVICE!
FDA
Try this,
WITH QRSLT AS (SELECT id, hin_id, name, code, valid_date_from, valid_date_to FROM diaries) SELECT * FROM QRSLT A WHERE (A.hin_id = (SELECT NVL (historic_id, id) FROM tutions WHERE id = /*???*/ 59615)) AND NVL (A.valid_date_to, TO_DATE ('22.12.2999', 'dd.mm.yyyy')) <= (SELECT NVL (valid_date_to, TO_DATE ('22.12.2999', 'dd.mm.yyyy')) FROM tutions WHERE id =/*???*/ 59615) AND TRUNC (A.valid_date_from) >= (SELECT TRUNC (valid_date_from) FROM tutions WHERE id = /*???*/ 59615) AND A.valid_date_from = (SELECT MAX (B.valid_date_from) FROM QRSLT B WHERE A.Name = B.Name AND A.Code = B.Code AND A.hin_id = B.hin_id)
-
Where conditional Clause based on the length of the field
Hello people,
I tried to search for this scenario in OTN and not been able to find any success so I will post the question here.
I have two tables - with the detail records and the other being a table of codes. I need to join these two tables based on the code and the length of the code. Let me explain using examples.
Scripts for creating the table and inserts
As you can see that patients * 1001 * and * 1002 * have no codes in the Master table. In this case, I want only the first 3 characters of the ILLNESS_CODES table.create table ILLNESS_CODES(illness_code varchar2(4), illness_description varchar2(100)); create table PATIENT_TB(patient_id varchar2(4), primary_cause varchar2(4)); insert into illness_codes values('B10', 'Flu'); insert into illness_codes values('B30', 'Hepatitis'); insert into illness_codes values('B301', 'Hepatitis A'); insert into illness_codes values('B302', 'Hepatitis B'); insert into illness_codes values('B303', 'Hepatitis C'); insert into patient_tb values ('1001', 'B101'); insert into patient_tb values ('1002', 'B102'); insert into patient_tb values ('1003', 'B30'); insert into patient_tb values ('1004', 'B301'); insert into patient_tb values ('1005', 'B302'); insert into patient_tb values ('1006', 'B302'); insert into patient_tb values ('1007', 'B303'); insert into patient_tb values ('1008', 'B30');
However, for B30, it has a Code and the same for B301, B302 B303 where I would meet the description based on the exact code.
Example of output
Thanks in advance!Patient ID Illness Description ===================================== 1001 Flu 1002 Flu 1003 Hepatitis 1004 Hepatitis A 1005 Hepatitis B 1006 Hepatitis B 1007 Hepatitis C 1008 Hepatitis
SELECT p.*, NVL ( (SELECT illness_description FROM ILLNESS_CODES I WHERE i.illness_code = p.primary_cause), (SELECT illness_description FROM ILLNESS_CODES I WHERE i.illness_code = SUBSTR (p.primary_cause, 1, 3))) FROM PATIENT_TB p;
-
where clause to query the hierarchy in the tree Apex area does not
Hi all
I am building a tree Menu in Apex 5.0.3 (Oracle 11 g XE), when using when the clause, it does show all the data, but without him, showing all the data.
I'm trying to populate Tree Menu with data specific to a user successfully logged on.
(A) table created as HR2. TREE_MENU
menu_name varchar2 (50).
number of menu_parent
number of menu_child
menu_id varchar2 (12),
menu_path varchar2 (100),
number of user_no
(B) SQL statement for the tree in the Apex region
Select case when connect_by_isleaf = 1 then 0
When level = 1 then 1
else -1
end the status,
level,
'Menu_name' as the title,
NULL as an icon,
"MENU_CHILD" as a value.
NULL as ToolTip,
NULL as link
to HR2. "" TREE_MENU ".
-WHERE USER_NO =: P_USERNO
Start with 'MENU_CHILD' is null
connect prior "MENU_PARENT" = "MENU_CHILD."
brothers and sisters of order by 'MENU_ID '.
Note: also used static value where clause but is not workd.
that the mistake of me or something else? When using the wizard, she asks (possibly) where clause, this means that when the clause can be used in the SQL statement.
Help, please.
Kind regards.
If you want to prune your tree to show only the elements of the No. 7 usermenu, copy the following code helps you
select case when connect_by_isleaf = 1 then 0 when level = 1 then 1 else -1 end as status, level, "MENU_NAME" as title, null as icon, "MENU_CHILD" as value, null as tooltip, null as link from HR2."TREE_MENU" start with "MENU_CHILD" is null connect by prior "MENU_PARENT" = "MENU_CHILD" and "USER_NO" = 7 order siblings by "MENU_ID"
Concerning
Mahmoud
-
SQL that are based on the values of the corresponding fields.
Hi my name is Hawk.
I'm new to the Forum, and I wanted to just introduce myself and say hi.
I have a daunting task to summarize values and filling in a spreadsheet with columns. I have 600 lines to go, and I was wondering if
someone knows a way in sql to sum (a body of numbers) based on the existence of a value being the same on another field of varchar2.
For example, here is an example of the data table that I have.
CREATE TABLE EXAMPLE
("FIRSTNAME", VARCHAR2 (20 BYTE),
VARCHAR2 (20 BYTE) "LASTNAME."
NUMBER OF "SUMVALUE."
NUMBER OF "ROW_ID".
);
Insert into SAMPLE (FIRSTNAME, LASTNAME, SUMVALUE, ROW_ID) values ('Charlie', 'chocolate factory', 100, 1);
Insert into SAMPLE values (FIRSTNAME, LASTNAME, SUMVALUE, ROW_ID) ('Johnny', 'Desire', 200, 2);
Insert into SAMPLE (FIRSTNAME, LASTNAME, SUMVALUE, ROW_ID) values ('P', 'Frankenstein', 300, 3);
Insert into SAMPLE (FIRSTNAME, LASTNAME, SUMVALUE, ROW_ID) values ("Charlie", "chocolate factory", 400, 4);
Insert into SAMPLE (FIRSTNAME, LASTNAME, SUMVALUE, ROW_ID) values ("Charlie", "chocolate factory", 500, 5);
and Yes, I have 600 lines having to ask and things to the top score on manually, it's just bs data...
So what I do is the following.
Write some sql that will total the number field (sumvalue) based on data with firstname = lastname = chocolate factory and Charlie.
It seems so simple, but still I can not understand how do.
Is that what I'm trying to make sense? Also, I hope this is the right place to post this. I looked on this before I posted to make sure.
Hawk.
Hi, Hawk,
Here's one way:
SELECT SUM (sumvalue) AS total_sumvalue
SAMPLE
WHERE firstname = 'Charlie '.
AND lastname = 'chocolate factory '.
;
Welcome to the forum!
There are those who use the forum for years and have not yet learned to post CREATES instructions TABLE and INSERT for their sample data, as you did. Keep up the good work!
You should also post the exact results you want from the data provided. For example
TOTAL_SUMVALUE
--------------
1000
(this is what produces the query I posted). As you can see, without that David and I came with 2 different interpretations of what you want and maybe aren't exactly what you need.
-
order by clause based on the value of the parameter
Hello
I use reports 6i with db 10 g
I need to create a report sorted in the order of four fields. There is a field selection parameter which should come first in the order by clause.
IE the user has available to display the report in a sorted order selected
Assume that the four fields are emp_id, name, dept_id desig.
If the user selects dept_id, then the order by clause should be in order of dept_id emp_id, name, desig
Please help solve this scenario.
Thank youHi Clement,.
Use the query as follows:
select column_name1, column_name1, .... from table_name &order_by_clause
Now in the trigger AFTER-PARAMETER-SHAPE has the order by clause below according to requirements:
if :sort_column = dept_id then :order_by_clause := 'order by dept_id,emp_id,name,desig'; else :order_by_clause := 'order by emp_id, dept_id, name,desig'; end if;
Here's sort_column setting user who will be selected by the user, provide the list of values for it.
Hope this helps
Best regards
Arif Khadas
-
case in PL/SQL where clause statement
- Hello
- I have a research procedure where the user can search on the city, street, zip code.
- I need meet the 6 different combinations as I don't know what value the user will pass.
- It should be checked if the user passes the value or not, and then look on values passed.
- But the procedure below is out.it the slightest mistake can be transformed with if-then-else, but case statement seems much cleaner in the code.
- procedure searchaddress (pc_town IN SEARCHADDRESS. CITY % TYPE,
pc_street IN SEARCHADDRESS. TYPICAL STREET %,
pc_postcode IN SEARCHADDRESS. POSTCODE % TYPE,
pResultSet to ref_cursor) as
Start
Open the pResultset for
Select searchaddress_pk from searchaddress
where
case
When pc_town is null then ((street = pc_street) and (ZipCode = pc_postcode))
When pc_street is null then ((town = pc_town) and (ZipCode = pc_postcode))
When pc_postcode is null then ((town = pc_town) and (street = pc_street))
When pc_town is null and pc_street is null then (postal code = pc_postcode)
When pc_street is null and pc_postcode is null then (city = pc_town)
When pc_town is null and pc_postcode is null then (street = pc_street)
end
end searchaddress;
Thank you
CenterB
A basic concept that is important to understand - sliders aren't 'sets of results' (sets of data in memory). A cursor is a series of executable steps (see plans run to cursor). It's like a program. An extraction run the program and output data. In general, which is repeated until the cursor (aka program) is no longer found the corresponding lines.
A ref cursor is a pointer or a handle for a such slider, passed to a caller, allowing the appellant to interface directly with this slider/program.
The slider more effective to create a search would be one without superfluous code and predicates and filters. Consider the following approach - a beefier PL/SQL procedure, do not try and play little tricks with SQL predicates in an attempt to create one (and probably not optimal) SQL.
(not tested/compiled code)
create or replace procedure SearchAddress( town IN SEARCHADDRESS.TOWN%TYPE, street IN SEARCHADDRESS.STREET%TYPE, postcode IN SEARCHADDRESS.POSTCODE%TYPE, refCur out ref_cursor ) is curHandle integer; res integer; searchSQL varchar2(1000); begin -- create base query searchSQL := 'select searchaddress_pk from searchaddress where 1 = 1 '; -- add dynamic predicates as needed if town is not null then searchSQL := searchSQL || 'and town = :town'; end if; if street is not null then searchSQL := searchSQL || ' and street = :street'; end if; if postcode is not null then searchSQL := searchSQL || ' and postcode = :postcode'; end if; -- create a DBMS_SQL cursor curHandle := DBMS_SQL.open_cursor; DBMS_SQL.parse( curHandle, searchSQL, DBMS_SQL.NATIVE ); -- bind the dynamic bind variables added as predicate values if town is not null then DBMS_SQL.Bind_Variable( curHandle, 'town', town ); end if; if street is not null then DBMS_SQL.Bind_Variable( curHandle, 'street', street ); end if; if postcode is not null then DBMS_SQL.Bind_Variable( curHandle, 'postcode', postcode ); end if; -- execute cursor (to create the cursor program) and pass it back as a ref cursor res := DBMS_SQL.Execute( curHandle ); refCur := DBMS_SQL.To_RefCursor( curHandle ); end;
-
Simple conditional SQL WHERE Clause with two Subselects
Hi SQL Experts,
I need some quick help with a query.
It is a ' select ' for a data source object repository phyiscal table OBI.
So, I can't put in PL/SQL or in stored procedures. I just need
have two conditions / selects different according to the user's role (this information comes
of the session).
The above does not work:-ORA00905. 00000 - 'lack the key word'
SELECT OFFICENO FROM orgunit
WHERE
BOX WHEN "SESSION_VARIABLE' LIKE '% globalmanager %' THEN
ASSIGNEDOFFICES =
(
SELECT DISTINCT ASSIGNEDOFFICES
FROM USERSTABLE INNER JOIN orgunit WE
OrgUnit. KEY = USERSTABLE. OFFICE
WHERE USERSTABLE. USERNAME ='VALUEOF (NQ_SESSION. THE USER)"
)
ON THE OTHER
OFFICENO =
(
SELECT DISTINCT USERSTABLE OFFICENO
INNER JOIN orgunit WE
OrgUnit. KEY = USERSTABLE. OFFICE
WHERE USERSTABLE. USERNAME ='VALUEOF (NQ_SESSION. THE USER)"
)
END;Can anyone help?
Hello
I can't tell what you want to do by looking at the code that do not do. Maybe:
SELECT officeno
For orgunit
WHERE (session_variable LIKE '% globalmanager %'
AND IN assignedofficies
(
SELECT assignedoffices
UserTable U1
JOIN orgunit o1 ON o1.officekey = u1.officekey
WHERE u1.username = ' VALUEOF (NQ_SESSION. THE USER)"
)
)
OR (NVL (session_variable
, '?'
) NOT LIKE '% globalmanager % '.
AND IN officeno
(
SELECT officeno
Of u2 usertable
JOIN orgunit o2 ON o2.officekey = u2.officekey
WHERE u2.username = ' VALUEOF (NQ_SESSION. THE USER)"
)
)
;
There might be a simpler and more efficient way in function your tables and your limit.
The condition u2.username = ' VALUEOF (NQ_SESSION. The USER) "almost certainly not what you really want.
.
Whenever you have any questions, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).See the FAQ forum: https://forums.oracle.com/message/9362002#9362002
-
Problem with the creation of date range with PL/SQL WHERE clause
Hello, everyone:
I'm unable to develop and the SQL statement to filter records today and seven days back. My condition is as follows:
I think I'm to mess with the (to_char (ALM_OG_ACTIVITY_DATE, ' mm/dd/yyyy ' ")) statement.from wsualumni.wsu_online_giving_table --where ALM_OG_ACTIVITY_DATE >= ALM_OG_ACTIVITY_DATE - 7 where ALM_OG_ACTIVITY_DATE >= SYSDATE - 7 and ALM_OG_CAMPAIGN_CODE = 'MED' OR ALM_OG_CAMPAIGN_CODE = 'MED1';
The actual code is below to:
Resultsset serveroutput ON SIZE 1000000 set heading off set feedback off set trimspool off set echo off set pagesize 0 DECLARE v_data_line_hdr varchar2(1000); v_data_file varchar2(80); v_sch_code varchar2(10); v_instance_name varchar2(10); ws_path payroll.pybutfl.pybutfl_utl_file_path%TYPE; v_data_line VARCHAR2 (4000) := NULL; fhandle_o UTL_FILE.file_type; v_line_count NUMBER := 0; v_selected_count NUMBER := 0; v_error_count NUMBER := 0; v_written_count NUMBER := 0; v_error_text VARCHAR2 (50) := ' Unable to write the line. '; v_errm VARCHAR2 (255); v_sqlerrm VARCHAR2 (255); CURSOR C1 IS select RTRIM ( ALM_OG_ID ||'|'|| NULL ||'|'|| (to_char(ALM_OG_AMOUNT, '999,999.99')) ||'|'|| 'Cash' ||'|'|| 'Credit Card' ||'|'|| (to_char(ALM_OG_ACTIVITY_DATE, 'mm/dd/yyyy')) ||'|'|| ALM_OG_ACCI_CODE ||'|'|| 'On-Line Giving' ||'|'|| 'On-Line giving' ||'|'|| ALM_OG_HONOR_MEM_NAME ||'|'|| NULL ||'|'|| 'Do not post' ||'|'|| 'StandardThankYou' ||'|'|| 'Not Acknowledged' ||'|'|| 'Do not receipt' ||'|'|| NULL ||'|'|| 'Banner Gift Number' ||'|'|| ALM_OG_BANNER_GIFT_NO ||'.'|| ALM_OG_ACCI_CODE ||'|'|| (to_char(ALM_OG_ACTIVITY_DATE, 'mm/dd/yyyy')) ||'|'|| NULL ||'|'|| 'Web ID' ||'|'|| ALM_OG_WEBID ||'|'|| NULL ||'|'|| 'Source' ||'|'|| ALM_OG_CAMPAIGN_CODE ||'|'|| 'On-Line Giving' ) data_line from wsualumni.wsu_online_giving_table --where ALM_OG_ACTIVITY_DATE >= ALM_OG_ACTIVITY_DATE - 7 where ALM_OG_ACTIVITY_DATE >= SYSDATE - 7 and ALM_OG_CAMPAIGN_CODE = 'MED' OR ALM_OG_CAMPAIGN_CODE = 'MED1'; CURSOR C2 IS select RTRIM( 'ConsID' ||'|'|| 'GFImpID' ||'|'|| 'GFTAmt' ||'|'|| 'GFType' ||'|'|| 'GFPayMeth' ||'|'|| 'GFDate' ||'|'|| 'FundID' ||'|'|| 'CAMPID' ||'|'|| 'GFAppeal' ||'|'|| 'GfRef' ||'|'|| 'GfPostDate' ||'|'|| 'GfPostStatus' ||'|'|| 'GfltrCode' ||'|'|| 'GfAck' ||'|'|| 'GfRcpt' ||'|'|| 'GfAttrlmpID00' ||'|'|| 'GfAttrCat00' ||'|'|| 'GfAttrdesc00' ||'|'|| 'GfAttrDate00' ||'|'|| 'GfAttrlmpD01' ||'|'|| 'GfAttrCat01' ||'|'|| 'GfAttrdesc01' ||'|'|| 'GfAttrlmpID02' ||'|'|| 'GfAttrCat02' ||'|'|| 'GfAttrdesc02' ||'|'|| 'GfSubType' ) line_header from DUAL; /**********************************************************************/ /* Main Program Processing */ /**********************************************************************/ BEGIN DBMS_OUTPUT.put_line ('Program Started in wsualumni.wsu_online_giving_online'); IF UTL_FILE.is_open (fhandle_o) THEN UTL_FILE.fclose (fhandle_o); END IF; /* Name The File Here */ v_data_file := ('MED_SCH_' || TO_CHAR(sysdate, 'dd-MON-yyyy') || '_OG_DATA.txt'); SELECT RTRIM (pybutfl_utl_file_path) INTO ws_path FROM payroll.pybutfl; fhandle_o := UTL_FILE.fopen (ws_path, v_data_file, 'w'); DBMS_OUTPUT.put_line ('UTLFILE file for this run is: ' || ws_path||'/'||v_data_file); v_written_count := 0; FOR c2_rec IN C2 LOOP BEGIN v_selected_count := v_selected_count + 1; v_data_line_hdr := rtrim(c2_rec.line_header); UTL_FILE.put_line (fhandle_o, v_data_line_hdr); v_written_count := v_written_count + 1; EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.put_line (v_error_text); v_error_count := v_error_count + 1; END; END LOOP; FOR c1_rec IN C1 LOOP BEGIN v_selected_count := v_selected_count + 1; v_data_line := rtrim(c1_rec.data_line); UTL_FILE.put_line (fhandle_o, v_data_line); v_written_count := v_written_count + 1; EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.put_line (v_error_text); v_error_count := v_error_count + 1; END; END LOOP; DBMS_OUTPUT.put_line ('Number of Records Selected: ' || v_selected_count); DBMS_OUTPUT.put_line ('Number of Records Written: ' || v_written_count); IF UTL_FILE.is_open (fhandle_o) THEN UTL_FILE.fclose (fhandle_o); END IF; END; /
ConsID|GFImpID|GFTAmt|GFType|GFPayMeth|GFDate|FundID|CAMPID|GFAppeal|GfRef|GfPostDate|GfPostStatus|GfltrCode|GfAck|GfRcpt|GfAttrlmpID00|GfAttrCat00|GfAttrdesc00|GfAttrDate00|GfAttrlmpD01|GfAttrCat01|GfAttrdesc01|GfAttrlmpID02|GfAttrCat02|GfAttrdesc02|GfSubType 000013505|| 20.00|Cash|Credit Card|06/22/2009|221686|On-Line Giving|On-Line giving|||Do not post|StandardThankYou|Not Acknowledged|Do not receipt||Banner Gift Number|1179534.221686|06/22/2009||Web ID|000013505||Source|MED|On-Line Giving 000013505|| 20.00|Cash|Credit Card|06/22/2009|770830|On-Line Giving|On-Line giving|||Do not post|StandardThankYou|Not Acknowledged|Do not receipt||Banner Gift Number|1179534.770830|06/22/2009||Web ID|000013505||Source|MED|On-Line Giving
Hello
The problem is due to the "OR" condition (I did not pay attention to it earlier).
Because of this condition, your query is given beyond 7 days recovery. You need to rewrite the code as:
ALM_OG_CAMPAIGN_CODE in ('MED', 'MED1')
Instead of
and ALM_OG_CAMPAIGN_CODE = 'MED' OR ALM_OG_CAMPAIGN_CODE = 'MED1';
This will do the magic for you.
Concerning
Asif Momen
http://momendba.blogspot.com -
For UNION in VOImpl SQL WHERE clause
Hey gurus,
I need the ability to add a condition to VOImpl to user_id for two queries in a UNION statement. However, setWhereClause only adds condition at the end of the query. Any suggestions? I tried to make a selection online and could not because of the 'double '.
Thank you
-Scott
Select "Sys" x double where exists)
Select responsibility_name in the fur of fnd_user_responsibility,
fnd_responsibility_tl frt
When user_id = 16448
and frt.responsibility_id = fur.responsibility_id
and frt.responsibility_name = "system administrator")
Union
Select "NoSys" x double where does not exist)
Select responsibility_name in the fur of fnd_user_responsibility,
fnd_responsibility_tl frt
When user_id = 16448
and frt.responsibility_id = fur.responsibility_id
and frt.responsibility_name = "system administrator")You can have the condition at the request of origin itself and in the VOImpl, just switch the setting.
select 'Sys' x from dual where exists ( select responsibility_name from fnd_user_responsibility fur, fnd_responsibility_tl frt where user_id = :1 and frt.responsibility_id = fur.responsibility_id and frt.responsibility_name = 'System Administrator') union select 'NoSys' x from dual where not exists ( select responsibility_name from fnd_user_responsibility fur, fnd_responsibility_tl frt where user_id = :2 and frt.responsibility_id = fur.responsibility_id and frt.responsibility_name = 'System Administrator')
See you soon
Ganesh -
How to pass the parameter in where clause contained in the custom file?
I have the tracking query
Blue are the parameters
I paste this to a custom folder
and
Select last_update_date, creation_date
of ra_customer_trx_all
"where trunc (last_update_date) = 29-SEP-2012."
and customer_trx_id = 1109
in another folder custom return 1 row only and create a different worksheet in the same workbook and create
3 setting and 2 of them pointing to the 1 row to query and create a calcualtion
SET_CONTEXT ("Date_From", TO_CHAR(:Date From)) and SET_CONTEXT ('Date_TO', TO_CHAR(:Date To))
and 1 condition 1 = SET_PARAM3(:Period)
but this does not work for me, no data back please help
Select m.party_name TENANT_NAME
b.interface_line_attribute10 lease_num
-, b.interface_line_attribute12 «PPS Number.
b.interface_line_attribute2 LOCATION_CODE
flexv.description property_name
INVOICE_NUMBER a2.trx_number
-, t.nom "Type of Transaction".
-, e.attribute15 "AS400 Key."
, b2.description 'BILL_ITEM_INVOCIE_DESCRIPTION '.
, case when gcc.segment5 like 6% ' then ' P/L '.
When gcc.segment5 like 7% ' then ' P/L '.
When gcc.segment5 as 8% ' then ' P/L '.
When gcc.segment5 like 9% ' then ' P/L '.
else "B/S".
end as account_nature
-, gcc.concatenated_segments as 'account of burden '.
gcc.segment1 company_code
gcc.segment2 department_code
gcc.segment3 property_code
gcc.segment4 business_segment
gcc.segment5 account_code
gcc.segment6 project_code
gcc.segment7 intercom_code
gcc.segment8 spare1
gcc.segment9 spare2
b2.extended_amount BILL_ITEM_INVOICE_AMOUNT
to_char (substr(ps.gl_date,4,8)) gl_period
b.interface_line_attribute11 bill_start_date
b.interface_line_attribute14 bill_end_date
decode (a2.invoicing_rule_id, '-2',
DECODE (TO_CHAR ("b.RULE_START_DATE, ' YYYYMM"), to_char (to_date (to_char (TRUNC (to_date (SETPARAM.) GET_PARAM3, "YYYYMM"), 'Month')-1), "MON-DD-YYYY"), "YYYYMM"), "Current", "Forward").
'In progress' Bill_nature)
, to_char (a2.trx_date, ' MON-DD-YYYY "") invoice_date
pal.lease_commencement_date
pal.lease_termination_date
h.user_name created_by
-, NULL as remarks
of ra_customer_trx_all one
ra_customer_trx_lines_all b
pn_leases_all d
e pn_tenancies_all
hz_cust_accounts l
hz_parties m
fnd_user h
ar_payment_schedules_all ps
RA_CUST_TRX_LINE_GL_DIST_ALL dist
gl_code_combinations_kfv gcc
AR_RECEIVABLE_APPLICATIONS_all app
ra_customer_trx_all a2
ra_customer_trx_lines_all b2
RA_CUST_TRX_TYPES_all t
fnd_flex_values_vl flexv
pn_lease_details_all pal
where
App. APPLICATION_TYPE = "CM".
and flexv.flex_value = gcc.segment3
and flexv. FLEX_VALUE_SET_ID = 1014916
and pal.lease_id = d.lease_id
and app.applied_customer_trx_id = a.customer_trx_id
and app.customer_trx_id = a2.customer_trx_id
and a2.cust_trx_type_id = t.cust_trx_type_id (+)
and a2.org_id = t.org_id (+)
and b.customer_trx_line_id = b2.previous_customer_trx_line_id
and dist. CUSTOMER_TRX_LINE_ID = b2. CUSTOMER_TRX_LINE_ID
and dist.account_class = 'REV '.
and dist.account_set_flag = DECODE (NVL(a2.invoicing_rule_id,1)-2, 'Y', 'n')
and gcc. CODE_COMBINATION_ID (+) is Dist. CODE_COMBINATION_ID
and b.interface_line_attribute10 = d.lease_num
and d.lease_id = e.lease_id
and e.primary_flag = 'Y '.
and b2.customer_trx_id = a2.customer_trx_id
and a2.bill_to_customer_id = l.cust_account_id
and l.party_id = m.party_id
and a2.created_by = h.user_id
and ps.customer_trx_id = app.customer_trx_id
and ps.gl_date between trunc (trunc (TO_DATE (SYS_CONTEXT ('DISCO_CONTEXT', 'Date_From')), 'MM')-1, 'MM') and trunc (TO_DATE (SYS_CONTEXT ('DISCO_CONTEXT', 'Date_To')), 'MM')-1
What exactly is the problem with the results? Can you do the report include the gl_date, so that you can see exactly what is included?
The only way to solve this is back to basics. You must be certain that the setting and calculations for the date work 100%. You have granted the Execute permission on the function to your landlord EUL - Yes? I did create the function in a package belonged to EUL_US, then I got no problem with permissions or grant.
Also, gl_date is a DATE string and not a right? I ask because if it is not a date, but a string then a few dates could be left out.
Assuming that you are 100% some of the building blocks, you should start by including only the gl_date and the primary key of the table you are using. Once you are sure you have found the right data, you can start adding in addition to fields.
I note that you use the E-Business Suite objects. I copied the code in my system where I don't use rental. So I put comment references to tables 3 PN. I had 150 lines of data when I asked for it by using the parameter, and then when I hard coded the BETWEEN operator for the gl_date. You don't have to make sure that your landlord EUL got right SELECT all tables and views used in your code and, if you want to share this code with someone else, you must also have LICENSING rights.
Try your code in a SQL like TOAD tool and see what happens. Are you absolutely sure that each of your transactions has an entry in the tables PN? Maybe it's why you don't get the results you expect. You can try, as I did, to comment these lines out and then see what happens.
Hopefully this has given you enough to solve your problem
Michael
PS. It would be nice to know your name. You have not used once it in your thread.
-
For each hit in the where clause, also get the entourage records
We have a table that contains the content of some files. The structure of the table is (Simplified):
CREATE TABLE LOG_LINES
(
FILE_ID NUMBER (15.0).
LOG_LINE_NUMBER NUMBER (9.0).
CLOB LOG_LINE
)
We build a search engine that looks through the lines to find a regular expression, it should return the lines that match the regular expression, in addition to 5 lines before this line and 5 rows after this line.
So to say that our regex match line 10, we must return the row 5 to 15.
Currently, this is how we solve our problem:
1 questioning the rows that match the regular expression (select file_id, log_line_number from log_lines where regexp_like (log_line, 'Search'))
2. for each record that is returned by this query: query the table log_lines to get the required rows (select * from log_lines where file_id = x and log_line_number between y and z)
Now, it seems to create a lot of overhead, because there could be 1000 matches, it takes to 1000 queries for all results.
I was wondering if there is a better way to tackle this problem. It may be possible to just 1 request that returns the corresponding lines more than 5 records before and after.
Any help on this would be greatly appreciated!
Published by: Peter Marcoen on 11 January 2013 04:22
Published by: Peter Marcoen on 11 January 2013 04:23with t as ( select file_id, log_line_number from log_lines where regexp_like(log_line,'search') ) select file_id, log_line_number from log_lines l, t where l.file_id = t.file_id and l.log_line_number between t.log_line_number - 5 and t.log_line_number + 5 /
SY.
-
Columns in the WHERE clause - order affect the output?
I work on some queries to feed a DWH and stumbled upon this question. Let's say I have this query:
The exit will happen anyway if I do like this:(SELECT ARTREGNROS FROM gx.artabo aa,gx.toccab tc1 where aa.artid=tc1.artid and t.tocid=tc1.tocid and aa.abocod=c.abocod and aa.artconcod=c.concod and aa.percod=a.percod and aa.ArtAboFlgA='S' ) Tarjeta
I guess what he used, or at least I him did not change with the data that I use, but I thought to check here once just to have peace of mind. Maybe it's not the happiest example, but I guess the question is clear(SELECT ARTREGNROS FROM gx.artabo aa,gx.toccab tc1 where aa.artid=tc1.artid and a.percod=aa.percod and aa.ArtAboFlgA='S and tc1.tocid=t.tocid and c.abocod=aa.abocod and aa.artconcod=c.concod ) Tarjeta
No difference.
Maybe you are looking for
-
When sending electronic mail it modifies the script or send pictures
When I use before or answer all e-mail is changed. script lowercase changes. Photos or engravings are not sent. People who receive my E Mails are unable to download or try to see all of the e-mail
-
Using a HARD drive in another computer?
The computer (where the hard drive comes from), is currently in a State of operation not. I want to do is start this drive on another computer to look through of essential programs, so I can mark down. I am aware that I can use another computer to lo
-
I tried the option auto-fix for my problem with updates not down loading. He said he could not fix 0 x 80246008 (2015-12-25-T-03_25_12P) what can I do? Also said to not correct update download problem.
-
Printing with Windows 8 Pro for HP Photosmart 8150
Since I installed Windows 8 Pro to my computer, I can't print to my HP Photosmart 8150 printer. Online "says" HP driver is up to date, but I deleted and reinstalled in any case. Still not printing. If anyone has had this problem and how solve you thi
-
Can I use CS4 with Windows 7?
I have CS4 which was installed on an old computer that I no longer use. Now I have Windows 7 on a new PC. CS4 running on Windows 7?