Combination of rownum and order by in where
Hi friends
This is the simple query pl. have a look.
SQL> select distinct sal from emp
2 order by sal desc;
SAL
5000
3000
2975
2850
2450
1600
1500
1300
1250
1100
950
SAL
800
500
200
14 rows selected.
Now I want to list only top 5 salaries from this with sql statement
like
5000
3000
2975
2850
2450
This feature is available from oracle's 8.1.5 onwards
Example with an Inline View
Suppose we have a table emp which contains empname and sal. then using Inline View we can write sql like this:
SELECT * FROM (SELECT * FROM emp ORDER BY sal DESC)
WHERE ROWNUM < 5;
here u will get the top 4 salaries.if u want to avoid same sal then use distict also.If u want 2nd maxima then put rownum=2;
I think u r tried with oracle 8.0 or below versions.test with oracle 8i or above.Then u will get the result.
Best wishes
SHINOY.V.V.
KODUNGALLUR,
THRISSUR
KERALA
INDIA
( WORKING IN[b] IBM BANGALORE)
Kerala,Thrissur,Kodungallur)
IBM Bangalore
Similar Messages
-
Problem with SDO_FILTER combined with Timestamp and Order By using JDBC
I'm having a problem with using SDO_FILTER. I've included a test driver below. It seems that I'm having a problem with combining the SDO_FILTER, Timestamp, ORDER BY and a nested table using the Oracle 11.1.0.7.0 driver against Oracle 11g. The below query queryNoWork results in the following error:
Caused by: java.sql.SQLException: ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "MDSYS.SDO_3GL", line 1320
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:206)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1034)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:194)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:791)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:866)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1186)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3387)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3488)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1374)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.execute(WrappedPreparedStatement.java:299)
All of the other query variations seem to work. The GEOM column referenced is a Linestring that has only 2 points, start and end. Any help on this would be greatly appreciated. Thanks!
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.Date;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Enumeration;
public class QueryTester
public static void main(String[] args)
try
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
ArrayList<Object> queryParameters = new ArrayList<Object>();
queryParameters.add(new BigDecimal(0));
queryParameters.add(new Double(0));
queryParameters.add(new BigDecimal(180));
queryParameters.add(new Double(90));
queryParameters.add(new java.sql.Date(sdf.parse("2005-12-25").getTime()));
queryParameters.add(new java.sql.Date(sdf.parse("2005-12-26").getTime()));
BigDecimal one = new BigDecimal(1);
DriverManager.registerDriver((Driver) Class.forName("oracle.jdbc.driver.OracleDriver").newInstance());
Enumeration<Driver> drivers = DriverManager.getDrivers();
while(drivers.hasMoreElements())
System.out.println(drivers.nextElement().getClass().getName());
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@xxxx:1521:xxxx", "xxxx", "xxxx");
String queryNoWork = "select * from (select ROWNUM rowcount, a.* from (select * from TRACK_SEGMENTS where ( ( sdo_filter(GEOM, sdo_geometry(2003, 8307, null, sdo_elem_info_array(1, 1003, 3), sdo_ordinate_array(?, ?, ?, ?) ), 'MASK=ANYINTERACT') = 'TRUE' and END_DATE >= ?and START_DATE < ?) and 1 = 1 and 1 = 1) and ((START_DATATYPE = 'maritime_dense')) ORDER BY ID ) a) where rowcount between 1 and 30000";
String queryWorks0 = "select * from (select ROWNUM rowcount, a.* from (select * from TRACK_SEGMENTS where ( ( sdo_relate(GEOM, sdo_geometry(2003, 8307, null, sdo_elem_info_array(1, 1003, 3), sdo_ordinate_array(?, ?, ?, ?) ), 'MASK=ANYINTERACT') = 'TRUE' and END_DATE >= ?and START_DATE < ?) and 1 = 1 and 1 = 1) and ((START_DATATYPE = 'maritime_dense')) ORDER BY ID ) a) where rowcount between 1 and 30000";
String queryWorks1 = "select * from (select ROWNUM rowcount, a.* from (select * from TRACK_SEGMENTS where ( ( sdo_filter(GEOM, sdo_geometry(2003, 8307, null, sdo_elem_info_array(1, 1003, 3), sdo_ordinate_array(?, ?, ?, ?) ), 'MASK=ANYINTERACT') = 'TRUE' and END_DATE >= TO_TIMESTAMP('2005-12-25','YYYY-MM-DD') and START_DATE < TO_TIMESTAMP('2005-12-26','YYYY-MM-DD')) and 1 = 1 and 1 = 1) and ((START_DATATYPE = 'maritime_dense')) ORDER BY ID ) a) where rowcount between 1 and 30000";
String queryWorks2 = "select * from (select ROWNUM rowcount, a.* from (select * from TRACK_SEGMENTS where ( ( sdo_filter(GEOM, sdo_geometry(2003, 8307, null, sdo_elem_info_array(1, 1003, 3), sdo_ordinate_array(?, ?, ?, ?) ), 'MASK=ANYINTERACT') = 'TRUE' and END_DATE >= ?and START_DATE < ?) and 1 = 1 and 1 = 1) and ((START_DATATYPE = 'maritime_dense')) ) a) where rowcount between 1 and 30000";
String queryWorks3 = "select * from TRACK_SEGMENTS where ( ( sdo_filter(GEOM, sdo_geometry(2003, 8307, null, sdo_elem_info_array(1, 1003, 3), sdo_ordinate_array(?, ?, ?, ?) ), 'MASK=ANYINTERACT') = 'TRUE' and END_DATE >= ?and START_DATE < ?) and 1 = 1 and 1 = 1) and ((START_DATATYPE = 'maritime_dense')) ORDER BY ID";
String query = queryWorks0;
PreparedStatement s = conn.prepareStatement(query);
int parameterIndex = 0;
for (Object object : queryParameters) {
if (object instanceof Timestamp)
s.setDate(++parameterIndex, (Date) object);
else
s.setObject(++parameterIndex, object);
s.execute();
ResultSet results = s.getResultSet();
results.next();
System.out.println("executed query - " + results.getLong(1));
catch (Exception e)
e.printStackTrace();
}Is the TRACK_SEGMENTS table partitioned ?
It looks like in the case where the SQL does not work, it is not using the Spatial index. So can you add some index hints
in the query to force it to use the spatial index TRACK_SEGMENTS table ?
siva -
Trouble with subquery and rownum and ordering
I'm having trouble making this subquery work. The basic idea is that the web app will show only so many rows of results on the page, but right now I'm just playing around in SQL*Plus. The address book holds mixed case, so in order to sort by name properly I need to use UPPER to ignore case sensitivity. This SQL statement works fine for me:
select addressbookid from addressbook where addressbookid like '905430931|%' order by upper(addressbookid);I know that if you mention ROWNUM in the WHERE clause, you're referring to the row numbers of the ResultSet that Oracle returns. How do I use both ORDER BY UPPER(ADDRESSBOOKID) and WHERE ROWNUM > 25 AND ROWNUM <= 50? I figured a subquery would do it, but I can't write a correct one that does it! Below are my 2 attempts with the errors, and then I just tried to play with rownum:
SQL> select addressbookid from addressbook where addressbookid in (select addressbookid from address book where addressbookid like '905430931|%' order by upper(addressbookid));
select addressbookid from addressbook where addressbookid in (select addressbookid from addressbook
ERROR at line 1:
ORA-00907: missing right parenthesis
SQL> select addressbookid from addressbook where addressbookid in upper(select addressbookid from addressbook where addressbookid like '905430931|%');
select addressbookid from addressbook where addressbookid in upper(select addressbookid from address
ERROR at line 1:
ORA-00936: missing expression
SQL> select addressbookid from addressbook where addressbookid like '905430931|%' and rownum > 25 and rownum <= 50 order by upper(addressbookid);
no rows selected
SQL> select addressbookid from addressbook where addressbookid like '905430931|%' and rownum > 25 and rownum <= 50;
no rows selectedLike I said, if I can get a working subquery, then I'd like to attach that restriction on the rownum stuff. I'm wondering if it will be a problem trying to get the ordering to happen and then the rownum restriction after that, and all in the same query...
Btw, we've made all the table and column names in our database uppercase, so that shouldn't matter.This is probably the most efficient way ...
select addressbookid
from
select addressbookid,
rownum rn
from
select addressbookid
from addressbook
where addressbookid like '905430931|%'
order by addressbookid
where rownum <= 50
where rn > 25 -
Rownum and order by as parameter
i want a procedure that will accept the 'from' and 'to' parameter (rownum) for paginaton as well as the order by column also as a parameter( the order by changes based on the parameter) , and my query is using multiple table which doesnt have Unique keys, the pagination is not working poperly at that time..
please have a look in to the procedure..
CREATE OR REPLACE Procedure P_pagination
(cur out sys_refcursor,end1 number,start1 number,ordr number)
as
Var_sql varchar2(4000);
begin
var_sql := ' Select * '||
' From '||
' (select rownum rwnum,aa.* from ' ||
' (select ti.a,t2.a,t3.a,t4.b from t1,t2,t3,t4 where < all the joins> order by '||ordr||' )aa'||
' where rownum <='|| end1 ||') ' ||
' where rwnum >='|| start1 ;
open cur for var_sql;
end ;
/If you don't specify explicit ORDER BY clause
Oracle wont guarantee the order of the sort. You specify ORDER BY ID , but
not ORDER BY ID, <<something>> , so you have unrepeatable results. Your order by ID but don't order inside ID. Look:
SQL> select *
2 from
3 (select a.*, rownum rnum
4 from
5 (select id, data
6 from t
7 order by id) a
8 where rownum <= 150
9 )
10 where rnum >= 148
11 /
ID DATA RNUM
0 34 148
0 54 149
0 81 150
SQL> select *
2 from
3 (select a.*, rownum rnum
4 from
5 (select id, data
6 from t
7 order by id) a
8 where rownum <= 151
9 )
10 where rnum >= 148
11 /
ID DATA RNUM
0 28 148
0 34 149
0 54 150
0 81 151
SQL> select *
2 from
3 (select a.*, rownum rnum
4 from
5 (select id, data
6 from t
7 order by id, rowid) a
8 where rownum <= 150
9 )
10 where rnum >= 148
11 /
ID DATA RNUM
0 24 148
0 21 149
0 35 150
SQL> select *
2 from
3 (select a.*, rownum rnum
4 from
5 (select id, data
6 from t
7 order by id, rowid) a
8 where rownum <= 151
9 )
10 where rnum >= 148;
ID DATA RNUM
0 24 148
0 21 149
0 35 150
0 68 151Rgds. -
How to : rownum and order by in select statement
Say I have a select statement with additional 'order by' clause.
The result set I want prepended by the rownum column.
But, and here comes the flaw, I want the rownum for the already ordered result set
not the unordered.
An example:
select firstname, lastname from myTable order by lastname;
When I add the rownum to the select clause,
'select rownum, firstname, lastname from myTable order by lastname;'
I might get something like:
20 Mike Adams
13 Nina Bravo
1 Tom Charlie
But I want the following result:
1 Mike Adams
2 Nina Bravo
3 Tom Charlie
I could now
'Select rownum, lastname, firstname from (select firstname, lastname from myTable order by lastname);
But I guess there is a better way!?!
which is the best way to accomplish that?
Thanks for your advice!>
'Select rownum, lastname, firstname from (select firstname, lastname from myTable order by lastname)
>
Well if you ask me there is very little difference between this query and the above query
select rownum, lastname, firstname from mytable;Because rownum is assigned before the order by. The difference is in your query you are assigning a rownum to an ordered resultset but still there is no guarantee oracle is going to read the data in an ordered fashion. In the second query rownum is assigned to an unordered resultset. Again it is the samething. So if you want to guarantee it then I will go for the following option
select row_number() over(order by lastname) rn, lastname, firstname from mytable
order by lastnameAlso check this link.
http://www.oracle.com/technology/oramag/oracle/07-jan/o17asktom.html
Regards
Raj
Edited by: R.Subramanian on Jan 13, 2009 6:20 AM -
ROWNUM and order of elements in PL/SQL collection
I have collection col of type tt_number is table of number.
For example, values in collection are:
col[1] = 123
col[2] = -123
col[3] = 999
I'm running such query:
select ROWNUM as "rn", column_value as "val"
from table(col)
Could I be sure, that my results always will look like:
RN VAL
1 123
2 -123
3 999
Does ROWNUM equals to collection index?
As I know, when querying tables, ROWNUM doesn't guarantee such things (unless querying "ordered by" subquery). But how about queries to collections?
Regards, Dmitry Kuitskiy, 3-T Ltd, Kiev, UkraineThese Tom Kyte's threads can help you:
http://asktom.oracle.com/pls/ask/f?p=4950:8:1193224283514449959::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:4447489221109
http://asktom.oracle.com/pls/ask/f?p=4950:8:1193224283514449959::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:3008276249843
Rgds. -
Question about order by and rownum and subqueries.
Can you explain why test 4 below results as it results- with returning no rows?
Identificator "PKG_INTRA_CUSTOMER_SEARCH.NAME" is a package function, which returns value from a variable declared in package body, the function returns value 'e%'.
Please note that tests 1-3 all returned data, but test 4 didn't. Why? My porpouse is that test 4 would also return data.
1. Query without "rownum" and with "Order by" returns 2 records:
select q.*--, rownum
,PKG_INTRA_CUSTOMER_SEARCH.NAME
from
select c.ID,
c.NAME,
c.CODE
from V_CUSTOMER c
where 1=1 and lower(c.NAME) like PKG_INTRA_CUSTOMER_SEARCH.NAME
order by c.NAME, c.ID
) q
10020 Ees Nimi 37810010237 e%
10040 ewewrwe werwerwer e%2. Query with "rownum" and without "Order by" returns 2 records:
select q.*, rownum
,PKG_INTRA_CUSTOMER_SEARCH.NAME
from
select c.ID,
c.NAME,
c.CODE
from V_CUSTOMER c
where 1=1 and lower(c.NAME) like PKG_INTRA_CUSTOMER_SEARCH.NAME
--order by c.NAME, c.ID
) q
10020 Ees Nimi 37810010237 e%
10040 ewewrwe werwerwer e%3.Query without "rownum" and with "Order by" returns 2 records:
select q.*--, rownum
,PKG_INTRA_CUSTOMER_SEARCH.NAME
from
select c.ID,
c.NAME,
c.CODE
from V_CUSTOMER c
where 1=1 and lower(c.NAME) like PKG_INTRA_CUSTOMER_SEARCH.NAME
order by c.NAME, c.ID
) q
10020 Ees Nimi 37810010237 e%
10040 ewewrwe werwerwer e% 4. Query with "rownum" and with "Order by" returns 0 records:
select q.*, rownum
,PKG_INTRA_CUSTOMER_SEARCH.NAME
from
select c.ID,
c.NAME,
c.CODE
from V_CUSTOMER c
where 1=1 and lower(c.NAME) like PKG_INTRA_CUSTOMER_SEARCH.NAME
order by c.NAME, c.ID
) qHi,
please reproduce the question in your test database with script below.
My general question is that wht Test5 below returns only 1 row, but Test5 returns 3 rows.
The difference between those two tests is only that one has "order by" clause, the other doesn't have.
I need the "order by" clause to stay, but seems like it is not allowed.
CREATE OR REPLACE
PACKAGE PACKAGE1 AS
function NAME return varchar2;
END PACKAGE1;
CREATE OR REPLACE
PACKAGE body PACKAGE1 AS
function NAME return varchar2
is
begin
return 'e%';
end NAME;
END PACKAGE1;
select PACKAGE1.name from dual--e%
create table Tbl AS
(SELECT 'e2b' Col1, 'A' Col2, 'AA' Col3 FROM dual
UNION
SELECT 'e3b', 'B','BB' FROM dual
--Test5:
select q.*, rownum pos, PACKAGE1.name f
from
select c.col1,
c.col2,
c.col3
from Tbl c
where 1=1 and lower(c.col1) like PACKAGE1.name
order by c.col2, c.col1
) q
union all
select '111' , '111' , '111' , 0 pos, PACKAGE1.name f from dual --return 1 row
--Test6
select q.*, rownum pos, PACKAGE1.name f
from
select c.col1,
c.col2,
c.col3
from Tbl c
where 1=1 and lower(c.col1) like PACKAGE1.name
--order by c.col2, c.col1
) q
union all
select '111' , '111' , '111' , 0 pos, PACKAGE1.name f from dual --return 3 rowsEdited by: CharlesRoos on Feb 17, 2010 5:30 AM -
Where clause and order by to DAO classes
Hi
Is it ok(I mean design wise) to pass the 'where clause' conditions and order by clause as a parameter to the method of DAO class?Well, I would suggest you write seperate methods in your dao , one to select data without the where clause and one to select data with the where clause thrown in. If you have different 'where' clauses for selecting different kinds of data, have that many dao methods. The dao methods being specific know exactly what is the data that's coming in.
Lets assume you have a list of purchase orders and each purchase order is indetified by a unique id called PURCHASE_ORDER_ID.
1. The following code would populate a purchase order's details given an id.
private statis final String QUERY_1 = "select * from PURCHASE_ORDERS where PURCHASE_ORDER_ID = ? ";
PurchaseOrderModel getPurchaseOrderData(long poId){
//get a prepared statement from your connection
PreparedStatement pst = conn.prepareStatement(QUERY_1);
//set the poId passed as params to your query
pst.setLong(1, poId);
ResultSet rs = pst.executeQuery();
if(rs.next()){
//populate data into a model
finally{
//clean up resources
return model;
}2. The following code would return a list of PurchaseOrderModel's whose shipping date falls between a set of dates selected by the user.
private statis final String QUERY_2 = "select * from PURCHASE_ORDERS where SHIPPING_DATE between ? and ? ";
PurchaseOrderModel getPurchaseOrdersBetweenDates(list bindValues){
//get a prepared statement from your connection
PreparedStatement pst = conn.prepareStatement(QUERY_1);
//set the dates passed as params to your query
//we know that the List ought to contain only 2 dates
pst.setDate(1, (Date)bindValues.get(0));
pst.setDate(2, (Date)bindValues.get(1));
ResultSet rs = pst.executeQuery();
if(rs.next()){
//iterate and populate data into a model
//add model to a list
finally{
//clean up resources
return list;
3. This is more interesting - the dao method searches a list of Purchase Orders starting with a set of specific words. The words themselves may be one or many. This means that the number of '?' in your prepared statement may be dynamic. Each element of the list is a String that contains the start substring of a purcahse order name. For example - the list may contain elements like ["a", "ab", "c", "gh"] and the dao method returns all purchase order starting with these names.
private statis final String QUERY_3 = "select * from PURCHASE_ORDERS where ";
PurchaseOrderModel getPurchaseOrderNameMatches(list bindValues){
//construct the query dynamically
StringBuffer query = new StringBuffer(QUERY_3);
int count = 0;
for(Iterator itr = bindValues.iterator(); itr.hasNext();;){
String value = (String)itr.next();
query.append ("name like 'value%' ");
if (count != 0 and (count+1 != bindValues.length)){
query.append(" or ");
count ++;
//get a prepared statement from your connection
PreparedStatement pst = conn.prepareStatement(query.toString());
ResultSet rs = pst.executeQuery();
if(rs.next()){
//iterate and populate data into a model
//add model to a list
finally{
//clean up resources
return list;
To sum up,
1. You need as many methods as you have different kinds of searches (one method for each kind of 'where' clause).
2. The ejb/business layer would examine the data and decide on which method to call.
3. Increases coding effort, but makes the code clean and readable. Each layer does it's job. Thus we dont have ejbs forming 'where' clauses and so on.
Having said that, it really is your decision - you should take into consideration the following factors -
1. How big is the project ? If its a huge codebase developed by many people, then segregate the responsibilities clearly in each layer as I have outlined. For a small scale project, you could go with your approach.
2. Whats the take on maintenance and future add-ons ? Do you see the codebase growing with time ?
3. Is your project a commercial one - is it a product that needs to be maintained or is it a one-off development - develop once and you are done with it.
4. What are the design considerations ? Is somebody going to audit code for quality ? Or is it a academic one ?
You should take into account all these before deciding to go one way or the other.
A general thumb rule should be that you should be convinced that your code readable (maintainable), scalable and efficient. Anything that you do towards these ends is good code/design despite what people/books/patterns say, IMO.
cheers,
ram. -
Order of Predicates and Joins in a where Clause
I always specify the join conditions and then predicates in where clause . But when i placed the predicates first and then joins the response was quicker . I compared the execution plan and each has a different approach .
Is it true in all cases or it doesn't matter ? Which one is better ? In the following examples I usually follow the first approach but when i tried the second one it was faster .
Query 1
select t1.something from
table1 t1 , table2 t2
where t1.id=t2.id
and t1.year = 2009
Query 2
select t1.something from
table1 t1 , table2 t2
where t1.year = 2009and
and t1.id=t2.id
Edited by: user561066 on Sep 24, 2010 11:57 AMWelcome to the forum.
As SomeoneElse already asked: mentioning your database version is crucial when it comes to these types of questions.
So just be default always post the result of:
SQL> select * from v$version;when asking a question.
Find more information here, it explains clearly what information is needed from you to post:
How to post a SQL statement tuning request HOW TO: Post a SQL statement tuning request - template posting
Execution plans, database version, optimizer settings.... -
Need to avoid ROWNUM and DISTINCT
Hi,
Below query is returning duplicate rows and to avoid i used ROWNUM.But now as per reviewer need to change the query
without using ROWNUM & DISTINCT.Can u some one please help?
SELECT file_count, audit_count INTO v_get_file_count,v_audit_count
FROM (SELECT COUNT(cpf.file_id) OVER() AS file_count,
( SELECT COUNT (DISTINCT cpf.file_id)
FROM ibis.cw_cand_portfolio_file cpf
LEFT OUTER JOIN ibis.cw_file_action cfa
ON cfa.file_id = cpf.file_id
INNER JOIN ibis.cw_action_lookup al
ON al.action_id = cfa.action_id
WHERE cfa.at_risk = v_at_risk_flag
AND cfa.person_code = v_examiner_code
AND al.action_description IS NOT NULL
) AS audit_count
FROM ibis.cw_candidate_portfolio cp
INNER JOIN ibis.cw_cand_portfolio_file cpf
ON cpf.candidate_portfolio_id = cp.candidate_portfolio_id
WHERE cp.year = v_year
AND cp.month = v_month
AND cp.paper_code = v_paper_code
AND cp.candidate = v_candidate
AND NOT EXISTS (SELECT 1
FROM ibis.subject_component sc
INNER JOIN ibis.cw_portfolio_template cpt
ON cpt.year = sc.year
AND cpt.month = sc.month
AND cpt.subject = sc.subject
AND cpt.subject_option = sc.subject_option
AND cpt.component = sc.component
INNER JOIN ibis.cw_portfolio_template_element cpte
ON cpte.portfolio_template_id = cpt.portfolio_template_id
INNER JOIN ibis.cw_upload_queue_item cuqi
ON cuqi.portfolio_template_element_id = cpte.portfolio_template_element_id
INNER JOIN ibis.cw_file cf
ON cf.unique_file_name = cuqi.unique_file_name
WHERE sc.year = cp.year
AND sc.month =cp.month
AND sc.paper_code=cp.paper_code
AND cf.file_id = cpf.file_id
AND cpt.combined = 'Y'
AND cpte.exclude_internal_view = 'Y'))
WHERE ROWNUM=1;
sample otput wihout rownum or DISTINCT
file_count audit_count
1 2
1 2this might help you
find duplicates and dont show it
i will give an example
SELECT a,
CASE
WHEN COUNT (*) OVER (PARTITION BY SUBSTR (a, 3) ORDER BY NULL ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) >
1
THEN 'DUP'
ELSE 'ok'
END duplicate_flag
FROM (SELECT 'ab12345' AS a
FROM DUAL
UNION ALL
SELECT 'ac12345' AS a
FROM DUAL
UNION ALL
SELECT 'ac12345' AS a
FROM DUAL
UNION ALL
SELECT 'ad12345' AS a
FROM DUAL
UNION ALL
SELECT 'ad123456' AS a
FROM DUAL
UNION ALL
SELECT 'ad654321' AS a
FROM DUAL
UNION ALL
SELECT 'ab123456' AS a
FROM DUAL
UNION ALL
SELECT 'ac1234567' AS a
FROM DUAL
UNION ALL
SELECT 'ad1234567' AS a
FROM DUAL
UNION ALL
SELECT 'ab12345678' AS a
FROM DUAL);
regards
friend -
Problem with nested select in procedure and order by
Hi,
I have this procedure:
CREATE OR REPLACE PROCEDURE Mkt_Flussi_Giornalieri2
( idGruppo IN VARCHAR2
, dataInizio IN DATE
, dataFine IN DATE
, startRow IN NUMBER
, endRow IN NUMBER
, column_order in varchar2
--, order_name in varchar2
, recordsetCursor OUT SYS_REFCURSOR
, countRow OUT NUMBER
) IS
order_clause varchar2(200) := ' ';
sql_stm varchar2(32000);
BEGIN
IF column_order IS NOT NULL
THEN
order_clause := column_order;
ELSE
order_clause := ' stato DESC ';
END IF;
dbms_output.put_line('clausola:'||order_clause);
sql_stm:='
SELECT idflusso, descrizioneFlusso, dataRiferimento, strDataRiferimento,
stato, dataElaborazione, ultimoMessaggio, livello, utentiRiferimento,
exec_seq, provider_description, log_info FROM
(SELECT idflusso, descrizioneFlusso, dataRiferimento, strDataRiferimento,
stato, dataElaborazione, ultimoMessaggio, livello, utentiRiferimento,
exec_seq, provider_description, log_info FROM
(SELECT
temp.flow_id AS idFlusso,
MKT_FLOW.flow_id || '' - '' || MKT_FLOW.flow_description || ''('' || temp.exec_seq || '')'' AS descrizioneFlusso,
TO_DATE(temp.date_id,''yyyymmddhh24miss'') AS dataRiferimento,
TO_CHAR(TO_DATE(temp.date_id,''yyyymmddhh24miss''),''dd/mm/yyyy'')||'' h. ''||TO_CHAR(TO_DATE(temp.date_id,''yyyymmddhh24miss''),''hh24:mi'') AS strDataRiferimento,
temp.status AS stato, temp.end_time AS dataElaborazione, DECODE(temp.status,3, ERROR_DESC, 1, TRACE_DES) AS ultimoMessaggio,
DECODE(temp.status,3, error_level, 1, fk_trace_level) AS livello,
Get_Group_Description(MKT_FLOW.flow_id) AS utentiRiferimento, temp.exec_seq AS exec_seq, mp.provider_description,
mp.provider_link, mfc.log_info
FROM (
SELECT v.*, tr.TRACE_ID, tr.TRACE_DES , tr.trace_date, tr.fk_trace_level, e.ERROR_ID, e.ERROR_CODE, NVL(e.ERROR_DESC, er.ERROR_DESC) AS ERROR_DESC, e.error_date, e.error_level,
MIN(e.error_id) OVER (PARTITION BY e.fk_exec_seq) eid,
MAX(tr.trace_id) OVER (PARTITION BY tr.fk_exec_seq) tid
FROM (
SELECT fc.*, MAX(exec_seq) OVER (PARTITION BY flow_id, flow_frequency, n_run, date_id) exsq
FROM mkt_flow_conf_view fc
WHERE TRUNC(end_time) >= :1
AND TRUNC(end_time) <= :2
) v, MKT_ERROR er, MKT_FLOW_ERROR e, MKT_FLOW_TRC tr
WHERE v.exec_seq = v.exsq
AND e.fk_exec_seq (+) = v.exec_seq
AND tr.fk_exec_seq (+) = v.exec_seq
AND er.error_id (+) = e.error_code
) temp
INNER JOIN MKT_FLOW
ON MKT_FLOW.flow_id = temp.flow_id AND MKT_FLOW.n_run = temp.n_run AND MKT_FLOW.flow_frequency = temp.flow_frequency
INNER JOIN MKT_FLOW_GROUP ON MKT_FLOW_GROUP.flow_id = MKT_FLOW.flow_id
LEFT OUTER JOIN
(SELECT DISTINCT flow_id, log_info
FROM mkt_flow_conf) mfc
ON mkt_flow.flow_id = mfc.flow_id
, mkt_provider mp
WHERE NVL(error_id, -1) = NVL(eid, -1)
AND NVL(trace_id, -1) = NVL(tid, -1)
AND MKT_FLOW_GROUP.group_id=:3
AND NVL (mkt_flow.fk_provider_id, '' '') =
NVL (mp.provider_id, '' '') )
WHERE ROWNUM <= :4
MINUS
(SELECT idflusso, descrizioneFlusso, dataRiferimento, strDataRiferimento,
stato, dataElaborazione, ultimoMessaggio, livello, utentiRiferimento,
exec_seq, provider_description, log_info FROM
(SELECT
temp.flow_id AS idFlusso,
MKT_FLOW.flow_id || '' - '' || MKT_FLOW.flow_description || ''('' || temp.exec_seq || '')'' AS descrizioneFlusso,
TO_DATE(temp.date_id,''yyyymmddhh24miss'') AS dataRiferimento,
TO_CHAR(TO_DATE(temp.date_id,''yyyymmddhh24miss''),''dd/mm/yyyy'')||'' h. ''||TO_CHAR(TO_DATE(temp.date_id,''yyyymmddhh24miss''),''hh24:mi'') AS strDataRiferimento,
temp.status AS stato, temp.end_time AS dataElaborazione, DECODE(temp.status,3, ERROR_DESC, 1, TRACE_DES) AS ultimoMessaggio,
DECODE(temp.status,3, error_level, 1, fk_trace_level) AS livello,
Get_Group_Description(MKT_FLOW.flow_id) AS utentiRiferimento, temp.exec_seq AS exec_seq, mp.provider_description,
mp.provider_link, mfc.log_info
FROM (
SELECT v.*, tr.TRACE_ID, tr.TRACE_DES , tr.trace_date, tr.fk_trace_level, e.ERROR_ID, e.ERROR_CODE, NVL(e.ERROR_DESC, er.ERROR_DESC) AS ERROR_DESC, e.error_date, e.error_level,
MIN(e.error_id) OVER (PARTITION BY e.fk_exec_seq) eid,
MAX(tr.trace_id) OVER (PARTITION BY tr.fk_exec_seq) tid
FROM (
SELECT fc.*, MAX(exec_seq) OVER (PARTITION BY flow_id, flow_frequency, n_run, date_id) exsq
FROM mkt_flow_conf_view fc
WHERE TRUNC(end_time) >= :5
AND TRUNC(end_time) <= :6
) v, MKT_ERROR er, MKT_FLOW_ERROR e, MKT_FLOW_TRC tr
WHERE v.exec_seq = v.exsq
AND e.fk_exec_seq (+) = v.exec_seq
AND tr.fk_exec_seq (+) = v.exec_seq
AND er.error_id (+) = e.error_code
) temp
INNER JOIN MKT_FLOW
ON MKT_FLOW.flow_id = temp.flow_id AND MKT_FLOW.n_run = temp.n_run AND MKT_FLOW.flow_frequency = temp.flow_frequency
INNER JOIN MKT_FLOW_GROUP ON MKT_FLOW_GROUP.flow_id = MKT_FLOW.flow_id
LEFT OUTER JOIN
(SELECT DISTINCT flow_id, log_info
FROM mkt_flow_conf) mfc
ON mkt_flow.flow_id = mfc.flow_id
, mkt_provider mp
WHERE NVL(error_id, -1) = NVL(eid, -1)
AND NVL(trace_id, -1) = NVL(tid, -1)
AND MKT_FLOW_GROUP.group_id=:7
AND NVL (mkt_flow.fk_provider_id, '' '') =
NVL (mp.provider_id, '' '') )
WHERE ROWNUM <= :8
) ) ORDER BY :9 ' ;
dbms_output.enable(30000);
dbms_output.put_line(sql_stm);
OPEN recordsetCursor FOR sql_stm USING dataInizio, dataFine, idGruppo, endRow, dataInizio, dataFine, idGruppo, startRow, order_clause;
SELECT COUNT(*) INTO countRow FROM
(SELECT
temp.flow_id AS idFlusso,
MKT_FLOW.flow_id || ' - ' || MKT_FLOW.flow_description || '(' || temp.exec_seq || ')' AS descrizioneFlusso,
TO_DATE(temp.date_id,'yyyymmddhh24miss') AS dataRiferimento,
TO_CHAR(TO_DATE(temp.date_id,'yyyymmddhh24miss'),'dd/mm/yyyy')||' h. '||TO_CHAR(TO_DATE(temp.date_id,'yyyymmddhh24miss'),'hh24:mi') AS strDataRiferimento,
temp.status AS stato, temp.end_time AS dataElaborazione, DECODE(temp.status,3, ERROR_DESC, 1, TRACE_DES) AS ultimoMessaggio,
DECODE(temp.status,3, error_level, 1, fk_trace_level) AS livello,
Get_Group_Description(MKT_FLOW.flow_id) AS utentiRiferimento, temp.exec_seq AS exec_seq, mp.provider_description,
mp.provider_link, mfc.log_info
FROM (
SELECT v.*, tr.TRACE_ID, tr.TRACE_DES , tr.trace_date, tr.fk_trace_level, e.ERROR_ID, e.ERROR_CODE, NVL(e.ERROR_DESC, er.ERROR_DESC) AS ERROR_DESC, e.error_date, e.error_level,
MIN(e.error_id) OVER (PARTITION BY e.fk_exec_seq) eid,
MAX(tr.trace_id) OVER (PARTITION BY tr.fk_exec_seq) tid
FROM (
SELECT fc.*, MAX(exec_seq) OVER (PARTITION BY flow_id, flow_frequency, n_run, date_id) exsq
FROM mkt_flow_conf_view fc
WHERE TRUNC(end_time) >= dataInizio
AND TRUNC(end_time) <= dataFine
) v, MKT_ERROR er, MKT_FLOW_ERROR e, MKT_FLOW_TRC tr
WHERE v.exec_seq = v.exsq
AND e.fk_exec_seq (+) = v.exec_seq
AND tr.fk_exec_seq (+) = v.exec_seq
AND er.error_id (+) = e.error_code
) temp
INNER JOIN MKT_FLOW
ON MKT_FLOW.flow_id = temp.flow_id AND MKT_FLOW.n_run = temp.n_run AND MKT_FLOW.flow_frequency = temp.flow_frequency
INNER JOIN MKT_FLOW_GROUP ON MKT_FLOW_GROUP.flow_id = MKT_FLOW.flow_id
LEFT OUTER JOIN
(SELECT DISTINCT flow_id, log_info
FROM mkt_flow_conf) mfc
ON mkt_flow.flow_id = mfc.flow_id
, mkt_provider mp
WHERE NVL(error_id, -1) = NVL(eid, -1)
AND NVL(trace_id, -1) = NVL(tid, -1)
AND MKT_FLOW_GROUP.group_id=idGruppo
AND NVL (mkt_flow.fk_provider_id, ' ') =
NVL (mp.provider_id, ' '));
END Mkt_Flussi_Giornalieri2;
/When I call the procedure, from java, I receive this error:
>
Caused by: java.sql.SQLException: invalid column index
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.jdbc.driver.OracleResultSetImpl.getString(OracleResultSetImpl.java:385)
at it.edison.markettracker.dao.spring.VistaFlussiGiornalieriDaoImpl.mapRow(VistaFlussiGiornalieriDaoImpl.java:155)
at it.edison.markettracker.dao.spring.VistaFlussiGiornalieriDaoImpl.mapRow(VistaFlussiGiornalieriDaoImpl.java:1)
at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:92)
at org.springframework.jdbc.core.JdbcTemplate.processResultSet(JdbcTemplate.java:1124)
at org.springframework.jdbc.core.JdbcTemplate.extractOutputParameters(JdbcTemplate.java:1085)
at org.springframework.jdbc.core.JdbcTemplate$5.doInCallableStatement(JdbcTemplate.java:997)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:936)
... 26 more
When I call the procedure from toad in this way:
SET serveroutput ON
DECLARE
TROVATI SYS_REFCURSOR;
NUMERO_TROVATI NUMBER;
BEGIN
DBMS_OUTPUT.ENABLE(30000);
dbms_output.put_line('INIZIO');
Mkt_Flussi_Giornalieri2(1, trunc(sysdate), trunc(sysdate), 100, 50, null, TROVATI, NUMERO_TROVATI);
dbms_output.put_line('RECORD TROVATI:'||NUMERO_TROVATI);
END; I don't receive any error messages but I don't see any message.
Why this behaviour? I work on this procedure from the last monday. Please help me. I need to call the procedure from java.
Thanks, bye bye.
Edited by: Abdujaparov on Mar 5, 2009 3:44 PMHi,
I have solved the problem, I forgot a parameter in the select, so java tells the an error. But now I have another problem. The procedure doesn't execute the order by. I pass the couple column_name order_type in a string as ("provider_description desc") dinamically but the procedure doesn't execute the ordering. Why?
The problem is in the dynamic query, I think:
sql_stm:='
SELECT idflusso, descrizioneFlusso, dataRiferimento, strDataRiferimento,
stato, dataElaborazione, ultimoMessaggio, livello, utentiRiferimento,
exec_seq, provider_description, provider_link, log_info FROM
(SELECT idflusso, descrizioneFlusso, dataRiferimento, strDataRiferimento,
stato, dataElaborazione, ultimoMessaggio, livello, utentiRiferimento,
exec_seq, provider_description, provider_link, log_info FROM
(SELECT
temp.flow_id AS idFlusso,
MKT_FLOW.flow_id || '' - '' || MKT_FLOW.flow_description || ''('' || temp.exec_seq || '')'' AS descrizioneFlusso,
TO_DATE(temp.date_id,''yyyymmddhh24miss'') AS dataRiferimento,
TO_CHAR(TO_DATE(temp.date_id,''yyyymmddhh24miss''),''dd/mm/yyyy'')||'' h. ''||TO_CHAR(TO_DATE(temp.date_id,''yyyymmddhh24miss''),''hh24:mi'') AS strDataRiferimento,
temp.status AS stato, temp.end_time AS dataElaborazione, DECODE(temp.status,3, ERROR_DESC, 1, TRACE_DES) AS ultimoMessaggio,
DECODE(temp.status,3, error_level, 1, fk_trace_level) AS livello,
Get_Group_Description(MKT_FLOW.flow_id) AS utentiRiferimento, temp.exec_seq AS exec_seq, mp.provider_description,
mp.provider_link, mfc.log_info
FROM (
SELECT v.*, tr.TRACE_ID, tr.TRACE_DES , tr.trace_date, tr.fk_trace_level, e.ERROR_ID, e.ERROR_CODE, NVL(e.ERROR_DESC, er.ERROR_DESC) AS ERROR_DESC, e.error_date, e.error_level,
MIN(e.error_id) OVER (PARTITION BY e.fk_exec_seq) eid,
MAX(tr.trace_id) OVER (PARTITION BY tr.fk_exec_seq) tid
FROM (
SELECT fc.*, MAX(exec_seq) OVER (PARTITION BY flow_id, flow_frequency, n_run, date_id) exsq
FROM mkt_flow_conf_view fc
WHERE TRUNC(end_time) >= :1
AND TRUNC(end_time) <= :2
) v, MKT_ERROR er, MKT_FLOW_ERROR e, MKT_FLOW_TRC tr
WHERE v.exec_seq = v.exsq
AND e.fk_exec_seq (+) = v.exec_seq
AND tr.fk_exec_seq (+) = v.exec_seq
AND er.error_id (+) = e.error_code
) temp
INNER JOIN MKT_FLOW
ON MKT_FLOW.flow_id = temp.flow_id AND MKT_FLOW.n_run = temp.n_run AND MKT_FLOW.flow_frequency = temp.flow_frequency
INNER JOIN MKT_FLOW_GROUP ON MKT_FLOW_GROUP.flow_id = MKT_FLOW.flow_id
LEFT OUTER JOIN
(SELECT DISTINCT flow_id, log_info
FROM mkt_flow_conf) mfc
ON mkt_flow.flow_id = mfc.flow_id
, mkt_provider mp
WHERE NVL(error_id, -1) = NVL(eid, -1)
AND NVL(trace_id, -1) = NVL(tid, -1)
AND MKT_FLOW_GROUP.group_id=:3
AND NVL (mkt_flow.fk_provider_id, '' '') =
NVL (mp.provider_id, '' '') )
WHERE ROWNUM <= :4
MINUS
(SELECT idflusso, descrizioneFlusso, dataRiferimento, strDataRiferimento,
stato, dataElaborazione, ultimoMessaggio, livello, utentiRiferimento,
exec_seq, provider_description, provider_link, log_info FROM
(SELECT
temp.flow_id AS idFlusso,
MKT_FLOW.flow_id || '' - '' || MKT_FLOW.flow_description || ''('' || temp.exec_seq || '')'' AS descrizioneFlusso,
TO_DATE(temp.date_id,''yyyymmddhh24miss'') AS dataRiferimento,
TO_CHAR(TO_DATE(temp.date_id,''yyyymmddhh24miss''),''dd/mm/yyyy'')||'' h. ''||TO_CHAR(TO_DATE(temp.date_id,''yyyymmddhh24miss''),''hh24:mi'') AS strDataRiferimento,
temp.status AS stato, temp.end_time AS dataElaborazione, DECODE(temp.status,3, ERROR_DESC, 1, TRACE_DES) AS ultimoMessaggio,
DECODE(temp.status,3, error_level, 1, fk_trace_level) AS livello,
Get_Group_Description(MKT_FLOW.flow_id) AS utentiRiferimento, temp.exec_seq AS exec_seq, mp.provider_description,
mp.provider_link, mfc.log_info
FROM (
SELECT v.*, tr.TRACE_ID, tr.TRACE_DES , tr.trace_date, tr.fk_trace_level, e.ERROR_ID, e.ERROR_CODE, NVL(e.ERROR_DESC, er.ERROR_DESC) AS ERROR_DESC, e.error_date, e.error_level,
MIN(e.error_id) OVER (PARTITION BY e.fk_exec_seq) eid,
MAX(tr.trace_id) OVER (PARTITION BY tr.fk_exec_seq) tid
FROM (
SELECT fc.*, MAX(exec_seq) OVER (PARTITION BY flow_id, flow_frequency, n_run, date_id) exsq
FROM mkt_flow_conf_view fc
WHERE TRUNC(end_time) >= :5
AND TRUNC(end_time) <= :6
) v, MKT_ERROR er, MKT_FLOW_ERROR e, MKT_FLOW_TRC tr
WHERE v.exec_seq = v.exsq
AND e.fk_exec_seq (+) = v.exec_seq
AND tr.fk_exec_seq (+) = v.exec_seq
AND er.error_id (+) = e.error_code
) temp
INNER JOIN MKT_FLOW
ON MKT_FLOW.flow_id = temp.flow_id AND MKT_FLOW.n_run = temp.n_run AND MKT_FLOW.flow_frequency = temp.flow_frequency
INNER JOIN MKT_FLOW_GROUP ON MKT_FLOW_GROUP.flow_id = MKT_FLOW.flow_id
LEFT OUTER JOIN
(SELECT DISTINCT flow_id, log_info
FROM mkt_flow_conf) mfc
ON mkt_flow.flow_id = mfc.flow_id
, mkt_provider mp
WHERE NVL(error_id, -1) = NVL(eid, -1)
AND NVL(trace_id, -1) = NVL(tid, -1)
AND MKT_FLOW_GROUP.group_id=:7
AND NVL (mkt_flow.fk_provider_id, '' '') =
NVL (mp.provider_id, '' '') )
WHERE ROWNUM <= :8
) ) ORDER BY :9' ;
OPEN recordsetCursor FOR sql_stm USING dataInizio, dataFine, idGruppo, endRow, dataInizio, dataFine, idGruppo, startRow, order_clause;Where order_clause is defined so:
IF column_order IS NOT NULL
THEN
order_clause := column_order;
ELSE
order_clause := ' stato DESC ';
END IF;If I insert manually a name of a column and a type of ordering (asc or desc) the ordering is executed correctly. How can I solve this issue?
Thanks, bye bye. -
How to combine Session Facade and Transfer object?
Hello All!
I'm working on an enterprise application. Presentation layer is a stand alone client, business logic is build on the Glassfish v2.1 and MySQL is used as a database. The client is connection to the GlassFishj server remotely using EJBs.
I have problems with business logic architecture.
Here is the brief description of backend application architecture design:
1. Session Facade pattern is used to simplify the client and application server interface and to provide application layers between backend (http://java.sun.com/blueprints/corej2eepatterns/Patterns/SessionFacade.html).
2.Transfer Object pattern to define update transfer objects strategy in order to decrease network overhead during client and application server interactions and to provide version control for objects. Transfer objects are designed as simple java business serializable objects. (http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html)
3. Originally the backend application consisted of three modules: users, storage and orders, but at the end I have decided to divide my application into the following parts - assortments, map, menu, orders, transactions, users.
4. All MySQL database transactions are via JDBC using procedures. No use of entity beans.
Questions:
1. I have some doubts about using Session Facade and Transfer object patterns at the same time. At first I'd mike to cite the definitions of the patters from the SUN official web site.
* Use a session bean as a facade to encapsulate the complexity of interactions between the business objects participating in a workflow. The Session Facade manages the business objects, and provides a uniform coarse-grained service access layer to clients.
* Use a Transfer Object to encapsulate the business data. A single method call is used to send and retrieve the Transfer Object. When the client requests the enterprise bean for the business data, the enterprise bean can construct the Transfer Object, populate it with its attribute values, and pass it by value to the client.
* So, if I use Transfer Object along with Session Facade, it makes some difficulties with object version control, because I 2 or
3 transfer objects controls with the 1 bean class. The best option for Transfer object Pattern is that each transfer object should have its own bean class to provide ability of object's version control. In the case it can bring the network overhead because of frequent remote calls caused by the large number of the bean classes.
* So, should I use the both patterns? If yes, how to manage the interaction the patterns. If no, which one to use.
2. E.g. I have a huge list of the Order objects and each Order object consists of other complicated objects. So, would I have trouble to transfer that list over network? If yes, how to manage it.
Thank you!
AstghikAstghik wrote:
Hello All!
I'm working on an enterprise application. Presentation layer is a stand alone client, business logic is build on the Glassfish v2.1 and MySQL is used as a database. The client is connection to the GlassFishj server remotely using EJBs.
I have problems with business logic architecture.
Here is the brief description of backend application architecture design:
1. Session Facade pattern is used to simplify the client and application server interface and to provide application layers between backend (http://java.sun.com/blueprints/corej2eepatterns/Patterns/SessionFacade.html).
I would simply recommend establishing a service tier. Your services should be stateless. You can go the extra mile and have a session facade, but in the majority of cases, coding to an interface for your service accomplishes the same goals.
2.Transfer Object pattern to define update transfer objects strategy in order to decrease network overhead during client and application server interactions and to provide version control for objects. Transfer objects are designed as simple java business serializable objects. (http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html)
The idea of the transfer object is very similar to the Command pattern. I think if you investigate that pattern, it will be more obvious. The transfer object reduces network latency by consolidating all the parameters into an object, ideally, this also consolidates multiple method calls. If you combine a transfer object (or command object) with a service tier, you get the best of both worlds. The service can delegate calls to helper objects (or other services or components) using the data in the transfer / command object.
3. Originally the backend application consisted of three modules: users, storage and orders, but at the end I have decided to divide my application into the following parts - assortments, map, menu, orders, transactions, users.
The is your domain. It will vary from application to application. The principles above are more general (e.g., patterns and architectural tiers) and should apply to most domains. However, your actual use case may require something different.
4. All MySQL database transactions are via JDBC using procedures. No use of entity beans.
Consider using something like iBatis or Spring's JDBC templating to make your life easier with JDBC.
Questions:
1. I have some doubts about using Session Facade and Transfer object patterns at the same time. At first I'd mike to cite the definitions of the patters from the SUN official web site.
* Use a session bean as a facade to encapsulate the complexity of interactions between the business objects participating in a workflow. The Session Facade manages the business objects, and provides a uniform coarse-grained service access layer to clients.
* Use a Transfer Object to encapsulate the business data. A single method call is used to send and retrieve the Transfer Object. When the client requests the enterprise bean for the business data, the enterprise bean can construct the Transfer Object, populate it with its attribute values, and pass it by value to the client.
* So, if I use Transfer Object along with Session Facade, it makes some difficulties with object version control, because I 2 or
3 transfer objects controls with the 1 bean class. The best option for Transfer object Pattern is that each transfer object should have its own bean class to provide ability of object's version control. In the case it can bring the network overhead because of frequent remote calls caused by the large number of the bean classes.
* So, should I use the both patterns? If yes, how to manage the interaction the patterns. If no, which one to use.
Versioning is a separate issue. Generally, the more coarsely grained your transfer / command object is, the more changes are likely to impact dependent objects.
Your command or transfer object does not have to be a vanilla JavaBean, where you are basically creating a bean that has data from other objects. You can simply use your command / transfer object to encapsulate already existing domain objects. I see no need to map to a JavaBean with what you have described.
Generally, a method signature should be understandable. This means that many times it is better to pass the method, say, two coarsely grained objects than a signature with a dozen primitives. There are no hard and fast rules here. If you find a method signature getting large, consider a transfer / command object. If you want one service to delegate calls to a number of other services, you can also create a transfer / command object to furnish the controlling service with the data it needs to invoke the dependent services.
2. E.g. I have a huge list of the Order objects and each Order object consists of other complicated objects. So, would I have trouble to transfer that list over network? If yes, how to manage it.
This is a large, open-ended question. If you are going to display it to a user on a screen, I do not see how you avoid a network transfer with the data. The general answer is to not pass the data itself but rather a token (such as a primary key, or a primary key and a start and stop range such as you see on a Google search result). You do want to limit the data over the network, but this comes at a cost. Usually, the database will receive additional load. Once that becomes unacceptable, you might start putting things into session. Then you worry about memory concerns, etc. There is no silver bullet to the problem. It depends on what issues you are trying to address and what trade-offs are acceptable in your environment.
Thank you!
AstghikBest of luck.
- Saish -
Customer and Order import via CSV (webshop to Business One Import)
I have an Oscommerce website that is currently processing around 200 orders aday.
Its a ballache to say the least to create 200 customers and then create 200 orders.
The website can export the orders in a csv file (Im sure all be it with the wrong fields)
Does Business One have the ability to batch import customers and orders? can someone give me a pointer of where to start looking.
Also to start me off, if it is possible, would I have to create the customer accounts first and then import, or can it all be done with on import combined
Thanks
Tim GuyTim Guy,
Yes. You can use DTW (Data Transfer Workbench) to import via CSV files. You need to files one by one. One is oBusinessPartner for Customer accounts. The other is oOrder for Sales Orders.
Thanks,
Gordon -
Select MOD(rownum,2) gf from a WHERE gf=0
hi all
select MOD(rownum,2) gf from a
where gf=0;
this query dod't give me rows
SQL> select MOD(rownum,2) gf from a;
GF
1
0
1
0
1
0
6 rows selected.Please correct me
Thanks And Regards
Vikas
Edited by: vikas singhal on May 28, 2011 5:02 PM
Edited by: vikas singhal on May 28, 2011 5:03 PMHi, Vikas,
When you define a column alias (such as gf), you can use that alias in the ORDER BY clause, but that's the only place where you can use it in the same query. If you assign the alias in a sub-query, then you can use it anywhere in a super-query, like this:
WITH got_gf AS
select MOD (rownum, 2) AS gf
from a
SELECT *
FROM got_gf
where gf = 0;If the aliased expression is simple, and you don't need to reference it often, then you may find it easier just to repeat the expression, like this:
select MOD (rownum, 2) AS gf
from a
where MOD (rownum, 2) = 0;Edited by: Frank Kulash on May 28, 2011 8:04 AM
Correction: repeating the expression in the WHERE clause doesn't always work when it involves ROWNUM, since ROWNUM depends on how many previous rows satisfied the WHERE clause. In this case, use a sub-query. -
Using Rownum and ROwid returns duplicate records
Hi All,
We have implemented pagination as below using rowid and rownum
SELECT
id
FROM
emp
WHERE
ROWID IN
SELECT RID FROM (SELECT
ROWID RID,
ROWNUM RNUM
FROM
SELECT ID FROM emp
WHERE
((T_ID IN (200005,200229,200230,200249,200250,200049))) AND
(dte >= sysdate-90) AND
(LOWER(DESC) = LOWER ('A') AND
LOWER(NVL(FLAG,'0')) != LOWER ('3') AND
LOWER(MODDE) like LOWER ('%210%')) ORDER BY dte ASC ))
WHERE ROWNUM < 11) WHERE RNUM>= 1)) ORDER BY dte emp.ASC
But, we face that - the query inserts duplicate records in consecutive pages. For Eg:
1.if a,b,c,d,e - is returned for first iteration, then for the next iteration - f,g,h,a,y is returned.
Is it because that the Order by clause doesnt have a Unique key column.
Please help. or suggest how to efficietly implement pagination without performance hittry distinct since you are using only one column it will eliminate any duplicates.
SELECT distinct id
FROM emp
WHERE (ROWID IN ( SELECT RID
FROM (SELECT ROWID RID,ROWNUM RNUM
FROM (SELECT ID
FROM emp
WHERE ((T_ID IN (200005,200229,200230,200249,200250,200049)))
AND (dte >= sysdate-90)
AND (LOWER(DESC) = LOWER ('A')
AND LOWER(NVL(FLAG,'0')) != LOWER ('3')
AND LOWER(MODDE) like LOWER ('%210%'))
ORDER BY dte ASC ))
WHERE ROWNUM < 11)
WHERE RNUM>= 1))
ORDER BY dte emp.ASC
Maybe you are looking for
-
Can I use the Microsoft's Messanger in MacBook Air?
Hi, I just to receive my first ever Mac. It is a Mac Book Air. My family & In-Laws are on PC's running on Microsoft's OS - XP,VISTA ect. Can I communicate with them the PC users on MS Messeanger through my Mac Book Air? Do I need any particular downl
-
Sooo is there anything you can do to get money back if its missing from your account?
so someone hacked my account and took 20 bucks from my account. anything i can do to get that back? and the 'report a problem' button under the account info is a joke and just sends me to the apple website.
-
BAPI for billing plan and billing order
Hi Sap Guru, i need your help on bellow questions : Are there any BAPIs or MF standard used to read billing plan from the business partner (header and lines) ? Are there any that permit to create, simulate, modifify or cancel a billing plan ? Are the
-
Reversed PGI on the wrong date
dear sir, i created a sto for a material and transferred the material from plant A to B. on 10th Oct, now against this material i created an order on 20th October. created delivery .and issued it against order. now on 25th..we had to cancel the order
-
Help! iPhone 4s in Recovery Mode after new IOS 7.1.1 update.
I went to update my iphone 4s earlier to IOS 7.1.1 and now it's in recovery mode. My issue with that is I keep trying to download the update on my computer so it can do the recovery and every time it gets to fully download (which bc I have a ****** i