Subquery in IN clause of an select statement
Hi friends,
The Subquery in IN clause of an select statement take long time , is there any alternate ??
>select * from oudata.SURVEY_USER_ANSWERS
>where user_id in (select user_id from oudata.SURVEY_USERS where trunc(course_start_date) <'01-Jun-2007');
thnaks,
raj
Edited by: infant_raj on May 28, 2009 12:09 AM
infant_raj wrote:
Hi friends,
The Subquery in IN clause of an select statement take long time , is there any alternate ??
select * from oudata.SURVEY_USER_ANSWERS
where user_id in (select user_id from oudata.SURVEY_USERS where trunc(course_start_date) <'01-Jun-2007');
No database version specified?
No table structures/indexes given?
No indication of the cardinality, selectivity, skew of the data being queried.
Have you got a function based index for "trunc(course_start_date)"?
Why are you not specifying your comparison date as a DATE datatype rather than relying on implicit conversion? i.e. it should be "to_date('01-Jun-2007','DD-MON-YYYY')"
Have statistics been gathered on the data
[How to post a SQL statement tuning request|http://forums.oracle.com/forums/thread.jspa?threadID=863295&tstart=0]
[When your query takes too long...|http://forums.oracle.com/forums/thread.jspa?messageID=1812597#1812597]
Similar Messages
-
Values from a Multi-Select in the where clause of a Select statement
I have a web page that solicits query parameters from the user.
The selections that the user makes will populate the WHERE clause of a Select statement.
One of the controls on the page is a multi-select control.
When this page posts, I would like to execute a Select statement wherein the selected values from this control appear in the .. Column IN ( <list here> ) portion of the WHERE clause.
This is an extremely common scenario, but I cannot seem to locate a how-to or message thread that addresses this specific case.
I have an idea that it may involve dynamic SQL or Execute Immediate, but cannot seem to pin down the answer.
Any help would be greatly appreciated!anonymous - As illustrated here: Re: Search on a typed in list of values
Scott -
Using if logic in the where clause of a select statement
I have a select clause. And in the select clause there is a variable all_off_trt that can be 'Y' or 'N'.
In the where clause I want to make it so that if a form variable is checked and all_off_trt is 'Y' then
exclude it else if the form variable isn't checked then select it no matter what all_off_trt is.
Is there any way to include either and if statement or a case statement within the where clause to acheive this? If not is there another way of doing it?
Basically I am looking for a case statement like this
case
when all_off_trt = 'Y' and mail_para.code = 'Y' then false
else true
end
Message was edited by:
Tugnutt7Ok, so that really doesn't solve my problem. I have 3 different fields that I need to do that with. Each combining in a select statement to print an email list, as well as other thing limiting the where clause.
This is currently what I have, tested and working 100%.
cursor email_cur is
select unique p.email,s.all_off_trt,s.all_deceased,s.no_enroll
from participant p, trialcom t, ethics s
where p.status='A'
and p.surname=t.surname
and p.initials=t.initials
and s.trial_cd = t.tricom
and s.centre = t.centre
and p.email is not null
and (t.centre in (select code from mail_parameters where user_name=user and mail_para='CENTRE')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='CENTRE'))
and (t.tricom in (select code from mail_parameters where user_name=user and mail_para='TRIAL')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='TRIAL'))
and (t.role in (select code from mail_parameters where user_name=user and mail_para='ROLE')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='ROLE'))
and (p.country in (select code from mail_parameters where user_name=user and mail_para='COUNTRY')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='COUNTRY'))
and (t.represent in (select code from mail_parameters where user_name=user and mail_para='REPRESENT')
or 'XX' in (select code from mail_parameters where user_name=user and mail_para='REPRESENT'));
This is in a program unit that runs when a button is clicked. At the end of that I need to add on the 3 case statements that help further narrow down the selection of emails to be printed. Then it prints the emails selected from this statement into a file. So it has to be done right in the select statement. The three table variables are the all_off_trt, all_deceased, and no_enroll. The form has 3 checkboxes. One for each, that when checked (giving the variable associated with the checkboxes a value of 'Y') excludes all emails that have a 'Y' in the coresponding table variable. -
INTO clause expected in SELECT statement
Hi all,
I have this pl sql code that errors out:an INTO clause is expected in this SELECT statement.
Code
Declare
prev_col1 FLOAT(10) := 0;
temp3 temp2%rowtype;
Begin
select * from
select col1, col2, col3,
lag(col1,1,0) over(order by rownum) prev_col1
from temp2 where <conditions here> order by col2
where col1- prev_col1 > 10000 and col1>0 and prev_col1>0;
End;
I have tried in vain to use select into, with both the select statements(separately). Please advise.
Basically, I am comparing a field with the previous field and identifying faulty fields. Then I want to replace the faulty field with the previous field.I have tried this in vain:
Declare
prev_col1 FLOAT(10) := 0;
v_col1 temp2.col1%type;
v_col2 temp2.col2%type;
v_col3 temp2.col3%type;
Begin
select col1, col2, col3, prev_col1 into v_col1, v_col2, v_col3, prev_col1 from
select col1, col2, col3,
lag(col1,1,0) over(order by rownum) prev_col1
from temp2 order by col3
where col1- prev_col1 > 10000 and prev_col1 > 0;
UPDATE temp2 SET col1= prev_col1 WHERE (col1- prev_col1 > 10000 and prev_col1 > 0);
End;
I am only able to update the declared variable:v_col1. How do I update the original value in table temp2? -
How to pass the parameter in the where clause of the select statement
Hi All,
Iam getting one of the value from the Input otd and using this value i need to query one of the tables in oracle database and selected the table using the oracle eway otd like shown below .
otdRISKBLOCK_1.getRISKBLOCK().select() .
where clause in side the select takes a string parameter as Iam getting the string parameter from the input otd and passing this to where clause by creating a string literal after deployment it is giving an error saying "ORA-00920: invalid relational operator".
can any one throw some input on this .
Thanks in Advance
SrikanthYou will see this error if the search condition was entered with an invalid or missing relational operator.
You need to include a valid relational operator such as
=, !=, ^=, <>, >, <, >=, <=, ALL, ANY, [NOT] BETWEEN, EXISTS, [NOT] IN, IS [NOT] NULL, or [NOT] LIKE in the condition. in the sql statement.
Can you throw some more light on how are you designing your project? -
Using ROWID in the WHERE clause of a SELECT statement
hi all,
my team is trying to select a value from a table using the rowid as the selection criterion
e.g. select column_name from table_name where rowid > 'AAA112BBBCCC12A'
this query does not appear to return accurate results e.g. it return rows instead of two. my questions are:
1. is this a legitimate approach?
2. should we convert the row id to varchar2? if so how should this be done?
thanks!SQL> select rowid,ename
2 from emp;
ROWID ENAME
AAAs8KAA+AAAVXCAAA KING
AAAs8KAA+AAAVXCAAB BLAKE
AAAs8KAA+AAAVXCAAC CLARK
AAAs8KAA+AAAVXCAAD JONES
AAAs8KAA+AAAVXCAAE SCOTT
AAAs8KAA+AAAVXCAAF FORD
AAAs8KAA+AAAVXCAAG SMITH
AAAs8KAA+AAAVXCAAH ALLEN
AAAs8KAA+AAAVXCAAI WARD
AAAs8KAA+AAAVXCAAJ MARTIN
AAAs8KAA+AAAVXCAAK TURNER
AAAs8KAA+AAAVXCAAL ADAMS
AAAs8KAA+AAAVXCAAM JAMES
AAAs8KAA+AAAVXCAAN MILLER
AAAs8KAA+AAAVXCAAO erwer
15 rows selected.
SQL> select ename from emp where rowid = 'AAAs8KAA+AAAVXCAAH';
ENAME
ALLEN
SQL> select ename from emp where rowid > 'AAAs8KAA+AAAVXCAAH';
ENAME
WARD
MARTIN
TURNER
ADAMS
JAMES
MILLER
erwer
7 rows selected.1) using rowid to access a record is the quickest way so it is legitimate
however using > has no real purpose as you point out you cannot get any meaningful results returned.
2) No real need to convert however beware storing values in tables as Oracle does not guarantee to preserve the format in different versions so upgrading from 9i to 10g would invalidate your data. -
Dynamic WHERE clause in SELECT statement
Hi,
I need to extract (SELECT) all the products in different salesorganizations. Since a product can be available in more than 1 salesorg I have created several properties in the PRODUCT dimension - 1 for each salesorganization (naming: Sxxxx where xxxx is the salesorganization number).
Since I need to prefix the salesorganization property with an "S" I have created a property on the SALESORG dimension called SALESORG.
Therefore I need to create a dynamic WHERE clause in the SELECT statement. Currently my script is:
*SELECT(%SORG%, "[SALESORG]",SALESORG, [ID]=%SALESORG_SET%)
*SELECT(%PROD%, "[ID]",PRODUCT, [%SORG%]="X")
My first SELECT find the Sxxx (equal to the property I need in the PRODUCT dimension). My second SELECT uses the variable in the first SELCT statement to use the correct property for the WHERE clause.
Unfortunately the code is not validated - any suggestions?
/LarsHi Lars,
If you run it from a DM package without validating it, does it still work? I would bet it does.
If this is the case I would open a message with SAP (it would be an enhancement request). Until they fix the validation code, you would just have to live with the script not validating.
Cheers,
Ethan -
SELECT statement in FROM clause - syntax help
Hi,
I want to have a SELECT statement in the FROM clause. I get syntax error when doing this and since I am new to ABAP I need som help.
I want to do the following, (and if anyone has any SELECT statement from their own system which you know there is no syntax error in please post it here so I can analyze the syntax):
*I leave the INTO itab clause out, since I only want to demonstrate the functionality
I am trying to get.
<b>SELECT</b> tableOne~someField
<b>FROM</b> tab <b>AS</b> tableOne (<b>SELECT</b> someField
<b>FROM</b> tab
<b>WHERE</b> someFiled > 1) <b>AS</b> tableTwo
<b>WHERE</b> tableOnesomeField > tableTwosomeField
like I said, the problem is that the select statement in the parenthesis in the from clause seems to be incorrect because I get "wrong expression" when trying to compile. Is this because I cannot have a select statement in the from clause or is it because of a minor syntax error, such as I forgot a dot, or some other sign?
thanks and regards
Baransorry i am not enough familiar with sub queries but some error i can see which i will state here.
1> you have to use sub queries i.e. select in ( ) after where clause because here you are fulfilling a where clause by another select statement.
like this
SELECT * FROM SFLIGHT
INTO WA
WHERE SEATSOCC = ( SELECT MAX( SEATSOCC ) FROM SFLIGHT ).
2> you cannot specify field name without into clause either you have to use
select * or select f1 into tab-f1 like this...
but if you are using select * without into you have to define
tables : dbtab.
selec * from dbtab. like that.
regards
shiba dutta -
Select Statement -- Where Clause Execution Order
What is the order of execution of the "AND" and "OR" in the WHERE clause of a Select statement?
Are the "AND"'s executed from the top down, left to right? Is it the same for the "OR"'s execution?
Thanks for any help...Not clear why you care. There is an order in which the optimizer parses the SQL (which may change from ver to ver), but this is a fairly quick operation. The order in which tables are visited and predicates evaluated is dependent on what the op[timizer does with the SQL.
Ken -
HOW CAN I USE MULTIPLE INNERJOINS IN A SINGLE SELECT STATEMENT?
HI,
I AM SHABEER AHMED,
I AM GETTING AN ERROR WHILE I ATTEMPT TO EXECUTE A SELECT STATEMENT WITH MULTIPLE INNER JOINS . BECOZ I WANT TO FETCH ITEM DATA, PARTNER DATA BASED ON HEADER DATA .
THEN OF COURSE I HAVE FETCH DATA FROM VBAK VBAP VBKD SO LZ SEND ME THE SOLUTION.
BYEHi,
1.Just see this:
SELECT * INTO CORRESPONDING FIELD OF TABLE itab
FROM t1 INNER JOIN t2 ON t1f4 EQ t2f4
INNER JOIN t3 ON t2f5 EQ t3f5 AND
t2f6 EQ t3f6 AND
t2f7 EQ t3f7.
2.But better to use for all entries.It increases the performance.
FOR ALL ENTRIES
Tabular Conditions
The WHERE clause of the SELECT statement has a special variant that allows you to derive conditions from the lines and columns of an internal table:
SELECT ... FOR ALL ENTRIES IN <itab> WHERE <cond> ...
<cond> may be formulated as described above. If you specify a field of the internal table <itab> as an operand in a condition, you address all lines of the internal table. The comparison is then performed for each line of the internal table. For each line, the system selects the lines from the database table that satisfy the condition. The result set of the SELECT statement is the union of the individual selections for each line of the internal table. Duplicate lines are automatically eliminated from the result set. If <itab> is empty, the addition FOR ALL ENTRIES is disregarded, and all entries are read.
The internal table <itab> must have a structured line type, and each field that occurs in the condition <cond> must be compatible with the column of the database with which it is compared. Do not use the operators LIKE, BETWEEN, and IN in comparisons using internal table fields. You may not use the ORDER BY clause in the same SELECT statement.
You can use the option FOR ALL ENTRIES to replace nested select loops by operations on internal tables. This can significantly improve the performance for large sets of selected data.
Example for ALL ENTRIES
DATA: TAB_SPFLI TYPE TABLE OF SPFLI,
TAB_SFLIGHT TYPE SORTED TABLE OF SFLIGHT
WITH UNIQUE KEY TABLE LINE,
WA LIKE LINE OF TAB_SFLIGHT.
SELECT CARRID CONNID
INTO CORRESPONDING FIELDS OF TABLE TAB_SPFLI
FROM SPFLI
WHERE CITYFROM = 'NEW YORK'.
SELECT CARRID CONNID FLDATE
INTO CORRESPONDING FIELDS OF TABLE TAB_SFLIGHT
FROM SFLIGHT
FOR ALL ENTRIES IN TAB_SPFLI
WHERE CARRID = TAB_SPFLI-CARRID AND
CONNID = TAB_SPFLI-CONNID.
LOOP AT TAB_SFLIGHT INTO WA.
AT NEW CONNID.
WRITE: / WA-CARRID, WA-CONNID.
ENDAT.
WRITE: / WA-FLDATE.
ENDLOOP.
INNER JOINS
In a relational database, you normally need to read data simultaneously from more than one database table into an application program. You can read from more than one table in a single SELECT statement, such that the data in the tables all has to meet the same conditions, using the following join expression:
SELECT...
FROM <tab> INNER JOIN <dbtab> AS <alias> ON <cond> <options>
where <dbtab> is a single database table and <tab> is either a table or another join expression. The database tables can be specified statically or dynamically as described above. You may also use aliases. You can enclose each join expression in parentheses. The INNER addition is optional.
A join expression links each line of <tab> with the lines in <dbtab> that meet the condition <cond>. This means that there is always one or more lines from the right-hand table that is linked to each line from the left-hand table by the join. If <dbtab> does not contain any lines that meet the condition <cond>, the line from <tab> is not included in the selection.
The syntax of the <cond> condition is like that of the WHERE clause, although individual comparisons can only be linked using AND. Furthermore, each comparison must contain a column from the right-hand table <dbtab>. It does not matter on which side of the comparison it occurs. For the column names in the comparison, you can use the same names that occur in the SELECT clause, to differentiate columns from different database tables that have the same names.
The comparisons in the condition <cond> can appear in the WHERE clause instead of the ON clause, since both clauses are applied equally to the temporary table containing all of the lines resulting from the join. However, each join must contain at least one comparison in the condition <cond>.
Example for INNER JOINS
REPORT demo_select_inner_join.
DATA: BEGIN OF wa,
carrid TYPE spfli-carrid,
connid TYPE spfli-connid,
fldate TYPE sflight-fldate,
bookid TYPE sbook-bookid,
END OF wa,
itab LIKE SORTED TABLE OF wa
WITH UNIQUE KEY carrid connid fldate bookid.
SELECT pcarrid pconnid ffldate bbookid
INTO CORRESPONDING FIELDS OF TABLE itab
FROM ( ( spfli AS p
INNER JOIN sflight AS f ON pcarrid = fcarrid AND
pconnid = fconnid )
INNER JOIN sbook AS b ON bcarrid = fcarrid AND
bconnid = fconnid AND
bfldate = ffldate )
WHERE p~cityfrom = 'FRANKFURT' AND
p~cityto = 'NEW YORK' AND
fseatsmax > fseatsocc.
LOOP AT itab INTO wa.
AT NEW fldate.
WRITE: / wa-carrid, wa-connid, wa-fldate.
ENDAT.
WRITE / wa-bookid.
ENDLOOP.
Regards,
Shiva Kumar(Reward if helpful). -
How to use a select statement with chinese characters?
I am currently developing a java servlet<using tomcat 4.x> which allows me to use select statement to retrieve results from the Microsoft SQL Server 2000 database. I am using a simple form to get the parameter for querying. The main problem i'm facing is that there are chinese information in the SQL database, but i can't retrieve it through the sql statement with the chinese characters input<thru the form with the help of NJ STAR>in the WHERE condition. When i execute the statement, it returns me no results even though the rows are present in the database.
Does anyone have the solution to using chinese words in the WHERE clause of the select statement to retrieve results with columns which contains chinese characters? Please help me. Thanks everyone. :)
PS: when i cut and paste those characters in the sql database and paste onto java.. it is ??? in questionmarks.. but when i paste them into excel 2000.. its shown as chinese chars again..
please heelppp~~Greetings,
PS: when i cut and paste those characters in thesql
database and paste onto java.. it is ??? in
questionmarks.. but when i paste them into excelThis is why the SELECT is not returning any results.
You need to set the character encoding set on your
statement and parameters for the characters to be
properly translated. Refer to the charsetName
parameter in the String class constructor in your API
docs and also to
$JDK_DOCS/guide/intl/encoding.doc.html in your JDK
documentation.
2000.. its shown as chinese chars again..Because Office programs are performing the same kind
of character translation with the appropriate MS APIs.
please heelppp~~Regards,
Tony "Vee Schade" Cookis it possible for you to show me some coding examples? i don't really understand what is to be done in order to set the char set and what does it really do.. tried reading up but still dun understand.. :(
pardon my shallow knowledge of java..
ok..
The thing is when i used an insert statement with chinese characters of GBK format hardcoded into the java servlet and then i use the insert statement to insert the chars into the database, it cannot be seen as a chinese word when i off the NJStar. and then it can be searched out with my current form of servlet.. below is my coding of the servlet..
note: i've set my html file to charset = GBK
//prototype of Search engine...
//workable for GBK input and output...
import java.io.*;
import java.io.OutputStream;
import java.io.IOException;
import javax.servlet.http.*;
import javax.servlet.ServletException;
import java.util.*;
import java.sql.*;
import java.nio.charset.Charset;
public class SearchBeta extends HttpServlet {
private Vector musicDetails = new Vector();
private String query = "";
public void service (HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException, UnsupportedEncodingException {
query = req.getParameter ("T1");
System.out.println("before:"+query);
String type = req.getParameter ("D1");//type
query = req.getParameter ("T1");
//query = "������";
System.out.println("after:"+query);
getResults(type,query);
System.out.println("locale = :"+req.getLocale());
res.setContentType ("text/html;charset=GBK");
PrintWriter out = res.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<body bgcolor = \"black\">");
out.println("<font face = \"comic sans ms\" color=\"Cornsilk\">");
if (query.length()==0)
out.println ("Please key in your search query.");
else if (musicDetails.size()==0)
out.println ("Sorry, no results matching your search can be found.");
else {
out.println("<center>");
out.println("<table cellspacing = \"50\">");
int i = 0;
//Display the details of the music
while (i<musicDetails.size()) {
Results details = (Results)musicDetails.get(i);
String dbArtist = "";
String dbAlbum = "";
String dbTitle = "";
String dbCompany = "";
dbAlbum = details.getAlbum();
dbTitle = details.getTitle();
dbCompany = details.getCompany();
dbArtist = details.getArtist();
try{
dbAlbum = new String(dbAlbum.getBytes("ISO-8859-1"),"GBK");
dbTitle = new String(dbTitle.getBytes("ISO-8859-1"),"GBK");
dbCompany = new String(dbCompany.getBytes("ISO-8859-1"),"GBK");
dbArtist = new String(dbArtist.getBytes("ISO-8859-1"),"GBK");//correct translation.
catch(UnsupportedEncodingException e){
System.out.print(e);
e.printStackTrace();
String dbImage_loc = details.getImage();
out.println("<tr>");
out.println("<td><table>");
out.println("<img src=C:\\Program Files\\Apache Group\\Tomcat 4.1\\webapps\\examples\\ThumbNails\\"+dbImage_loc+">");
out.println("<tr>");
out.println("<th><font color=\"violet\"> Artist: </font></th>");
out.println("<td><font color=\"Cornsilk\">"+dbArtist+"</font></td>");
out.println("</tr>");
out.println("<tr>");
out.println("<th><font color=\"violet\"> Title: </font></th>");
out.println("<td><font color=\"Cornsilk\">"+dbTitle+"</font></td>");
out.println("</tr>");
out.println("<tr>");
out.println("<th><font color=\"violet\"> Company: </font></th>");
out.println("<td><font color=\"Cornsilk\">"+dbCompany+"</font></td>");
out.println("</tr>");
System.out.println("album: "+ dbAlbum);
out.println("<tr>");
out.println("<th><font color=\"violet\"> Album: </font></th>");
out.println("<td><font color=\"Cornsilk\">"+dbAlbum+"</font></td>");
out.println("</tr>");
System.out.println("company: "+ dbCompany);
out.println("</table></td>");
out.println("</tr>");
i++;
out.println("</table>");
out.println("</center>");
out.println("</font>");
out.println("</body>");
out.println("</head>");
out.println("</html>");
out.close();
//to remove all the elements from the Vector
musicDetails.removeAllElements();
//get Searched Music Details and store in Results object which is stored in musicDetails vector
public void getResults (String type, String searchQuery) {
try {
Class.forName ("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=music","sa","kokkeng");
Statement stmt = con.createStatement();
String query = "SELECT * FROM MusicDetails WHERE "+type+" = '"+searchQuery+"'";
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String artist = rs.getString("Artist");
String title = rs.getString("Song");
String company = rs.getString("Company");
String album = rs.getString("Album");
String image_loc = rs.getString("Image");
Results details = new Results (artist,title,company,album,image_loc);
musicDetails.add(details);
stmt.close();
con.close();
catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
with the above servlet i created, i can search out the data in the database which i've inserted through the insert statement. I still can't search for things i've keyed into the database directly using NJStar..
thank you so much for helping.. really hope any one else who knows the answer to this will reply too... thank you all so much...
-KK -
Order of records in o/p of select statement
Hi all
I have doubt regarding the select statement. I need to execute a select statement (with out any order ie with out "order by") which searchs a table. I want to know whether in any
circumstances the order of the records of the select statement is different.
sample select statement which I need to execute
select emp_no from emplyees where designation = 'programer'
in one word order of records of in the o/p of a select statement will be unique ?
(provided same query same, table,)
can u plz quote the link to get more information
regards
RenjithHi,
YES, you can
Do Order By Without Using Order By Clause
in your select statement.
I assume that you have unique data ( e.g. emp_no in Emp Table ) and you you do not want to use Order by clause.
Solution 1:
Select Emp_no
from Emp
group by Emp_no;
the o/p will be in the sorted in the Ascending order.
Solution 2: ( Only for columns holding Numeric Values )
Select Emp_No
From Emp
Where 99999 - Emp_no in ( Select 99999 - Emp_no from Emp );
Again this will sort the result will be in the Descending Order. you can use any big number instead of 99999 but it should be greater than Emp_no value.
Note: You Should only use this method on not very large tables coz of performance issue.
Hope this will solve your problem.
Any Comment on this, any body.
Thanks and Regards
There is always a solution to the problem, And if there is no solution of a problem then problem is not a problem. -
Sql Error in Select statement when doing subquery
Hi,
I am trying to see what the error is in the subquery part of the select statement.
Subquery should be fetching the safety_stock_quantity based on the MAX(effectivity_date).
Any suggestions?
SELECT kbn.last_update_date,itm.segment1,itm.description,kbn.kanban_card_number,kbn.kanban_size,
(SELECT msc.safety_stock_quantity
FROM mtl_safety_stocks msc
WHERE msc.effectivity_date = (select MAX(msc2.effectivity_date)
from mtl_safety_stocks msc2
where msc2.inventory_item_id = itm.inventory_item_id
and msc2.organization_id = itm.organization_id)
AND msc.inventory_item_id = itm.inventory_item_id
AND msc.organization_id = itm.organization_id
FROM mtl_system_items_b itm
,mtl_onhand_quantities_detail moqd
,mtl_safety_stocks msc
,mtl_kanban_card_activity kbn
WHERE itm.inventory_item_id = kbn.inventory_item_id
AND itm.organization_id = kbn.organization_id
AND itm.inventory_item_id = moqd.inventory_item_id
AND itm.organization_id = moqd.organization_id
AND moqd.subinventory_code = kbn.source_subinventory
AND kbn.card_status = 1
AND kbn.supply_status = 5
AND msc.inventory_item_id = itm.inventory_item_id
AND msc.organization_id = itm.organization_id
GROUP BY
kbn.last_update_date,itm.segment1,itm.description,kbn.kanban_card_number,kbn.kanban_size;
Thanks
PravnHi, Pravn,
Remember the ABC's of GROUP BY:
When you use a GROUP BY clause and/or an aggregate fucntion, then every item in the SELECT clause must be:
(A) an <b>A</b>ggregate function,
(B) one of the "group <b>B</b>y" expressions,
(C) a <b>C</b>onstant, or
(D) something that <b>D</b>epends entirely on the above. (For example, if you "GROUP BY TRUNC(dt)", you can "SELECT TO_CHAR (TRUNC(dt), 'Mon-DD')").
There's a GROUP BY clause in your main query, so every item in the main SELECT clause must be one of the above. The last item, the unnamed scalar sub-query, is none of the above.
How can you fix this problem? That depends on your data, the results you want, and perhaps on your Oracle version. If you'd like help, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved. Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
Always say which version of Oracle you're using.
You may have noticed that this site normally doesn't display multiple spaces in a row.
Whenever you post formatted text (including, but limited to, actual code) on this site, type these 6 characters:
\(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing. -
How to model in OWB if you have a subquery in your select statement? (11.2)
Which operator (is it the Table operator) to use if I have a subquery as part of my select statement? (The way I do it works, but is not elegant. What I do is create a table for the subquery and than join that with the other sources to point to my target.) But, would appreciate the best way with OWB's features.
Here is the entire SQL (including the subquery):
SELECT to_numbe (null), course_id
at.book, lp.NAME,
(select b.pricing from qp_pricing_attributes b
where b.list_id = ll.list_id and b.product = at.product) sign,
ll.operand AS price, lhb.comments
FROM
pricing_attribs at,
list_lines ll,
list_h lp,
list_b lhb
WHERE 1 = 1
and ll.list_line_id = atrib.list_line_id
AND ll.list_header_id = lp.list_header_id
AND lp.list_header_id = lhb.list_header_id
Thanks you.Hi
Doesn't need to be a table in the target. Let's take a very simple example, let's say you wanted to do the following;
select ename,(select dname from dept d where d.deptno=e.deptno) from emp e
Then DEPT is your lookup table and EMP is your driving table.
1. Add EMP on to the canvas.
2. Add in lookup operator
3. Bind lookup to DEPT
4. Hit finish
5. Map EMP.DEPT to DEPT.INGRP1 (the lookup operator)
6. Edit lookup operator, on Lookup Conditions tab set DEPTNO for lookup column, and DEPTNO for input attribute
7. Lookup complete now
You can add in a target table operator and map from the source EMP table and the output attributes of the lookup operator. you can change step 4 to carry on through wizard and define lookup, but I have chosen to do 5, to automatically get the names and datatypes of the inputs. There are lot of other options now in 11gR2 in the lookup.
Hope this makes sense.
Cheers
David -
How build where clause in select statement in FM for Virtual provider
Hi
I looking for example of FM for Virtual provider where I find code how assign to select statement "where" clause value from query variable.
In following code how build t_r_custtype range and how assign value to it.
CODE********************************
TYPE-POOLS: abap.
initialize
CLEAR: e_t_data, e_t_msg.
this is specific to infoprovider VIRTPROV
CHECK i_infoprov = 'VIRTPROV'.
FIELD-SYMBOLS: <l_s_sbook> TYPE sbook,
<l_s_data> TYPE ANY.
DATA: l_t_component TYPE abap_compdescr_tab,
l_t_sbook TYPE TABLE OF sbook.
initialize
CLEAR e_t_data.
Data selection / only Business Customer
SELECT * FROM sbook
INTO CORRESPONDING FIELDS OF TABLE l_t_sbook
WHERE custtype in t_r_custtype.
ENDCODE********************************
Thanks a lot
AdamHello,
Would you like fill the ranges in Customer exit for BEx..?
If Yes. please refer the attachment for the whole code...
"Sample code in Customer Exit in BEx"
IF i_step = 2.
CASE i_vnam.
WHEN 'ZDAY_CX'.
LOOP AT i_t_var_range INTO loc_var_range WHERE vnam = 'ZDAY_IN'.
CLEAR: l_s_range.
ZT_DT1 = loc_var_range-low.
ZT_DT2 = loc_var_range-HIGH.
CALL FUNCTION 'DATE_CREATE'
EXPORTING
ANZAHL_JAHRE = 0
ANZAHL_KALTAGE = 0
ANZAHL_MONATE = '-1'
ANZAHL_TAGE = 0
DATUM_EIN = ZT_DT1
DATUM_EIN_ULT = ' '
ULTIMO_SETZEN = ' '
IMPORTING
DATUM_AUS = ZFIDAY .
E_TT =
E_ULTKZ =
CALL FUNCTION 'DATE_CREATE'
EXPORTING
ANZAHL_JAHRE = 0
ANZAHL_KALTAGE = 0
ANZAHL_MONATE = '-1'
ANZAHL_TAGE = 0
DATUM_EIN = ZT_DT2
DATUM_EIN_ULT = ' '
ULTIMO_SETZEN = ' '
IMPORTING
DATUM_AUS = ZLSDAY.
E_TT =
E_ULTKZ =
l_s_range-low = ZFIDAY .
l_s_range-high = ZLSDAY .
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
APPEND l_s_range TO e_t_range.
ENDLOOP.
*****************************************End*************************************
**To get the From date (For Text Variable) as per the user input date interval range**
WHEN 'ZR_S'.
LOOP AT i_t_var_range INTO loc_var_range WHERE vnam = 'ZDAY_IN'.
CLEAR: l_s_range.
ZT_DT1 = loc_var_range-low.
ZT_DT2 = loc_var_range-HIGH.
CALL FUNCTION 'DATE_CREATE'
EXPORTING
ANZAHL_JAHRE = 0
ANZAHL_KALTAGE = 0
ANZAHL_MONATE = 0
ANZAHL_TAGE = 0
DATUM_EIN = ZT_DT1
DATUM_EIN_ULT = ' '
ULTIMO_SETZEN = ' '
IMPORTING
DATUM_AUS = ZFIDAY .
E_TT =
E_ULTKZ =
l_s_range-low0(2) = ZFIDAY6(2).
l_s_range-low+2(1) = '.'.
l_s_range-low3(2) = ZFIDAY4(2).
l_s_range-low+5(1) ='.'.
l_s_range-low6(4) = ZFIDAY0(4).
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
APPEND l_s_range TO e_t_range.
ENDLOOP.
*****************************************End*************************************
Please let me know if any clarification required..
Rinku..
Maybe you are looking for
-
Can Not Sync Contacts and Calendar to iPhone Since iTunes Upgrade to 7.6
Hello, I have an iPhone and iTunes installed on my PC--which is running Windows XP Home Edition 2002 SP2, and I only sync my Contacts and Calendar using the sync functionality through iTunes and MS Outlook 2007. I was on iTunes 7.4 and everything wor
-
My iCloud account has been hacked
I think my iCloud account was hacked this morning. I went to log in and iCloud refused my password was refused and I noticed an email from Apple iCloud in Chinese. I have now reset the password, but just as a heads up to the wider Apple community tha
-
Error in DTW trying to update BP master Data
Dear All I'm trying to update the BP master data with the House Bank details but i get the following error "cannot find this object in B1 Application-defined or object-defined error 65171", which does not help in correcting the actual error. What can
-
It would really save me time to use the quiz feature of Captivate 8, but so far I'm not able to because every time I add a quiz, the player buttons are completely gone from my skin. I cannot add them again because they are disabled!! In preferences I
-
I downloaded the ios7 onto my Ipad2 and now I can't get online!
I am at a loss! I am not technically knowledgable at all. I downloaded the ios7 onto my Ipad and now its telling me the ipad isnt connected to the server. Then I looked somewhere within the ipad itself and saw a whole list of things that said it cr