Select Statement Query
Hi,
I need to perform the following selection:
a. Based on Position Number -> select associate Pernr from PA0001
b. based on this Pernr find value of STAT2 in PA0000.
Is there an efficient way of carrying out this selection other than using 2 Select Statements?
Note Pernr field is a primary key in both tables.
How about using join statement:
Since PERNR is a key field in both tables;
SELECT P0~STAT2
INTO TABLE <itab>
FROM PA0001 AS P1 INNER JOIN PA0000 AS P0
ON P1PERNR = P0PERNR
WHERE <position number condition>
Regards,
A.Singh
Similar Messages
-
How to edit the records value fetched by select statement query in sqldever
How to edit the records value fetched by select statement query in sqldever 2.1.1.
EX-
SELECT * FROM emp WHERE ename like 'Jaga%'
Edited by: user9372056 on Aug 31, 2010 2:16 AMHi,
Although some forum members may be using that tool, there is still a dedicated forum for SQL Developer.
SQL Developer
Maybe your chances are better there.
Regards
Peter -
Re: Select statement query
Hi Expert,
I have one report which display employee transfer details In that report i have added two new fields i.e Action type and Reason for Action.My requirement is in the selection screen i have given date.What ever date i have given in the selection screen it should fetch the data of employee transfer I have written the code but in the output the field which i have added
two fied i.e Action type and Reason for action data is not comming for this two fields.
Below is my code .
loop at p0000 where pernr = i_transfers-pernr and massn eq '02'.
i_transfers-massg = p0000-massg.
select single * from t530t into ls_t530t where massn eq '02' AND massg = i_transfers-massg AND sprsl = 'E'.
if sy-subrc = 0.
i_transfers-mgtxt = ls_t530t-mgtxt.
endif.
endloop.
Regards,
Mdaddu.Hi Deepak,
I have added the code like this below still outptut is not comming.
LOOP AT I_TRANSFERS.
V_SERIAL_NO = V_SERIAL_NO + 1.
I_TRANSFERS-SRNO = V_SERIAL_NO.
SELECT SINGLE NAME1 FROM T500P INTO I_TRANSFERS-WERKSTXT
WHERE PERSA = I_TRANSFERS-WERKS.
SELECT SINGLE NAME1 FROM T500P INTO I_TRANSFERS-OLD_WERKSTXT
WHERE PERSA = I_TRANSFERS-OLD_WERKS.
SELECT SINGLE BTEXT FROM T001P INTO I_TRANSFERS-BTRTLTXT
WHERE BTRTL = I_TRANSFERS-BTRTL.
SELECT SINGLE BTEXT FROM T001P INTO I_TRANSFERS-OLD_BTRTLTXT
WHERE BTRTL = I_TRANSFERS-OLD_BTRTL.
SELECT SINGLE LTEXT FROM CSKT INTO I_TRANSFERS-KOSTLTXT
WHERE KOSTL = I_TRANSFERS-KOSTL
AND SPRAS = 'EN'.
ENDSELECT.
SELECT SINGLE LTEXT FROM CSKT INTO I_TRANSFERS-OLD_KOSTLTXT
WHERE KOSTL = I_TRANSFERS-OLD_KOSTL
AND SPRAS = 'EN'.
SELECT SINGLE PLSTX FROM T528T INTO I_TRANSFERS-PLSTX
WHERE PLANS = I_TRANSFERS-PLANS
AND ENDDA = '99991231'.
ENDSELECT.
SELECT SINGLE ORGTX FROM T527X INTO I_TRANSFERS-OLD_ORGUNITTXT WHERE ORGEH = I_TRANSFERS-OLD_ORGUNIT.
SELECT SINGLE ORGTX FROM T527X INTO I_TRANSFERS-NEW_ORGUNITTXT WHERE ORGEH = I_TRANSFERS-NEW_ORGUNIT.
" Description for payment method
IF I_TRANSFERS-ZLSCH EQ 'C' OR I_TRANSFERS-ZLSCH EQ ' '.
I_TRANSFERS-ZLSCH = 'Cash Payment'.
ELSEIF I_TRANSFERS-ZLSCH EQ 'T'.
I_TRANSFERS-ZLSCH = 'Bank Transfers'.
ENDIF.
IF I_TRANSFERS-OLD_ZLSCH EQ 'C' OR I_TRANSFERS-OLD_ZLSCH EQ ' '.
I_TRANSFERS-OLD_ZLSCH = 'Cash Payment'.
ELSEIF I_TRANSFERS-OLD_ZLSCH EQ 'T'.
I_TRANSFERS-OLD_ZLSCH = 'Bank Transfers'.
ENDIF.
SELECT SINGLE NATIO50 FROM T005T INTO I_TRANSFERS-NATIO
WHERE LAND1 = I_TRANSFERS-NATIO
AND SPRAS = 'E'.
sort p0000 by pernr massn.
Read table p0000 with key pernr = i_transfers-pernr
massn = '02'.
if sy-subrc = '0'.
loop at p0000 where pernr = i_transfers-pernr and massn eq '02'.
i_transfers-massg = p0000-massg.
select single * from t530t into ls_t530t where massn eq '02' AND massg = i_transfers-massg AND sprsl = 'E'.
if sy-subrc = 0.
i_transfers-mgtxt = ls_t530t-mgtxt.
endif.
append i_transfers.
clear i_transfers.
endloop.
MODIFY I_TRANSFERS transporting mgtxt.
endif.
ENDLOOP.
Regards,
Mdaddu -
Using plsql tables in select statement of report query
Hi
Anyone have experience to use plsql table to select statement to create a report. In otherwords, How to run report using flat file (xx.txt) information like 10 records in flat files and use this 10 records to the report and run pdf files.
thanks in advance
sureshhi,
u can use the utl_file package to do that using a ref cursor query in the data model and u can have this code to read data from a flat file
declare
ur_file utl_file.file_type;
my_result varchar2(250);
begin
ur_file := UTL_FILE.FOPEN ('&directory', '&filename', 'r') ;
utl_file.get_line(ur_file, my_result);
dbms_output.put_line(my_result);
utl_file.fclose(ur_file);
end;
make sure u have an entry in ur init.ora saying that your
utl_file_dir = '\your directory where ur files reside'
cheers!
[email protected] -
Slow query results for simple select statement on Exadata
I have a table with 30+ million rows in it which I'm trying to develop a cube around. When the cube processes (sql analysis), it queries back 10k rows every 6 seconds or so. I ran the same query SQL Analysis runs to grab the data in toad and exported results, and the timing is the same, 10k every 6 seconds or so. r
I ran an execution plan it returns just this:
Plan
SELECT STATEMENT ALL_ROWSCost: 136,019 Bytes: 4,954,594,096 Cardinality: 33,935,576
1 TABLE ACCESS STORAGE FULL TABLE DMSN.DS3R_FH_1XRTT_FA_LVL_KPI Cost: 136,019 Bytes: 4,954,594,096 Cardinality: 33,935,576 I'm not sure if there is a setting in oracle (new to the oracle environment) which can limit performance by connection or user, but if there is, what should I look for and how can I check it.
The Oracle version I'm using is 11.2.0.3.0 and the server is quite large as well (exadata platform). I'm curious because I've seen SQL Server return 100k rows ever 10 seconds before, I would assume an exadata system should return rows a lot quicker. How can I check where the bottle neck is?
Edited by: k1ng87 on Apr 24, 2013 7:58 AMk1ng87 wrote:
I've notice the same querying speed using Toad (export to CSV)That's not really a good way to test performance. Doing that through Toad, you are getting the database to read the data from it's disks (you don't have a choice in that) shifting bulk amounts of data over your network (that could be a considerable bottleneck) and then letting Toad format the data into CSV format (process the data adding a little bottleneck) and then write the data to another hard disk (more disk I/O = more bottleneck).
I don't know exedata but I imagine it doesn't quite incorporate all those bottlenecks.
and during cube processing via SQL Analysis. How can I check to see if its my network speed thats effecting it?Speak to your technical/networking team, who should be able to trace network activity/packets and see what's happening in that respect.
Is that even possible as our system resides off site, so the traffic is going through multiple networks.Ouch... yes, that could certainly be responsible.
I don't think its the network though because when I run both at the same time, they both are still querying at about 10k rows every 6 seconds.I don't think your performance measuring is accurate. What happens if you actually do the cube in exedata rather than using Toad or SQL Analysis (which I assume is on your client machine?) -
"select into" query statements using the DI API
I am trying to use the DI API (6.5) t create a temp table based on an existing table. For example, here is a query string....
select * into ORDR_TEMP from ORDR
Code...
oRecordSet := IRecordset(oCompany.GetBusinessObject(BoRecordset));
oRecordset.DoQuery(sSql);
Error I get...
1). [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot use SELECT INTO in browse mode. 2). [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared
For any other regular select statements the previous code works. Does anyone know for sure if a "select into" statement is not possible using the DI API?Hi Bill,
I´m not really sure if select into is avaiable. But here you´ve got a hint: You could use a user defined function to do it, and just call the function from your code.
SELECT dbo.MyFunction()
Having this function defined in your SQL Server:
CREATE function MyFunction ()
returns char(2)
AS
Begin
select * into ORDR_TEMP from ORDR
Return ('OK')
End
Hope this helps,
Ibai Peñ -
Select Statement to query smallest ID
<My_Table>
ID
PHOENIX005
PHOENIX006
PHOENIX007
PHOENIX008
TUCSON001
TUCSON002
TUCSON003
TEMPE010
TEMPE011
TEMPE002
CHANDLER030
CHANDLER031
CHANDLER032
Whats the best way to write a select statement that would only bring back the IDs with the smallest numerical value? I ultimately want my Query to display:
ID
PHOENIX005
TUCSON001
TEMPE010
CHANDLER030Or may be like this...
SQL> ed
Wrote file afiedt.buf
1 with t as (
2 select 'PHOENIX005' id from dual union all
3 select 'PHOENIX006' from dual union all
4 select 'PHOENIX007' from dual union all
5 select 'PHOENIX008' from dual union all
6 select 'TUCSON001' from dual union all
7 select 'TUCSON002' from dual union all
8 select 'TUCSON003' from dual union all
9 select 'TEMPE010' from dual union all
10 select 'TEMPE011' from dual union all
11 select 'TEMPE002' from dual union all
12 select 'CHANDLER030' from dual union all
13 select 'CHANDLER031' from dual union all
14 select 'CHANDLER032' from dual
15 )
16 select *
17 from
18 (
19 select id, row_number()over(partition by trim(translate(id,'0123456789', rpad(' ',10))) order by
20 to_number(trim(translate(id,'ABCDEFGHIJKLMNOPQRSTUVWXYZ', rpad(' ',26)))) ) as rno
21 from t
22* ) where rno=1
SQL> /
ID RNO
CHANDLER030 1
PHOENIX005 1
TEMPE002 1
TUCSON001 1
SQL> -
Need help with select statement or query
Not familiar with what to call it, but here is what i need...
To give our analyst a better idea of warranty on some of our
equipment, i
would like to add to the page a column that displays if the
device is still
under warranty
I currently capture the date the equipment was returned from
repair, so what
could i use within my select statement or query to display a
warranty
expiration date or display on the page...
example :
Returned from repair 10/20/2006 warranty expires on
11/20/2006
each equipment has different warranties, so i need a formula
or something to
say... device #1 has 60 day warranty ( so 10/20/2006 + 60days
=
12/19/2006 )
I would imagine this to be a query
Table 1 would contain the equipment type and warranty time
Table 2 would contain the current status of the equipment
Query would take the back from repair date + warranty =
expiration dateSimple. Join the two tables and create a derived column for
the expiration date. The exact syntax is dependant on your DBMS, so
check the manual for whichever you are using and look at the date
functions. There will be a function that will allow you to add a
number of date units (day, month, year, etc) to a date
field. -
Dear All,
I have a small query on the Select Statement. If there are 2 identical rows and if i am retrieving them using the Select Statement, then will the select statement retrieves both the rows which are identical or only the first possible occurence? Pls help me out in this.
Thanks,
Sirisha.Hi,
That depends on the statement u use. If u use, 'SELECT' statment, u can retrieve all the records which are identical with one or few fields. For that, u need to put the output INTO A TABLE.
Ex. 1
data : int_ekko type table of ekko with header line,
fs_ekko type ekko.
select * from ekko into table int_ekko where ebeln = '6361003191'.
Here, int_ekko is an internal table contains all records whose EBELN = 63610003191.
2) If u use 'SELECT SINGLE', then it will retrieve only the first record out of all the records who satisfy the condition EBELN = 6361003191.
Ex 2:
select single * from ekko into fs where ebeln = '63610003191'.
'fs' is not a table, just of type structure. so contains only one record.
Hope it help u..
Kindly reward points if hepful
Regards,
Shanthi.
Edited by: Shanthi on Mar 4, 2008 8:17 AM -
Query in SELECT statement!!!!
Hi all,
I have a SELECT statement as follows:
SELECT aguid_hi bpartner_no
FROM crmd_link AS a
INNER JOIN crmd_partner AS b ON bguid EQ aguid_set
INTO TABLE p_partners
FOR ALL ENTRIES IN i_sub_contracts
WHERE a~guid_hi EQ i_sub_contracts-guid
AND a~objtype_hi EQ '05'
AND b~partner_fct EQ p_partner_fct.
Please tell me if I can create a view for the above.
Once I create a view for the above will it really boost the performance.
Kindly reply immediately as this is bit urgent.
Regards,
Vijayhi,
As said above view is nothing but an inner join between tables which you are already doing it in your program ... So i don't think there will be any improvement in the performance of the program ...
Regards,
Santosh -
Query regarding Oracle SQL select statement
Hi,
How does Oracle ensures a consistent snapshot with the select statement
without locking the table. My question is summarized with an example below:
1. At time T1, Oracle select statement is fired and is fetching the result.
2. At time T2, some DML operation is performed on the same table on which
the select was executed and a commit was fired.
3. At time T3, The Oracle select statement (Step 1) completes.
My question is whether the records of transaction at time T2 will be visible at time T3 or not?
If "not", then does it mean that Oracle retrieves the rows from the time of last commit.
I would also like to know if for the above mechanism, Oracle would make use of the rollback segemt to access the rows at a particular instant of time.
TIA
Regards,
RajThis is called Read Consistency in the oracle. Its all about SCN before starting the transaction.
Lets say
1. T1 executs SELECT statement on EMP table.
2. T2 made an update on the EMP and commited.
But, T1 only still sees only old image of the data not the new one. This is called read consistency.
You will be having two images in the buffer, one is consistent and changed image.
When the T1 give SELECT statement it notes the SCN of the transaction. Read oracle document about read consistency.
SJH. -
Querying many tables at once from a select statement for specific values
Hi all,
I'm very new to PL/SQL and have a daunting task ahead of me. I'm pretty sure our database normalization scheme is all out of whack, which I dont have the experience to fix yet, but this is the task ahead of me without getting to change or fix our structure:
in the universe has 1000+ tables.
need--> Some of those tables have fields that contain a value that has to be changed.
The only thing I have to go on is the column name will contain 'EMP'... but there is no specific naming convention for the column names.
When I search on:
select * from all_tab_columns where column_name like UPPER('%EMP%')
It returns 750 rows. (So 750 rows = 750 columns in 500 different tables (some tables have 2 or more columns in it))
tables names are random (table1, table2, etc).
columns names are random with EMP in it (column1,column2,etc).
I have 75 possible field values that I need to check each of those 750 columns for.
Maybe this is too messy, but I'm looking at subqueries, joins, arrays, cursors, etc, anything to minimize the amount of work I have to do.
I think this is too much to do a join with, but that seems to be what all the documentation is pointing me to.
can you point me to a simple example of what i could
write?
the logic i see it would be
run the select statement to grab the column names that meet EMP.
one at a time, search each column in the corresponding table for the 75 values.
return the results of rows for each column/table that meet one of the 75 unique values.
I'll have to also update each of the 75 values to (used to be values 1, 2, 3 ... to new values X1, X2, X3, etc.)
Any help at all would be very helpful,
aspiring pl/sql programmer but having a rough time of itI think you're looking to do something like the following pseudocode:
BEGIN
FOR tblrec IN (SELECT table_name, column_name
FROM all_tab_columns
WHERE column_name LIKE '%EMP%')
LOOP
FOR rec IN (SELECT ROWID
FROM tblrec.table_name
WHERE REGEXP_LIKE(tblrec.column_name, '(expr1|expr2|...)')
LOOP
DBMS_OUTPUT.PUT_LINE(
'Found expression on ROWID ' || rec.rowid
|| ' in column ' || tblrec.column_name
|| ' on table ' || tblrec.table_name);
END LOOP;
END LOOP;
END; -
Function with select if statement query
Hi,
I want to use if condition in select statement in function.
But i implemented in case too ,its taking more time to return the value while using case statement.
My function is like this
create or replace FUNCTION GET_CODE
(pv_type IN table1.type%TYPE,
pv_desc1 IN table2.type%TYPE,
pv_desc2 IN table3.type%TYPE)
RETURN varchar2(35 byte)
IS
V_ret_string varchar2(35 byte);
BEGIN
SELECT case when(table2.xxx like 'fff%') then 1
when (table3.yyy like 'fff%') then 2
when (table4.zzz like 'fff%') then 3
else table1.aaa
INTO V_ret_string
FROM
table1 a,table2 b,table3 c table4 d
WHERE
table1.column1=table2.column1
and (table1.column2=table3.column1 or table1.column2=table4.column1) and
UPPER(b.type) = UPPER(pv_type) and
(UPPER(c.desc) = UPPER(pv_desc1) or UPPER(d.desc1) = UPPER(pv_desc2)) ;
RETURN V_ret_string;
END GET_TRANSACTION_CODE;
Pls help me how to use if condition.
Regards,
Punitha936698 wrote:
Hi,
I want to use if condition in select statement in function.Oracle SQL SELECT statement does not support IF condition syntax. But what it does is CASE and DECODE. And CASE statement is sufficient to achieve what ever you want to do with IF condition.
But i implemented in case too ,its taking more time to return the value while using case statement.So the issue is not with CASE its with the SELECT Statement. What you have to do is Isolate your SELECT statement and try to tune it for performance.
To do that i would suggest you to read the folloing threads which could be of good use.
{thread:id=501834} and {thread:id=863295}.
>
>
My function is like this
create or replace FUNCTION GET_CODE
(pv_type IN table1.type%TYPE,
pv_desc1 IN table2.type%TYPE,
pv_desc2 IN table3.type%TYPE)
RETURN varchar2(35 byte)
IS
V_ret_string varchar2(35 byte);
BEGIN
SELECT case when(table2.xxx like 'fff%') then 1
when (table3.yyy like 'fff%') then 2
when (table4.zzz like 'fff%') then 3
else table1.aaa
INTO V_ret_string
FROM
table1 a,table2 b,table3 c table4 d
WHERE
table1.column1=table2.column1
and (table1.column2=table3.column1 or table1.column2=table4.column1) and
UPPER(b.type) = UPPER(pv_type) and
(UPPER(c.desc) = UPPER(pv_desc1) or UPPER(d.desc1) = UPPER(pv_desc2)) ;
RETURN V_ret_string;
END GET_TRANSACTION_CODE;When ever posting code please make sure the code is well formatted and you use the {noformat}{noformat} tag to preserve the format. An unformatted code is very hard to read.
The usage of the tag is like this.
<place your code here>\ -
Hint in Update or Select Statement in an inline query ??
Hi ,
I had an update statement that will get the data from the inline select statement,now where can i can keep the hint ,either in update statement or in Select statement...
Please let me know if my sample script is wrong or any better way to approach...Please assume that Salary table had millions of employee's salary records.
update emp
set salary = salary + (select /*+ full(a) parallel(a,4) */ salary from Salary
where experience > 5 and empno = 55 )
where empno = 85Thanks
RedeYou would put the hint in the select statement as you have it, but it won't work until you alias your table name to "a" since that is how you are referencing it in the hint:
update emp
set salary = salary + (select /*+ full(a) parallel(a,4) */ salary from Salary a
where experience > 5 and empno = 55 )
where empno = 85
NOTE I added the "a" right after the Salary table name AND you can only do parallel updates on partitioned table, but the select will run in parallel to at least get the data for you quickly.
To answer your other question about syntax, it is incorrect and there are a lot of ways to write it but a straight forward way would be to use the merge statement
merge into emp e
using (select /*+ full(s) parallel(s,4) */ s.salary from salary s where s.experience > 5) s
on (e.empno = s.empno)
when matched then update
set salary = s.salary; -
Dear all
is there any option in select statement to automatically generate serial number respect of data.
for eg.
1 101100110 shetal trade
2 1110001178 CHEMICAL SOAP WORKS
3..
4..
i don't want to use loop (sy-tabix) ..
thanks,
AbhiHi ,
i don't want to use loop (sy-tabix) ..
any particular reason for this ?
as u cannot automatically generate serial number, u have to go for loop....endloop.
Thanks
Karthik
Maybe you are looking for
-
How do I install fonts from Type On Call into Win 8.1
I have been using Trade Gothic Condensed as my default Excel font for many years. Each time I get a new computer I have been able to install the font in the new OS. I am having trouble doing that with Win 8.1. It says it is installed but does not app
-
Issue with XML & XSL...
Hi All, I am trying to display a saved XML file with a pre-defined XSL, which was provided to us by a third party vendor. The XML file is the same format the third party vendor expects it to be: This is the code I am using to display the XML file in
-
CC Risk Analysis (Off line)
In CC User Analysis, there is additional option to run analysis 'offline'. Can someone explain how is this achieved? is there some programs which will download the data from SAP and then uploaded into CC ? Please advise. Cheers!
-
Enter key does not work anymore in address bar after FF update
After the update the Enter key does not work anymore. Neither when I type the url directly, nor when I select it from the history. In short FF has become unusable. Now I need to install and use a less crappy browser. Extremely sloppy, amateuristic up
-
dear all i have the following code in browsing button Filename := Get_File_Name(' ','','(*.jpg)|*.jpg|(*.gif)|*.gif|(*.jpeg)|*.gpeg|(*.DOC)|*.DOC|(*.PDF)|*.PDF|'); read_image_file(Filename,'ANY','CONTROL_PIC.PICTURE'); :LB_INC_PIC.PATH:=Filename; :LB