Select query using variable
Hi all,
If I have a variable with multiple value (returned from bulk collect), how can I pass it into a select query as a condition?
Eg.
set serveroutput on
declare
type v_LockSessInfo is table of integer;
empdata v_LockSessInfo;
begin
select unique sid bulk collect into empdata from v$lock;
[select sid,serial#,username from v$session where sid in (empdata)]
end;
I hope to be able to pass in the variable collected, into the next select statement. How can I achieve it?
Thanks in advance.
Eugene
Sorry for any confusion caused, I have almost 0 knowledge on pl/sql, only can survie on normal sql query.
Further elaboration, the intention of my query is to query out any locking that exists in my DB. It meant to serve as a report to management, so I have to break it down into couple of sections for easier reference (minimising the complication that may arise from others who view the report).
Couple of steps/procedures I am thinking of:
1) query out the unique sid that exists in v$lock (blocking and blocked sessions) <<< this set of returned record (SIDs) should be stored in a variable.
Eg. achived by the select statement "select unique sid from v$lock into [variable]"
2) query v$sessions for the lock details from step 1's output. Username, sid, serial#, machine etc.
Eg. To be achieved by "select sid,serial#...... from v$session where sid in [variable]; Same condition applies to 2 and 3.
3) query v$locked_object to identify which are the blocking/blocked sessions, and who's blocking who from step 1's output.
4) query the locked object and locked record (based on rowid locked) from step 1's output.
This is all that I can think of at the moment. Any opinions that can perform the above activity will be appreciated alot. Hope I'm able to clear up any confusion triggered.
PS: I can't re-query the SID as the SID may change or be lost upon the re-query therefore losing any evident. Thus I was thinking of putting it into a variable for consistent querying for step 2,3 and 4. All 4 steps will be performed within a single script.
Regards
Eugene
Edited by: eteo78 on May 28, 2009 8:40 AM
Similar Messages
-
Hi,
Please give me the Select query
I have to fetch EBELN,BUKRS,LIFNR,BSART,EKORG,EKGRP,WAERS,WKURS from EKKO and
EBELP,LGORT,MATKL ,WERKS,BEDNR,IDNLF,BPRME,NETPR from EKPO and
MENGE, SAKTO,AUFNR,ANLN1,GSBER,PS_PSP_PNR from EKKN and
LPEIN,EINDT,SLFDT, from EKET.
I have to fetch all the data into an single internal table(Mandatory) by a select query using Joins.
EKKO is having EBELN as primary key
EKPO is having EBELN,EBELP as primary key
EKKN is having EBELN,EBELP as primary key
EKET is having EBELN,EBELP as primary key
Can anybody Please give me the Select query.
With Regards
AjayHi ,
I am sending this sample coed for the Inner joins .Hope this will help you:
Inner joins using 3 tables
Try this :-
SELECT stpostlnr stpoidnrk mastmatnr maramtart stpo~menge
INTO CORRESPONDING FIELDS OF TABLE zmat1 FROM mast
JOIN stpo ON stpostlnr = maststlnr
JOIN mara ON maramatnr = mastmatnr
WHERE stpostlty = 'M' "AND stpoidnrk IN s_matnr
AND mast~werks = 1000.
Here s_matnr is a select-options on the selection-screen.
Or this.
Code:
Select single VbrkBukrs VbrkKunrg Vbrk~Vbeln
VbrkFkdat VbrkBstnk_Vf Vbrk~Zterm
Tvzbt~Vtext
VbakVbeln VbakBstdk
LikpVbeln Likplfdat Likp~Lfuhr
into w_vbrk
from vbrk
inner join Tvzbt on TvzbtZterm = VbrkZterm and
Tvzbt~Spras = sy-langu
Inner join Vbfa as SalesLnk
on SalesLnk~vbeln = pu_vbeln and
SalesLnk~vbtyp_v = c_order
inner join Vbak on VbakVbeln = SalesLnkVbelv
Inner join Vbfa as DeliveryLnk
on DeliveryLnk~vbeln = pu_vbeln and
DeliveryLnk~vbtyp_v = c_Delivery
inner join Likp on LikpVbeln = DeliveryLnkVbelv
where vbrk~vbeln = pu_Vbeln.
This code locates sales, delivery and payment terms info from a billing document number.
or
Here, this one also works fine :
select zfpcdcadivi zfpcdproforma zfpcdfactura zfpcdaniofactura
zfpcdmontousd zfpcdmontoap zfpcdebeln zfpcdinco1
zfpcdlifnr lfa1name1 zcdvsstatus zfpcdconint
into it_lista
from zfpcd inner join zcdvs
on zfpcdebeln = zcdvsebeln
and zfpcdproforma = zcdvsproforma
and zfpcdlifnr = zcdvslifnr
inner join lfa1
on zfpcdlifnr = lfa1lifnr
where zcdvs~status = '04'.
Also Here is another solution that just uses inner joins:
SELECT vbakvbeln vbfaerdat INTO (itab-vbeln, itab-wadat)
FROM ( vbak INNER JOIN vbap
ON vbapvbeln = vbakvbeln )
INNER JOIN vbfa ON vbakvbeln = vbfavbelv
WHERE vbak~kunnr = m_wm AND
vbak~vbtyp = 'C' AND
vbfa~erdat IN s_date AND
vbap~matnr = 'MZ1807F' AND
vbfaposnv = vbapposnr AND
vbfa~vbtyp_n = 'J'.
<REMOVED BY MODERATOR>
Cheers,
Chandra Sekhar.
Edited by: Alvaro Tejada Galindo on Apr 10, 2008 5:20 PM -
Select query with variable no of conditions
Hi,
I want to write a select query such that the conditions mentioned under WHERE clause can be variable .like :
Select * from TABLE where F1 = var1 and F2 = var2 and F3 = var3.
Now on the basis of some conditons the equations in where clause should be used.Say condition is variable value >6.
Now in this case ,if
var1 =7 var2 =3 var3 = 8 then the query shud behave like
select * from TABLE where F1 = var1 and F3 = var3
if :
var1 =3 var2 = 4 var3 =3 the :
select * from TABLE
But only one query is to be wrote that satisfies all of these
thanx
Edited by: aachal on Feb 4, 2011 11:36 AMHi Aachal,
Use Dynamic select statement.
Ex:
data : lv_wherecond type string.
Select * from TABLE where ( lv_wherecond ).
Before Select stmt, code as follows.
if var1 > 6.
if lv_wherecond is initial.
F1 = var1.
else.
concatenate lv_wherecond ' and F1 = var1' into lv_wherecond.
endif.
elseif var 2 > 6.
if lv_wherecond is initial.
F2 = var2
else.
concatenate lv_wherecond ' and F2 = var2' into lv_wherecond.
endif.
elseif var3 > 6.
same as above ..
endif.
Hope it helps..
Regards,
Sravan Guduru. -
How to execute SQL SELECT QUERY using VB in FDMEE
Hi Experts,
We are struggling with converting some of the FDM VB Scripts to FDMEE. While in FDM it was possible to simply create a RS Object, it doesnt seem to work in FDMEE. Can you please help me with some code samples that will help me execute SELECT Query and taking the output of the Query to Appropriate Variables.
Also it seems that the Accelerators in erstwhile FDM are no longer available in FDMEE. So we have to re-write our entire code all over again
ThanksThere are plenty of code examples in the FDMEE guide and al of the API methods are documented for both Visual Basic and Jython. Personally, I think, if you are having to re-factor your code because you have migrated from FDM to FDMEE I would look at doing it in Jython not the VB API. Jython is the scripting language that will be the mainstream choice going forward and athough the VB API is present to ease the move from FDM to FDMEE I wouldn't be sure how long it will be supported and you therefore may have to perform another code migration not too far down the line. Jython is a very powerful and easy to use if you spend a bit of time familiarizing yourself with the syntax and also opens up the opportunity to leverage the myriad of Java classes out there. Also all of your import scripts have to be in Jython with no VB alternative.
One other piece of advice is do not try and replicate allyour old code line for line. Look at what you were trying to achieve, assess whether it is still relevant or can it be faciliated by the new extended out of the box constructs and functionality FDMEE offers over classic FDM. -
How to use user defined function in select query using Toplink
Hi Friends
I am little bit of new in Toplink stuff... so please help me...
I have to database functions 1. encrypt and 2. decrypt.
I want to exceute the following sql query using toplink
select port, database, user_name, decrypt(encrypt('String which is to be encrypt ','password'),'password') from CONFIGURATION
can anyone tell me , how to write code in toplink which will give the about sql output.
thanks .....The "Specifying a Custom SQL String in a DatabaseQuery" section in the TopLink Developer's Guide may help... http://download-uk.oracle.com/docs/cd/B32110_01/web.1013/b28218/qrybas.htm#BCFHDHBG
-
Sparql query using variable paths
Hi,
I have a following graph in Oracle that I like to query using Jena 2.6.4 and OracleJenaAdaptor 11.2.0.3
ind:123 :hasA ind:124
ind:124 :hasB ind:125
ind:125 :hasC ind:126
ind:123 :hasD ind:127
Is there a way to construct a sparql query to return all ind: without "hard-conding" the full property name? Something in these lines (note, this query doesn't really work).
select *
where { ind:123 (:has*)+ ?x }
Thanks.:hasA rdf:type owl:ObjectProperty ;
rdfs:subPropertyOf :hasRelation .
:hasB rdf:type owl:ObjectProperty ;
rdfs:subPropertyOf :hasRelation .
:hasC rdf:type owl:ObjectProperty ;
rdfs:subPropertyOf :hasRelation .
:hasD rdf:type owl:ObjectProperty ;
rdfs:subPropertyOf :hasRelation .
String q1 = "SELECT ?x, ?y
where {?x (:hasRelation)+ ?y} ";
Stirng q2 = "SELECT ?x, ?y
where {?x :hasRelation ?y} ";
Oracle oracle = new Oracle(szJdbcURL, szUser, szPasswd);
Attachment attachment = Attachment.createInstance(new String[]{"my_asset","my_model"},
new String[]{"OWLPRIME"}, InferenceMaintenanceMode.UPDATE_WHEN_COMMIT, QueryOptions.ALLOW_QUERY_INVALID_AND_DUP);
GraphOracleSem graph = new GraphOracleSem(oracle, "vm_model", attachment);
ModelOracleSem inferencedModel = new ModelOracleSem(graph);
Query query = QueryFactory.create(q1);
Edited by: a1239090 on Aug 15, 2012 4:54 PM -
Friends,
I need to select some fields from two different tables which doesnot contain any field in common.How to Get this using a select query..
But there is a field X in table 1 which is equalient to eight char of another field y in table 2.I tried using offset but it is giving error.
Thanks in Advance
Regards
YaminiHello,
You can use a subquery
SELECT * FROM SFLIGHT AS F INTO WA_SFLIGHT
WHERE SEATSOCC < F~SEATSMAX
AND EXISTS ( SELECT * FROM SPFLI
WHERE CARRID = F~CARRID
AND CONNID = F~CONNID
AND CITYFROM = 'FRANKFURT'
AND CITYTO = 'NEW YORK' )
AND FLDATE BETWEEN '19990101' AND '19990331'.
WRITE: / WA_SFLIGHT-CARRID, WA_SFLIGHT-CONNID,
WA_SFLIGHT-FLDATE.
ENDSELECT.
or simply query the first table and then the second table with select endselect.
select * from table a.
select * from table b into output_table
where b-field1 eq a-field2.
endselect.
or read the data into one internal table loop at it and then query the other table.
Regards,
Shekhar Kulkarni -
Problem in SELECT TAG using variables
Hi all,
I have a JSP page which updates the record for a user.Now there is a HTML select tag and when the user queries its data this SELECT tag will automaticaly select the user stored item in database automatically. It means the select tag will have a variable to select the options. Now how can i use variables in SELECT TAG. Please help needed.I'm not exactly sure what you are asking, but here goes.
First, are you able to populate the select box with all the names... this is what it sounds like to me.
Or are you not able to populate it nor select it.
I use JSTL for all my jsps... so for me I would store a collection on the form and then iterate through it. (arrayList being my preference)
look into using <c:forEach> or you could try <logic:iterate> which I've used before but it has been several years.
here is an example block of code.
Sorry this is going to be a bit convoluted because of what I'm doing with it..
but I have an ArrayList that contains string arrays... position 0 being the value I want returned (like 1 through 10) and position 1 being the text representation..
so it comes out like
1 - Option 1
2 - Option 2
You will notice the if statement where I check to see if the localList[0] is equal to the view field. view would be your selected value.
<SELECT name="view" size="7"
multiple="multiple" class='OmniDlgLabel'>
<c:if test="${sessionScope.PHI2Form.localList!=null}">
<c:forEach var="localList"
items="${sessionScope.PHI2Form.localList}" varStatus="status">
<OPTION value='<c:out value="${localList[0]}"/>'
<c:if test="${sessionScope.PHI2Form.view==localList[0]}">SELECTED</c:if>>
<c:out value="${localList[0]}"/>-<c:out value="${localList[1]}" /></OPTION>
</c:forEach>
</c:if>
</SELECT></TD>There is an extra > that I cannot get rid of.. should be there after the
<OPTION value='<c:out value="${localList[0]}"/>' -
Executing Select query using JDBC Receiver Adapter
I created couple types in Oracle and also new function instead of procedure
Can I execute the above query using JDBC Receiver Adapter.
select *
from the ( select cast( apr.get_distribut('', '', '', 'hdfcgd', 'CAN') as dsrTable )
from dual );
If possible how my message structure should look like...Hi vikram,
If you use JDBC as Receiver Adapter you can only post the data to the data base I do no think so we can select the records from the data base.
If you use JDBC as Sender hope,we can the select query in the sender communication channel.
Hope I am clear.
Thanks and Regardds,
Chandu. -
SELECT QUERY USING STORED PROCEDURE
Hi,
I am using stored procedure in package, i need to execute select statement using
stored procedure.
regards,
p.kumaran? not framed properly i think so if u dnt mind plz check it out once
if u wnt to invoke a proc from package 2 ways r there
1) execute pac_name.proc_name[(arg_list)];
2) pl/sql
[declare]
begin
pac_name.proc_name[(arg_list)];
end;
/ -
When I do a select query, using DB Toolkit, I get less data than I expect
I run a select query and I want to get test number 271 and above. The data that is returned begins with test 273 instead. If I do a query in Access I can see that tests 271 and 272 are in the database. What can I do to get the right data?
CharlieThe issue as you have described just does not make sense unless the recorders ae not ordered by the test number.
Does the number of records returned match the number in the DB?
Ben
PS: No Mike, you are still the DB guy. Relax.
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction -
How to use a SELECT QUERY using fdmAPI.executeDML in FDMEE Jython Script?
Hi,
Just the way we use DELETE and INSERT Statement using fdmAPI.executeDML, is there any way of executing a SELECT Statement and get the output in variables?
I would like to refrain from using import java.sql and enter the connection details in a script.I would like to rather use SELECT directly if possible. I want to read the TDATASEG.DATAKEY column and use it for some custom process in a custom table
Thanks!Hi SH,
Somehow after upgrading to FDMEE 11.1.2.3.530, this is not working.
I get an error saying
while (RSTxnType.Next()):
Attribute Error: 'oracle.jdbc.driver.OracleResultSetImpl' object has no attribute 'Next' -
Select query-using Union All display duplicate records.
Hello All Gurus-
I am using Oracle 9.i
When i use the following query to fetch the records based on BUILDNUMBERNAME and ASSIGNED_BUILD then i am getting duplicate records -
select T1.ID FROM Defect T1,statedef T2,repoproject T3
WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1. ASSIGNED_BUILD like '1.4.5.6'
Union All
select T1.ID FROM Defect T1,statedef T2,repoproject T3
WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1.BUILDNUMBERNAME like '1.4.5.6'
How can i use the order by on T1.ID ? When i use the Order by T1.ID then it throws some error.
Kindly help me in this :(
Thanks in advance.Sorry for not providing all of the details -
I am using Toad tool to run the query.
1-When i use the following query -
Select T1.ID FROM Defect T1,statedef T2,repoproject T3
WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1. ASSIGNED_BUILD like '1.4.5.6' order by T1.ID
Union All
select T1.ID FROM Defect T1,statedef T2,repoproject T3
WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1.BUILDNUMBERNAME like '1.4.5.6' order by T1.ID
ORA-00933: SQL command not properly ended.
2-If i am not using the T1.ID and run the following query
Select T1.ID FROM Defect T1,statedef T2,repoproject T3
WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1. ASSIGNED_BUILD like '1.4.5.6'
Union All
select T1.ID FROM Defect T1,statedef T2,repoproject T3
WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1.BUILDNUMBERNAME like '1.4.5.6'
Then it is running fine but it is displaying the duplicate values like -
00089646
00087780
00089148
00090118
00090410
00088503
00080985
00084526
00087108
00087109
00087117
00088778
00086714
00079518
00087780
00089148
00090392
00090393
00090395
00090398
00090401
00090402
00090403
00090406
00090408
00088503
00080985
00084526
00087108
00087109
00087117
00088778
00086714
00079518 -
Error in select query using join
hi all
please help.
The follwing code givs this error....
select skb1-bukrs ska1-ktoks skb1-saknr skb1-waers skb1-xsalh skb1-xopvw skb1-xkres
into corresponding fields of table it_skab1
from ( skb1
OUTER JOIN ska1 on ska1-saknr=skb1-saknr ) .
*Error while executing....*
Program ZABHI_FIREPORT
"(" has no closing ")".
Please guide me for the correct syntax.
Thank u.hi,
use this code n check
tables: ska1,skb1.
data: begin of it_skab1 occurs 0,
bukrs like skb1-bukrs,
ktoks like ska1-ktoks,
saknr like skb1-saknr,
waers like skb1-waers,
xsalh like skb1-xsalh,
xopvw like skb1-xopvw,
xkres like skb1-xkres,
end of it_skab1.
select skb1~bukrs
ska1~ktoks
skb1~saknr
skb1~waers
skb1~xsalh
skb1~xopvw
skb1~xkres
from skb1 left outer join ska1 on skb1saknr = ska1saknr
into corresponding fields of table it_skab1 up to 10 rows.
loop at it_skab1.
write: / it_skab1-bukrs,it_skab1-ktoks,it_skab1-saknr,it_skab1-waers,it_skab1-xsalh,
it_skab1-xopvw,it_skab1-xkres.
endloop.
n let me knw is ur doubt cleared
rgds
shivraj
Edited by: ShivrajSinha on May 27, 2009 8:27 AM -
Select Query using AND operation
Hello,
I am developing RFC which will retrieve some records from SAP HR module table.
Input will be one structure (INPUT_TABLE) containing 4 fields. User may enter values for any fields, and my requirement is to perform a AND operation on those entered fields only. Currently i am writing query as follows :
SELECT DISTINCT apernr aVORNA aNACHN acname a~gbdat FROM
PA0002 as a INTO CORRESPONDING FIELDS OF TABLE Z_PD_TABLE
WHERE apernr = INPUT_TABLE-pernr AND aVNAMC = INPUT_TABLE-VORNA AND aNCHMC = INPUT_TABLE-NACHN AND agbdat = INPUT_TABLE-GBDAT .
If only 2 values are entered by user out of 4 , it will perform AND operation by taking other values as blank or 000000. I want to skip these AND operation on fields which are not entered by user.
Please help for writing query.
Thanks in advance,
PrashantHi,
Create dynamic where condition based upon user input.
Try like this....
IF NOT INPUT_TABLE-pernr IS INITIAL.
CLEAR : lv_pernr_condition.
CONCATENATE 'PERNR' ' = ' '''' INPUT_TABLE-pernr '''' INTO
lv_pernr_condition.
ENDIF.
IF NOT INPUT_TABLE-vnamc IS INITIAL.
CLEAR : lv_vnamc_condition.
CONCATENATE 'VNAMC' ' = ' '''' INPUT_TABLE-vnamc '''' INTO
lv_vnamc_condition.
ENDIF.
IF NOT INPUT_TABLE-vorna IS INITIAL.
CLEAR : lv_vorna_condition.
CONCATENATE 'VORNA' ' = ' '''' INPUT_TABLE-vorna '''' INTO
lv_vorna_condition.
ENDIF.
IF NOT INPUT_TABLE-nchmc IS INITIAL.
CLEAR : lv_nchmc_condition.
CONCATENATE 'NCHMC' ' = ' '''' INPUT_TABLE-nchmc '''' INTO
lv_nchmc_condition.
ENDIF.
IF NOT INPUT_TABLE-gbdat IS INITIAL.
CLEAR : lv_gbdat_condition.
CONCATENATE 'GBDAT' ' = ' '''' INPUT_TABLE-gbdat '''' INTO
lv_gbdat_condition.
ENDIF.
IF NOT lv_pernr_condition IS INITIAL.
CONCATENATE lv_pernr_condition lv_condition
INTO lv_condition SEPARATED BY space.
ENDIF.
IF NOT lv_vnamc_condition IS INITIAL.
IF lv_condition IS INITIAL.
CONCATENATE lv_vnamc_condition lv_condition
INTO lv_condition SEPARATED BY space.
ELSE.
CONCATENATE lv_condition 'AND' lv_vnamc_condition
INTO lv_condition SEPARATED BY space.
ENDIF.
ENDIF.
IF NOT lv_vorna_condition IS INITIAL.
IF lv_condition IS INITIAL.
CONCATENATE lv_vorna_condition lv_condition
INTO lv_condition SEPARATED BY space.
ELSE.
CONCATENATE lv_condition 'AND' lv_vorna_condition
INTO lv_condition SEPARATED BY space.
ENDIF.
ENDIF.
IF NOT lv_nchmc_condition IS INITIAL.
IF lv_condition IS INITIAL.
CONCATENATE lv_nchmc_condition lv_condition
INTO lv_condition SEPARATED BY space.
ELSE.
CONCATENATE lv_condition 'AND' lv_nchmc_condition
INTO lv_condition SEPARATED BY space.
ENDIF.
ENDIF.
IF NOT lv_gbdat_condition IS INITIAL.
IF lv_condition IS INITIAL.
CONCATENATE lv_gbdat_condition lv_condition
INTO lv_condition SEPARATED BY space.
ELSE.
CONCATENATE lv_condition 'AND' lv_gbdat_condition
INTO lv_condition SEPARATED BY space.
ENDIF.
ENDIF.
SELECT DISTINCT pernr VORNA NACHN cname gbdat FROM
PA0002 INTO CORRESPONDING FIELDS OF TABLE Z_PD_TABLE
WHERE lv_condition . " Dynamic where condition
Hope it will helps
Maybe you are looking for
-
Prevent Identical Selection in Drop Down List in an Expanding Table
Hi All, I have a 2x2 table in which the top row is a header row and the bottom row 'Row1'. Row1 Cell1 has two buttons in it, one to add a new Row1 using Javascript click instance script: this.parent.parent.instanceManager.addInstance() ...and one to
-
How to manage 2 ipads in family (trying to update games on both)
Hi all, a few questions please. I am trying to sort out the 2 ipads so its more easy to manage. I am trying to use one for work so trying to make sure that emails etc do not go to both but still allowing the kids to play on both when I am at home. 1)
-
Problem with Recovery Partition(After i got a Virus)
Hi all, I am using HP Envy 15 notebook with windows 7 home premium x64-bit installed.I didnt create the recovery disks since i got this notebook and what happened is that i got a virus from the internet but i almost repaired all system faults caused
-
Vendor and Material (MARA and LFA1) linking
Hi , I have created a view on top of mara marc and mard for one of my report requirements. Here I have mara-mfrnr field is mapping to manufacurer field in BW. Now I need to restrict the data in to this field by acct group which is available in 0vendo
-
Connect 2nd monitor in imac 10.9.1
Help