Strange in this sql query , kindly help
I have aqry with ed_eff_m as some value and ed_end_m as NULL. I am replaing the NULL with sysdate. BOTH columns are TIMESTAMP
subquery :
SELECT MAX(ED_EFF_M),MAX(NVL(ED_END_M,SYSDATE))
FROM AUDIT_GRN ag2
where ag2.grn_n=281421
This is giving two dates.
when i execute another sql on top of this with the same condition, its not giving any result. (the same table and the same condition is used)
SELECT OPT_WA_FAIR_VAL_A
FROM AUDIT_GRN ag
WHERE ag.GRN_N = 281421
AND (ag.ED_EFF_M,NVL(ag.ED_END_M,SYSDATE)) IN
SELECT MAX(ED_EFF_M),MAX(NVL(ED_END_M,SYSDATE))
FROM AUDIT_GRN ag2
WHERE ag2.grn_n=ag.grn_n
)
Hello, thanks for your reply.
There is only one record which ed_eff_m = 04-Aug-2006 and Ed_END_M AS NULL.
I am replacing the null with sysdate. I am getting the result with the subquery
SELECT to_char(MAX(ED_EFF_M)),to_char(MAX(NVL(ED_END_M,SYSDATE)))
FROM AUDIT_GRN ag2
WHERE ag2.grn_n=281421
04-AUG-06 12.24.13.764450 PM 17-AUG-06 12.57.59.000000 PM
when i run the same query on top of this using IN clause, i should get the same result but its not ginving it. I am not using any other condition.
SELECT OPT_WA_FAIR_VAL_A, ag.ED_EFF_M,NVL(ag.ED_END_M,SYSDATE)
FROM AUDIT_GRN ag WHERE ag.GRN_N = 281421
AND (to_char(ag.ED_EFF_M),to_char(NVL(ag.ED_END_M,SYSDATE))) IN (
SELECT to_char(MAX(ED_EFF_M)),to_char(MAX(NVL(ED_END_M,SYSDATE)))
FROM AUDIT_GRN ag2
WHERE ag2.grn_n=281421)
It should give me the same row, since the first query and second query is giving output when i execute it seperatly
Similar Messages
-
What's wrong with this sql query? Help
hi
i am having difficulty executing this query
ResultSet s=st.executeQuery("select * from employee where iden = ?"+id);
here in my program st is statement obg
iden is attribute name in table
id i am getting at run time from user
please help...it says wrong number of parameters
thank youThat's correct, get rid of the Question mark. Questions marks are used in PreparedStatements, but they are also used in pattern matching. I am assuming the iden is the table identity. Therefore, I am assuming it is numeric. If so, you can't use the question mark because pattern matching is only done with strings. If you are treating your statement as a PreparedStatement, then you have done it wrong. (See the API) Here is a code snippet from the API:PreparedStatement pstmt =
con.prepareStatement("UPDATE EMPLOYEES SET SALARY = ? WHERE ID = ?");
pstmt.setBigDecimal(1, 153833.00)
pstmt.setInt(2, 110592)It seems you are using a Statement object, so, you need to get rid of that question mark.
tajenkins -
Cluster bar chart- sql query please help-
Hi,
I am trying to create cluster bar chart and am stumped with this sql query.Any help is appreciated.
Here is my table
city region issue value
c1 north i1 y
c1 north i2 y
c2 north i1 n
c2 north i2 y
c3 south i1 y
c3 south i2 n
c4 east i1 n
c4 east i2 n
The bar chart will have 3 series, north south and east.
And labels will be i1 and i2. value will be number of times this issue was encountered(y) in this region.
How can I get something like this from the above table-
region issue count(yes)
north i1 1
north i2 2
south i1 1
south i2 0
east i1 0
east i2 0
thanksWITH table1 AS
(SELECT 1435177 qte_id, 2 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 5 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 7 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 8 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 12 seq_no
FROM dual
UNION ALL
SELECT 1435177 qte_id, 14 seq_no
FROM dual
table2 AS
SELECT 1435177 qte_id, 1 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 2 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 3 seq_no, 0 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 4 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 5 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 7 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 8 seq_no, 98500 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 11 seq_no, 59300 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 12 seq_no, 59300 cmmt_curr_amt
FROM dual
UNION ALL
SELECT 1435177 qte_id, 14 seq_no, 59300 cmmt_curr_amt
FROM dual
SELECT qte_id, t2_seq_no, cmmt_curr_amt - cmmt_curr_lag diff
FROM
(SELECT t2.qte_id, t2.seq_no t2_seq_no, t1.seq_no t1_seq_no, cmmt_curr_amt, LAG(cmmt_curr_amt,1,0) OVER (PARTITION BY t2.qte_id ORDER BY t2.seq_no) cmmt_curr_lag
FROM table1 t1, table2 t2
WHERE t2.qte_id = t1.qte_id (+)
AND t2.seq_no = t1.seq_no(+)
ORDER BY 1,2
WHERE t1_seq_no IS NOT NULL
ORDER BY 1,2
QTE_ID T2_SEQ_NO DIFF
1435177 2 0
1435177 5 0
1435177 7 0
1435177 8 0
1435177 12 0
1435177 14 0 -
How to execute this SQL Query in ABAP Program.
Hi,
I have a string which is the SQL Query.
How to execute this sql Query (SQL_STR) in ABAP Program.
Code:-
DATA: SQL_STR type string.
SQL_STR = 'select * from spfli.'.
Thanks in Advance,
VinayHi Vinay
Here is a sample to dynamically generate a subroutine-pool having your SQL and calling it.
REPORT dynamic_sql_example .
DATA: BEGIN OF gt_itab OCCURS 1 ,
line(80) TYPE c ,
END OF gt_itab .
DATA gt_restab TYPE .... .
DATA gv_name(30) TYPE c .
DATA gv_err(120) TYPE c .
START-OF-SELECTION .
gt_itab-line = 'REPORT generated_sql .' .
APPEND gt_itab .
gt_itab-line = 'FORM exec_sql CHANGING et_table . ' .
APPEND gt_itab .
gt_itab-line = SQL_STR .
APPEND gt_itab .
gt_itab-line = 'ENDFORM.' .
APPEND gt_itab .
GENERATE SUBROUTINE POOL gt_itab NAME gv_name MESSAGE gv_err .
PERFORM exec_sql IN PROGRAM (gv_name) CHANGING gt_restab
IF FOUND .
WRITE:/ gv_err .
LOOP AT gt_result .
WRITE:/ .... .
ENDLOOP .
*--Serdar -
Hi,
I have a question about the performace of this SQL query. I have to display only 8 rows from this query. How is this query will be executed? What happens if the inside query returns more than 500 rows? Will it slow down?
SELECT * FROM (SELECT prod_date, create_date, prod_name, priority, status FROM CUST_PROD
WHERE cust_id = 100 and Status in(1, 5) order by priority, prod_name ) WHERE ROWNUM < = 8
Thank you..Its hard to tell what effect more data will have on a query until it happens. As BluShadow pointed out you're not talking about huge amounts of data; with luck the numbers you mentioned will not make any difference.
It looks like you're using the inline view to a top N query. You could look into using the RANK() function to do something similar. -
Please help me with this SQL query
I am practicing SQL queries and have come across one involving fetching data from 3 different tables.
The three tables are as below
<pre>
Country
location_id country
loc1 Spain
loc2 England
loc3 Spain
loc4 USA
loc5 Italy
loc6 USA
loc7 USA
</pre>
<pre>
User
user_id location_id
u1 loc1
u2 loc1
u3 loc2
u4 loc2
u5 loc1
u6 loc3
</pre>
<pre>
Post
post_id user_id
p1 u1
p2 u1
p3 u2
p4 u3
p5 u1
p6 u2
</pre>
I am trying to write an SQL query - for each country of users, display the average number of posts
I understand the logic behind this that we first need to group together all the locations and then the users belonging to one country and then find the average of their posts.
But, i'm having a difficulty in putting this in SQL form. Could someone please help me with this query.
Thanks.select
country.country,
count(*) Totalpostspercountry,
count(distinct post.user_id) Totaldistincuserspercountry,
count(*)/count(distinct post.user_id) Avgpostsperuserbycountry
from
country, muser, post
where country.location_id = muser.location_id
and muser.user_id = post.user_id
group by country.country
The output is like this for your sample data - hope this is what you were looking for :)
COUNTRY,TOTALPOSTSPERCOUNTRY,TOTALDISTINCUSERSPERCOUNTRY,AVGPOSTSPERUSERBYCOUNTRY
England,1,1,1,
Spain,5,2,2.5, -
How to convert this SQL query to PL/SQL
I basically need to create an anonymous block that will display each student's first name, last name and the count of students who scored less on test 1 than the student.
So basically we need to find the count of students who have scored less than that particular student and we do it for all students in the table.
So for this particular query i designed my code in SQL
select g1.gr_fname, g1.gr_lname, count(*)
from grade g1, grade g2
where g1.gr_t1 > g2.gr_t1 and
g1.std_code = g2.std_code
group by g1.gr_fname, g1.gr_lname;
But i am unable to get the logic as to how to execute it in PL/SQL,I am missing something a minor detail to execute the same in PL/SQL
could someone please help me with the logic.
ThanksHi welcome to the forum try some thing below
SQL> DECLARE
2 CURSOR c1
3 IS
4 SELECT ename, sal, d.deptno
5 FROM scott.emp e, scott.dept d
6 WHERE e.deptno = d.deptno
7 GROUP BY ename, sal, d.deptno;
8 BEGIN
9 FOR c2 IN c1
10 LOOP
11 DBMS_OUTPUT.put_line ('name is ' || c2.ename);
12 END LOOP;
13 END;
14 /
name is CLARK
name is KING
name is JONES
name is MARTIN
name is FORD
name is SCOTT
name is ALLEN
name is TURNER
name is WARD
name is MILLER
name is ADAMS
name is BLAKE
name is JAMES
name is SMITH
PL/SQL procedure successfully completed.This is just to demonstrate the use of PL/SQL block -
Strange problem with SQL query in toad.
Guys,
My colleague is up with a strange problem with an SQL query that if it is run in toad encounters the "ORA-03113: end-of-file on communication channel" problem,but if run in SQL plus executes just fine.
Do anyone have thoughts about this strange error in toad?
Thanks!!!!
Regards,
BhagatNot sure what version of TOAD you have but it may have shipped with SQLMonitor which montiors SQL sent from Windows apps . Navigation should be similar to;
Start~Programs~Quest Software~TOAD for Oracle~Tools~SQLMonitor
or
C:\Program Files\Quest Software\Toad for Oracle\SQLMonitor.exe
To use it, start TOAD and connect, start SQLMonitor and click the checkbox for TOAD.exe, then execute the query. SQLMonitor will show you the actual query that TOAD sent to the client. It may be exactly what you sent or it may contain some extras. -
Passing parameter to a SQL query - Please help
Hi All,
I am new to JDBC. I have been trying to pass an external variable to an SQL Query.
The query is
String username1="le";
PreparedStatement pstmt = null;
pstmt = c.prepareStatement("select * from users where USER_NAME like '%?%'");
pstmt.setString(1, username1);
pstmt.executeQuery();
ResultSet rs = pstmt.getResultSet();
I am trying to retrieve values from the users table where the USER_NAME column value that is a String contains the supplied value username1.
I am using the question mark (?) character to pass the value from the variable username1. I am also using the '%' substitution character which matches for any number of characters. So, the above query should retrieve rows where the USER_NAME is something like "charles","leander","Elena" etc.( that contains "le")
I am getting the error:
SQLException: java.sql.SQLException: ORA-01006: bind variable does not exist
I changed the query to
PreparedStatement pstmt = null;
pstmt = c.prepareStatement("select * from users where USER_NAME like '% " + username1 + "%'");
//pstmt.setString(1, username1);
pstmt.executeQuery();
This time , it is not giving the error and retrieving properly.
But I want to use the original query and use the "pstmt.setString(1, username1); " . Is there any way of achieving this?
Please help.
Cheers,
charles_amhi,
try this...
String username1="%le%";
pstmt = c.prepareStatement("select * from users where USER_NAME like ?")
pstmt.setString(1,username1);
cheers,
rpk -
Creating a report for the following Query --Kindly help.
Here when we use select options
1) you have to use 4 different "Select Option" Statement to select this Below.
1) Sales Organisation -- VBAK -VKORG
2) Distribution Channel -- VBAK - VTWEG
3) Division -- VBAK -- SPART
4) Created Date -- VBAK -- ERDAT.
The following fields have to be displayed.
1) Order no. -- VBAK - VBELN.
2) Created date -- VBAK - ERDAT
3) Sold To Party -- VBAK - KUNNR
4) Shiped to party -- VBPA -- KUNNR.
5) Item no -- VBAP -- POSNR
6) Material no. -- VBAP -- MATNR
7) Material Discription -- VBAP - ARKTX.
By using the select options of Sales organisation, Distribution channnel and so on I am not able to get the out put of the order no , created date , sold to party , shipped to party (Which is in a different tableVBPA) and Item no Material No and material Discription which are in table VBAP.Here I am getting a run time error.
Kindly help and inform how to code this .
Also When we click the Order no in the list we have to get the screen VA03.
RegardHi John,
Use the following Select statement for Query :-
Code A )
SELECT vbak~vkorg
vbak~vtweg
vbak~spart
vbak~erdat
vbak~vbeln
vbak~erdat
vbak~kunnr
vbpa~kunnr
vbap~posnr
vbap~matnr
vbap~arktx
into corresponding fields of table ITAB
FROM ( vbak INNER JOIN vbap
ON vbakvbeln = vbapvbeln
INNER JOIN vbpa
ON vbakvbeln = vbpavbeln
WHERE vbak~vkorg IN s_vkorg
AND vbak~vtweg IN s_vtweg
and vbak~spart in s_spart
AND vbak~erdat in s_erdat.
And Use this part of the code to show the selected Sales order :-
code B)
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE r_ucomm.
WHEN '&IC1'.
CASE rs_selfield-sel_tab_field.
WHEN 'ITAB-VBELN'.
CHECK NOT rs_selfield-value IS INITIAL.
SET PARAMETER ID 'AUN' FIELD rs_selfield-value.
CALL TRANSACTION 'VA02' AND SKIP FIRST SCREEN.
ENDCASE.
ENDCASE.
ENDFORM.
Award points if useful !
Regards
Hrishi -
Hi All,
We have a native SQL query accessing Oracle database(given below).
Can anyone please let me know what this query is about and how can we fine tune the query?
SELECT O.OBJECT_NAME ,
H.SID,
HS.MACHINE,
HS.PROCESS,
W.SID,
WS.MACHINE,
WS.PROCESS,
H.CTIME,
W.CTIME,
WS.ROW_WAIT_OBJ#,
WS.ROW_WAIT_FILE#,
WS.ROW_WAIT_BLOCK#,
WS.ROW_WAIT_ROW#,
HP.SPID,
WP.SPID
FROM V$LOCK H, V$LOCK W, V$LOCK I, V$LOCK I2, ALL_OBJECTS O,
V$SESSION HS, V$SESSION WS, V$PROCESS HP, V$PROCESS WP
WHERE H.ID1 = W.ID1
AND H.SID <> W.SID
AND H.TYPE IN ('TX','DL')
AND H.REQUEST = 0
AND H.SID = I.SID
AND I.TYPE = 'TM'
AND I.ID1 = O.OBJECT_ID
AND I.ID1 = I2.ID1
AND W.SID = I2.SID
AND I2.TYPE = 'TM'
AND H.SID = HS.SID
AND W.SID = WS.SID
AND HS.PADDR = HP.ADDR
AND WS.PADDR = WP.ADDR
INTO :EXCL_LOCK_WAITERS-OBJ_NAME ,
:EXCL_LOCK_WAITERS-HOLDER_SID ,
:EXCL_LOCK_WAITERS-H_HOSTNAME ,
:EXCL_LOCK_WAITERS-HOLDER_PID ,
:HOLDER_PID ,
:EXCL_LOCK_WAITERS-WAITER_SID ,
:EXCL_LOCK_WAITERS-W_HOSTNAME ,
:EXCL_LOCK_WAITERS-WAITER_PID ,
:WAITER_PID ,
:EXCL_LOCK_WAITERS-HELD_SINCE ,
:EXCL_LOCK_WAITERS-WAITSSINCE,
:ROW_WAIT_OBJ,
:ROW_WAIT_FILE,
:ROW_WAIT_BLOCK,
:ROW_WAIT_ROW,
:H_PROCESS,
:W_PROCESS
ENDEXEC
Thanks in advance.
Neethu MohanHi Neethu,
It gives you an overwiew of blocking Oracle sessions.
1. In general, the SQL checks Oracle sessions (SID's) that were requirering a DML lock ('TM') and now holding row locks (TX) to prevent destructive interference of simultaneous conflicting DML or DDL operations. DML statements automatically acquire both table-level locks and row-level locks ('TX') => holders
It joins these with the sessions that are waiting of releasing the lock by the holders => waiters.
2. it retrieves the detail information wich Oracle process , the object (table) , it's row , block and file
are affected by the locks.
3. Normally, the locks are only hold for a short period of time. If you have blocking sessions it may be of a log running task (i.e. mass data update of a table) ; but it could also be a application bug due to improper handling of concurrent updates of the same object.
4. Tuning
V$tables are expensive to query: Why?
v$ tables are generally Oracle memory structures.
v$ tables are not read consistent.
v$ tables require latches to access -- cannot modify and read memory at the same
time.
heavy access to v$ tables like this may cause some serious heavy duty contention.
Especially if you self join V$lock several times.
So the best would be to save the contents of V$LOCK in some table:
Create table mylocks as select * from v$lock;
Use that table for self-joining and joins to the other tables.
You can also CTAS the other v$ tables to bypass the performance bottleneck while retrieving
v$ directly.
You can empty or drop the created tables any time for new data.
Because you want to investigate only lock hold for a longert time to copy the v$ memory structures into
physical tables is not a disadvantage. You certainly will wait longer on finishing your query
instead of copy them into the tables.
Hope this helped
yk -
How to add pl sql query into help text of an item.
Hi
In my database i have added comments to the colums. I would like to use this comments in the help text of the items of my application. I have the query but when I use it in the help text attribute it does not execute the query, it presents the query.
Any ideas?It is probably too late now, but note that if you create your application using the Create Application Wizard and Application Models, based on User Interface Defaults created in the SQL Workshop, any column comments will automatically become application help text.
-
Hi All,
Could you please help me out the below SQL query tuning .
Temp table is having 1 Million records
Master table is having 60 Million records
Query :
SELECT B.*,U.ID, SD, LE, LAE
FROM client.Temp B, client.Master
U WHERE U.policyno = B.policyno
AND B.UPFLAG = 0
1. Indexes are created on both email columns and Upflag for both tables.
2. Gathered DBMS Stats for MASTER Table
Data is loading 100k/hour on production .When your query takes too long ...
When your query takes too long ...
HOW TO: Post a SQL statement tuning request - template posting
HOW TO: Post a SQL statement tuning request - template posting -
oracle 10g.
os : linux
table data appears like this
SQL> select * from test_grp;
COL1 COL2
aaa 111
aaa 444
aaa 222
bbb 333
bbb 555
SQL> select * from test_grp order by 2;
COL1 COL2
aaa 111
aaa 222
bbb 333
aaa 444
bbb 555
As per my application requirement I need to seggerage the data as
follows
aaa (2) ie --- 111,222
bbb(1) is --- 333
aaa(1) is --- 444
bbb(1) is -- 555
I am not able to frame this. Any help ?SQL> create table test_grp
2 as
3 select 'aaa' col1, 111 col2 from dual union all
4 select 'aaa', 444 from dual union all
5 select 'aaa', 222 from dual union all
6 select 'bbb', 333 from dual union all
7 select 'bbb', 555 from dual
8 /
Tabel is aangemaakt.
SQL> select col1
2 , col2s
3 from ( select col1
4 , rtrim(col2s,',') col2s
5 , rn
6 , sumn
7 from ( select col1
8 , col2
9 , sum(n) over (order by col2) sumn
10 from ( select col1
11 , col2
12 , case when col1 = lag(col1) over (order by col2) then 0 else 1 end n
13 from test_grp
14 ) t
15 )
16 model
17 partition by (sumn)
18 dimension by (row_number() over (partition by sumn order by col2) rn)
19 measures (col1, cast(col2 as varchar2(100)) col2s)
20 rules
21 ( col2s[any] order by rn desc = col2s[cv()] || ',' || col2s[cv()+1]
22 )
23 )
24 where rn = 1
25 order by sumn
26 /
COL COL2S
aaa 111,222
bbb 333
aaa 444
bbb 555
4 rijen zijn geselecteerd.Regards,
Rob. -
How to use this sql query in oracle?
Hi all,
i am using one sql query that is
SELECT @ToDate = '2012-10-03 00:00:00.000'
select @BetweenDate = DATEADD(MM,-1,@ToDate)
select @FromDate = DATEADD(m,DATEDIFF(m,0,@BetweenDate),0)
SELECT @ToDate = DATEADD(month, ((YEAR(@BetweenDate) - 1900) * 12) + MONTH(@BetweenDate), -1)
so @todate value is = '2012-10-03 00:00:00.000'
so in @betweendate value will come 1 month before like '2012-09-03 00:00:00.000'
again in @fromdate value will come like that '2012-09-01 00:00:00.000' means first date of @betweendate
and again @todate value will come like that '2012-09-30 00:00:00.000' means last date of @betweendate
it's happening in sql and i have to use same logic in oracle also.
how to use it??
thanksdeclare
todate date:= to_date('2012-10-03 00:00:00','yyyy-mm-dd hh:mi:ss');
betwendate date := add_months(todate,-1);
for datediff / additions you can direct subtract/add two different date variables
like
datediff = betweendate -todate
dateadd := todate+1;
Maybe you are looking for
-
It use to work fine, but now it doesn't work. It had that folder thing pop up but then i reset it so the main screen comes up. Then I connect it to my laptop and the updater and itunes do not work and freeze. I cannot update my ipod
-
My Time Machine did not backup of my iPhoto library
I change macbooks recently and, before sell the old one (wich has just 6 months old) i make a Time Machine. Anyway, when i try to restore my library from that Time Machine, it has pictures of 7 year ago, all the pictures that i take in those last 6 m
-
What is settlement rule and profile, what configuration settings needed?.
-
How do i down load version 11.i to my current itunes as iso 7 wont use my itunes
How do i down load version 11.1 so i can use my iphone now iv got iso7
-
Please go through the following... look at my parameters here: 1 select rtrim(name)||', '||rtrim(value) from v$parameter 2* where name like 'nls%' SQL> / RTRIM(NAME)||','||RTRIM(VALUE) nls_language, AMERICAN nls_territory, AMERICA nls_sort, nls_date_