Complex Query Question-ADF/JSP/10g
I have a query in a VO that I'm programmatically creating the where clause for that has been working fine.
I need to extend the functionality to include other tables. I had thought that adding a union to my programmatically generated SQL would work, but it fails at execution. Apparently the environment adds a "select count(1) from(" to the front of my query to generate a row output count, and then closes the parenthesis in the wrong place, which causes the query to fail with an "ORA-00933 SQL command not properly ended".
How can I accomplish this? I've looked at creating a new VO which includes multiple tables, but what I really need is a union of output from the single primary table with multiple from and where that are dynamically generated based upon user input.
Here is the logging output when it throws the exception:
04/08/05 09:16:14 [497] Reusing a cached session application module instance
04/08/05 09:16:14 [498] Getting a connection for internal use...
04/08/05 09:16:14 [499] Creating internal connection...
04/08/05 09:16:14 [500] Oracle SQLBuilder: Registered driver: oracle.jdbc.driver.OracleDriver
04/08/05 09:16:14 [501] DCUtil.findSpelObject - Tokenizer : searchMasterNamesUIModel
04/08/05 09:16:14 [502] DCUtil.RETURNING oracle.jbo.uicli.binding.JUFormBinding
04/08/05 09:16:14 [503] **** refreshControl() for BindingContainer :searchMasterNamesUIModel
04/08/05 09:16:14 [504] *** DCDataControl.sync() called from :DCBindingContainer.refresh
04/08/05 09:16:14 [505] **** refreshControl() for BindingContainer :searchMasterNamesUIModel
04/08/05 09:16:14 [506] Changing iterator range size from :20 to :10
04/08/05 09:16:14 [507] *** DCDataControl.sync() called from :DCBindingContainer.refresh
04/08/05 09:16:14 [508] [RangeRefreshEvent: MasterNamesView1 start=0 count=0]
04/08/05 09:16:14 [509] SELECT MasterNames1.MNI, to_char(date_of_birth,'MM/DD/YYYY') AS DOB, MasterNames1.LAST_NAME, MasterNames1.EYE_COLOR, MasterNames1.HAIR_COLOR, MasterNames1.MIDDLE_NAME, MasterNames1.DATE_OF_BIRTH, MasterNames1.HEIGHT, MasterNames1.SUFFIX, MasterNames1.FIRST_NAME, MasterNames1.WEIGHT, MasterNames1.USER_INSERTED, MasterNames1.DATE_INSERTED, MasterNames1.SKIN_TONE, MasterNames1.LANGUAGE, MasterNames1.OCCUPATION, MasterNames1.PLACE_OF_BUSINESS, MasterNames1.E_MAIL_ADDRESS, MasterNames1.DATE_MODIFIED, MasterNames1.USER_MODIFIED, MasterNames1.ETHNICITY, MasterNames1.RACE, MasterNames1.MARITAL_STATUS, MasterNames1.SEX, MasterNames1.OFFENDER_COMMENTS, Last_Name||', '||First_Name AS FULLNAME FROM MASTER_NAMES MasterNames1 WHERE (upper(last_name) = 'SMITH' and upper(first_name) like '%') union all select MasterNames1.MNI, to_char(date_of_birth,'MM/DD/YYYY') AS DOB, MasterNames1.LAST_NAME, MasterNames1.EYE_COLOR, MasterNames1.HAIR_COLOR, MasterNames1.MIDDLE_NAME, MasterNames1.DATE_OF_BIRTH, MasterNames1.HEIGHT, MasterNames1.SUFFIX, MasterNames1.FIRST_NAME, MasterNames1.WEIGHT, MasterNames1.USER_INSERTED, MasterNames1.DATE_INSERTED, MasterNames1.SKIN_TONE, MasterNames1.LANGUAGE, MasterNames1.OCCUPATION, MasterNames1.PLACE_OF_BUSINESS, MasterNames1.E_MAIL_ADDRESS, MasterNames1.DATE_MODIFIED, MasterNames1.USER_MODIFIED, MasterNames1.ETHNICITY, MasterNames1.RACE, MasterNames1.MARITAL_STATUS, MasterNames1.SEX, MasterNames1.OFFENDER_COMMENTS, Last_Name||', '||First_Name AS FULLNAME FROM MASTER_NAMES MasterNames1 where mni in (select mni from pointer.aliases where upper(last_name) = 'SMITH' and upper(first_name) like '%')
04/08/05 09:16:14 [510] ViewObject: MasterNamesView1 Estimated Row Count Query Statement:
04/08/05 09:16:14 [511] "SELECT count(1) FROM (SELECT MasterNames1.MNI, to_char(date_of_birth,'MM/DD/YYYY') AS DOB, MasterNames1.LAST_NAME, MasterNames1.EYE_COLOR, MasterNames1.HAIR_COLOR, MasterNames1.MIDDLE_NAME, MasterNames1.DATE_OF_BIRTH, MasterNames1.HEIGHT, MasterNames1.SUFFIX, MasterNames1.FIRST_NAME, MasterNames1.WEIGHT, MasterNames1.USER_INSERTED, MasterNames1.DATE_INSERTED, MasterNames1.SKIN_TONE, MasterNames1.LANGUAGE, MasterNames1.OCCUPATION, MasterNames1.PLACE_OF_BUSINESS, MasterNames1.E_MAIL_ADDRESS, MasterNames1.DATE_MODIFIED, MasterNames1.USER_MODIFIED, MasterNames1.ETHNICITY, MasterNames1.RACE, MasterNames1.MARITAL_STATUS, MasterNames1.SEX, MasterNames1.OFFENDER_COMMENTS, Last_Name||', '||First_Name AS FULLNAME FROM MASTER_NAMES MasterNames1 WHERE (upper(last_name) = 'SMITH' and upper(first_name) like '%') union all select MasterNames1.MNI, to_char(date_of_birth,'MM/DD/YYYY') AS DOB, MasterNames1.LAST_NAME, MasterNames1.EYE_COLOR, MasterNames1.HAIR_COLOR, MasterNames1.MIDDLE_NAME, MasterNames1.DATE_OF_BIRTH, MasterNames1.HEIGHT, MasterNames1.SUFFIX, MasterNames1.FIRST_NAME, MasterNames1.WEIGHT, MasterNames1.USER_INSERTED, MasterNames1.DATE_INSERTED, MasterNames1.SKIN_TONE, MasterNames1.LANGUAGE, MasterNames1.OCCUPATION, MasterNames1.PLACE_OF_BUSINESS, MasterNames1.E_MAIL_ADDRESS, MasterNames1.DATE_MODIFIED, MasterNames1.USER_MODIFIED, MasterNames1.ETHNICITY, MasterNames1.RACE, MasterNames1.MARITAL_STATUS, MasterNames1.SEX, MasterNames1.OFFENDER_COMMENTS, Last_Name||', '||First_Name AS FULLNAME FROM MASTER_NAMES MasterNames1 where mni in (select mni from pointer.aliases where upper(last_name) = 'SMITH' and upper(first_name) like '%')) "
04/08/05 09:16:14 [512] ViewObject: MasterNamesView1 Estimated Row Count: 5
04/08/05 09:16:14 [513] DCBindingContainer.reportException :oracle.jbo.RowNotAvailableException
04/08/05 09:16:14 [514] oracle.jbo.RowNotAvailableException: JBO-25046: Requested row not available in row set iterator MasterNamesView1.
at oracle.jbo.client.remote.RowSetIteratorImpl.getAllRowsInRange(RowSetIteratorImpl.java:2002)
at oracle.jbo.client.remote.RowSetImpl.getAllRowsInRange(RowSetImpl.java:729)
at oracle.jbo.client.remote.ViewUsageImpl.getAllRowsInRange(ViewUsageImpl.java:1069)
at oracle.jbo.common.ws.WSRowSetIteratorBase.getAllRowsInRange(WSRowSetIteratorBase.java:746)
at oracle.adf.model.binding.DCIteratorBinding.getAllRowsInRange(DCIteratorBinding.java:1523)
at oracle.adf.model.binding.DCIteratorBinding.refreshControl(DCIteratorBinding.java:533)
at oracle.adf.model.binding.DCBindingContainer.refreshControl(DCBindingContainer.java:1580)
at oracle.adf.controller.lifecycle.PageLifecycle.refreshModel(PageLifecycle.java:677)
at oracle.adf.controller.struts.actions.DataAction.refreshModel(DataAction.java:374)
at oracle.adf.controller.struts.actions.DataAction.refreshModel(DataAction.java:563)
at oracle.adf.controller.lifecycle.PageLifecycle.handleLifecycle(PageLifecycle.java:128)
at oracle.adf.controller.struts.actions.DataAction.handleLifecycle(DataAction.java:233)
at oracle.adf.controller.struts.actions.DataAction.execute(DataAction.java:163)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1485)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:527)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
at oracle.security.jazn.oc4j.JAZNFilter.doFilter(Unknown Source)
at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:16)
at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:228)
at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:600)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:317)
at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
at java.lang.Thread.run(Thread.java:534)
04/08/05 09:16:14 [515] DCUtil.findSpelObject - Tokenizer : SearchMNUIModel
04/08/05 09:16:14 [516] DCUtil.RETURNING oracle.jbo.uicli.binding.JUFormBinding
04/08/05 09:16:14 [517] **** refreshControl() for BindingContainer :SearchMNUIModel
04/08/05 09:16:14 [518] Column count: 29
04/08/05 09:16:14 [519] ViewObject: MasterNamesView1 close prepared statements...
04/08/05 09:16:14 [520] ViewObject: MasterNamesView1 Created new QUERY statement
04/08/05 09:16:14 [521] SELECT MasterNames1.MNI, to_char(date_of_birth,'MM/DD/YYYY') AS DOB, MasterNames1.LAST_NAME, MasterNames1.EYE_COLOR, MasterNames1.HAIR_COLOR, MasterNames1.MIDDLE_NAME, MasterNames1.DATE_OF_BIRTH, MasterNames1.HEIGHT, MasterNames1.SUFFIX, MasterNames1.FIRST_NAME, MasterNames1.WEIGHT, MasterNames1.USER_INSERTED, MasterNames1.DATE_INSERTED, MasterNames1.SKIN_TONE, MasterNames1.LANGUAGE, MasterNames1.OCCUPATION, MasterNames1.PLACE_OF_BUSINESS, MasterNames1.E_MAIL_ADDRESS, MasterNames1.DATE_MODIFIED, MasterNames1.USER_MODIFIED, MasterNames1.ETHNICITY, MasterNames1.RACE, MasterNames1.MARITAL_STATUS, MasterNames1.SEX, MasterNames1.OFFENDER_COMMENTS, Last_Name||', '||First_Name AS FULLNAME FROM MASTER_NAMES MasterNames1 WHERE (upper(last_name) = 'SMITH' and upper(first_name) like '%') union all select MasterNames1.MNI, to_char(date_of_birth,'MM/DD/YYYY') AS DOB, MasterNames1.LAST_NAME, MasterNames1.EYE_COLOR, MasterNames1.HAIR_COLOR, MasterNames1.MIDDLE_NAME, MasterNames1.DATE_OF_BIRTH, MasterNames1.HEIGHT, MasterNames1.SUFFIX, MasterNames1.FIRST_NAME, MasterNames1.WEIGHT, MasterNames1.USER_INSERTED, MasterNames1.DATE_INSERTED, MasterNames1.SKIN_TONE, MasterNames1.LANGUAGE, MasterNames1.OCCUPATION, MasterNames1.PLACE_OF_BUSINESS, MasterNames1.E_MAIL_ADDRESS, MasterNames1.DATE_MODIFIED, MasterNames1.USER_MODIFIED, MasterNames1.ETHNICITY, MasterNames1.RACE, MasterNames1.MARITAL_STATUS, MasterNames1.SEX, MasterNames1.OFFENDER_COMMENTS, Last_Name||', '||First_Name AS FULLNAME FROM MASTER_NAMES MasterNames1 where mni in (select mni from pointer.aliases where upper(last_name) = 'SMITH' and upper(first_name) like '%') ORDER BY fullname
04/08/05 09:16:14 [522] Bind params for ViewObject: MasterNamesView1
04/08/05 09:16:14 [523] [RangeRefreshEvent: MasterNamesView1 start=0 count=5]
04/08/05 09:16:14 [524] A formatting exception occured: DateOfBirthJBO-29000: Unexpected exception caught: java.lang.IllegalArgumentException, msg=Illegal pattern character 'Y'A formatting exception occured: DateOfBirthJBO-29000: Unexpected exception caught: java.lang.IllegalArgumentException, msg=Illegal pattern character 'Y'A formatting exception occured: DateOfBirthJBO-29000: Unexpected exception caught: java.lang.IllegalArgumentException, msg=Illegal pattern character 'Y'*** DCDataControl.sync() called from :somestring
04/08/05 09:16:14 [525] **** refreshControl() for BindingContainer :SearchMNUIModel
04/08/05 09:16:14 [526] DCUtil.findSpelObject - Tokenizer : showMasterNamesUIModel
04/08/05 09:16:14 [527] DCUtil.RETURNING oracle.jbo.uicli.binding.JUFormBinding
04/08/05 09:16:14 [528] **** refreshControl() for BindingContainer :showMasterNamesUIModel
04/08/05 09:16:14 [529] Changing iterator range size from :10 to :20
04/08/05 09:16:14 [530] *** DCDataControl.sync() called from :DCBindingContainer.refresh
04/08/05 09:16:14 [531] [RangeRefreshEvent: MasterNamesView1 start=0 count=5]
04/08/05 09:16:14 [532] A formatting exception occured: DateOfBirthJBO-29000: Unexpected exception caught: java.lang.IllegalArgumentException, msg=Illegal pattern character 'Y'A formatting exception occured: DateOfBirthJBO-29000: Unexpected exception caught: java.lang.IllegalArgumentException, msg=Illegal pattern character 'Y'A formatting exception occured: DateOfBirthJBO-29000: Unexpected exception caught: java.lang.IllegalArgumentException, msg=Illegal pattern character 'Y'**** refreshControl() for BindingContainer :showMasterNamesUIModel
04/08/05 09:16:14 [533] *** DCDataControl.sync() called from :DCBindingContainer.refresh
04/08/05 09:16:14 [534] A formatting exception occured: DateOfBirthJBO-29000: Unexpected exception caught: java.lang.IllegalArgumentException, msg=Illegal pattern character 'Y'A formatting exception occured: DateOfBirthJBO-29000: Unexpected exception caught: java.lang.IllegalArgumentException, msg=Illegal pattern character 'Y'A formatting exception occured: DateOfBirthJBO-29000: Unexpected exception caught: java.lang.IllegalArgumentException, msg=Illegal pattern character 'Y'Warning! Using introspection to lookup and return value for :Find
04/08/05 09:16:14 [535] A formatting exception occured: DateOfBirthJBO-29000: Unexpected exception caught: java.lang.IllegalArgumentException, msg=Illegal pattern character 'Y'A formatting exception occured: DateOfBirthJBO-29000: Unexpected exception caught: java.lang.IllegalArgumentException, msg=Illegal pattern character 'Y'A formatting exception occured: DateOfBirthJBO-29000: Unexpected exception caught: java.lang.IllegalArgumentException, msg=Illegal pattern character 'Y'Application Module failover is enabled
04/08/05 09:16:14 [536] Getting a connection for internal use...
04/08/05 09:16:14 [537] Creating internal connection...
04/08/05 09:16:14 [538] Oracle SQLBuilder: Registered driver: oracle.jdbc.driver.OracleDriver
04/08/05 09:16:14 [539] <AM MomVer="0">
<cd/>
<TXN Def="1" New="0" Lok="1"/>
<VO>
<VO It="1" Sz="20" St="0" Ex="1" Def="model.MasterNamesView" Name="MasterNamesView1" cli="1">
<Wh>
<![CDATA[upper(last_name) = 'SMITH' and upper(first_name) like '%') union all select MasterNames1.MNI, to_char(date_of_birth,'MM/DD/YYYY') AS DOB, MasterNames1.LAST_NAME, MasterNames1.EYE_COLOR, MasterNames1.HAIR_COLOR, MasterNames1.MIDDLE_NAME, MasterNames1.DATE_OF_BIRTH, MasterNames1.HEIGHT, MasterNames1.SUFFIX, MasterNames1.FIRST_NAME, MasterNames1.WEIGHT, MasterNames1.USER_INSERTED, MasterNames1.DATE_INSERTED, MasterNames1.SKIN_TONE, MasterNames1.LANGUAGE, MasterNames1.OCCUPATION, MasterNames1.PLACE_OF_BUSINESS, MasterNames1.E_MAIL_ADDRESS, MasterNames1.DATE_MODIFIED, MasterNames1.USER_MODIFIED, MasterNames1.ETHNICITY, MasterNames1.RACE, MasterNames1.MARITAL_STATUS, MasterNames1.SEX, MasterNames1.OFFENDER_COMMENTS, Last_Name||', '||First_Name AS FULLNAME FROM MASTER_NAMES MasterNames1 where mni in (select mni from pointer.aliases where upper(last_name) = 'SMITH' and upper(first_name) like '%']]>
</Wh>
<Key>
<![CDATA[000100000003313431]]>
</Key>
</VO>
</VO>
</AM>
04/08/05 09:16:14 [540] **insert** id=1, parid=-1, collid=3051, keyArr.len=-1, cont.len=1416
04/08/05 09:16:14 [541] stmt: begin insert into "PS_TXN" values (:1, :2, :3, empty_blob(), sysdate) returning content into :4; end;
04/08/05 09:16:14 [542] **commit** #pending ops=1
04/08/05 09:16:15 [543] Getting a connection for internal use...
04/08/05 09:16:15 [544] Creating internal connection...
04/08/05 09:16:15 [545] Oracle SQLBuilder: Registered driver: oracle.jdbc.driver.OracleDriver
04/08/05 09:16:15 [546] **deleteAll** collid=3050
04/08/05 09:16:15 [547] stmt: delete "PS_TXN" where collid=:1
04/08/05 09:16:15 [548] **commit** #pending ops=1
Interestingly enough, it returns data correctly even if the exception is thrown.
Similar Messages
-
I am doing a 9-1-1 reporting system. I am selecting calls by
Agency and type of call for a given month. That works fine, but I
need them printed in desending sequence by number call far a call
type. Don't see anyway to accomplish that with one query.
Is that a way? If not, the second part of this question is
that I have not created a table using SQL. I need 3 fields, Field_A
is Text (9 positions); Field_B is Text (40 Positions) and the last
is my summarized count from the query. How do I create a Table to
support this function?
Query
<cfquery name="GetEventCount"
datasource="JasperCountyDB">
select count(AG_ID) as EventCount, TYCOD, TYP_ENG, CURENT
from aeven
where ((AG_ID = '#Session.InquiryAgencyCode#')
AND (CURENT = 'T') AND (CDTS LIKE '#EventReportDate#'))
group by AG_ID, TYCOD, TYP_ENG, CURENT
</cfquery>
Thanks for any guideance that you can provide.
RonYour question wasn't very clear, but if you only want to sort
them by the count in descending order, just ORDER BY 1 DESC.
<cfquery name="GetEventCount"
datasource="JasperCountyDB">
SELECT COUNT(AG_ID) as EventCount, TYCOD, TYP_ENG, CURENT
FROM aeven
WHERE AG_ID = '#Session.InquiryAgencyCode#'
AND CURENT = 'T'
AND CDTS LIKE '#EventReportDate#'
GROUP BY AG_ID, TYCOD, TYP_ENG, CURENT
ORDER BY 1 DESC
</cfquery>
Phil -
Complex Query Question(s)
I have two tables; one where I am defining questions and
possible answers and another where you insert the answers. The
table of questions is called 'public_survey', and SURVEY_ID is the
primary key.
The table of answers is called 'public_surveydata', where
SURVEYDATA_ID is the primary key, SURVEYDATA_QUESTIONID is what
links the primary key to public_survey and SURVEYDATA_CONTENTID is
what is needed for output; the other columns are the answers.
I need to:
(a) output public_survey so it displays in a searchable
manner;
(b) using variables from the search I need to search
public_surveydata and pull SURVEYDATA_CONTENTID.
Now comes the part I cannot figure out; I search and I can
pull up all the contentids that are related to each question; but I
cannot figure out to only pull results that are shared over all
returns. My query is a mess; somehow I need to either combine the
query or run another query after the fact that only pulls common
ids.
How do I output only common contentid that are shared in all
the queries?
To see all the code and cfdumps in regards to this post go to
this page:
http://208.106.208.43/data/query.cfm
To see the page in action sans cfdump and code go to this
page:
http://208.106.208.43/data/
Thanks!Thanks Phil; I'm beginning to think I need to redesign it as
well. Basically my reasoning for the tables was that I wanted a
table where I could dynamically add questions that would display a
y/n, dropdown or checkbox answer - this in turn is linked to
another table (posts) by the contentid (see
http://208.106.208.43/data/query.cfm
The idea is to have a dynamic database feature that I could
change on the fly; for example -- if another question is to be
added to the post (i.e. Region) then I can quickly add it to all
data using a query without having to actually touch the database.
This is the form that creates these questions:
http://208.106.208.43/data/survey.cfm
However... that said - I know the easiest way to fix it would
be to just pull these columns out and stick them in the content
table; however that doesn't allow me to set up a dynamic table
where I can quickly change the questions.
How would you write a dynamic databases where you can quickly
insert fields and link them to other tables? -
Hi,
I'm kind of embarrassed to be asking such a basic question, but here goes.
In earlier versions of Forms, it was easy to put &A into a field, and on execute query, Forms would pop up a box, and you could write "&a is null" (or some other more complex query fragment) which allowed you do a query for situations were a field was null.
You can't seem to do this now in forms 10g.
You can still put "# is null" into a field if the query length is long enough I know, but I have seen no documentation on the loss of this query by example facility.
We're using v10.1.2 by the way.
As usual, any help gratefully received.
cheers
TonyYou're right ...
Found this : http://groundside.com/blog/DuncanMills.php?m=200407 (search for QBE on the page). Not sure what the setting is for 10g - I assume FORMS_RESTRICT_ENTER_QUERY
Otherwise it is as you say ...
Steve -
How to store data from a complex query and only fresh hourly or daily?
We have a report which runs quite slow (1-2 minutes) because the query is quite complicate, so we would like to run this query daily only and store in a table so for those procedures that need to use this complex query as a subquery, can just join to this table directly to get results.
However, I am not sure what kind of object I should use to store data for this complex query. Is data in global temp table only persist within transaction? I need something that can persist the data and be access by procedures.
Any suggestions are welcome,
CheersThank you for your reply. I looked at the materialized view earlier on, but have some difficulties to use it. So I have some questions here:
1.The complex query is not a sum or aggregate functions, it just need to get data from different tables based on different conditions, in this case is it still appropriate to use meterialized view?
2.If it is, I created one, but how to use it in my procedure? From the articles I read, it seems I can't just query from this view directly. So do I need to keep the complex query in my procedure and how the procedure will use the meterialized view instead?
3. I also put the complex query in a normal view, then create a materialized view for this normal view (I expect the data from the complex query will be cache here), then in the procedure I just select * from my_NormalView, but it takes the same time to run even when I set the QUERY_REWRITE_ENABLED to true in the alter session. So I am not sure what else I need to do to make sure the procedure use the materialized view instead of the normal view. Can I query from the Materialized View directly?
Below in the code I copied from one of the article to create the materialized view based on my normal view:
CREATE MATERIALIZED VIEW HK3ControlDB.MW_RIRating
PCTFREE 5 PCTUSED 60
TABLESPACE "USERS"
STORAGE (INITIAL 50K NEXT 50K)
USING INDEX STORAGE (INITIAL 25K NEXT 25K)
REFRESH START WITH ROUND(SYSDATE + 1) + 11/24
NEXT NEXT_DAY(TRUNC(SYSDATE), 'MONDAY') + 15/24
enable query rewrite
AS SELECT * FROM HK3ControlDB.VW_RIRating;
Cheers -
Complex query crashing database!
Hi
Our 10g database runs on Windows 2003 (with 32 GB RAM on server).
Whenever a user is running a particular complex query, the database just crashes suddenly.
In fact, it doesn't write anything in alert log file for any problem.
The user starts the query, it runs for sometime, then suddenly database crashes!
Only way to work there after is to restart the database.
Although I asked the user to not to run that query again but it is generated by some application which may generate similar query again!
So, how I can prevent database from crashing again?
Will creating a resource profile to allocate finite resource help? Problem is since database crashes so suddenly, I can't find any info from log files!
ThanxThe database instance crashes. We have to start the ORACLE.EXE again to up the database.
Here is last few lines of the alert.log
Fri Feb 05 11:14:59 2010
Setting recovery target incarnation to 1
Fri Feb 05 11:14:59 2010
Successful mount of redo thread 1, with mount id 1911309359
Fri Feb 05 11:14:59 2010
Database mounted in Exclusive Mode
Completed: alter database mount exclusive
Fri Feb 05 11:14:59 2010
alter database open
Fri Feb 05 11:15:00 2010
Beginning crash recovery of 1 threads
parallel recovery started with 7 processes
Fri Feb 05 11:15:00 2010
Started redo scan
Fri Feb 05 11:15:00 2010
Completed redo scan
3886 redo blocks read, 276 data blocks need recovery
Fri Feb 05 11:15:00 2010
Started redo application at
Thread 1: logseq 179837, block 3
Fri Feb 05 11:15:00 2010
Recovery of Online Redo Log: Thread 1 Group 6 Seq 179837 Reading mem 0
Mem# 0 errs 0: F:\DB LOG FILES\ORADATA\REDO06.LOG
Mem# 1 errs 0: F:\DB LOG FILES MULTIPLEXED\ORADATA\REDO06.LOG
Fri Feb 05 11:15:00 2010
Completed redo application
Fri Feb 05 11:15:00 2010
Completed crash recovery at
Thread 1: logseq 179837, block 3889, scn 10584777673
276 data blocks read, 276 data blocks written, 3886 redo blocks read
Fri Feb 05 11:15:01 2010
LGWR: STARTING ARCH PROCESSES
ARC0 started with pid=21, OS id=5752
Fri Feb 05 11:15:01 2010
ARC0: Archival started
ARC1: Archival started
ARC1 started with pid=22, OS id=4548
Fri Feb 05 11:15:02 2010
LGWR: STARTING ARCH PROCESSES COMPLETE
Thread 1 advanced to log sequence 179838
Thread 1 opened at log sequence 179838
Current log# 7 seq# 179838 mem# 0: F:\DB LOG FILES\ORADATA\REDO07.LOG
Current log# 7 seq# 179838 mem# 1: F:\DB LOG FILES MULTIPLEXED\ORADATA\REDO07.LOG
Successful open of redo thread 1
Fri Feb 05 11:15:02 2010
ARC1: STARTING ARCH PROCESSES
Fri Feb 05 11:15:02 2010
ARC0: Becoming the 'no FAL' ARCH
ARC0: Becoming the 'no SRL' ARCH
Fri Feb 05 11:15:02 2010
SMON: enabling cache recovery
Fri Feb 05 11:15:02 2010
ARC2: Archival started
ARC1: STARTING ARCH PROCESSES COMPLETE
ARC2 started with pid=23, OS id=6120
Fri Feb 05 11:15:02 2010
Successfully onlined Undo Tablespace 1.
Fri Feb 05 11:15:02 2010
SMON: enabling tx recovery
Fri Feb 05 11:15:02 2010
Database Characterset is WE8MSWIN1252
replication_dependency_tracking turned off (no async multimaster replication found)
Starting background process QMNC
QMNC started with pid=25, OS id=5312
Fri Feb 05 11:15:03 2010
Completed: alter database open
Fri Feb 05 11:15:03 2010
ARC1: Becoming the heartbeat ARCH
Fri Feb 05 11:16:01 2010
Shutting down archive processes
Fri Feb 05 11:16:06 2010
ARCH shutting down
ARC2: Archival stopped -
How can i imrove peroformance of complex Query
How can i improve performance of complex Query
which used CASE WHEN , GROUP By Rollup
for example
SELECT CASE WHEN null then a
ELSE b END
FROM (
SELECT a,b,c,..........
FROM table1
UNION ALL
SELECT a,b,c,..........
FROM table2
GROUP BY ROLLUP a,b,c ,............
this query take 18 min to return 180000 record
is there is any way to improve the performance of this queryHello
Have you considered using
ALTER SYSTEM SET _fast=TRUE;-)
Alternatively you could provide some more information such as an execution plan for your query:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production
SQL> set linesize 200
SQL> set pages 50000
SQL> EXPLAIN PLAN FOR
2 select * from dual;
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | | | |
| 1 | TABLE ACCESS FULL | DUAL | | | |
Note: rule based optimization
9 rows selected.If you want general info on tuning, I suggest you read the Perfomance tuning guide and the Data Warehousing guide. These are the best place to find information about concepts and techniques. The forums are better suited to specific questions.
HTH
David -
Hi,
I'm new in Enterprise javabeans, I have been looking for (almost five days) the
best way to get the result for a complex query. I tried with example Weblogic
BeanManaged. I put the query directly in a method in entityBean class with prepareStatament
and that worked.
But, I have to evaluate the best way to get result with EJB's. So, I think that
I have to evaluate others like containerManaged, in this case I have to define
each entity Bean and relationships and everything, isn't it?
Is there another way to develop it with good results? and fast?
If someone have any good idea to develop a solution with EJB's for this query.
I'm really appreciate it.
select CU.ID_CUENTA_USO, C.CLASE_CUENTA, C.ESTADO, P.ID_PRODUCTO, P.NOMBRE_PRODUCTO,
CU.ID_TIPO_PAGO, AOA.ID_AREA, AOA.NOMBRE_AREA, AOA.ID_TIPO_AOA, CU.ID_CLIENTE_USUARIO,
decode (PN.ID_PERSONA,null, decode (PJ.ID_PERSONA,null, PR.APELLIDOS || ' ' ||PR.NOMBRES,
PJ.NOMBRE_EMPRESA),PN.APELLIDOS || ' ' ||PN.NOMBRES)
from ATRIBUTOS A, CUENTA_USO CU, CUENTA C, PRODUCTO P,
AREA_OPERACIONES_ADM AOA, PERSONA_NATURAL PN, PERSONA_JURIDICA PJ, PERSONA_REPRESENTADO
PR
where A.ABREVT_ATRIB_CTA_USO = 'NRO_CELULAR'
and A.VALOR = '142000000'
and CU.ID_CUENTA_USO = A.ID_CUENTA_USO
and C.ID_CUENTA = CU.ID_CUENTA_USO
and P.ID_PRODUCTO = CU.ID_PRODUCTO
and AOA.ID_AREA(+) = CU. ID_AREA_ACTIVACION
and AOA.ID_TIPO_AOA(+) = CU.ID_TIPO_AREA_ACTIVACION
and PN.ID_PERSONA(+) = CU.ID_CLIENTE_USUARIO
and PJ.ID_PERSONA(+) = CU.ID_CLIENTE_USUARIO
and PR.ID_PERSONA(+) = CU.ID_CLIENTE_USUARIO
order
by P.ID_PRODUCTO, CU.ID_CUENTA_USO;
Thank's in advanced
YoseHola/Hello Ryan
Muchas Gracias por tu respuesta/ Thank's a lot for your answer, I'm trying with
relationship-caching but something is missing.. because i got an error:
ejbc:
[java] [EJBCompiler] : Recompiling because no previous hashes found
[java] [EJBCompiler] : Compliance Checker said bean was compliant
[java]
[java]
[java]
[java] ERROR: Error from ejbc: While reading META-INF/weblogic-cmp-rdbms-jar.xml,
the Entity EJB's peristence layer failed to deploy. The error was:
[java] Error in descriptor line 44: Element type "relationship-caching"
must be declared.
[java]
[java]
[java] ERROR: ejbc found errors
I have two EJB Cuenta and Atributo I defined a relationship in the weblogic-cmp-rdbms-jar.
(I want to start with two entity and add later the others producto, cuenta, persona_x)
<relationship-caching>
<caching-name>Cuenta-Atributo</caching-name>
<caching-element>
<cmr-field>cuenta</cmr-field>
<group-name>cuentas_group</group-name>
<caching-element>
<cmr-field>atributos</cmr-field>
<group-name>atrib_group</group-name>
</caching-element>
</caching-element>
</relationship-caching>
Where i have to defined it? Thanks a lot for your help..
Yosemarlyn
"Ryan LeCompte" <[email protected]> wrote:
>
Hola/Hello Yosemarlyn,
You can utilize EJB 2.0 CMP to model the query that you specified. You
would model
the business domain as CMP Entity beans and then specify the various
relationships
among them. You actually may get an increase in performance by utilizing
CMP/CMR
in WebLogic due to the new features such as relationship caching, optimistic
concurrency
strategy support, etc. Utilizing these features will drastically reduce
the number
of SQL Joins (and overall hits to the database, due to caching). Below
are various
links for learning more:
Mastering EJB II (Good book for learning about CMP/CMR):
http://www.theserverside.com/books/masteringEJB/index.jsp
Optimistic Concurrency:
http://dev2dev.bea.com/resourcelibrary/technicalguides/Optimistic_Concurrency.jsp
http://edocs.bea.com/wls/docs70/ejb/EJB_environment.html#1153757
Relationship caching:
http://edocs.bea.com/wls/docs70/ejb/EJB_environment.html#1151177
Espero que esto te sirva bien. :-)
Saludos,
Ryan LeCompte
[email protected]
http://www.louisiana.edu/~rml7669
"Yosemarlyn Lopez" <[email protected]> wrote:
Hi,
I'm new in Enterprise javabeans, I have been looking for (almost five
days) the
best way to get the result for a complex query. I tried with example
Weblogic
BeanManaged. I put the query directly in a method in entityBean class
with prepareStatament
and that worked.
But, I have to evaluate the best way to get result with EJB's. So, I
think that
I have to evaluate others like containerManaged, in this case I have
to define
each entity Bean and relationships and everything, isn't it?
Is there another way to develop it with good results? and fast?
If someone have any good idea to develop a solution with EJB's for this
query.
I'm really appreciate it.
select CU.ID_CUENTA_USO, C.CLASE_CUENTA, C.ESTADO, P.ID_PRODUCTO, P.NOMBRE_PRODUCTO,
CU.ID_TIPO_PAGO, AOA.ID_AREA, AOA.NOMBRE_AREA, AOA.ID_TIPO_AOA, CU.ID_CLIENTE_USUARIO,
decode (PN.ID_PERSONA,null, decode (PJ.ID_PERSONA,null, PR.APELLIDOS
|| ' ' ||PR.NOMBRES,
PJ.NOMBRE_EMPRESA),PN.APELLIDOS || ' ' ||PN.NOMBRES)
from ATRIBUTOS A, CUENTA_USO CU, CUENTA C, PRODUCTO P,
AREA_OPERACIONES_ADM AOA, PERSONA_NATURAL PN, PERSONA_JURIDICA PJ, PERSONA_REPRESENTADO
PR
where A.ABREVT_ATRIB_CTA_USO = 'NRO_CELULAR'
and A.VALOR = '142000000'
and CU.ID_CUENTA_USO = A.ID_CUENTA_USO
and C.ID_CUENTA = CU.ID_CUENTA_USO
and P.ID_PRODUCTO = CU.ID_PRODUCTO
and AOA.ID_AREA(+) = CU. ID_AREA_ACTIVACION
and AOA.ID_TIPO_AOA(+) = CU.ID_TIPO_AREA_ACTIVACION
and PN.ID_PERSONA(+) = CU.ID_CLIENTE_USUARIO
and PJ.ID_PERSONA(+) = CU.ID_CLIENTE_USUARIO
and PR.ID_PERSONA(+) = CU.ID_CLIENTE_USUARIO
order
by P.ID_PRODUCTO, CU.ID_CUENTA_USO;
Thank's in advanced
Yose
[weblogic-cmp-rdbms-jar.xml] -
Hi!!
First of all sorry for the long thread but i really don't know how to explain otherwise. Please let me know if my question is not clear enough. I hope that this is possible.
I have the follwing query:
SELECT MAX(CASE WHEN t.plate_column=1 THEN t.u_box_code || '-' || t.u_box_position ELSE null END) c1,
MAX(CASE WHEN t.plate_column=2 THEN t.u_box_code || '-' || t.u_box_position ELSE null END) c2,
MAX(CASE WHEN t.plate_column=3 THEN t.u_box_code || '-' || t.u_box_position ELSE null END) c3,
MAX(CASE WHEN t.plate_column=4 THEN t.u_box_code || '-' || t.u_box_position ELSE null END) c4,
MAX(CASE WHEN t.plate_column=5 THEN t.u_box_code || '-' || t.u_box_position ELSE null END) c5,
MAX(CASE WHEN t.plate_column=6 THEN t.u_box_code || '-' || t.u_box_position ELSE null END) c6,
MAX(CASE WHEN t.plate_column=7 THEN t.u_box_code || '-' || t.u_box_position ELSE null END) c7,
MAX(CASE WHEN t.plate_column=8 THEN t.u_box_code || '-' || t.u_box_position ELSE null END) c8,
MAX(CASE WHEN t.plate_column=9 THEN t.u_box_code || '-' || t.u_box_position ELSE null END) c9,
MAX(CASE WHEN t.plate_column=10 THEN t.u_box_code || '-' || t.u_box_position ELSE null END) c10,
MAX(CASE WHEN t.plate_column=11 THEN t.u_box_code || '-' || t.u_box_position ELSE null END) c11,
MAX(CASE WHEN t.plate_column=12 THEN t.u_box_code || '-' || t.u_box_position ELSE null END) c12
FROM ( SELECT plate.plate_id,
aliquot.plate_column,
aliquot.plate_row,
sample_user.u_box_code,
sample_user.u_box_position,
sample_user.u_box_column,
sample_user.u_box_row
FROM lims_sys.plate, lims_sys.aliquot,lims_sys.sample,lims_sys.sample_user
WHERE plate.plate_id = aliquot.plate_id
AND aliquot.sample_id = sample.sample_id
AND sample.sample_id = sample_user.sample_id
AND plate.plate_id IN (874)
) t
GROUP BY t.plate_id,t.plate_row
ORDER BY t.plate_id,t.plate_row
[pre/]
The results of this query are:
[pre]
C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 C11 C12
F515-C07 F515-C08 F515-C09 F515-C10 F515-G05 F515-G06 F515-G07 F515-G08 F515-G09 F516-G10
F516-G11 F516-G12 F516-H01 F516-H02 F516-H03 F516-H04 F516-H05 F516-H06 F516-H07 N451-C04 N451-C05 N451-C06
N451-C07 N451-C08 N451-C09 N451-G02 N451-G03 N451-G04 N452-F11 N452-F12 N452-G01 N452-G02 N452-G03
N452-G04 N452-G05 N452-G06 N452-G07 N452-G08 N453-B05 N453-B06 N458-A11 N458-A12 N458-B03
N458-B04 N458-B05 N458-B06 N458-B07 N458-B08 N458-B09 N458-B10 N458-B11 N458-B12 N458-C01 N458-C02 N458-C03
N458-C04 N458-C05 N458-C06 N458-C07 N458-C08 N458-C09 N458-C10 N458-C11 N458-C12 N458-D01 N458-D02 N458-D03
N458-D04 N458-D05 N458-D06 N458-D07 N458-D08 N458-D09 N458-D10 N458-D11 N458-D12 N458-E03
N458-E04 N458-E05 N458-E06 N458-E07 N458-E08 N458-E09 N458-E10 N458-E11 N458-E12 N458-F01 N458-F02 N458-F03
[pre/]
What I actually want is that for each new u_box_code a status (C1status, C2status etc.) for every value change from 0 to 1 to 0 to 1 etc.Then the wanted results looks like:
[pre]
C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 C11 C12 C1status C2status C3status C4status C5status C6status C7status C8status C9status C10status C11status C12status
F515-C07 F515-C08 F515-C09 F515-C10 F515-G05 F515-G06 F515-G07 F515-G08 F515-G09 F516-G10 0 0 0 0 0 0 0 0 0 1
F516-G11 F516-G12 F516-H01 F516-H02 F516-H03 F516-H04 F516-H05 F516-H06 F516-H07 N451-C04 N451-C05 N451-C06 1 1 1 1 1 1 1 1 1 0 0 0
N451-C07 N451-C08 N451-C09 N451-G02 N451-G03 N451-G04 N452-F11 N452-F12 N452-G01 N452-G02 N452-G03 0 0 0 0 0 0 1 1 1 1 1
N452-G04 N452-G05 N452-G06 N452-G07 N452-G08 N453-B05 N453-B06 N458-A11 N458-A12 N458-B03 1 1 1 1 1 0 0 1 1 1
N458-B04 N458-B05 N458-B06 N458-B07 N458-B08 N458-B09 N458-B10 N458-B11 N458-B12 N458-C01 N458-C02 N458-C03 1 1 1 1 1 1 1 1 1 1 1 1
N458-C04 N458-C05 N458-C06 N458-C07 N458-C08 N458-C09 N458-C10 N458-C11 N458-C12 N458-D01 N458-D02 N458-D03 1 1 1 1 1 1 1 1 1 1 1 1
N458-D04 N458-D05 N458-D06 N458-D07 N458-D08 N458-D09 N458-D10 N458-D11 N458-D12 N458-E03 1 1 1 1 1 1 1 1 1 1
N458-E04 N458-E05 N458-E06 N458-E07 N458-E08 N458-E09 N458-E10 N458-E11 N458-E12 N458-F01 N458-F02 N458-F03 1 1 1 1 1 1 1 1 1 1 1 1
[pre/]
The most difficult part is the combination of the wanted results from thread complex query and this.
Conclusion:
The final results must be :
[pre]
C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 C11 C12 C1status C2status C3status C4status C5status C6status C7status C8status C9status C10status C11status C12status
C07-F515 C10-F515 G05-F515 G09-F515 G10-F516 0 0 0 0 0 0 0 0 0 1
G11-F516 G12-F516 H01-F516 H07-F516 C04-N451 C06-N451 1 1 1 1 1 1 1 1 1 0 0 0
C07-N451 C09-N451 G02-N451 G03-N451 G04-N451 F11-N452 F12-N452 G01-N452 G02-N452 G03-N452 0 0 0 0 0 0 1 1 1 1 1
G04-N452 G08-N452 B05-N453 B06-N453 A11-N458 A12-N458 B03-N458 1 1 1 1 1 0 0 1 1 1
B04-N458 B12-N458 C01-N458 C03-N458 1 1 1 1 1 1 1 1 1 1 1 1
C04-N458 C12-N458 D01-N458 D03-N458 1 1 1 1 1 1 1 1 1 1 1 1
D04-N458 D12-N458 E03-N458 1 1 1 1 1 1 1 1 1 1
E04-N458 E12-N458 F01-N458 F03-N458 1 1 1 1 1 1 1 1 1 1 1 1
[pre/]
The query of this without the statusses is:
[pre]
SELECT c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,plate_id,plate_row
FROM ( SELECT c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12, rownum r1,plate_id,plate_row
FROM ( SELECT MAX(CASE WHEN t.plate_column=1 THEN t.u_box_position|| '-' || t.u_box_code ELSE null END) c1,
MAX(CASE WHEN t.plate_column=2 THEN t.u_box_position || '-' || t.u_box_code ELSE null END) c2,
MAX(CASE WHEN t.plate_column=3 THEN t.u_box_position || '-' || t.u_box_code ELSE null END) c3,
MAX(CASE WHEN t.plate_column=4 THEN t.u_box_position || '-' || t.u_box_code ELSE null END) c4,
MAX(CASE WHEN t.plate_column=5 THEN t.u_box_position || '-' || t.u_box_code ELSE null END) c5,
MAX(CASE WHEN t.plate_column=6 THEN t.u_box_position || '-' || t.u_box_code ELSE null END) c6,
MAX(CASE WHEN t.plate_column=7 THEN t.u_box_position || '-' || t.u_box_code ELSE null END) c7,
MAX(CASE WHEN t.plate_column=8 THEN t.u_box_position || '-' || t.u_box_code ELSE null END) c8,
MAX(CASE WHEN t.plate_column=9 THEN t.u_box_position || '-' || t.u_box_code ELSE null END) c9,
MAX(CASE WHEN t.plate_column=10 THEN t.u_box_position || '-' || t.u_box_code ELSE null END) c10,
MAX(CASE WHEN t.plate_column=11 THEN t.u_box_position || '-' || t.u_box_code ELSE null END) c11,
MAX(CASE WHEN t.plate_column=12 THEN t.u_box_position || '-' || t.u_box_code ELSE null END) c12,
t.plate_id,
t.plate_row
FROM ( SELECT plate.plate_id,
aliquot.plate_column,
aliquot.plate_row,
sample_user.u_box_code,
sample_user.u_box_position,
sample_user.u_box_column,
sample_user.u_box_row
FROM lims_sys.plate, lims_sys.aliquot,lims_sys.sample,lims_sys.sample_user
WHERE plate.plate_id = aliquot.plate_id
AND aliquot.sample_id = sample.sample_id
AND sample.sample_id = sample_user.sample_id
AND plate.plate_id IN (874)
) t,
( SELECT min(u_box_column) min_col ,max(u_box_column) max_col,u_box_row,u_box_code,plate_row
FROM ( SELECT plate.plate_id,
aliquot.plate_column,
aliquot.plate_row,
sample_user.u_box_code,
sample_user.u_box_position,
sample_user.u_box_column,
sample_user.u_box_row
FROM lims_sys.plate, lims_sys.aliquot,lims_sys.sample,lims_sys.sample_user
WHERE plate.plate_id = aliquot.plate_id
AND aliquot.sample_id = sample.sample_id
AND sample.sample_id = sample_user.sample_id
AND plate.plate_id IN (874))
GROUP BY u_box_row,u_box_code,plate_row
) s
WHERE t.u_box_column in (min_col,max_col)
AND t.u_box_row = s.u_box_row
AND t.plate_row = s.plate_row
GROUP BY t.plate_id,t.plate_row
ORDER BY t.plate_id,t.plate_row)
) a,
( SELECT rownum r2
FROM all_objects
WHERE rownum <9
) b
WHERE a.r1(+) = b.r2
[pre/]Hi,
Your query does not work. when i exttract the subqueries i get the message "not a group by expression" on plate_column with subquery:I fired the below query posted by me and got the output. Its not giving any error for me.
C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 C11 C12 S1 S2 S3 S4 S5 S6 S7 S8 S9 S10 S11 S12
F515-C07 F515-C10 F515-G05 F515-G09 F516-G10 0 0 0 0 0 0 0 0 0 1
F516-G11 F516-G12 F516-H01 F516-H07 N451-C04 N451-C06 1 1 1 1 1 1 1 1 1 0 0 0
N451-C07 N451-C09 N451-G02 N451-G03 N451-G04 N452-F11 N452-F12 N452-G01 N452-G02 N452-G03 0 0 0 0 0 0 1 1 1 1 1
N452-G04 N452-G08 N453-B05 N453-B06 N458-A11 N458-A12 N458-B03 1 1 1 1 1 0 0 1 1 1
N458-B04 N458-B12 N458-C01 N458-C03 1 1 1 1 1 1 1 1 1 1 1 1
N458-C04 N458-C12 N458-D01 N458-D03 1 1 1 1 1 1 1 1 1 1 1 1
N458-D04 N458-D12 N458-E03 1 1 1 1 1 1 1 1 1 1
N458-E04 N458-E12 N458-F01 N458-F03 1 1 1 1 1 1 1 1 1 1 1 1
Also the subquery you posted me saying that it gives error also gives the output.
select rownum rn,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12
from (
select (select status from stat where box_code = st1) s1,
(select status from stat where box_code = st2) s2,
(select status from stat where box_code = st3) s3,
(select status from stat where box_code = st4) s4,
(select status from stat where box_code = st5) s5,
(select status from stat where box_code = st6) s6,
(select status from stat where box_code = st7) s7,
(select status from stat where box_code = st8) s8,
(select status from stat where box_code = st9) s9,
(select status from stat where box_code = st10) s10,
(select status from stat where box_code = st11) s11,
(select status from stat where box_code = st12) s12
from (
select MAX(CASE WHEN plate_column=1 THEN t.u_box_code ELSE null END) st1,
MAX(CASE WHEN plate_column=2 THEN t.u_box_code ELSE null END) st2,
MAX(CASE WHEN plate_column=3 THEN t.u_box_code ELSE null END) st3,
MAX(CASE WHEN plate_column=4 THEN t.u_box_code ELSE null END) st4,
MAX(CASE WHEN plate_column=5 THEN t.u_box_code ELSE null END) st5,
MAX(CASE WHEN plate_column=6 THEN t.u_box_code ELSE null END) st6,
MAX(CASE WHEN plate_column=7 THEN t.u_box_code ELSE null END) st7,
MAX(CASE WHEN plate_column=8 THEN t.u_box_code ELSE null END) st8,
MAX(CASE WHEN plate_column=9 THEN t.u_box_code ELSE null END) st9,
MAX(CASE WHEN plate_column=10 THEN t.u_box_code ELSE null END) st10,
MAX(CASE WHEN plate_column=11 THEN t.u_box_code ELSE null END) st11,
MAX(CASE WHEN plate_column=12 THEN t.u_box_code ELSE null END) st12
from t
group by plate_id,plate_row
o/p :
RN S1 S2 S3 S4 S5 S6 S7 S8 S9 S10 S11 S12
1 0 0 0 0 0 0 0 0 0 1
2 1 1 1 1 1 1 1 1 1 0 0 0
3 0 0 0 0 0 0 1 1 1 1 1
4 1 1 1 1 1 0 0 1 1 1
5 1 1 1 1 1 1 1 1 1 1 1 1
6 1 1 1 1 1 1 1 1 1 1 1 1
7 1 1 1 1 1 1 1 1 1 1
8 1 1 1 1 1 1 1 1 1 1 1 1
Rgds
Sandesh -
I created a complex query to extract data from Journal entry and from Journal voucher. I post here a simplified version where I have deleted UDO references.
I buit it in the Query analizer and it runs ok.
I copied in SAP and it runs ok too.
Now, I need to ask for the start date and end date, as in the first lines of script. But SAP raise an error message I dont understand. I tried to use '[%0]' and '[%1]' insthead of '2008/01/01' and '2008/02/29'
DECLARE @D1 DATETIME
DECLARE @D2 DATETIME
SET @D1='2008/01/01'
SET @D2='2008/02/29'
SELECT * FROM
SELECT
A.ACCOUNT AS 'CO.GE ITALIA',
OACT.ACCTNAME AS 'NOME CO.GE ITALIA',
SUM(CASE WHEN (A.ACCOUNT>='500000' AND A.ACCOUNT<'600000' AND DEBIT<>0) THEN -DEBIT WHEN (A.ACCOUNT>='600000' AND A.ACCOUNT<'700000')THEN 0 ELSE CREDIT END -
CASE WHEN (A.ACCOUNT>='500000' AND A.ACCOUNT<'600000') THEN 0 WHEN (A.ACCOUNT>='600000' AND A.ACCOUNT<'700000' AND CREDIT<>0)THEN -CREDIT ELSE DEBIT END) AS 'TOTALE'
FROM (
SELECT BTF1.* FROM BTF1
UNION ALL
SELECT JDT1.* FROM JDT1
) AS A
LEFT JOIN OACT ON (OACT.ACCTCODE=A.ACCOUNT)
LEFT JOIN OBTF ON (OBTF.BATCHNUM=A.BATCHNUM AND OBTF.TRANSID=A.TRANSID)
WHERE A.REFDATE>=@D1 AND A.REFDATE<=@D2 AND (OBTF.BTFSTATUS<>'C' OR OBTF.BTFSTATUS IS NULL) AND (OACT.U_CUENTA<>'' AND OACT.U_CUENTA IS NOT NULL) AND (OACT.U_CUENTA<>'432000000')
GROUP BY A.ACCOUNT, OACT.ACCTNAME
UNION ALL
SELECT
A.SHORTNAME AS 'CO.GE ITALIA',
OCRD.CARDNAME AS 'NOME CO.GE ITALIA',
SUM(CASE WHEN (A.ACCOUNT>='500000' AND A.ACCOUNT<'600000' AND DEBIT<>0) THEN -DEBIT WHEN (A.ACCOUNT>='600000' AND A.ACCOUNT<'700000')THEN 0 ELSE CREDIT END -
CASE WHEN (A.ACCOUNT>='500000' AND A.ACCOUNT<'600000') THEN 0 WHEN (A.ACCOUNT>='600000' AND A.ACCOUNT<'700000' AND CREDIT<>0)THEN -CREDIT ELSE DEBIT END) AS 'TOTALE'
FROM (
SELECT BTF1.* FROM BTF1
UNION ALL
SELECT JDT1.* FROM JDT1
) AS A
LEFT JOIN OACT ON (OACT.ACCTCODE=A.ACCOUNT)
LEFT JOIN OBTF ON (OBTF.BATCHNUM=A.BATCHNUM AND OBTF.TRANSID=A.TRANSID)
LEFT JOIN OCRD ON (OCRD.CARDCODE=A.SHORTNAME)
WHERE A.REFDATE>=@D1 AND A.REFDATE<=@D2 AND (OBTF.BTFSTATUS<>'C' OR OBTF.BTFSTATUS IS NULL) AND (OACT.U_CUENTA<>'' AND OACT.U_CUENTA IS NOT NULL) AND (OACT.U_CUENTA='432000000')
GROUP BY A.SHORTNAME, OCRD.CARDNAME
) AS BThank you to everybody for your answers.
I need to know more about this way to declare a variable in SAP.
This is my question:
If I need to filter by date a result from a Union All select, is sufficent to declare the Date Variable for one of the two tables in the Union All?
Following a simple code to explain my dubt:
DECLARE @D1 DATETIME
DECLARE @D2 DATETIME
SET @D1='2008/01/01'
SET @D2='2008/02/29'
SELECT A.ACCOUNT, A.DEBIT, A.CREDIT FROM
SELECT * FROM JDT1
UNION ALL
SELECT * FROM BTF1
) AS A
WHERE A.REFDATE>=@D1 AND A.REFDATE<=@D2
Do you think the WHERE statment will continue to run as well for the Union All in the script main too?
This is the modified initial code:
/*SELECT * FROM JDT1 T0*/
DECLARE @D1 DATETIME
DECLARE @D2 DATETIME
/* WHERE */
SET @D1=/* T0.REFDATE */ '[%0]'
SET @D2=/* T0.REFDATE */ '[%1]'
Thanks in advance,
Jonny Cortonicchi -
1. How to create an explain plan with rowsource statistics for a complex query that include multiple table joins ?
When multiple tables are involved , and the actual number of rows returned is more than what the explain plan tells. How can I find out what change is needed in the stat plan ?
2. Does rowsource statistics gives some kind of understanding of Extended stats ?You can get Row Source Statistics only *after* the SQL has been executed. An Explain Plan midway cannot give you row source statistics.
To get row source statistics either set STATISTICS_LEVEL='ALL' in the session that executes theSQL OR use the Hint "gather_plan_statistics" in the SQL being executed.
Then use dbms_xplan.display_cursor
Hemant K Chitale -
Java.lang.NullPointerException warning beside components on ADF JSP page
java.lang.NullPointerException warning beside components on ADF JSP page problem
Hello
i developed a web application with the help of the Adf technology On jdeveloper 10.1.3.3.0 . Everything is Ok.
But when i use application sometimes on the page i take a java.lang.NullPointerException warn beside the some components like a inputbox or a radio button ..)
i looked the logs but nothing.
How can i solve this problem.
Have you got any idea?Hi,
it's the validator property on inputText components that causes it. not validation or StateValidation or EnableTokenValidation.
Paste your inputText source from the page if you are not sure.
Brenden -
I am novice in PL/Sql. I need some help in writing a complex query.
I imagine the following table structure.
Type(string) Date(date) count(int)
Given a date range
The query needs to group the records on type and return the record (type and count) which has the max date (its just date, no time is involved) for each group (which is based on type) . If there are more than one records which have the max date then the average count should be returned for that type
i would be glad if someone could give any ideas as to how to go about this query. Thanking you in advance.
regards.Heres the query ... Forget the period .... wht this query is supposed to do is group on assigned ki for a given date range. then it has to get the value which is for the last record for that Ki in the date range. If there are 2 records which have max date then it should give an average.
e.g
assignedKI / date / value
a 1st may 2008 10
b 2nd may 2008 12
c 1st may 2008 13
a 30 - apr-2008 16
b 4th may 2008 17
a 1st may 2008 20
The query should return
a 1st may 2008 15 (which is the average as there are 2 values for the max date for a)
b 4th may 2008 17
c 1st may 2008 13
the following query doesnot work ....
SELECT
kiv2.assigned_k_i,
kiv2.ki_name,
kiv.period,
max( kiv2.ki_value_date) ,
avg(kiv2.ki_value)
FROM
SELECT
assigned_k_i,
period p1,
TO_CHAR(ki_value_date, period) period,
MAX(ki_value_date) ki_value_date
FROM
v_ki_value,
(select ? period from dual)
WHERE
(status = 'APPROVED' OR status = 'AUTOAPPROVED')
AND ( trunc(to_date(to_char(ki_value_date, 'DD/MM/YYYY'), 'DD/MM/YYYY')) >= ?)
AND ( trunc(to_date(to_char(ki_value_date, 'DD/MM/YYYY'), 'DD/MM/YYYY')) <= ?)
AND (INSTR(?, TO_CHAR(assigned_k_i)) > 0)
GROUP BY
assigned_k_i,
TO_CHAR(ki_value_date, period)
) kiv,
v_ki_value kiv2
WHERE
kiv.assigned_k_i = kiv2.assigned_k_i
AND to_char(kiv.ki_value_date, kiv.p1) = to_char(kiv2.ki_value_date, kiv.p1)
GROUP BY
kiv2.assigned_k_i,
kiv2.ki_name,
kiv.period,
kiv2.ki_value
ORDER BY
kiv2.assigned_k_i -
How to bind local variables in complex query in PL/SQL
Hi
I have long complex query with local varibales; when I run in Dynamic SQL I get an error. Not sure which is the easiest way to bind local variables.
L_QUERY := q'[select m.segment1 col1,
'1' col2,
'13' col3,
l.operand col4,
0 col5,
'Y' col8,
'N' col9,
'N' col10,
decode(h.name,'09_UKOR_*','EOS Credit','10_UKOR_*','TopUp','11_UKOR_*','Main') col18
from qp_list_headers_v h,
qp_list_lines_v l,
mtl_system_items m
where h.name in ('09_UKOR_*','10_UKOR_*','11_UKOR_*')
and h.list_header_id = l.list_header_id
and m.inventory_item_id = l.product_attr_value
and m.organization_id = 84
UNION all
SELECT qs.PRODUCT_ATTR_VALUE col1,
hca.account_number col2,
decode (su.site_use_code,'BILL_TO','21','SHIP_TO','18') col3,
0 col4,
qs.operand col5,
null col6,
null col7,
'N' col8,
'Y' col9,
'N' col10,
--Local variables
(case when (trunc(nvl(qq.start_date_active,sysdate)) between l_cur_year_from and l_cur_year_to) and
( trunc(nvl(qq.end_date_active,l_cur_year_to)) >= trunc(l_cur_year_to) ) then 'TopUp'
when (trunc(qq.start_date_active) between l_next_year_from and l_next_year_to) and
( trunc(nvl(qq.end_date_active,l_next_year_to)) >= l_next_year_to) then 'Main'
when (trunc(qq.start_date_active) between l_last_year_from and l_last_year_to) and
( trunc(nvl(qq.end_date_active,l_last_year_to)) >= l_last_year_to ) then 'EOS Return'
end )col18,
--Local variables
(case when (trunc(qq.start_date_active) between l_next_year_from and l_next_year_to) and
( trunc(nvl(qq.end_date_active,l_next_year_to)) >= l_cur_year_to ) then 'N'
else
'Y' end ) col21
FROM qp.qp_list_headers_b qlhb,
qp.qp_list_headers_tl qlht,
qp.qp_qualifiers qq,
qp_modifier_summary_v qs,
hz_cust_site_uses_all su,
hz_cust_acct_sites_all sa,
hz_cust_accounts hca
WHERE 1=1
and qlhb.LIST_TYPE_CODE = 'DLT'
and nvl(qlhb.active_flag,'Y') = 'Y'
and qlhb.list_header_id = qlht.list_header_id
AND qq.list_header_id = qlhb.list_header_id
and qq.list_type_code = qlhb.LIST_TYPE_CODE
and qq.QUALIFIER_CONTEXT = 'CUSTOMER'
and qs.list_header_id = qlhb.list_header_id
and qs.LIST_LINE_TYPE_CODE = 'DIS'
and su.site_use_id = qq.qualifier_attr_value --1064
AND su.cust_acct_site_id = sa.cust_acct_site_id
AND sa.cust_account_id = hca.cust_account_id ]';
--call Dynamic SQL function
l_cursor := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(l_cursor, p_QUERY , DBMS_SQL.NATIVE);
l_rows := DBMS_SQL.EXECUTE(l_cursor);
Any help will be much appreciated.
iI guess I should use DBMS_SQL.BIND_VARIABLE to bind all variables seperately so not to mess with query1) What is the error you get?
2) If you use bind variables inside a query, you should prefix them with colons, so use :l_cur_year_from etc.
3) Why are you using dbms_sql instead of native dynamic sql and/or ref-cursors?
Toon -
Trying to form complex query - need help
I have a fairly complex query that I need to join the results of to show actual and goal by day. The actuals are an aggregation of records that get put in every day, while the targets are a single entry in range format indicating an active range for which the target applies. I'm working on a query that will put things together by month and I'm running into a snag. Can someone please point out where appropriate naming needs to go to get this to come together?
This one works:
(select DATE_INDEX, SUM(LDS) as TTLLDS, SUM(TONS) as TTLTONS from
(select DATE_INDEX, VEH_LOC, SUM(LDS) as LDS, SUM(WT) as TONS from
(select c.DATE_INDEX, c.VEH_LOC, COUNT(j.LOAD_JOB_ID) as LDS,
CASE WHEN SUM(w.SPOT_WEIGHT) = 0 THEN SUM(j.MAN_SPOT_WT)
ELSE SUM(w.SPOT_WEIGHT)
END as WT
from TC c, TC_LOAD_JOBS j, LOAD_RATES r, SPOT_WEIGHTS w
where c.TC_ID = j.TC_ID and j.LOAD_RATE_ID = r.LOAD_RATE_ID
and c.DATE_INDEX = w.DATE_INDEX and j.LOAD_RATE_ID = w.LOAD_RATE_ID
and c.VEH_LOC in (select ORG_ID from ORG_ENTITIES where MNG_ORG_ID = 200)
and c.DATE_INDEX between to_date('08/01/2010','MM/DD/YYYY') and to_date('07/31/2011','MM/DD/YYYY')
group by c.DATE_INDEX, c.VEH_LOC
union
select c.DATE_INDEX, c.VEH_LOC, COUNT(j.JOB_ID) as LDS,
DECODE(SUM(j.AVG_SPOT_WEIGHT),0,SUM(r.BID_TONS),SUM(j.AVG_SPOT_WEIGHT)) as WT
from TC_3RDPARTY c, TC_3RDPARTY_JOBS j, LOAD_RATES r
where c.TC_ID = j.TC_ID and j.LOAD_RATE_ID = r.LOAD_RATE_ID
and c.DATE_INDEX between to_date('08/01/2010','MM/DD/YYYY') and to_date('07/31/2011','MM/DD/YYYY')
and j.FACTORY_ID in (select ORG_ID from ORG_ENTITIES where MNG_ORG_ID = 200)
group by c.DATE_INDEX, c.VEH_LOC)
group by DATE_INDEX, VEH_LOC)
group by DATE_INDEX)Now I need to add in the following query:
select (u.MACH_TPH_D+u.MACH_TPH_N)/2 as MTPH_TGT, (u.LABOR_TPH_D+u.LABOR_TPH_N)/2 as LTPH_TGT
from UTIL_TARGET_LOADERS u
where u.ORG_ID in (select ORG_ID from ORG_ENTITIES where MNG_ORG_ID = 200)The join needs to be based on VEH_LOC and DAY in the form:
... WHERE u.ORG_ID = x.VEH_LOC
AND x.DATE_INDEX between u.START_DATE and NVL(u.END_DATE,sysdate)I had one that worked just fine when only one entity was involved; the complication arises in that this is a division-level report so I have to individually resolve the subordinates and their goals before I can aggregate. This is one of two queries I need to tie together using a WITH clause so I can pivot the whole thing and present it in month-by-month fashion. When I try to tie it together like the query below, I get: invalid relational operator.
select ttls.DATE_INDEX, SUM(ttls.LDS) as TTLLDS, SUM(ttls.TONS) as TTLTONS, u.TARGET_LTPH, u.TARGET_MTPH
from UTIL_TARGET_LOADERS u,
(select DATE_INDEX, VEH_LOC, SUM(LDS) as LDS, SUM(WT) as TONS from
(select c.DATE_INDEX, c.VEH_LOC, COUNT(j.LOAD_JOB_ID) as LDS,
CASE WHEN SUM(w.SPOT_WEIGHT) = 0 THEN SUM(j.MAN_SPOT_WT)
ELSE SUM(w.SPOT_WEIGHT)
END as WT
from TC c, TC_LOAD_JOBS j, LOAD_RATES r, SPOT_WEIGHTS w
where c.TC_ID = j.TC_ID and j.LOAD_RATE_ID = r.LOAD_RATE_ID
and c.DATE_INDEX = w.DATE_INDEX and j.LOAD_RATE_ID = w.LOAD_RATE_ID
and c.VEH_LOC in (select ORG_ID from ORG_ENTITIES where MNG_ORG_ID = 200)
and c.DATE_INDEX between to_date('08/01/2010','MM/DD/YYYY') and to_date('07/31/2011','MM/DD/YYYY')
group by c.DATE_INDEX, c.VEH_LOC
union
select c.DATE_INDEX, c.VEH_LOC, COUNT(j.JOB_ID) as LDS,
DECODE(SUM(j.AVG_SPOT_WEIGHT),0,SUM(r.BID_TONS),SUM(j.AVG_SPOT_WEIGHT)) as WT
from TC_3RDPARTY c, TC_3RDPARTY_JOBS j, LOAD_RATES r
where c.TC_ID = j.TC_ID and j.LOAD_RATE_ID = r.LOAD_RATE_ID
and c.DATE_INDEX between to_date('08/01/2010','MM/DD/YYYY') and to_date('07/31/2011','MM/DD/YYYY')
and j.FACTORY_ID in (select ORG_ID from ORG_ENTITIES where MNG_ORG_ID = 200)
group by c.DATE_INDEX, c.VEH_LOC)
group by DATE_INDEX, VEH_LOC) ttls
where ttls.DATE_INDEX beween u.START_DATE and NVL(u.END_DATE,sysdate)
and ttls.VEH_LOC = u.ORG_ID
group by ttls.DATE_INDEXI know this is a nested mess, as it has to grab the production from two tables for a range of VEH_LOC values and sum and aggregate by day and VEH_LOC, then I have to try and match that to the targets based on VEH_LOC and day. My final query is to aggregate the whole mess of sums and averages by month.
I'd appreciate it if someone can point me in the right direction.Figured it out.
select ttl.DATE_INDEX, SUM(ttl.LDS) as TTLLDS, SUM(ttl.TONS) as TTLTONS,
AVG((u.MACH_TPH_D+u.MACH_TPH_N)/2) as MTPH_TGT,
AVG((u.LABOR_TPH_D+u.LABOR_TPH_N)/2) as LTPH_TGT
from
(select DATE_INDEX, VEH_LOC, SUM(LDS) as LDS, SUM(WT) as TONS from
(select c.DATE_INDEX, c.VEH_LOC, COUNT(j.LOAD_JOB_ID) as LDS,
CASE WHEN SUM(w.SPOT_WEIGHT) = 0 THEN SUM(j.MAN_SPOT_WT)
ELSE SUM(w.SPOT_WEIGHT)
END as WT
from TC c, TC_LOAD_JOBS j, LOAD_RATES r, SPOT_WEIGHTS w
where c.TC_ID = j.TC_ID and j.LOAD_RATE_ID = r.LOAD_RATE_ID
and c.DATE_INDEX = w.DATE_INDEX and j.LOAD_RATE_ID = w.LOAD_RATE_ID
and c.VEH_LOC in (select ORG_ID from ORG_ENTITIES where MNG_ORG_ID = 200)
and c.DATE_INDEX between to_date('08/01/2010','MM/DD/YYYY') and to_date('07/31/2011','MM/DD/YYYY')
group by c.DATE_INDEX, c.VEH_LOC
union
select c.DATE_INDEX, c.VEH_LOC, COUNT(j.JOB_ID) as LDS,
DECODE(SUM(j.AVG_SPOT_WEIGHT),0,SUM(r.BID_TONS),SUM(j.AVG_SPOT_WEIGHT)) as WT
from TC_3RDPARTY c, TC_3RDPARTY_JOBS j, LOAD_RATES r
where c.TC_ID = j.TC_ID and j.LOAD_RATE_ID = r.LOAD_RATE_ID
and c.DATE_INDEX between to_date('08/01/2010','MM/DD/YYYY') and to_date('07/31/2011','MM/DD/YYYY')
and j.FACTORY_ID in (select ORG_ID from ORG_ENTITIES where MNG_ORG_ID = 200)
group by c.DATE_INDEX, c.VEH_LOC)
group by DATE_INDEX, VEH_LOC) ttl, UTIL_TARGET_LOADERS u
where u.ORG_ID = ttl.VEH_LOC
and ttl.DATE_INDEX between u.START_DATE and NVL(U.END_DATE,sysdate)
group by ttl.DATE_INDEX, (u.LABOR_TPH_D+u.LABOR_TPH_N)/2
Maybe you are looking for
-
Dear SAP Guru's, I have a query my user needs to prepare the report in that report he needs to identify actaul quantity and free quantity. conditions are: 1. in free goods/ sales promotion scenario business offerd some fre
-
Hi All Iam designing a PLD for Query Report *In the PLD iam designing the Report for Open Purchase Order Status Report Query run fine but the problem came under designing the Document.My Query as above. My Client have requirement not repeat the PO N
-
How to handle field symbols internal table values?
HI all, I declared field string as below.The below code is working fine. Data : ITAB TYPE STANDARD TABLE OF YAPOPLN, (Custom table). wa_itab like line of ITAB. field-symbol : <fs> type ITAB. ASSIGN PARAM TO <FS> LOOP AT <FS> INTO
-
I cannot install Photoshop Elements 2.0 on the iMac I got last year. I have been using the PSElements on my PC OK. What should I do besides getting the latest PSElements?
-
My library is on an old (dead) computer - can I add somehow without deleting e
Probably a stupid question-here goes....my library was created on an old, now dead computer. Is there any way to add to my ipod without losing everything on it?