Using EXISTS in SELECT
In general,
If I want to construct a query, such as,
SELECT t1.fld1,t1.fld2,t1.fld3, mStr
FROM tbl t1
WHERE fld3 = 1
WHERE fld* are fields in table "tbl" and mStr is dynamic and is to hold a TRUE/FALSE value.
mStr is to be constructed using something like,
EXISTS ( SELECT * FROM tbl t2 where t2.fld2 = t1.fld2)
What's the correct syntax here?
I just realized that the code above will produce duplicate rows if there is more than one child, so DISTINCT should be added. The corrected code would look like this:
CREATE OR REPLACE PROCEDURE GetRecords
AS
CURSOR toplevel_cur
IS
SELECT DISTINCT b1.label,
b1.target,
b1.type,
b1.objectid,
DECODE (b2.parentid,
null, 'false ',
'true ') has_children
FROM buttons b1, buttons b2
WHERE b2.parentid(+) = b1.objectid
AND b1.lvl = 0;
BEGIN
FOR rec IN toplevel_cur
LOOP
DBMS_OUTPUT.PUT_LINE (rec.label
| | ' '
| | rec.target
| | ' '
| | rec.type
| | ' '
| | rec.objectid
| | ' '
| | rec.has_children);
END LOOP;
END GetRecords;
Also, if you are determined to use EXISTS, or just want to see that it produces the same results, you code use the code below, but I expect that it would run slower:
CREATE OR REPLACE PROCEDURE GetRecords
AS
CURSOR toplevel_cur
IS
SELECT b1.label,
b1.target,
b1.type,
b1.objectid,
'true ' has_children
FROM buttons b1
WHERE EXISTS
(SELECT b2.parentid
FROM buttons b2
WHERE b2.parentid = b1.objectid)
AND b1.lvl = 0
UNION
SELECT b1.label,
b1.target,
b1.type,
b1.objectid,
'false ' has_children
FROM buttons b1
WHERE NOT EXISTS
(SELECT b2.parentid
FROM buttons b2
WHERE b2.parentid = b1.objectid)
AND b1.lvl = 0;
BEGIN
FOR rec IN toplevel_cur
LOOP
DBMS_OUTPUT.PUT_LINE (rec.label
| | ' '
| | rec.target
| | ' '
| | rec.type
| | ' '
| | rec.objectid
| | ' '
| | rec.has_children);
END LOOP;
END GetRecords;
null
Similar Messages
-
Can we use EXISTS in where condition
hi all,
can we use EXISTS (instead of IN) in where condition of a query which is not part of a subquery ?
for e.g:
update gpf_vou_sm set up_amt=0 where src_cd exists ('1101','1201');
the query works fine with the IN operator in place of EXISTS.
anybody please help.
thomas k prakashHi:
You can use EXISTS in where clause but not in that syntax.
UPDATE gpf_vou_sm g
SET up_amt = 0
WHERE EXISTS (SELECT 1
FROM gpf_vou_sm
WHERE src_cd IN ('1101', '1201') AND id = g.id);Using IN in your case is better...
Saad, -
Please help to re-write this query using exists or with
Hi please help to re-write this query using exists or with, i need to write same code for 45 day , 90 days and so on but sub query condition is same for all
SELECT SUM (DECODE (t_one_mon_c_paid_us, 0, 0, 1)) t_two_y_m_mul_ca_
FROM (SELECT SUM (one_mon_c_paid_us) t_one_mon_c_paid_us
FROM (
SELECT a.individual_id individual_id,
CASE
WHEN NVL
(b.ship_dt,
TO_DATE ('05-MAY-1955')
) >= SYSDATE - 45
AND a.country_cd = 'US'
AND b.individual_id in (
SELECT UNIQUE c.individual_id
FROM order c
WHERE c.prod_cd = 'A'
AND NVL (c.last_payment_dt,
TO_DATE ('05-MAY-1955')
) >= SYSDATE - 745)
THEN 1
ELSE 0
END AS one_mon_c_paid_us
FROM items b, addr a, product d
WHERE b.prod_id = d.prod_id
AND d.affinity_1_cd = 'ADH'
AND b.individual_id = a.individual_id)
GROUP BY individual_id)
Edited by: user4522368 on Aug 23, 2010 9:11 AMPlease try and place \ before and after you code \Could you not remove the inline column select with the following?
SELECT a.individual_id individual_id
,CASE
when b.Ship_dt is null then
3
WHEN b.ship_dt >= SYSDATE - 90
3
WHEN b.ship_dt >= SYSDATE - 45
2
WHEN b.ship_dt >= SYSDATE - 30
1
END AS one_mon_c_paid_us
FROM items b
,addr a
,product d
,order o
WHERE b.prod_id = d.prod_id
AND d.affinity_1_cd = 'ADH'
AND b.individual_id = a.individual_id
AND b.Individual_ID = o.Individual_ID
and o.Prod_CD = 'A'
and NVL (o.last_payment_dt,TO_DATE ('05-MAY-1955') ) >= SYSDATE - 745
and a.Country_CD = 'US' -
Can any one tell me how to use EXISTS clause inplace of IN operator.
Hi All,
Can any one tell me how to use EXISTS clause AND (JC.EMPL_ID, JC.EMPL_RCD) inplace of IN operator.
SELECT COUNT (1)
FROM SYSADM.OHR_PERS_CURR PC
, SYSADM.OHR_JOB_CURR JC
WHERE PC.EMPL_ID = JC.EMPL_ID
AND (JC.EMPL_ID, JC.EMPL_RCD) in (
SELECT HS.EMPL_ID, HS.EMPL_RCD
FROM SYSADM.HU_SCRTY_JOB HS, ODSHR.OHR_SCRTY_USER_CFG OS
WHERE HS.HU_SCRTY_CFG_ID = OS.HU_SCRTY_CFG_ID
AND OS.DB_LOGIN = USER)
Thank you.SELECT COUNT (1)
FROM SYSADM.OHR_PERS_CURR PC
, SYSADM.OHR_JOB_CURR JC
WHERE PC.EMPL_ID = JC.EMPL_ID
AND EXISTS (
SELECT null
FROM SYSADM.HU_SCRTY_JOB HS, ODSHR.OHR_SCRTY_USER_CFG OS
WHERE HS.HU_SCRTY_CFG_ID = OS.HU_SCRTY_CFG_ID
AND OS.DB_LOGIN = USER
AND HS.EMPL_ID = JS.EMPL_ID AND HS.EMPL_RCD = JC.EMPL_RCD)
But why ?
Rgds. -
SAP Cloud SDK : Default Check in Marketing Lead for Field "Use Existing Account"
Hi Experts,
I have requirement to enhance the standard business object Marketing Lead screen. In that screen i need to make default check on "Use Existing Account" checkbox when user click on New Marketing Lead or QC option.
I have tried using Application studio but the field "Use Existing Account" not exist in cloud repository its on Front-end UI screen.
How i can make default value check to this checkbox in UI designer for standard screen
Or
How i can make default value check to this checkbox using ABSL code.
Please refer the screen as shown below.
Regards,
MithunMithun,
Could you please check Fine tune options available for Leads ?
Under Involved Parties there is an option "Forbid Manual Changes". For Account Party Role if you select that it will not allow user to enter new account information.
Fine -Tune -> Leads - > Involved Parties -> Account
- Shrikant -
Use Javascript to select artwork on a particular artboard?
Is there a way to use Javascript to select all artwork on a particular artboard?
Or if you couldn't designate the selection based on the artboard index, another way i could see doing it would be to select all artwork within a bounding box? For example if i were to measure the artboardRect of an artboard and then set the selection to all pageItems within that bounding box?
Thanks in advance!awesome. i'll keep that one for my records. for my purposes right now, the selection by active artboard function is perfect. now i just need to work out how to loop through each pathItem within that selection and determine if it contains a certain spot color (and if it does, add to a counter of some sort) and verify that the number of occurrences of that spot color equal the total number of arboards in the doc (that is to say.. verify that a certain spot color exists at least once on every artboard).
so i assure you i'll be back to soak up as much of your experience and knowledge as i can get my grubby paws on. =)
Thanks again, so much. you've been incredibly helpful. CarlosCanto as well. -
I try to install it, but i select my free (fresh formated) partition with 35GB free space and i see:
Setup was unable to use existing system partition because it does now contain the required free space.
if i select partition with partition that does not contain the required i see
"Windows cannot be installed to Disk 0 Partition 1. (show details)"
so what is it? what can i test?
My Disk has 250GB, my partitions:
C: 8MB - Boot (7MB Free) - FAT
D: 37,5GB - WINXP (27,9GB Free space) - NTFS
E: 35,3GB - New (35,2GB Free) - NTFS - i want to install on it
F: 160GB - Data (6GB Free) - ntfskolorafa_ said:
I try to install it, but i select my free (fresh formated) partition with 35GB free space and i see:
Setup was unable to use existing system partition because it does now contain the required free space.
if i select partition with partition that does not contain the required i see
"Windows cannot be installed to Disk 0 Partition 1. (show details)"
so what is it? what can i test?
My Disk has 250GB, my partitions:
C: 8MB - Boot (7MB Free) - FAT
D: 37,5GB - WINXP (27,9GB Free space) - NTFS
E: 35,3GB - New (35,2GB Free) - NTFS - i want to install on it
F: 160GB - Data (6GB Free) - ntfs
Is this 8MB "Boot" partition (formatted as FAT???) something you created when you partitioned this disk for the Windows XP installation, or is this an 8MB OEM partition that you've somehow assigned drive letter C: to?
I wouldn't be surprised at all that your error message is being generated because thsi "BOOT" partition, labelled as drive C:, is only 8MB in size, and you can be absolutely positive that an 8MB partition is going to generate this error: "Setup was unable to use existing system partition because it does not contain the required free space."
The correct answer really depends on whether that drive C: is the boot (sic) (the proper terminology is to call it the system partition) partition for the Windows XP installation. If it is, then you're going to have some repair work to do on your Windows XP installation first, so that you can free up that 8MB partition.
In any event, I'm fairly certain that the solution is going to require the removal of that 8MB partition, as you've suggested in your most recent post.
Lawrence Garvin, M.S., MCITP(x2), MCTS(x5), MCP(x7), MCBMSP
Principal/CTO, Onsite Technology Solutions, Houston, Texas
Microsoft MVP - Software Distribution (2005-2009) -
What can be used for replacing SELECT SINGLE * ?
What can be used for replacing SELECT SINGLE * for improving the performance in the following statements?
SELECT SINGLE * FROM REGUV
WHERE LAUFD = G_WLAUFD "RUN DATE ,SY-DATUM
AND LAUFI = P_LAUFI. "IDENTICATION NO
SELECT SINGLE * FROM T100
INTO CORRESPONDING FIELDS OF G_T100_WA
WHERE SPRSL = G_T_IALLMESS-MSGSPRA
AND ARBGB = G_T_IALLMESS-MSGID
AND MSGNR = G_T_IALLMESS-MSGNR.
SELECT SINGLE * FROM TBTCO
INTO CORRESPONDING FIELDS OF TBTCO
WHERE JOBNAME = FS_JOBNAME.If you need all the fields and you know that only one record exists then u need to use select single * only. You can improve the performance by specifying key fields in the where clause of select statements. If the structure of the work area or internal table in which you are fetching the data is same as that of the database table then no need to use corresponding fields clause.
Best Regards,
Vibha
*Please mark all the helpful answers -
Using applet to select a part of an image and then save it
Hi ,
I want to use applet to select a part of an image and then save that particular selected part to a server. can anyone provide me a code for this. I have found codes on the sun site which help in uploading an image but I am having trouble in trying to select a part of the image.Sorry to get back to you so late, but I was away from my computer this afternoon.
I'm not sure just what you are after. I do see that you have positioned the tree on the labels. I went to the web site for the label company, and their instructions are not too helplful.
http://www.pixentral.com/show.php?picture=15sBkl9OZE9xSkHoLMxgwjTFv2VCg1
I changed the white portion of 1 label to black - - this can be any color. To do this use the magic wand tool, tolerance=10 worked for me, then go to Edit>fill selection. -
How can i use index in select query.. facing problem with the select query.
Hi Friends,
I am facing a serious problem in one of the select query. It is taking a lot of time to fetch data in Production Scenario.
Here is the query:
SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
FROM ztftelat LEFT JOIN ztfzberep
ON ztfzberep~gjahr = st_input-gjahr
AND ztfzberep~poper = st_input-poper
AND ztfzberepcntr = ztftelatrprctr
WHERE rldnr = c_telstra_accounting
AND rrcty = c_actual
AND rvers = c_ver_001
AND rbukrs = st_input-bukrs
AND racct = st_input-saknr
AND ryear = st_input-gjahr
And rzzlstar in r_lstar
AND rpmax = c_max_period.
There are 5 indices present for Table ZTFTELAT.
Indices of ZTFTELAT:
Name Description
0 Primary key( RCLNT,RLDNR,RRCTY,RVERS,RYEAR,ROBJNR,SOBJNR,RTCUR,RUNIT,DRCRK,RPMAX)
005 Profit (RCLNT,RPRCTR)
1 Ledger, company code, account (RLDNR,RBUKRS, RACCT)
2 Ledger, company code, cost center (RLDNR, RBUKRS,RCNTR)
3 Account, cost center (RACCT,RCNTR)
4 RCLNT/RLDNR/RRCTY/RVERS/RYEAR/RZZAUFNR
Z01 Activity Type, Account (RZZLSTAR,RACCT)
Z02 RYEAR-RBUKRS- RZZZBER-RLDNR
Can anyone help me out why it is taking so much time and how we can reduce it ? and also tell me if I want to use index number 1 then how can I use?
Thanks in advance.Hi Shiva,
I am using two more select queries with the same manner ....
here are the other two select query :
***************1************************
SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
FROM ztftelpt LEFT JOIN ztfzberep
ON ztfzberep~gjahr = st_input-gjahr
AND ztfzberep~poper = st_input-poper
AND ztfzberepcntr = ztftelptrprctr
WHERE rldnr = c_telstra_projects
AND rrcty = c_actual
AND rvers = c_ver_001
AND rbukrs = st_input-bukrs
AND racct = st_input-saknr
AND ryear = st_input-gjahr
and rzzlstar in r_lstar
AND rpmax = c_max_period.
and the second one is
*************************2************************
SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
FROM ztftelnt LEFT JOIN ztfzberep
ON ztfzberep~gjahr = st_input-gjahr
AND ztfzberep~poper = st_input-poper
AND ztfzberepcntr = ztftelntrprctr
WHERE rldnr = c_telstra_networks
AND rrcty = c_actual
AND rvers = c_ver_001
AND rbukrs = st_input-bukrs
AND racct = st_input-saknr
AND ryear = st_input-gjahr
and rzzlstar in r_lstar
AND rpmax = c_max_period.
for both the above table program is taking very less time .... although both the table used in above queries have similar amount of data. And i can not remove the APPENDING CORRESPONDING. because i have to append the data after fetching from the tables. if i will not use it will delete all the data fetched earlier.
Thanks on advanced......
Sourabh -
I need to use an existing ID (email address) on a new iPhone. It tells me "choose another ID - that one is in use," with the option to "use existing ID," however, it is an endless loop, referring me only to change my password on the existing ID.
How do I enable my new device with an existing ID - I do not need to change the password for the millionth time!
None of the FAQs (or the Community choices below) address new devices, they are all about APPS and iCloud stuff.If it is an existing iCloud ID, you should be able to just go to Settings>iCloud and sign in with it.
-
Logical database EQI (equipment) .. I dont want to use the default selecti
i am using Logical database EQI (equipment) its realated to PM module.....
i dont want to use the default selection screen.
instead i want to process my own selection screen inputs..
(ie..) i want to fetch the data using the GET event using my own selection screen inputs.
my selection screen inputs is equipmentnumber (equnr)
and the output list : 1.equnr "equipment number
2.shtxt "Equipment Description
3.tplnr "Functional Location
4.pltxt "Functional Location Description
5.qmnum "Notification Number
6.qmtxt "Notification Description
and so on ..........
how to do this ... can any one give sample code... or logicHi Victor,
I have a simple solution for this.i think it will help you.Do u have any idea about query designer in SAP.
by using it we can satisfy u r reuqirement.follow the below steps.
1)Go to SQ01
2)In the screen click on QuickViewer option.then you will go to another screen.
3)In that screen give any name starting with 'Z' in the QuickView box and then click on create.
4)In the dialogbox enter title and comments and then select LogicalDatabase as the DATASOURCE and give DataSourceLogicalDatabase as EQI.check the radio button Basis Mode and then click on ok.
5)then on the screen in the first half of leftside you will get another screen with the columns DATAFIELDS,LISTFIELDS,SELECTIONFIELDS,TECHNICALNAME.
6)In the DATAFIELDS column expand the tree,then u can see the fields what we have,and what you want.and also you can see the check boxes in front of the columns LISTFIELDS,SELECTIONFIELDS.
7)LISTFIELDS means the output fields,SELECTIONFIELDS means the selection screen fields(equnr).
check the checkboxes as per u r requirement and click on execute.
8)then a progam will be created.to know the program name after executing the program GO TO
SYSTEM->STATUS.then u can see the program name there.
If u know all these,let me know so that i can try for another solution.
Thanks,
N.K.C -
Using procedure in SELECT statement
I have a select statement that currently uses 4 functions to receive necessary values. All the functions are recursive and returns values from the same row.
What I would like to do is replace these for function calls with 1 procedure. Does anybody know if it possible to use a procedure in this way inside a select statement?
If so, do you have the syntax for doing this?
E.g
SELECT
Mdbrd_Pkg.calculate_fixed_charge_fn(in_rc_id, ap.CONFIGSET_ID) AS FIXED_CHARGE,
Mdbrd_Pkg.calculate_charge_rate_fn(in_rc_id, ap.CONFIGSET_ID) AS CHARGE_RATE,
Mdbrd_Pkg.tax_liable_fn(in_rc_id, ap.CONFIGSET_ID) AS TAX_LIABLE,
Mdbrd_Pkg.charge_unit_fn( in_rc_id, ap.CONFIGSET_ID) AS CHARGEUNIT_ID
FROM .....This cannot be done. The part of the function used in the SELECT statement is the return value: procedures don't have return values (that's what makes tham procedures and not functions).
Obviously I don't know what your code does, but you should consider putting them into a single function that returns a TYPE with four attributes and then using the TABLE() function to cast them into something you could reference in the FROM clause of a correlated sub-query. Sounds a bit messy though.
Do these functions actually select data? Where does the recursion fit in?
Cheers, APC -
Delete statement that uses a sub-select with the statement in the cursor
Hi all,
How to write write a delete statement that uses a sub-select with the statement in the cursor?
CURSOR excluded_dates IS
SELECT TO_TIMESTAMP(report_parameter_value, in_date_format_mask)
INTO my_current_date_time
FROM report_parameters
WHERE report_parameters.report_parameter_id = in_report_parameter_id
AND report_parameters.report_parameter_group = 'DATE_TIME'
AND report_parameters.report_parameter_name = 'EXCLUDED_DATE';
OPEN excluded_dates;
LOOP
FETCH excluded_dates INTO my_excluded_date;
EXIT WHEN excluded_dates%NOTFOUND;
DELETE FROM edr_rpt_tmp_inclusion_table
WHERE TO_CHAR(date_time, 'mm/dd/yyyy') = TO_CHAR(my_excluded_date, 'mm/dd/yyyy');
END LOOP;
CLOSE excluded_dates;ThanksHi,
In such case I think is better to create a view an perform the delete using it. Example (using HR schema):
Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
Connected as hr
SQL> create or replace view v_employees as select * from employees where first_name like 'J%';
View created
SQL> select * from v_employees;
EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
110 John Chen JCHEN 515.124.4269 28/09/1997 FI_ACCOUNT 8200,00 108 100
112 Jose Manuel Urman JMURMAN 515.124.4469 07/03/1998 FI_ACCOUNT 7800,00 108 100
125 Julia Nayer JNAYER 650.124.1214 16/07/1997 ST_CLERK 3200,00 120 50
127 James Landry JLANDRY 650.124.1334 14/01/1999 ST_CLERK 2400,00 120 50
131 James Marlow JAMRLOW 650.124.7234 16/02/1997 ST_CLERK 2500,00 121 50
133 Jason Mallin JMALLIN 650.127.1934 14/06/1996 ST_CLERK 3300,00 122 50
139 John Seo JSEO 650.121.2019 12/02/1998 ST_CLERK 2700,00 123 50
140 Joshua Patel JPATEL 650.121.1834 06/04/1998 ST_CLERK 2500,00 123 50
145 John Russell JRUSSEL 011.44.1344.429268 01/10/1996 SA_MAN 14000,00 0,40 100 80
156 Janette King JKING 011.44.1345.429268 30/01/1996 SA_REP 10000,00 0,35 146 80
176 Jonathon Taylor JTAYLOR 011.44.1644.429265 24/03/1998 SA_REP 8600,00 0,20 149 80
177 Jack Livingston JLIVINGS 011.44.1644.429264 23/04/1998 SA_REP 8400,00 0,20 149 80
181 Jean Fleaur JFLEAUR 650.507.9877 23/02/1998 SH_CLERK 3100,00 120 50
186 Julia Dellinger JDELLING 650.509.3876 24/06/1998 SH_CLERK 3400,00 121 50
189 Jennifer Dilly JDILLY 650.505.2876 13/08/1997 SH_CLERK 3600,00 122 50
200 Jennifer Whalen JWHALEN 515.123.4444 17/09/1987 AD_ASST 4400,00 101 10
16 rows selected
SQL> delete from v_employees where hire_date >= to_date('01/06/1998', 'dd/mm/yyyy');
2 rows deleted
SQL> regards, -
Automatically name computers using existing computer name
In my environment, I have brand new computers to be imaged. The computer name needs to consist of the room number and the serial number.
I am utilizing the Collection Variables within All Unknown Computers collection to define the room number. And I am using CustomSettings.ini to automatically grab the serial number and combining that to the room number to OSDComputerName.
That is working perfectly fine.
My question is how to automatically use existing computer name as the name of the re-imaged computer?
If I use the same task sequence, because the computer is no longer an unknown computer, it doesn't prompt me for the room number. The computer name ended up containing the variable %roomnum% plus the serial number. I do not want SCCM to prompt
me for anything but automatically use the existing computer name.
Please advise.Maybe I am missing a step.
This is my current CustomSettings.ini file
[Settings]
Priority=Init, Default
Properties=ComputerSerialNumber
[Init]
ComputerSerialNumber=#Left("%SerialNumber%",7)#
[Default]
OSDComputerName=%RoomNumber%%ComputerSerialNumber%
OSInstall=Y
SkipCapture=YES
SkipAdminPassword=NO
The variable %RoomNum% is defined in the All Unknown Computer collection and a prompt appears for me to manually enter that information before imaging the computer the first time.
But when I reimage an existing computer, I get no prompt and because the variable is not defined, the final computer name because %RoomNumber%9999999, which is longer than 15 characters and so the task sequence fails.
How and where in the task sequence do I define: if this is not an unknown computer, then use existing computername?
I also notice that I can add a step called "Capture Windows Settings-Migrate Computer Name". Is this the step that I need? Where in the task sequence should it be added to?
Here is a section of my task sequence. I didn't change much from the default created MDT Task Sequence.
Maybe you are looking for
-
Can't download or update apps from App Store
I'm using a MBP Retina Display with Mountain Lion. Whenever I attempt to update apps or download new ones, the sign in window pops down. I type in my log in information and the window goes back up, just to come back down again. It doesn't stop no mat
-
Hello All, I have uploaded the documents in CV01N Tcode.I want to write a report for printing the documents. Can you please send me the code or any function module. Thank You, Suresh
-
For some reason Flex 3 does not understand the mouse scroll to move the scrollbar vertically. Is there anyway to make that work?
-
How to make Measuring Point Description Field scrollable on the Detail Read Screen
In the Measuring Point Read Detail Screen (Rounds Manager), the description field does not have a scroll bar like it does on the Point Read Counter Detail Screen. This means that the end-user has to arrow-over to the right on the handheld device to
-
Revert BBerry settings to an earlier date
Hello again, I synced my blackberry with a previous blackberry thru the desktop software, I didn't realize that it would mirror on the new blackberry the same stuff I had on the old blackberry. Somethings I didn't want to change, like my new email a