Help about SQL statement
There is one table AA£º
A varchar2(10);--goods name
B number(30);--amount
C date;--date
There are millions of records in the table, now to calculate the top ten good's acount and total amount, could you pls tell me how to do it?
by using
select A,count(A),sum(B) from AA group by A order by sum(B)
it's extermely slow. Could you pls tell me how to optimize it, Thank you very much
Now I understand better your concern. It's about "to use, or not to use" a materialized view for your query.
I listed bellow a basic example of using of a materialized view, reusing the tables from my previous sample. Note that the table "bb" has a MV, while table "bb1" is without MV.
The results are very clear simple, and similar results can be expected for many similar cases. Note that the Oracle manuals warn us about this, but it is using words which are not strong enough.
1. The INSERT is about 20 times slower in the presence of MVs. The usage of many small transactions is probably slower then fewer and larger transactions. Note that the MVs usage increase considerably the duration of locking, affecting negatively the level of concurrency, and increases the storage requirements.
2. The SELECT from your aggregate query is about 15 times faster when using a dedicated MV. But many other other SELECT queries are not made faster by this MV, obviously.
This is the reason for which the MVs are generally not well suited in transactional environments, with a lot of frequent data updates and many different queries, but play a major role in DSS environments. The MVs are still useful in some transactional applications, where long running queries are executed frequently (but your query does not seem to be in this situation).
create table bb0 as select * from bb where rownum <= 1000000;
truncate table bb;
create table bb1 as select * from bb0 where rownum < 1
create materialized view log on bb
with sequence, rowid
(a, b)
including new values;
create materialized view bb_mv
build immediate refresh fast on commit
as (select a, count(*) c, count(*) c1, sum(b) s from bb group by a);
insert into bb
select *
from (select * from bb0 order by b)
where rownum <= 1000000;
1000000 rows inserted
executed in 180.579 seconds <<==
commit;
executed in 123.838 seconds <<==
insert into bb1
select *
from (select * from bb0 order by b)
where rownum <= 1000000;
1000000 rows inserted
executed in 15.182 seconds <<==
commit;
executed in 0.01 seconds
select *
from (select a, c, s from bb_mv order by 3 desc)
where rownum <= 10;
10 rows selected
executed in 0.16 seconds <<==
select *
from (select a, count(a), sum(b) from bb1 group by a order by 3 desc)
where rownum <= 10;
10 rows selected
executed in 2.373 seconds <<==
Similar Messages
-
Where to find information about SQL States ?
Hello,
I'm trying to find information about X/OPEN SQL States explanation. Can anyone help me. ?SQLStates are part of the SQL standard and so you can read up on them from any vendor's site.Here is an IBM explanation that talks about the SQLStates class (first two chars) and subcode.
http://publib.boulder.ibm.com/pubs/html/as400/v5r1/ic2924/index.htm?info/rzala/rzalaint.html -
Hi expert,
I have following sql statement, function 'hiroc_get_delta_amount1' and 'hiroc_get_delta_amount2' are separately used in select and where subclause. these two function are exactly same, except that there is a inserting log statement inside. for function 'hiroc_get_delta_amount1' , logs are supposed to write into log table1, whereas for function 'hiroc_get_delta_amount2' , logs are supposed to write into log table2. after running this sql, I got data loaded into log table2, however, there is no data loaded into log table1.
could you please tell me why there is no data in log table2 for function
1. sql statement;
select
pp.policy_premium_pk,
pp.policy_fk,
pp.policy_term_fk,
pp.risk_fk,
pp.coverage_fk,
pp.transaction_log_fk,
pp.coverage_component_code,
hiroc_rpt_user.hiroc_get_delta_amount1(pp.policy_fk, pp.policy_term_fk, pp.risk_fk, pp.coverage_fk, pp.transaction_log_fk, pp.coverage_component_code),
pp.rate_period_from_date
from PRODBKUPDW_MART.rmv_policy_premium pp
where pp.rate_period_type_code = 'TERM_COVG'
and pp.coverage_component_code 'NETPREM'
and hiroc_rpt_user.hiroc_get_delta_amount2(pp.policy_fk, pp.policy_term_fk, pp.risk_fk, pp.coverage_fk, pp.transaction_log_fk, pp.coverage_component_code) != 0
group by pp.policy_premium_pk,
pp.policy_premium_pk,
pp.policy_fk,
pp.policy_term_fk,
pp.risk_fk,
pp.coverage_fk,
pp.transaction_log_fk,
pp.coverage_component_code,
pp.rate_period_from_date;
2. log inserting statement used for both functions:
(1) function 'hiroc_get_delta_amount1'
insert into HIROC_RPT_USER.LOG_TEST1 values (v_start, sysdate,
p_policy_fk,p_policy_term_history_fk,p_risk_fk,p_coverage_fk,p_transaction_log_fk,p_comp_code);
COMMIT;
(2) function 'HIROC_GET_DELTA_AMOUNT_1'
insert into HIROC_RPT_USER.LOG_ZB_TEST_1 values (v_start, sysdate,
p_policy_fk,p_policy_term_history_fk,p_risk_fk,p_coverage_fk,p_transaction_log_fk,p_comp_code);
COMMIT;Are your functions using autonomous transactions?
We also need more information about the log tables etc. as we cannot tell what the problem would be from just that query, and no data. -
I need help in creating a sql statement. For example lets say i have 3 tables one(key_id, os), two(key_id, type, desc), three(type, desc). I need to create a statement that is kind of like this but i need all rows in table one returned also.
select a.key_id, b.key_id, c.desc
from one a, two b, three c
where a.key_id = b.key_id and b.type = c.type;
Message was edited by:
user457357Or
michaels> with one as
(select 10 key_id from dual union all
select 20 from dual union all
select 30 from dual union all
select 40 from dual union all
select 50 from dual),
two as
(select 10 key_id,'aa' type from dual union all
select 20, 'aa' from dual union all
select 30, 'bb' from dual),
three as
(select 'aa' type ,'Artificial' des from dual union all
select 'bb','Bulk' from dual)
select a.*, b.key_id, c.des
from one a, two b, three c
where a.key_id = b.key_id(+)
and b.type = c.type(+)
KEY_ID KEY_ID_1 DES
10 10 Artificial
20 20 Artificial
30 30 Bulk
40
50 -
I am using Sybase as my back end database. I need help on my SQL statement regarding datetime. The datetime is store as a 9 digit integer in the database (...I believe it is a Decimal(30,6) format, let me know if I am wrong).
If I do this, "select * from mytable;" It works out fine (except I don't know what the date means e.g. 998919534)
If I do this, "select * from mytable where datetime_col < '9/5/2002' ; I got an error. I even tried '9/5/02 11:00 000 am' but it didn't help.
How do I specify a date or datetime in my query?
Thanks in advance.I execute the sql statement
select * from mytable where datetim_col < convert(datetime, '3/4/2002', 101) ;
I got mix result. I got an error message "cannot convert 10375584 to a date.
Yet, he statistics window of the I-sql says
"estimated 493 rows in query (I/O estimate 87)
PLan> mytable (seq)"
It looks like I my the SQL statement is correct and then the system can't display it in the Data window.
Any thought ? -
Hi,
Need help to write sql statement.
create table t_dt ( dt_start date, dt_end date, amount number);
insert into t_dt values('1-Jan-10','10-Feb-10',12);
insert into t_dt values('11-Feb-10','10-Mar-10',10);
insert into t_dt values('11-Mar-10','20-Apr-10',8);
insert into t_dt values('21-Apr-10','28-Jun-10',10);
insert into t_dt values('29-Jun-10','20-Sep-10',10);
insert into t_dt values('21-Sep-10','10-Oct-10',10);
insert into t_dt values('11-Oct-10','31-Dec-10',8);
insert into t_dt values('1-Jan-11','10-Feb-11',8);
insert into t_dt values('11-Feb-11','10-Mar-11',7);
insert into t_dt values('11-Mar-11','20-Apr-11',6);
insert into t_dt values('21-Apr-11','28-Jun-11',6);
insert into t_dt values('29-Jun-11','20-Sep-11',6);
insert into t_dt values('21-Sep-11','10-Oct-11',4);
insert into t_dt values('11-Oct-11','31-Dec-11',8);
Result should be like below..
dt_start dt_end Amount
1-Jan-10 10-Feb-10 12
11-Feb-10 10-Mar-10 10
11-Mar-10 20-Apr-10 8
21-Apr-10 10-Oct-10 10
11-Oct-10 10-Feb-11 8
11-Feb-11 10-Mar-11 7
11-Mar-11 20-Sep-11 6
21-Sep-11 10-Oct-11 4
11-Oct-11 31-Dec-11 8
Just to explain the example, take a row with start date as 21-Apr-10 in the above insert statements, since it has the same amount for next two rows (i.e. with start date '29-Jun-10' and '21-Sep-10') these 3 rows should be converted to represent only 1 row in the result and the start date and end date should be changed per the result shown above.
Thanks.Hello
I think this gives yuo what you need....
SELECT
MIN(dt_start),
MAX(dt_end),
amount
FROM
( SELECT
dt_start,
dt_end,
MAX(marker) OVER(ORDER BY dt_start) marker,
amount
FROM
Select
dt_start,
dt_end,
amount,
CASE
WHEN LAG(amount) OVER(ORDER BY dt_start) <> amount THEN
ROW_NUMBER() OVER(ORDER BY dt_start)
END marker
from t_dt
GROUP BY
amount,
marker
order by
MIN(dt_start)
MIN(DT_START) MAX(DT_END) AMOUNT
01-JAN-2010 00:00:00 10-FEB-2010 00:00:00 12
11-FEB-2010 00:00:00 10-MAR-2010 00:00:00 10
11-MAR-2010 00:00:00 20-APR-2010 00:00:00 8
21-APR-2010 00:00:00 10-OCT-2010 00:00:00 10
11-OCT-2010 00:00:00 10-FEB-2011 00:00:00 8
11-FEB-2011 00:00:00 10-MAR-2011 00:00:00 7
11-MAR-2011 00:00:00 20-SEP-2011 00:00:00 6
21-SEP-2011 00:00:00 10-OCT-2011 00:00:00 4
11-OCT-2011 00:00:00 31-DEC-2011 00:00:00 8
9 rows selected.HTH
David
Edited by: Bravid on Feb 23, 2012 12:08 PM
Beaten to it by Frank! :-) -
Need help on SQL Statement for UDF
Hi,
as I am not so familiar with SQL statements on currently selected values, I urgently need help.
The scenario looks as follows:
I have defined two UDFs named Subgroup1 and Subgroup2 which represent the subgroups dependent on my article groups. So for example: When the user selects article group "pianos", he only sees the specific subgroups like "new pianos" and "used pianos" in field "Subgroup1". After he has selected one of these specific values, he sees only the specific sub-subgroups in field "Subgroup2", like "used grand pianos".
I have defined UDTs for both UDFs. The UDT for field "Subgroup1" has a UDF called "ArticleGroup" which represents the relation to the article group codes. The UDT for field "Subgroup2" has a UDF called "Subgroup1" which represents the relation to the subgroups one level higher.
The SQL statement for the formatted search in field "Subgroup1" looks as follows:
SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP1] T0 WHERE T0.[U_ArticleGroup] = (SELECT $[OITM.ItmsGrpCod])
It works fine.
However, I cannot find the right statement for the formatted search in field "Subgroup2".
Unfortunately this does NOT WORK:
SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP2] T0 WHERE T0.[U_Subgroup1] = (SELECT $[OITM.U_Subgroup1])
I tried a lot of others that didn't work either.
Then I tried the following one:
SELECT T0.[Name] FROM [dbo].[@B_SUBGROUP2] T0 WHERE T0.[U_Subgroup1] = (SELECT T1.[Code] FROM [dbo].[@B_SUBGROUP1] T1 WHERE T1.[U_ArticleGroup] = (SELECT $[OITM.ItmsGrpCod]))
Unfortunately that only works as long as there is only one specific subgroup1 for the selected article group.
I would be sooooo happy if there is anyone who can tell me the correct statement for my second UDF!
Thanks so much in advance!!!!
Edited by: Corinna Hochheim on Jan 18, 2010 10:16 PM
Please ignore the "http://" in the above statements - it is certainly not part of my SQL.
Please also ignore the strikes.Hello Dear,
Use the below queries to get the values:
Item Sub Group on the basis of Item Group
SELECT T0.[Name] FROM [dbo].[@SUBGROUP] T0 WHERE T0.[U_GroupCod] =$[OITM.ItmsGrpCod]
Item Sub Group 1 on the basis of item sub group
SELECT T0.[Name] FROM [dbo].[@SUBGROUP1] T0 WHERE T0.[U_SubGrpCod]=(SELECT T0.[Code] FROM [dbo].[@SUBGROUP] T0 WHERE T0.[Name] =$[OITM.U_ItmsSubgrp])
Sub group 2 on the basis of sub group 1
SELECT T0.[Name] FROM [dbo].[@SUBGROUP2] T0 WHERE T0.[U_SubGrpCod1]=(SELECT T0.[Code] FROM [dbo].[@SUBGROUP1] T0 WHERE T0.[Name] =$[OITM.U_ItmsSubgrp1])
this will help you.
regards,
Neetu -
Help with SQL statement in a coldfusion application
I created 2 drop down list boxes one that contains the months
and the second that contains the year. Right now my sql statement
is Select * from job where releaseDate=#imageDate#. Now this was
written in 2006 and I didn't know they were going to continue to
use the tool in 2007. So now I need a sql statement that if a user
selects Jan 2007 that all of jan 2007 will display. The format for
the datetime field in the database is Jan 2 2007 hh:mm:ss the first
box is named imageDate and the second is called StatusDateTake a look at the T-SQL datepart function.
Bryan Ashcraft (remove BRAIN to reply)
Web Application Developer
Wright Medical Technology, Inc.
Macromedia Certified Dreamweaver Developer
Adobe Community Expert (DW) ::
http://www.adobe.com/communities/experts/
"rere" <[email protected]> wrote in message
news:fjp4im$fqk$[email protected]..
>I created 2 drop down list boxes one that contains the
months and the
>second
> that contains the year. Right now my sql statement is
Select * from job
> where
> releaseDate=#imageDate#. Now this was written in 2006
and I didn't know
> they
> were going to continue to use the tool in 2007. So now I
need a sql
> statement
> that if a user selects Jan 2007 that all of jan 2007
will display. The
> format
> for the datetime field in the database is Jan 2 2007
hh:mm:ss the first
> box is
> named imageDate and the second is called StatusDate
> -
Help in SQL statement!!
How to pass in the strings with commas in the SQL statement. I have a SQL statement which looks like this:
String query = "SELECT Product FROM Product where Risk LIKE "+ risk +" and Priority="+ priority +"";
And the 2 values that I'm going to pass in is "R1,R2" and "P1,P2"; When I run it, there is an error. May I know how to improve my SQL statement so that it can accept the two values. Thanx
I would have used keyword in instead ie
String query = "SELECT Product FROM Product where Risk IN "+ risk +" and Priority IN "+ priority ; -
Hi, I want to search for account balance that is less than $10.00 from my database. My account balance is in 'varchar'.
I try to use the following sql statemennt but it's not working, can anybody tell me the correct sql statement?
String balance="10.00";
SELECT * FROM ACCOUNT WHERE balance < '"+balance+"'Hi, thanks mohan for answering my question. I solve my problem in another way. Bu now , I have problem with the following sql statement, please check for me.
I want to display the account info where the account balance is less than 10.00.
my ACCCOUNT table
account number customer_id admin_id balance interest_rate start_date
123456 1234 1 5.00 3.21 5/11/2001
<%@ page import="java.sql.*"%>
<%try
String url = "jdbc:jrun:sqlserver://127.0.0.1:1433;databaseName=bank";;;
Class.forName("allaire.jrun.jdbc.JRunDriver").newInstance();
Connection conn=
DriverManager.getConnection(url,"sa","bepyng");
String sql = "SELECT customer_id,account_num,balance,start_date,interest_rate FROM ACCOUNT WHERE balance < 10.00";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next())
String id = rs.getString(1);
%>
<%=id%>
<table width="63%" border="0" align="center" bordercolor="#000000" bgcolor="#FFFFFF">
<tr>
<td>Customer ID</td>
<td><%=rs.getString("customer_id")%></td>
</tr>
<tr>
<td width="42%">Account Number</td>
<td width="58%"><%=rs.getString("account_num")%></td>
</tr>
<tr>
<td>Balance</td>
<td><%=rs.getString("balance")%></td>
</tr>
<tr>
<td>Start Date</td>
<td><%=rs.getDate("start_date")%></td>
</tr>
<tr>
<td>Interest Rate</td>
<td><%=rs.getString("interest_rate")%></td>
</tr>
</table>
<%}
catch(Exception e)
System.out.println("An error occurred while connecting to onlinebanking database!"+e.getMessage());
%>
but I don't get anything, why?
Thanks in advance. -
Help with sql statements and Java
Hi,
How can I create a string kind of like this
Select * From Students Where Name Like "Bob Burns";
As the sql statement might indicate I am using MS Access. I seem to be having problems with the double quotes required by the Like operator in MS Access, Java views that as a beginning of a string as oppposed to an actual string value.Like this:
Connection connection = null;
PreparedStatement stmt = null;
ResultSet res = null;
try {
connection = ...get from connection pool...;
String sql = "select ... from ... where name like ?";
stmt = connection.prepareStatement(sql);
stmt.setObject(1, "%Bob%", java.sql.Types.VARCHAR);
res = stmt.executeQuery();
while (res.next()) { ...the usual...; }
} finally {
...close res, stmt & return connection to pool...
}You can try stmt.setString() instead of setObject() but rumor has it that some mssql drivers have a bug that makes setString() not work with "like", but oddly enough setObject() works. -
Hello all,
im working in hr schema
i need sql statement to answer my question
i need all employees information
where average salary = average salary department 50
sorry i can't speak english very well
thank's allThere is no need to do it in two queries. All you need is:
select *
from (
select e.*,
avg(case department_id when 50 then salary end) over() dept_50_avg_sal
from hr.employees e
where salary <= dept_50_avg_sal
EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL
198 Donald OConnell DOCONNEL 650.507.9833 21-JUN-07 SH_CLERK 2600 124 50 3475.55556
199 Douglas Grant DGRANT 650.507.9844 13-JAN-08 SH_CLERK 2600 124 50 3475.55556
115 Alexander Khoo AKHOO 515.127.4562 18-MAY-03 PU_CLERK 3100 114 30 3475.55556
116 Shelli Baida SBAIDA 515.127.4563 24-DEC-05 PU_CLERK 2900 114 30 3475.55556
117 Sigal Tobias STOBIAS 515.127.4564 24-JUL-05 PU_CLERK 2800 114 30 3475.55556
118 Guy Himuro GHIMURO 515.127.4565 15-NOV-06 PU_CLERK 2600 114 30 3475.55556
119 Karen Colmenares KCOLMENA 515.127.4566 10-AUG-07 PU_CLERK 2500 114 30 3475.55556
125 Julia Nayer JNAYER 650.124.1214 16-JUL-05 ST_CLERK 3200 120 50 3475.55556
126 Irene Mikkilineni IMIKKILI 650.124.1224 28-SEP-06 ST_CLERK 2700 120 50 3475.55556
127 James Landry JLANDRY 650.124.1334 14-JAN-07 ST_CLERK 2400 120 50 3475.55556
128 Steven Markle SMARKLE 650.124.1434 08-MAR-08 ST_CLERK 2200 120 50 3475.55556
EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL
129 Laura Bissot LBISSOT 650.124.5234 20-AUG-05 ST_CLERK 3300 121 50 3475.55556
130 Mozhe Atkinson MATKINSO 650.124.6234 30-OCT-05 ST_CLERK 2800 121 50 3475.55556
131 James Marlow JAMRLOW 650.124.7234 16-FEB-05 ST_CLERK 2500 121 50 3475.55556
132 TJ Olson TJOLSON 650.124.8234 10-APR-07 ST_CLERK 2100 121 50 3475.55556
133 Jason Mallin JMALLIN 650.127.1934 14-JUN-04 ST_CLERK 3300 122 50 3475.55556
134 Michael Rogers MROGERS 650.127.1834 26-AUG-06 ST_CLERK 2900 122 50 3475.55556
135 Ki Gee KGEE 650.127.1734 12-DEC-07 ST_CLERK 2400 122 50 3475.55556
136 Hazel Philtanker HPHILTAN 650.127.1634 06-FEB-08 ST_CLERK 2200 122 50 3475.55556
138 Stephen Stiles SSTILES 650.121.2034 26-OCT-05 ST_CLERK 3200 123 50 3475.55556
139 John Seo JSEO 650.121.2019 12-FEB-06 ST_CLERK 2700 123 50 3475.55556
140 Joshua Patel JPATEL 650.121.1834 06-APR-06 ST_CLERK 2500 123 50 3475.55556
EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL
142 Curtis Davies CDAVIES 650.121.2994 29-JAN-05 ST_CLERK 3100 124 50 3475.55556
143 Randall Matos RMATOS 650.121.2874 15-MAR-06 ST_CLERK 2600 124 50 3475.55556
144 Peter Vargas PVARGAS 650.121.2004 09-JUL-06 ST_CLERK 2500 124 50 3475.55556
180 Winston Taylor WTAYLOR 650.507.9876 24-JAN-06 SH_CLERK 3200 120 50 3475.55556
181 Jean Fleaur JFLEAUR 650.507.9877 23-FEB-06 SH_CLERK 3100 120 50 3475.55556
182 Martha Sullivan MSULLIVA 650.507.9878 21-JUN-07 SH_CLERK 2500 120 50 3475.55556
183 Girard Geoni GGEONI 650.507.9879 03-FEB-08 SH_CLERK 2800 120 50 3475.55556
186 Julia Dellinger JDELLING 650.509.3876 24-JUN-06 SH_CLERK 3400 121 50 3475.55556
187 Anthony Cabrio ACABRIO 650.509.4876 07-FEB-07 SH_CLERK 3000 121 50 3475.55556
190 Timothy Gates TGATES 650.505.3876 11-JUL-06 SH_CLERK 2900 122 50 3475.55556
191 Randall Perkins RPERKINS 650.505.4876 19-DEC-07 SH_CLERK 2500 122 50 3475.55556
EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL
194 Samuel McCain SMCCAIN 650.501.3876 01-JUL-06 SH_CLERK 3200 123 50 3475.55556
195 Vance Jones VJONES 650.501.4876 17-MAR-07 SH_CLERK 2800 123 50 3475.55556
196 Alana Walsh AWALSH 650.507.9811 24-APR-06 SH_CLERK 3100 124 50 3475.55556
197 Kevin Feeney KFEENEY 650.507.9822 23-MAY-06 SH_CLERK 3000 124 50 3475.55556
37 rows selected.
SQL> SY. -
Using jdev11.1.1..5.0
select 1 from dual where DUMMY = :pdummy ;@ run time if i give :pdummy as String X means i get an value 1
so same try to do in AM.
public void dummy(String pdummy)
CallableStatement cs = null;
try{
String sql = "select 1 from dual where DUMMY = :pdummy ;" ;
cs = getDBTransaction().createCallableStatement(sql,0);
cs.registerOutParameter(1, Types.VARCHAR);
cs.setString(2,pdummy );
cs.executeUpdate();
catch(SQLException e)
throw new JboException(e);
finally
if (cs!=null)
try
cs.close();
catch (Exception e){System.out.println ("Dummy Exception Thrown "+e);}
}Error throwing such invalid index. can anyone re-correct me.public void dummy(String pdummy)
CallableStatement cs = null;
try{
String sql = "select 1 from dual where DUMMY = ?" ;
cs = getDBTransaction().createCallableStatement(sql,0);
cs.setString(1,pdummy );
System.out.println("ex"+ cs.execute());
catch(SQLException e)
throw new JboException(e);
finally
if (cs!=null)
try
cs.close();
catch (Exception e){System.out.println ("Dummy Exception Thrown "+e);}
}sir,
thank you but..i want to see the value of sql statement. how can i see that?
above code is working but i want to see the value.
so i did like this.
public String dummies(String pdummy)
CallableStatement cs = null;
try{
String sql = "select 1 from dual where DUMMY = ?" ;
cs = getDBTransaction().createCallableStatement(sql,0);
cs.setString(1,pdummy );
cs.execute();
return cs.getString(1);
catch(SQLException e)
throw new JboException(e);
finally
if (cs!=null)
try
cs.close();
catch (Exception e){System.out.println ("Dummy Exception Thrown "+e);}
}some invalid index error.. can show me way to see the value of sql statement.
Edited by: subu123 on Apr 18, 2012 1:59 AM -
Need Help: Complex SQL statement
select segment3, 0 "Other Income"
, 0 "Sales of Services"
, 0 "Personnel Costs"
, 0 "Other Staff Cost"
, 0 "General Admin"
, 0 "Travel"
, 0 "Collaborator"
, 0 "Training"
, 0 "Capital"
, nvl(round(sum (nvl(PERIOD_ACTIVITY_A,0) + nvl(PERIOD_ACTIVITY_E,0) + nvl(PRDOPEN_A,0) + nvl(PRDOPEN_E,0)),0),0) "Overhead"
, 0 "Finance Charges"
from PAYMAN.SNP_OP_DETAIL@OFA
where segment3= x.new_cc and period_name = p_period
and segment2 in (select acc_t from CRP_REPORT_ACCT_DETAIL_T where group_id = 10)
group by segment3
Please I don't understand select segment3, 0 "Other Income"....there's no column called 0, what is the 0s doing in the select statement?
Secondly, I don't understand from PAYMAN.SNP_OP_DETAIL@OFAHi,
OlaTunde wrote:
select segment3, 0 "Other Income"
, 0 "Sales of Services"
, 0 "Personnel Costs"
, 0 "Other Staff Cost"
, 0 "General Admin"
, 0 "Travel"
, 0 "Collaborator"
, 0 "Training"
, 0 "Capital"
, nvl(round(sum (nvl(PERIOD_ACTIVITY_A,0) + nvl(PERIOD_ACTIVITY_E,0) + nvl(PRDOPEN_A,0) + nvl(PRDOPEN_E,0)),0),0) "Overhead"
, 0 "Finance Charges"
from PAYMAN.SNP_OP_DETAIL@OFA
where segment3= x.new_cc and period_name = p_period
and segment2 in (select acc_t from CRP_REPORT_ACCT_DETAIL_T where group_id = 10)
group by segment3
Please I don't understand select segment3, 0 "Other Income"....there's no column called 0, what is the 0s doing in the select statement?Columns are one of the expressions that can be in a SELECT clause. There are many other kinds of expressions, including liteals (as in this example), pseudo-columns, functions, and compound expressions that are also allowed.
Consider the following query:
SELECT deptno AS raw_detpno
, 1 + deptno AS one_plus
, 0 + deptno AS zero_plus
, 0 AS zero
FROM scott.dept
ORDER BY deptno
;Output:
RAW_DETPNO ONE_PLUS ZERO_PLUS ZERO
10 11 10 0
20 21 20 0
30 31 30 0
40 41 40 0No doubt you're familiar with using table columns (such as deptno) by themselves as an expression, as in the output column raw_deptno.
You're probably familiar with using a table column and a numeric literal together, as in the ouptuput columns one_plus and zero_plus.
It's also allowed to use numeric literals by themselves, as in the output column called zero.
Expressions are part of the SQL language, so you can read about them in the SQL language manual:
http://docs.oracle.com/cd/E11882_01/server.112/e26088/expressions001.htm#sthref1844
Secondly, I don't understand from PAYMAN.SNP_OP_DETAIL@OFA@OFA is a database link. See
http://docs.oracle.com/cd/E11882_01/server.112/e26088/queries010.htm#sthref2287 -
Hi All,
I have 3 tables. DEV,APPS,DISC
DEV Contains data as follows.
Cardnum Stat Flag
324657 A GAPPS contains as follows.
Cardnum Stat balance Product
324657 A 90 HYG
3276890 D 0 BNH
32675 S 89 HGF
DISC contains
Cust_Num Num
898777 1
231321 2
38927 898now I have written SELECT query as follows.
SELECT c.cardnum, cust_num
FROM tmp.ccard_gen g,
tmp.ccard_tmp c,
ods.phonenr p
WHERE flag = 'V'
AND c.cardnum = g.cardnum
AND '32' || p.num = c.cardnum
AND c.balancel > 0
AND c.product = 'SEWING';I don't have product SEWING in DISC and flag 'V'. so I am going to Insert those two values into two tables and then trying to retrieving the records by using above mentioned SELECT Statement.
But I want to write a single query for Inserting records into those 2 tables and retrieving the records.
can any one please help me out to writ a query for the issue.
Thank you,You can't insert records with a query. These are two different things.
What you can do is generate records on the fly
e.g.
SQL> ed
Wrote file afiedt.buf
1 with myemps as (select empno, ename, sal from emp
2 union all select 8000, 'FRED', 1000 from dual
3 union all select 8001, 'BOB', 1200 from dual)
4 --
5 select *
6* from myemps
SQL> /
EMPNO ENAME SAL
7369 SMITH 800
7499 ALLEN 1600
7521 WARD 1250
7566 JONES 2975
7654 MARTIN 1250
7698 BLAKE 2850
7782 CLARK 2450
7788 SCOTT 3000
7839 KING 5000
7844 TURNER 1500
7876 ADAMS 1100
7900 JAMES 950
7902 FORD 3000
7934 MILLER 1300
8000 FRED 1000
8001 BOB 1200
16 rows selected.
SQL>
Maybe you are looking for
-
How can I transfer albums from one of my accounts to another? My new account (Apple ID) email address is no longer available to me since I lost my job.
-
I would like to download and install Photoshop CS6 for Mac
I bought last year Photoshop CS6, and up to now I used it on windows system. Now I chaged system to mac, and I would like to download product Adobe Photoshop CS6, for mac - but when I try, I get offer for creative cloud membership for one year insted
-
I'm trying to delete itunes so i can eventually reinstall
I have been trying to download the newest version of itunes, but an error message kept occurring and I haven't been able to complete the download. So to fix this problem, I decided to delete itunes and all of its components and start fresh. I am ab
-
How To Find Oracle Home Directory Path...
Hello, I am working on deployment of java web service on Oracle Application Server(LINUX) 10g, EBS - R12. I am working on other system and i want to deploy web service remotely on application server. And i am not getting the oracle home directory pat
-
Optical Out 5.1 not working
Optical Out 5. not working?Hi everyone. I have a Sound Blaster X-Fi Xtreme Audio PCI Express card on a windows XP SP3 PC. I connected the optical OUT to a Sony 5. Home Theather system, DTS and Dolby Digital capable. When I configure the creative cons