Select Statement Hangs often
Hello ,
I have very strange issue, Any select statement on few tables takes very long time( in fact it hangs) often but the same SQL runs in a second all other times in the same database. Please note that it is a simple select statement without any 'for update' clause.
After recycling the database, the select statement runs faster but this situation comes back after couple of days on the same set of tables.
We are using 9i release 2.
Can you please advise how to go about solving this type of issue.
Thanks.
438628, Robert is correct in that the board would need to see an explain plan to have any chance of narrowing the problem down. If bind variable peeking is involved the plan may not match what Oracle is actually doing to solve the query.
When the problem occurs try looking in v$plan_table and see if the plan matches the explain plan output. A difference would be a clue that a reparse of sometype is being done so the plan could be different for each execution. The presence of child cursors would also point to something causing reparses.
Do any of the columns for this table involved in the where clause has histograms on them? What is the value of the spfile/init.ora parameter cursor_sharing?
If cursor_sharing is EXACT then bind variable peeking should not be the problem. If the parameter is SIMILAR or FORCE then it could be. On 9.2 I believe there is a bug that causes a reparse for every execution when SIMILAR is used so evey execution could be a different plan.
To check for skewed data just count the values in the column and then count by value. If the max(value_count) / count(*) is greater than a small percentage of the data then the column is skewed. The worse the skew the more likely that a plan chosen for a distinctive value is not a good plan for a non-distinctive value.
HTH -- Mark D Powell --
Similar Messages
-
SELECT statements hang (e.g., SELECT * FROM <table>). My connection is fine but when I attempt to execute a SQL statement (F9) it hangs; the progress bar just goes back and forth with no error reported.
Any ideas???P.S. I get the following error when selecting a database connection from Tools >> SQL Worksheet:
java.lang.NoClassDefFoundError: oracle/bali/xml/dom/buffer/util/EncodingUtils
at oracle.jdeveloper.model.JavaEditionAddin$2.recognize(JavaEditionAddin.java:356)
at oracle.ide.model.NodeFactory.findOrCreateUsingDefault(NodeFactory.java:159)
at oracle.ide.model.NodeFactory.findOrCreate(NodeFactory.java:89)
at oracle.ide.editor.RecentFile.getNode(RecentFile.java:168)
at oracle.ide.editor.RecentFile._getNode(RecentFile.java:217)
at oracle.ide.editor.RecentFile.getContext(RecentFile.java:46)
at oracle.ideimpl.editor.RecentFilesLRU.removeOldest(RecentFilesLRU.java:94)
at oracle.ideimpl.editor.RecentFilesLRU.adjustSize(RecentFilesLRU.java:76)
at oracle.ideimpl.editor.RecentFilesLRU.raiseContextInLRUList(RecentFilesLRU.java:157)
at oracle.ideimpl.editor.EditorManagerImpl.raiseContextInLRUList(EditorManagerImpl.java:1705)
at oracle.ideimpl.editor.TabGroup.setCurrentTabGroupState(TabGroup.java:1316)
at oracle.ideimpl.editor.TabGroup.activateEditor(TabGroup.java:639)
at oracle.ideimpl.editor.EditorManagerImpl.createEditor(EditorManagerImpl.java:1292)
at oracle.ideimpl.editor.EditorManagerImpl.createEditor(EditorManagerImpl.java:1215)
at oracle.ideimpl.editor.EditorManagerImpl.openEditor(EditorManagerImpl.java:1150)
at oracle.dbtools.sqlworksheet.sqlview.SqlEditorWizard.invoke(SqlEditorWizard.java:128)
at oracle.ide.wizard.WizardManager.invokeWizard(WizardManager.java:310)
at oracle.dbtools.sqlworksheet.sqlview.SqlEditorAddin$1.actionPerformed(SqlEditorAddin.java:151)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.AbstractButton.doClick(AbstractButton.java:302)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1000)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1041)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Right-clicking on a database connection (or double-clicking) connects fine without error. -
Only select statements work (update/insert hang)
Hi, I am running CF MX version 7,0,2,142559 Standard Edition
and ColdFusion is hanging everytime I attempt an insert or update
statement again Oracle 8i and 9i using the jdbc thin driver and an
odbc socket driver.
Select statements work fine. I have tried everything I could
think of and I get the same results. All rights are given to the
datasource and the user. I can do insert and update statement via
another application (Toad) with the same Oracle user.
Any suggestions??? I don't see any hot fixes for this but
that doesn't mean one doesn't exist.
Also, many times it causes the system cpu utlization to stick
at 100% until I restart ColdFusion.
Thanks for any help.Hi,
I had similar results on Oracle 10G while using cfmx 7.02. I
actually updated the macromedia_drivers.jar from the coldfusion
support site.
http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=42dcb10a
An update to the datadirect JDBC drivers. Try that. If not,
make sure you have the latest JDBC drivers from Oracle. Since
previous versions would make the update/insert;s hang. -
Hi,
we are running a query with a big dunamic select statement from VB code using ADO command object. When Execute method is called system hangs and control won't return back to the application. it seems to be that there is some type limitation on Query string length. Please tell us if there is any?
we are running Oracle 8.1.7 Server on Windows 200 Server and connecting from a W2K professional, ADO 2.6 and Oracle OLEDB 8.1.7.1 OLEDB Driver.
Sample code:
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
Set cmd = New Command
With cmd
.CommandText = ' some text with more than 2500 characters
.CommandType = adCmdText
Set rs = .Execute
End With
when i debug using VB6 and when .Execute line is called system hangs or return a message method <<somemethod> of <<some class name>> failed error.
Any help is appreciated.
Thanks,
AnilA stored procedure would only slow you down here if it was poorly written. I suspect you want to use the translate function. I'm cutting & pasting examples from the documentation-- a search at tahiti.oracle.com will give you all the info you'll need.
Examples
The following statement translates a license number. All letters 'ABC...Z' are translated to 'X' and all digits '012 . . . 9' are translated to '9':
SELECT TRANSLATE('2KRW229',
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'9999999999XXXXXXXXXXXXXXXXXXXXXXXXXX') "License"
FROM DUAL;
License
9XXX999
The following statement returns a license number with the characters removed and the digits remaining:
SELECT TRANSLATE('2KRW229',
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', '0123456789')
"Translate example"
FROM DUAL;
Translate example
2229
Also, LIKE '%<string>%' is going to be rather expensive simply because it has to compare the entire string and because it forces full table scans, rather than using indexes. You could speed this sort of query up by using interMedia Text (Oracle Text now in 9i). If you can eliminate one of the '%' options, you could also improve things.
My guess is that your stored procedure is inefficient and that's causing the problem-- 5k rows per table should be pretty trivial.
If you post your query over on the PL/SQL forum, there are better performance tuners than I that might have more hints for you. To get really good advice, though, you'lllikely have to get at least the execution plan for this statement and may need to do some profiling to identify the problem areas.
Justin -
Using TRIM function in select statement
Hi All,
I'm using the TRIM function in my select statement to eliminate the white spaces.
But while using in select the TRIM function is not working in SQL*PLUS client(The query returns the white spaces also)
Kindly provide some pointers regarding the issue.........
I want to get only the data without the spaces in select statement
Regards,
MohanHi, Mohan,
SQL*Plus always pads columns to make them line up nicely.
If you have a column declared as VARCHAR2 (20), then SQL*Plus will normally display 20 characters for that column, even in the maximum actual length is, say, 5 (or even if the column always happens to be NULL).
If you want the output to include only the actual data, without the padding that SQL*Plus adds, then concatenate all the columns into one big string column.
People often do something like the following to generate a CSV file, with no exta spaces:
SELECT TO_CHAR (empno)
|| ',' || ename
|| ',' || job
|| ',' || TO_CHAR (deptno)
|| ',' || TO_CHAR (hiredate, 'DD-Mon-YYYY') AS all_data
FROM scott.emp; -
Sql statement hanging in prod. fast in dev.
Hi,
Sql statement is hanging in production.
In development it is executing in 2 secs.
From explainplan , noticed that taking different indexes.
I have posted the staement and explain plan (prod and dev) below.
Statement:
SELECT
REP_V_SERVICE_REQUEST.SERVICE_REQ_ID,
REP_V_ACTIVITY.EXTERNAL_REF,
REP_V_ACTIVITY.VENUS_PROBLEM_START,
REP_V_ACTIVITY.VENUS_ALERT_ISSUED,
REP_V_ACTIVITY.VENUS_NOTIFIED,
REP_V_ACTIVITY.ACTIVITY_ID,
REP_V_ACTIVITY.CREATED_BY_WORKGROUP,
REP_V_ACTIVITY.ABSTRACT,
REP_V_ACTIVITY.TIME_TO_VENUS_ALERT,
REP_V_ACTIVITY.TIME_TO_VENUS_ISSUE,
REP_V_ACTIVITY.TIME_TO_VENUS_NOTIFIED,
REP_V_SERVICE_REQUEST.TYPE,
REP_V_SERVICE_REQUEST.SUB_TYPE,
REP_V_SERVICE_REQUEST.CLASSIFICATION_TYPE,
REP_V_SERVICE_REQUEST.CLASSIFICATION_SUB_TYPE,
( REP_V_SERVICE_REQUEST.TIME_OPENED ),
REP_V_SERVICE_REQUEST.CREATED_BY_WORKGROUP,
REP_V_ACTIVITY.VENUS_SENT_TO_SDN,
SR_RESOLVER_WG.WORKGROUP
FROM
REP_V_SERVICE_REQUEST,
REP_V_ACTIVITY,
REP_V_WORKGROUP SR_RESOLVER_WG
WHERE
( SR_RESOLVER_WG.WORKGROUP_ID=REP_V_SERVICE_REQUEST.RESOLUTION_GROUP_ID )
AND ( REP_V_ACTIVITY.SERVICE_REQUEST_ROW_ID=REP_V_SERVICE_REQUEST.SERVICE_REQUEST_ROW_ID )
AND (
REP_V_ACTIVITY.PLANNED_START_TIME BETWEEN '01-JAn-2006' AND '19-Jun-2006'
AND REP_V_ACTIVITY.VENUS_PROBLEM_STATUS NOT IN ('Information', 'Planned')
AND REP_V_ACTIVITY.VENUS_ALERT_STATUS != 'Withdrawn'
AND REP_V_ACTIVITY.CREATED_BY_WORKGROUP LIKE '%SSHD%'
AND REP_V_ACTIVITY.STATUS != 'Cancelled'
AND REP_V_ACTIVITY.CREATED_BY_WORKGROUP NOT LIKE 'GLO_SSHD_MTC'
Exp. plan(prod)
24 SELECT STATEMENT
23 NESTED LOOPS (OUTER)
21 NESTED LOOPS (OUTER)
19 NESTED LOOPS
16 NESTED LOOPS
13 NESTED LOOPS
10 NESTED LOOPS (OUTER)
8 NESTED LOOPS
5 NESTED LOOPS
2 TABLE ACCESS (BY INDEX ROWID), S_ORG_EXT (SIEBEL)
1 INDEX (FULL SCAN), S_ORG_EXT_F13 (SIEBEL)
4 TABLE ACCESS (BY INDEX ROWID), S_BU (SIEBEL)
3 INDEX (UNIQUE SCAN), S_BU_P1 (SIEBEL)
7 TABLE ACCESS (BY INDEX ROWID), S_SRV_REQ (SIEBEL)
6 INDEX (RANGE SCAN), S_SRV_REQ_U2 (SIEBEL)
9 INDEX (UNIQUE SCAN), S_SRV_REGN_P1 (SIEBEL)
12 TABLE ACCESS (BY INDEX ROWID), SERVICE_REQUEST (CRMREP_REP)
11 INDEX (UNIQUE SCAN), PK_SR (CRMREP_REP)
15 TABLE ACCESS (BY INDEX ROWID), S_EVT_ACT (SIEBEL)
14 INDEX (RANGE SCAN), S_EVT_ACT_F14 (SIEBEL)
18 TABLE ACCESS (BY INDEX ROWID), ACTIVITY (CRMREP_REP)
17 INDEX (UNIQUE SCAN), PK_A (CRMREP_REP)
20 INDEX (RANGE SCAN), S_EVT_MAIL_U1 (SIEBEL)
22 INDEX (RANGE SCAN), S_EVT_ACT_X_U1 (SIEBEL
Exp plan(Dev):
24 SELECT STATEMENT
23 NESTED LOOPS (OUTER)
21 NESTED LOOPS (OUTER)
19 NESTED LOOPS
16 NESTED LOOPS
13 NESTED LOOPS (OUTER)
11 NESTED LOOPS
8 NESTED LOOPS
5 NESTED LOOPS
2 TABLE ACCESS (BY INDEX ROWID), S_EVT_ACT (SIEBEL)
1 INDEX (RANGE SCAN), S_EVT_ACT_M8 (SIEBEL)
4 TABLE ACCESS (BY INDEX ROWID), S_SRV_REQ (SIEBEL)
3 INDEX (UNIQUE SCAN), S_SRV_REQ_P1 (SIEBEL)
7 TABLE ACCESS (BY INDEX ROWID), S_ORG_EXT (SIEBEL)
6 INDEX (UNIQUE SCAN), S_ORG_EXT_U3 (SIEBEL)
10 TABLE ACCESS (BY INDEX ROWID), S_BU (SIEBEL)
9 INDEX (UNIQUE SCAN), S_BU_P1 (SIEBEL)
12 INDEX (UNIQUE SCAN), S_SRV_REGN_P1 (SIEBEL)
15 TABLE ACCESS (BY INDEX ROWID), SERVICE_REQUEST (REPORT)
14 INDEX (UNIQUE SCAN), PK_SR (REPORT)
18 TABLE ACCESS (BY INDEX ROWID), ACTIVITY (REPORT)
17 INDEX (UNIQUE SCAN), PK_A (REPORT)
20 INDEX (RANGE SCAN), S_EVT_MAIL_U1 (SIEBEL)
22 INDEX (RANGE SCAN), S_EVT_ACT_X_U1 (SIEBEL)
I checked the v$session_wait while it is hanging,
It is waiting for table s_evt_act (prod. 1.6 crores,dev. 1 crore)
In development it is accessing S_EVT_ACT_M8 (SINGLE COLUMN)index,in production
it is accessing S_EVT_ACT_F14(COMBN. TWO COLUMNS BUT DIFFERENT FROM PRODUCTION).
Thanks,
kumar.This query is not executing for last 5 to 6 months.
I am new to this issue.
pls find the outof v$session_event for this session.
It is waiting for db file sequential read and the wait is keep on increasing.
SID EVENT TOTAL_WAITS TOTAL_TIMEOUTS TIME_WAITED AVERAGE_WAIT MAX_WAIT TIME_WAITED_MICRO
43 db file sequential read 141459 0 130565 1 66 1305647401
43 db file scattered read 77437 0 54259 1 466 542587342
43 direct path write 1222 0 867 1 26 8671937
43 buffer busy waits 570 0 318 1 4 3175286
43 SQL*Net message to client 339 0 0 0 0 866
43 SQL*Net message from client 338 0 84716 251 32623 847156015
43 latch free 14 12 6 0 2 59905
43 direct path read 6 0 1 0 0 12290
43 log file sync 1 0 0 0 0 2268 -
Concat java variable to a MySql select statement and exeucte
Hi,
I am trying to append a variable to a MySql select statement.
Overview: I need to retrieve data from a MySql database with a java variable as a reference and select the data in the database based on that variable.
CODE THAT I CURRENTLY HAVE:
// Declare variables
Connection conn = null;
Statement st = null;
Resultset rs2 = null;
String st2 = null;
String keyid = null;
// Connect to database
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://" + mysql_host + ":3306/" + mysql_database, mysql_login, mysql_password);
st = conn.createStatement();
// Select data in Database with hanging equal sign
st2 = ("SELECT * FROM table WHERE keyid= ");
// Append keyid to hanging equal sign of select statement
rs2 = st.executeQuery(st2 + keyid);
}This is not working when I try to display the data.What is not working about it? Is there an error message? Stack Trace?
Where do you get the value of keyId from?
I would suggest that you use a prepared statement rather than building up a sql string like this. It prevents sql injection attacks
// Declare variables
Connection conn = null;
PreparedStatement stmt = null;
Resultset rs2 = null;
String sql= null;
String keyid = null;
// Connect to database
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://" + mysql_host + ":3306/" + mysql_database, mysql_login, mysql_password);
// Select data in Database with place holder for parameter
sql = "SELECT * FROM table WHERE keyid= ?";
// prepare the statement
stmt = conn.prepareStatement(sql);
// set the value of key id to use with the query
stmt.setString(1, keyId);
// run the query
rs2 = st.executeQuery();
catch (Exception e){
System.out.println("An error occurred " + e.getMessage());
e.printStackTrace();
finally{
if (rs2 != null) try { rs2.close(); } catch(SQLException ex){}
if (stmt != null) try { stmt.close(); } catch(SQLException ex){}
if (conn != null) try { con.close(); } catch(SQLException ex){}
} -
Update with a select statement
hi experts,
I need some help again.. :)
I have an insert query here with a select statement.. Juz wondering how to do it in update?
insert into newsmail_recipient
(IP_RECIPIENTID,NF_LISTID,NF_STATUSID,D_CREATED,D_MODIFIED,C_NAME,C_EMAIL,USER_ID,NEWSMAIL_ID)
select newsmail_recipientid_seq.nextval
, liste
, 1
, sysdate
, sysdate
, null
, null
, ru.nf_userid
, null
from roleuser ru, unit u, userinfo ui
where u.ip_unitid = ru.nf_unitid
and u.ip_unitid = unit_id
and ui.ip_userid = ru.nf_userid
and ui.nf_statusid = 1
and n_internal = 0
and ui.ip_userid not in (select user_id
from newsmail_recipient
where user_id = ui.ip_userid
and nf_listid = liste
and nf_statusid = 1);let me know your thoughts.
Regards,
jpHi,
924864 wrote:
... I have an insert query here with a select statement.. Juz wondering how to do it in update?How to do what, exactly?
MERGE can UPDATE existing rows, and INSERT new rows at the same time. In a MERGE statement, you give a table or a sub-query in the USING clause, and define how rows from that result set match rows in your destination table. If rows match, then you can UPDATE the matching row with values from the sub-query.
Very often, MERGE is easier to use, and perhaps more efficient, than UPDATE just for changing existing rows. That is, while MERGE can do both INSERT and UPDATE, it doesn't have to . You can tell MERGE just to do one or the other if you wish.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
Since you're asking about a DML statement, such as UPDATE, the sample data will be the contents of the table(s) before the DML, and the results will be state of the changed table(s) when everything is finished.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
Select Query Hangs / No DB Locks / Query Plan is good
I have below query in application which hangs ( Only sometimes ) and there are some session which also try to insert data into this tables also starts getting hanged.
SELECT DISTINCT F2 || ' - ' || F3 || ' - ' || F4
FROM Table1
WHERE F4 = 6160
AND F1|| F2|| F3 NOT IN (
SELECT F2|| F3 || F4
FROM Table2
WHERE F1 = 181)
F2 - varchar(4)
F3- varchar(100)
F4- varchar(20)
F1,F1 are NUMBER
Table1 has one unique index comprising all fields in ORDER F1,F2, X,F3, F4,Y - X,Y are some different field.
Table2 has one unique index comprising all fields in ORDER F1,F3, F4,F2 are some different field.
Below are facts from DBA ----
1- Session Query Plan was excellent -
2 - No tables were locked in DB
3 - Statistics on this table Table1 was calculated on Feb, 2008 and shows 8 millions rows but actual current row count is 13 million. DBA says sometime analyzing statistics again may cause poor query performance.
4- There were 8 session in DB, 1 was for above select statement and other 7 were trying to insert data into above table.
Can you please advise what could else be verified to root cause issue as it has been hanging many times - hence causing other session to hang ?
Many ThanksCan you clarify exactly what the DBA meant by "No tables were locked in DB"? What was the exact query that was used to determine this? Was it hitting V$LOCK (GV$LOCK in a RAC system)? Or the DBA_BLOCKERS and DBA_WAITERS tables? Or something else? The specific query here is important because there is a world of difference between a row-level lock and a table-level lock. Of course, locks would never prevent a SELECT statement from running, but it could cause problems for the INSERT statements.
I strongly concur with Old DBA's suggestion about refactoring the query to not do the concatenation in the NOT IN clause.
Are the F4 = 6160 and F1 = 181 conditions really using hard-coded numeric literals? Or are these bind variables? Is the data in F1 or F4 skewed-- that is, are there certain values that are more likely than other values?
How many rows would you expect to be in Table1 with an F4 value of 6160? How many rows in Table2 with a F1 value of 181?
Justin -
Use of cursors insted of select statements
could any one please explain what is the advantage of using cursors instead of simple select statements
thanks
sibyA benefit to using an explicit cursor rather than a select statement, is for the NO_DATA_FOUND exception. Its kind of like a free IF statment. IF no data is found, then stop.
if you write a select statement, and no data is returned, you SHOULD code for the NO_DATA_FOUND exception. Often people say, "i'll ALWAYS get a row returned". but you should always cover your code "just in case". so you must code an exception...
declare
v_var varchar2(1);
procedure do_something(p_parm varchar2) is
begin
null;
end do_something;
procedure log_error is
begin
null;
end log_error;
begin <<main>>
do_something('x');
begin <<selectblock>>
select dummy
into v_var
from dual
where dummy = 'a';
do_something(v_var);
exception
when no_data_found then
log_error;
end selectblock;
do_something (v_var||'abc');
end main;
if you use an explicit cursor instead, you don't need to code for the NO_DATA_FOUND. If an explicit cursor opens and finds no rows, there are simply no rows. of course, you don't need a loop if you expect only 1 row returned under normal circumstances.
BTW, don' forget that SQL%ROWCOUNT and your_cursor%ROWCOUNT are not initialized. There is a null, until a row is successfully fetched. therefore if no rows are returned at all, %ROWCOUNT is NULL.
declare
v_var varchar2(1);
cursor my_cur is
select dummy
from dual
where dummy = 'a';
procedure do_something(p_parm varchar2) is
begin
null;
end do_something;
procedure log_error is
begin
null;
end log_error;
begin << main>>
for cur_rec in my_cur loop
dbms_output.put_line('inside');
begin <<loop_block>>
if nvl(my_cur%rowcount,0) > 1 then
do_something(cur_rec.dummy);
else
log_error;
end if;
end loop_block;
end loop;
end main;
/ -
Convert sql select statement to oracle
Hi All,
Can anyone help me converting this Sql select statement to oracle ....
-----------------------------------------Query--------------------------------------------------------------
select emp_master.emp_code ,
emp_master.dept_cd ,
attendance_master.daily_attn_code ,
attendance_master.linked_column ,
case when location.payroll_status <> 'N' and eDocsNetEmployeesLeave.StartDate < dateadd(mm, 1 , convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01'))
then
dateadd(mm, 1 , convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01'))
when eDocsNetEmployeesLeave.StartDate < convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01')
then convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01') else eDocsNetEmployeesLeaveDetails.StartDate
end ,
eDocsNetEmployeesLeaveDetails.NoOfDays,
case when eDocsNetEmployeesLeave.StartDate > location.next_pay_date
then convert(datetime , convert(varchar, dateadd(ss,-1, dateadd(mm, 1, convert(datetime , datename(yy,eDocsNetEmployeesLeave.StartDate)+ '/' + datename(mm,eDocsNetEmployeesLeave.StartDate)+ '/01') )),106) )
else
case when location.payroll_status <> 'N'
then dateadd(mm,1,location.next_pay_date)
else location.next_pay_date
end
end as PaymentDate ,
isnull(grade_master.leave_type,'C') ,
eDocsNetEmployeesLeave.StartDate ,
eDocsNetEmployeesLeaveDetails.LeaveType
from eDocsNetEmployeesLeave ,
eDocsNetEmployeesLeaveDetails ,
eDocsNetLeaveTypes ,
emp_master ,
grade_master ,
attendance_master ,
location
where eDocsNetEmployeesLeaveDetails.RequestID = eDocsNetEmployeesLeave.RequestID and
eDocsNetEmployeesLeave.EmployeeID = emp_master.emp_code and
eDocsNetEmployeesLeaveDetails.LeaveType = eDocsNetLeaveTypes.LeaveTypeID and
eDocsNetLeaveTypes.loc_cd = emp_master.loc_cd and
location.loc_cd = emp_master.loc_cd and
attendance_master.loc_cd = emp_master.loc_cd and
attendance_master.linked_column = eDocsNetLeaveTypes.LinkedAttendance and
grade_master.loc_cd = emp_master.loc_cd and
grade_master.grade_cd = emp_master.grade_cd and
eDocsNetEmployeesLeaveDetails.RequestID = @RequestID
order by eDocsNetEmployeesLeaveDetails.StartDate
Thanks in Advance
SmileySeems like you want to convert a SQL statement from the ??? dialect to the Oracle dialect. *(It would be useful to indicate the non-ANSI standard SQL you are starting with.)
Part of the problem is that you use several date related functions. Some are unnecessary in Oracle and some need to translated into Oracle functions as found in the Functions section (chapter 5) of the SQL Reference manual at http://www.oracle.com/pls/db102/homepage
Note that columns and expressions of type 'date' in ORacle always contain all of "yyyy mm dd hh mi ss" and you need to format and trauncate as necessary.
Also note that '09-JAN-31' is NOT an Oracle date, but rather a character representation of a date which must be converted to/from a date expression. You will often need to use the to_date() and to_char() functions with a format mask as the second parameter. This is also descreibed in the first 2 chapters of the SQL Reference manual. -
Error "SELECT statement includes a reserved word"
Dear Sir,
I am developing Ms Access 2010 and XP is the operating system.
I have placed a combobox on a form, but when I tired to update new string value in the same combobox, it generates an error "The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is
incorrect." .
I have debuged "Not In List" event and find this error generates soon after completing the "Not In List" event. I tried to find out any help on the internet but failed.
I shall be ever grateful if some one could help this regards.
KazimI think you need to do some homework on how relational databases work.
The following is my short description of the database relational model, but I emphasise the word 'short'.
The subject is a complex one with a huge body of academic and technical literature, so I can only hope to touch upon the basic principles of the model:
"The database relational model was originally proposed by E F Codd in a paper in 1970 in the journal 'Communications
of the Association for Computing Machinery'. Since then there has been a vast amount of further theoretical work, and the relational model has shown itself to be a robust one.
Without going too deeply into the theoretical basis, which can be quite abstract, a relational database in essence models a part of the real world in terms of its entity types and the relationship types between them.
Note the inclusion of the word 'type' in both cases here.
While its almost always used in the former case, its often omitted in the latter case.
This is a little bit sloppy but not too important. When one talks about a 'relationship' it really refers to a relationship value.
As an example 'marriage' is a relationship type, but my being married to my wife Fiona is a relationship value, represented by our names on the marriage certificate, which is the physical equivalent of a row in a Marriages table with columns Husband
and Wife, each referencing the primary key of a table People.
This is a many-to-many relationship type (I've been married twice so would be in two rows, my first wife would also be in two rows as she remarried too).
It is resolved into two one-to-many relationship types, People to Marriages in each case, in one case via the Husband column in the other via the Wife column.
In a relational database tables model Entity Types.
In the above example People is an entity type, modelled by the People table.
Marriage is also an entity type, modelled by the Marriages table.
As we've seen it's also a relationship type. In fact a relationship type is just a special kind of entity type.
Each column in a table represents an attribute type of each entity type, so attribute types of People might be FirstName,
LastName, DateOfBirth etc. This table would also have a PersonID numeric column (usually an autonumber) as its primary key as names are not distinct.
Each row in a table represents one instance of the entity type, and the attributes of each instance are represented by values at column positions in the row.
This is the only way that data can be legitimately stored in a relational database.
It's important that there is no redundancy in the information content of the database.
This is achieved by the process of 'normalization'. Normalization is based on a set of 'normal form's ranging from First Normal Form (1NF) to Fifth Normal Form (5NF) and beyond, though the higher normal forms are of a rather
different nature and we need not concern ourselves unduly with them.
There is also a Boyce/Codd Normal Form (BCNF) which was inserted when it was found that the original Third Normal Form was deficient; it didn't cater satisfactorily for tables with two or more candidate keys where the keys were composite and overlapped,
i.e. Had a column in common. I won't go into the details of normalization here; you'll find it written up in plenty of places.
To see an example of redundancy and therefore a table which is not properly normalized take a look at the Customers table
in the sample Northwind database which comes with Access. You'll see that it includes City, State/Region and Country columns.
If you look at its data you'll see for instance that we are redundantly told twice that Boston is in Massachusetts, and that this is in the USA
twice. This is not just inefficient, it is dangerous as it leaves the table open to inconsistent data being entered.
There is nothing to stop somebody putting Boston in the Massachusetts in one row and Milwaukee
in another, or putting Milwaukee in the UK in one row and the USA in another.
To normalize the table it should be decomposed into Customers, Cities, Regions and Countries tables, each of the first three with a foreign key referencing the primary key of the next table up in the hierarchy."
In your case you say a book can have more than one publisher.
This is true if you regard the entity as the book as a single 'work', not as a title.
I have two copies of Jane Austen's Mansfield Park for instance, each by a different publisher.
It is a single 'work' however. I've no idea if anyone else has written a book called Mansfield Park, but there is no reason why not, so let's assume that one exists.
This is not the same 'work' as Jane Austen's book, so conceptually is a different entity of type Books, and would be represented by a separate row in a table Books.
In the above context there is a many-to-many relationship type between Books and Publishers.
There is only one way to model such a relationship type, which is by a table which resolves the relationship type into two one-to-many relationship types.
So the model would, diagrammatically be:
Books----<BookPublishers>----Publishers
Title is a non-key column of Books.
The same title may appear in different rows, as with our hypothetical Mansfield Park by another author.
The primary key of books is a numeric BookID, usually an autonumber.
The BookPublishers table would have foreign keys BookID and PublisherID referencing the primary keys of the two referenced tables.
It would also have columns representing any attributes of the relationship type between the book and the publisher.
The primary key of this table is a composite one of BookID and Publisher.
To record multiple editions of a book published by a publisher requires another table along the following lines:
BookEditions
....PublisherID
(FK)
....BookID
(FK)
....EditionNumber
....EditionDate
.....ISBN
In this table PublisherID and BookID are a composite foreign key referencing the primary key of BookPublishers.
Note that ISBN is a column in this table as it applies to each edition of a book.
In the language of the relational model it is said to be functionally determined by the key of BookEditions.
Hopefully my short stock description of the relational model above, and my brief description of how it applies to the reality
which you are attempting to model will give you an insight into how to build a database, but I would strongly recommend that you first do some background work on how the database relational model works and how to apply its principles in Access.
I'll leave you with my own four, not altogether serious but nevertheless valid, ground rules for designing a relational database:
1.
KISS (Keep it simple, stupid!).
2.
When in a hole the first thing to do is stop digging.
3.
Always take account of Murphy's Law: 'If something can go wrong, it will go wrong'
4.
Always follow the advice given by Richard Feynman to his students: 'Don't write it down until you understand it'.
Ken Sheridan, Stafford, England -
MacBook Pro suddenly really slow, hangs often
My MacBook Pro is about 2 years old. It had been slowing down and occasionally running out of memory, which I figured was due to the fact that my hard disk was kind of full (had about 100 Gig of space available, which I thought should be enough, but whatever). But in the past 2 days this has gotten really, really worse. It's almost unusable. It's running Snow Leopard.
It takes a full 5 mibutes to start.
When I open an application it takes really long to open, then evey few things I do it hangs for a couple of minutes with the rainbow wheel spinning. Occasionally an application completely stops responding, and has to be force quit.
This even happens if I have only one app open at a time.
What has changed recenttly:
• 2 weeks ago I switched from DSL to cable. I have a new cable modem and wireless router. There is some random software that Comcast sent me but I don't think it's even installed.Things were still running slow and frustrating but pasable after that.
• 5 days ago I bought a new Droid 3 cell phone, and installed The Missing Sync on my computer to sync music, photos and calendar. It still ran slow after that, but not crazy messed up like now. I don't remember if the speed seemed any worse -- I just know that it didn't hang often the way it does now.
• 2 days ago I bought a new MacBook Pro with a faster processor, runnign Lion. I started migration assistant, then realized it was going to take 14 hours and I had work to do, so I stopped the assistant. and decided to run it again later. I think it's since then things became a complete mess, and every day that passes seems worse.
• In the meantime, I may or may not have installed some software updates. I get update notices all the time, and generally install them right away without giving them much thought. In fact, now that I think of it, Firefox startded acting pretty slow after the last update (spinning wheel when opening new tabs, loading information, switching from one tab to the other), which I attributed to a buggy new release but it might be related. I don't know how long ago that was; I think about a week or two. There may have beensome OS udates too, I can't remember.
I did run migration assistant again late last night, after cleaning out my old hard disk (backing things up to DVDs and external drives) so it would have less data to transfer. But it transfered over everything, including old apps thatI don't need and don't know how to uninstall, and I am worried that I might have transeferred over whatever the problem was with the old computer. I can't easily test because the apps that I use every day (Microsoft Office 2008 and the Adobe Creative Suite CS4) don't run on Lion so I will have to buy upgrades for everythign before I can do any work on this computer, which is quite frustrating in itself but a different story. So I haven't been able to test whether my new laptop has the same problem; it does generally seem faster but not as much of a speed increase as I had hoped.
I ran disk utility on the old laptop, and it did find some directory issues, but I can't repair it because I don't have any discs to start up from. Why is it that Apple doesn't ship disks with its software? Granted, my new laptop runs a different operating system from the old one, but I didn't receive any system disks with it so I really don't have anything to start externally from if there ever are any problems.
I want to keep the old mac. I occasionally travel to countries where I don't feel comfortable bringing a new expensive computer, so I intend to use my old computer as a travel laptop and the new one as my primary work laptop in my home office. But that means that I don't want to have to throw out the old one, I need to get it working again.
(also, until I install the Microsoft and Adobe upgrades, I can't do any work on my new laptop and I have deadlines to meet that I will need to continue working on with the old laptop) (which, in fact, makes thisissue rather urgent -- I ned to keep working while it's being resolved)OK, so someine suggested I run AppleJack -- it did make some repairs and now Disk Utility doesn't see anything wrong with my directory, but still finds some permissions problems. Almost all of them seem to be in System/Library/CoreServices/Front Row.app. Says:
should be -rw-r--r--, they are lrw-r--r--
Do I need to fix these or can I leave as is? What is Front Row? Does it make any difference who has permissions on these if they are for a program I don't use?
Also:
stalling problems seem to have been resolved for now (I opened 3 different apps and they seemto work OK). But I still have a problem with the Microsoft Office applications -- I can't easily switch to/from Excel or Word from/to any other apps, I can't CTRL-TAB and select the app, I have to go to that app's window (means moving other windows around until I can see it) and click on it to switch to that app. It's doable but a nuisance. Can it be fixed?
Also - important:
Would the directory problems I had on my old hard disk have affected the information I ported over to the new laptop yesterday? Will I have the same problems on my new laptop? I can't check because I haven't downloaded the upgrades to Microsoft Office and to the Adobe CS Suite, so I pretty much can't open hardly any programs on my new machine right now. I thought maybe I should run Applejack on that too, just to check, but apparently it doesn't work with OSX 7 Lion. -
Apex_util.prepare_url within a select statement
APEX Version: 3.1.2.00.02
Need help with embedding APEX_UTIL.PREPARE_URL in select statement. Unable to reference column name as a bind variable...or it allows as in code below, but no values are included in the URL. Using PREPARE_URL so checksum is created.
URL created:*
https://.../f?p=108:90:623968923157010::NO::P90_RID:&cs=3CB12F3B467B3989B51377487817BDB08
Note: href >> replaced with >> hrf
declare
q varchar2(32767); -- query
w varchar2(4000) ; -- where clause
we varchar2(1) := 'N'; -- identifies if where clause exists
begin
q := 'select "RID", '||
' "EMPLOYEE_NO", '||
' InitCap(first_name)||
'||''' '''||
'||InitCap(last_name) as "Name", '||
' "HIRE_DATE", '||
' "JOB_TITLE", '||
' CASE '||
' WHEN CORRECTION_IND = 'X' '||
' THEN ''<a hrf="' ||
apex_util.prepare_url('f?p='||:APP_ID||':90:'||:APP_SESSION||'::'||:DEBUG||'::P90_RID:'||:RID) ||
'">Correction</a>'' ' ||
' ELSE NULL '||
' END CORRECTED '||
' from "#OWNER#"."EMPLOYEE_TABLE" ';
if :P28_FIRST_NAME IS NOT NULL
then
w := w || ' AND first_name LIKE UPPER(:P28_FIRST_NAME||'||'''%''' ||')' ;
we := 'Y';
end if;
if :P28_LAST_NAME IS NOT NULL
then
w := w || ' AND last_name LIKE UPPER(:P28_LAST_NAME||'||'''%''' ||')' ;
we := 'Y';
end if;
if we = 'Y'
then q := q || w;
end if;
return q;
end;Edited by: JSandoval on May 25, 2011 1:03 PMI think that the problem is that the function apex_util.prepare_url is executed building the "q" variable, not during query execution. (you have to try to quote it ...)
I often use the "Query from function".
There a couple of things that helps me:
- I always put in the page an item PXX_SHOW_SQL(checkbox) visible only to administrator (a user setting in my application...).
Before the "return q" put a htp.p(q) if this Item is not null. So you can see the actual SQL (often helps reformattig the output with SqlDeveloper)
- I'm became crasy tring to quote complex query ... Now I write the query code in a TABLE
Example AUXSQL(APP_ID number,APP_PAGE number, PRG number, sql VARCHAR2(4000))
More "PRG" if more than 4000 chars. (I start in this way, but someone use CBLOB ...)
I find this very usefully!!
Thanks
Stefano Corradi -
Create procedure statement Hangs in 11g database, doesn't hang in 10.2
I have installed 11g on a windows workstation and created a new database. I then attempted to import a schema from a tried and tested 10.2 database, this hung.
I pinpointed the cause of the hang to a create procedure sstatement within the import file.
I removed the procedure from the 10.2 database, re-exported and imported sucessfully in to the 11g database minus the rogue prrocedure.
I now have a create statement for the procedure thats causing the hangs, and this hangs when I try and run it - it runs fine against my 10.2 database?
I can comment large chunks of the create procedure statment out so I get an anonymous block that runs, and pinpoint the hang down to the inclusion of the the line marked below
(starting FOR UPDATE OF...........).
I cant work out whats going on, I'm no programmer by the way!
Any pointers would be greatly appreciated.
Nick
declare
job_rec job_table%ROWTYPE;
err_msg varchar2(2000);
abort_msg varchar2(2000);
l_ok boolean := TRUE;
l_bat_job varchar2(14) := 's2_novate_RIC';
LINES DELETED FOR PURPOSE OF POSTING CURSOR c_sah IS
SELECT
sah_next,
sah_table_key,
sah_old_status,
sah_new_status,
sah_processed_ind,
sah_processed_date,
sah_processed_time
FROM senatordba.sah_status_audit_history
JOIN (SELECT distinct to_char(spd_next) spd_next
FROM senatordba.spd_std_risk_dets
JOIN senatordba.rso_risk_system_options
ON rso_spd_next = spd_next
AND spd_ric_code = l_ric_code
AND coalesce(l_uw_year, spd_yr) = spd_yr
AND coalesce(l_risk_ref, spd_ref) = spd_ref
ON spd_next = sah_table_key
AND sah_table_code = 'SPD'
AND sah_status_table_code = 'NOV'
AND sah_processed_ind = 'N';
FOR UPDATE OF sah_processed_ind, sah_processed_date, sah_processed_time; <---------if this line is commented out runs OK, if left in, it hangs??
r_sah c_sah%ROWTYPE;
begin
open c_sah;
close c_sah;
end;Hi Nick, no one else has answered so I thought I'd answer my own question, it appears that I was hitting Oracle bug 9294110. had to uninstall 11.2 and install 11.0.7 instead. very annoyed that I wasted ages diagnosing this known problem. The following test should replicate the hang
connect / as sysdba
create user test identified by test default tablespace users temporary tablespace temp;
grant connect, resource to test;
connect test/test
create table a_tab
( col001 number, col002 number, col003 number, col004 number);
create table b_tab( col001 number);
-- the next statement hangs forever
select
a.col002,
a.col003,
a.col004
from
a_tab a
left outer join b_tab
on a.col001 = b_tab.col001
for update of a.col002,
a.col003,
a.col004;
Maybe you are looking for
-
How do I import an iPhoto Library (V.7.1.5) created on my old MacBook (10. 6.8) into my new Macbook pro (10.9.1) running iPhoto 9.5.1? I tried copying onto memory stick and moving to new mac, but new iPhoto doesn't recognise the library.
-
Creation of Variable for Hierarchy Node
Greetings...fellow matez, I am using Characteristic "0PROFIT_CTR" : PROFIT CENTER Here, I created used SAP <b>Standard</b> variable 0N_PCTR (Profit Center/Profit Center Hierarchy) This meets my requirement of allowing User to Input the TOP M
-
Dear Experts. I have the following problem. I am using a User-Exit for Travel that is called from a program standard with use the T.Code TRIP. The program standard use a structure that when entry in the user exit not is. I need use this structure in
-
HAP_DOCUMENT_BODY
Hi All, I want to post some validation in the tab Individual Targets and it should trigger when i click continue or save button. Continue is in the component HAP_MAIN_DOCUMENT. And the tab is in HAP_DOCUMENT_BODY. If any of you have worked on these c
-
http:119.235.49.218:8001 this URL not opening in safari