SQL Statement as Loop - easy question?
Am reading from S. Feuerstein's book:
DECLARE
CURSOR checked_out_cur IS
SELECT pet_id, name, checkout_date
FROM occupancy WHERE checkout_date IS NOT NULL;
BEGIN
FOR checked_out_rec IN checked_out_cur
LOOP
INSERT INTO occupancy_history (pet_id, name, checkout_date)
VALUES (checked_out_rec.pet_id, checked_out_rec.name, checked_out_rec.checkout_date);
My question is - where did checked_out_rec came from? Doesn't look like it's declared.
Thanks,
http://www.unix.org.ua/orelly/oracle/prog2/ch07_07.htm
In fact the very next section begins,
"This will work just fine. But do we really need to use a cursor FOR loop to accomplish this task?"
(I think the above is from an earlier edition of the book, but later editions make the same point.)
If you flip back a couple of pages there is whole section on the convenience of the implicit record declaration, along with the implicit open, fetch and close.
Similar Messages
-
Hi,
I have a requirment where in i will have to insert some records 100 times and one of the inserted values should be a unique number and the rest of the values are same like
insert into table (col1, col2, col3) values(X, 1000,sysdate);
where the value of x should be from 1 to 100 for each insert.
I would appreciate if some one could tell me how to write using a loop.
ThanksCreate a sequence
CREATE SEQUENCE my_sequence_nameand then use the sequence in the loop
INSERT INTO table_name( col1, col2, col3 )
VALUES( my_sequence_name.nextval, 1000, sysdate );Of course, it would be better if you inserted 100 rows in a single INSERT rather than using a loop in the first place.
Justin -
SQL Statement for Post-Interview Question
Hello,
I was recently asked a question for an interview and think I got (part of it) wrong, but here is the question followed by my query with output. If someone could show me where I went wrong I would greatly appreciate it. It would be a great learning experience
for me. I think where I fell short was the count of each repeating output row.
Q: There is a table called Member with three columns: MemberID, FirstName, and LastName. We need a query to find how many First Name and Last Name combination duplicates exists.
The desired output is First Name, Last Name, total number times the combination is repeated.
• BONUS question 1: Have the result set with the largest number of duplicates first.
• BONUS question 2: What do you do if there are extraneous leading or trailing spaces on each name cause the same first name last name combination showing up on multiple lines?
SELECT * FROM (
SELECT (ROW_NUMBER() OVER (
ORDER BY a.LastName, a.FirstName, a.MemberID DESC
)) AS ROWNUM
, a.MemberID
, rtrim(ltrim(a.LastName))
, rtrim(ltrim(a.FirstName))
, a.name
FROM User_Details AS a INNER JOIN
(SELECT rtrim(ltrim(LastName)), rtrim(ltrim(FirstName))
FROM User_Details
WHERE LastName !='' AND FirstName != ''
GROUP BY LastName, FirstName
HAVING
(COUNT(*) > 1)) AS b ON rtrim(ltrim(a.LastName)) = rtrim(ltrim(b.LastName)) AND rtrim(ltrim(a.FirstName)) = rtrim(ltrim(b.FirstName))
WHERE 0=0
--first placeholder condition
) AS TEAM_OUTPUT
WHERE ROWNUM BETWEEN 1 and 100
Output:
123456 Allen Michael
123456 Allen Michael
46683 Allen Michael
46683 Allen Michael
71795 Allen Mike
71795 Allen Mike
32171 Allen Mike
32171 Allen Mike
38058 Allen Patricia
32524 Allen Patricia
211454 Allen Susan
34679 Allen Susan
29826 Allen Susan
39684 Allen Teri
77557 Allen Terri
227006 Allen Theresa
107360 Allen Theresa
Thanks,
BusterShouldn't it be as simple as
SELECT FirstName, LastName, COUNT(*) AS C
FROM Member
GROUP BY FirstName, LastName
HAVING COUNT(*) > 1
ORDER BY COUNT(*) DESC
(add the LTRIM AND RTRIMs back in to deal with the possible extra spaces) -
How can i use one SQL statement to solve problem?
How can i use one SQL statement to solve the question below?
For a Table named A, there is a column named F(char type).
Now select all the records where F like '%00' and update their F value to '%01'
Just one SQL statement.Do not use PL/SQL block.
How to do that?
Thanks.What is the data volume for this table?
Do you expect lots of rows to have '%00' as their value?
Following two statements come to mind. Other experts would be able to provide better alternatives:
If you have index on SUBSTR(f, 2):
UPDATE A
SET f = SUBSTR(f,
1,
length(f) - 2) || '01'
WHERE substr(f,
-2) = '00';If most of the rows have pattern '%00':
UPDATE A
SET f = SUBSTR(f,
1,
length(f) - 2) ||
DECODE(SUBSTR(f,
-2),
'00',
'01',
SUBSTR(f,
-2)); -
Hello all,
im working in hr schema
i need sql statement to answer my question
i need all employees information
where average salary = average salary department 50
sorry i can't speak english very well
thank's allThere is no need to do it in two queries. All you need is:
select *
from (
select e.*,
avg(case department_id when 50 then salary end) over() dept_50_avg_sal
from hr.employees e
where salary <= dept_50_avg_sal
EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL
198 Donald OConnell DOCONNEL 650.507.9833 21-JUN-07 SH_CLERK 2600 124 50 3475.55556
199 Douglas Grant DGRANT 650.507.9844 13-JAN-08 SH_CLERK 2600 124 50 3475.55556
115 Alexander Khoo AKHOO 515.127.4562 18-MAY-03 PU_CLERK 3100 114 30 3475.55556
116 Shelli Baida SBAIDA 515.127.4563 24-DEC-05 PU_CLERK 2900 114 30 3475.55556
117 Sigal Tobias STOBIAS 515.127.4564 24-JUL-05 PU_CLERK 2800 114 30 3475.55556
118 Guy Himuro GHIMURO 515.127.4565 15-NOV-06 PU_CLERK 2600 114 30 3475.55556
119 Karen Colmenares KCOLMENA 515.127.4566 10-AUG-07 PU_CLERK 2500 114 30 3475.55556
125 Julia Nayer JNAYER 650.124.1214 16-JUL-05 ST_CLERK 3200 120 50 3475.55556
126 Irene Mikkilineni IMIKKILI 650.124.1224 28-SEP-06 ST_CLERK 2700 120 50 3475.55556
127 James Landry JLANDRY 650.124.1334 14-JAN-07 ST_CLERK 2400 120 50 3475.55556
128 Steven Markle SMARKLE 650.124.1434 08-MAR-08 ST_CLERK 2200 120 50 3475.55556
EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL
129 Laura Bissot LBISSOT 650.124.5234 20-AUG-05 ST_CLERK 3300 121 50 3475.55556
130 Mozhe Atkinson MATKINSO 650.124.6234 30-OCT-05 ST_CLERK 2800 121 50 3475.55556
131 James Marlow JAMRLOW 650.124.7234 16-FEB-05 ST_CLERK 2500 121 50 3475.55556
132 TJ Olson TJOLSON 650.124.8234 10-APR-07 ST_CLERK 2100 121 50 3475.55556
133 Jason Mallin JMALLIN 650.127.1934 14-JUN-04 ST_CLERK 3300 122 50 3475.55556
134 Michael Rogers MROGERS 650.127.1834 26-AUG-06 ST_CLERK 2900 122 50 3475.55556
135 Ki Gee KGEE 650.127.1734 12-DEC-07 ST_CLERK 2400 122 50 3475.55556
136 Hazel Philtanker HPHILTAN 650.127.1634 06-FEB-08 ST_CLERK 2200 122 50 3475.55556
138 Stephen Stiles SSTILES 650.121.2034 26-OCT-05 ST_CLERK 3200 123 50 3475.55556
139 John Seo JSEO 650.121.2019 12-FEB-06 ST_CLERK 2700 123 50 3475.55556
140 Joshua Patel JPATEL 650.121.1834 06-APR-06 ST_CLERK 2500 123 50 3475.55556
EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL
142 Curtis Davies CDAVIES 650.121.2994 29-JAN-05 ST_CLERK 3100 124 50 3475.55556
143 Randall Matos RMATOS 650.121.2874 15-MAR-06 ST_CLERK 2600 124 50 3475.55556
144 Peter Vargas PVARGAS 650.121.2004 09-JUL-06 ST_CLERK 2500 124 50 3475.55556
180 Winston Taylor WTAYLOR 650.507.9876 24-JAN-06 SH_CLERK 3200 120 50 3475.55556
181 Jean Fleaur JFLEAUR 650.507.9877 23-FEB-06 SH_CLERK 3100 120 50 3475.55556
182 Martha Sullivan MSULLIVA 650.507.9878 21-JUN-07 SH_CLERK 2500 120 50 3475.55556
183 Girard Geoni GGEONI 650.507.9879 03-FEB-08 SH_CLERK 2800 120 50 3475.55556
186 Julia Dellinger JDELLING 650.509.3876 24-JUN-06 SH_CLERK 3400 121 50 3475.55556
187 Anthony Cabrio ACABRIO 650.509.4876 07-FEB-07 SH_CLERK 3000 121 50 3475.55556
190 Timothy Gates TGATES 650.505.3876 11-JUL-06 SH_CLERK 2900 122 50 3475.55556
191 Randall Perkins RPERKINS 650.505.4876 19-DEC-07 SH_CLERK 2500 122 50 3475.55556
EMPLOYEE_ID FIRST_NAME LAST_NAME EMAIL PHONE_NUMBER HIRE_DATE JOB_ID SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID DEPT_50_AVG_SAL
194 Samuel McCain SMCCAIN 650.501.3876 01-JUL-06 SH_CLERK 3200 123 50 3475.55556
195 Vance Jones VJONES 650.501.4876 17-MAR-07 SH_CLERK 2800 123 50 3475.55556
196 Alana Walsh AWALSH 650.507.9811 24-APR-06 SH_CLERK 3100 124 50 3475.55556
197 Kevin Feeney KFEENEY 650.507.9822 23-MAY-06 SH_CLERK 3000 124 50 3475.55556
37 rows selected.
SQL> SY. -
I'm trying compare two table in Oracle and with a firstname and
lastname
matches fill-in a pager pin number.
This is the sql statement I'm running
update addressbook2 set pin =
(select pin from phonebook where
phonebook.firstname=addressbook2.firstname
and
phonebook.lastname=addressbook2.lastname)
where addressbook2.firstname IN (select firstname from phonebook)
and addressbook2.lastname IN (select lastname from phonebook)
but I get an error message saying:
ORA-01427: single-row subquery returns more than one row
My question is can I update the table even when there are
duplicates in the tables. The query runs perfect when both
tables are unique.
Thank you for any help.
MN
nullI presume you are trying to update the pin of only those people
in the addressbook table that also exist in the phonebook table.
The following will work:
update addressbook a
set a.pin = (
select f.pin from phonebook f
where f.fname = a.fname
and f.lname = a.lname
ie remove the last two lines from your DML statement.. be aware
that you are using a denormalised design (pin is not normalised
on the primary key) and the use of first and last names as a
method of identifying people is not a good idea (does 'smith' =
'smyth'?)
MN (guest) wrote:
: I'm trying compare two table in Oracle and with a firstname and
: lastname
: matches fill-in a pager pin number.
: This is the sql statement I'm running
: update addressbook2 set pin =
: (select pin from phonebook where
: phonebook.firstname=addressbook2.firstname
: and
: phonebook.lastname=addressbook2.lastname)
: where addressbook2.firstname IN (select firstname from
phonebook)
: and addressbook2.lastname IN (select lastname from phonebook)
: but I get an error message saying:
: ORA-01427: single-row subquery returns more than one row
: My question is can I update the table even when there are
: duplicates in the tables. The query runs perfect when both
: tables are unique.
: Thank you for any help.
: MN
null -
Oracle + Unix question , Error validation for SQL statements in co process
Hi,
If I use co process in a shell script , what is the best way to do the error validation of the execution of any sql statements . I was trying to change the following code to make use of co process concept. When I tried echo $? after the execution of a "wrong statements"
it is still giving Zero output ( meaning success)
<<<<<<<<<<<<<<<<<<<<<<<<<<<
cat ${CFG_DIR}/srs_indx.lst | egrep -v '^#' | egrep -v '^[ ]*$' | while read x
do
echo " Processing values :: pre $pre tbl $tbl indx $indx tblspc $tblspc cols $cols param $param" >> ${LOGS_DIR}/srs_indx.log
sqlplus ${BIZSTG} << EOT >> ${LOGS_DIR}/srs_indx.log
set verify on timing on term on echo on feedback on serveroutput on
WHENEVER SQLERROR CONTINUE
drop index $indx;
WHENEVER SQLERROR EXIT FAILURE
alter session set query_rewrite_enabled = true;
create $pre index $indx on $tbl ($cols)
tablespace $tblspc
$param;
exit
EOT
RC=$?
if ( test $RC -ne 0 )
then
ERR_MSG="ERROR in creating index $indx for table $tbl from srs_indx.ksh of $ENVIR : $APP by `whoami`@`hostname` on `date` "
echo $ERR_MSG >> ${LOGS_DIR}/srs_indx.log
process_warning ${LOGS_DIR}/srs_indx.log
exitstat=1
else
echo "$indx created at `date`" >> ${LOGS_DIR}/srs_indx.log
fi
done
>>>>>>>>>>>>>>>>>>>>
Any help will be appreciated .
with thanks and regards
Ranjeesh K RHi,
Thanks for the response, I guess people misunderstood my question .
My question was about "error handling in case of CO PROCESS". For those who don't know about this, in case CO PROCESS you just need to login once to Oracle. In my above code It is logging in & out for each entry in the list. CO process statements may look Similar to SQL statements in pro*C. In PRO*C we use EXEC, but here print -p statements..
a sample is given for those who are new to co process.
sqlplus -s /nolog |& # Open a pipe to SQL*Plus
print -p -- 'connect user/password@instance'
print -p -- 'set feed off pause off pages 0 head off veri off line 500'
print -p -- 'set term off time off'
print -p -- "set sqlprompt ''"
print -p -- "select sysdate from dual;"
read -p SYSDATE
print -p -- "select user from dual;"
read -p USER
print -p -- "select global_name from global_name;"
read -p GLOBAL_NAME
print -p -- exit
echo SYSDATE: $SYSDATE
echo USER: $USER
echo GLOBAL_NAME: $GLOBAL_NAME
But I got stuck during error handling of these SQL statements, especially the $? / $* returns 0 even after an erroneus execution.
Regards -
PL/SQL how to loop thru SQL statement?
Hey guys. I have this bit of a complicated problem.
I have a cursor that selects a DISTINCT field called Term and a StudentID.
I am looping thru that cursor.
Inside that loop I have another SQL statement that is pulling all rows from the DB where the Term = the Term and the StudentID= the StudentID from the crusor loop.
My problem is how do I get all the information/rows returned from that SQL statement? I need to loop thru it somehow, but I am not sure how to do it.
If there is a better way to get this done feel free to chime in.
Here is my code.
/* CURSOR*/
CURSOR c_GPAPerTerm IS
SELECT DISTINCT Term, Student_ID FROM course_grades
WHERE STUDENT_ID = p_StudentID;
/* OPEN AND LOOP THRU CURSOR*/
OPEN c_GPAPerTerm;
LOOP
FETCH c_GPAPerTerm INTO v_Terms,v_StudentID;
/* SQL STATEMENT NEED TO LOOP THRU AND GET VALUES FOR EACH ROW*/
SELECT Score
INTO v_Scores
FROM course_grades
WHERE Term = v_Terms and StudentID = v_StudentID;
EXIT WHEN c_GPAPerTerm%NOTFOUND;
END LOOP;
CLOSE c_GPAPerTerm;Ok here's my complete code....it's pretty big though...hope it's not too confusing.
It compiles fine if I take the new cursor out, so the error is somewhere in that cursor.
CREATE OR REPLACE PROCEDURE get_Student_GPA(p_StudentID IN NUMBER) AS
/*VARIABLES*/
v_Terms VARCHAR2(6);
v_Courses VARCHAR2(6);
v_Scores NUMBER;
v_Grade CHAR;
v_GPA NUMBER;
v_ScoresTotal NUMBER :=0;
v_StudentID NUMBER;
/*CURSORS*/
CURSOR c_GetTerms IS
SELECT Term
FROM course_grades
WHERE STUDENT_ID = p_StudentID;
CURSOR c_GetCourseAndGrade IS
SELECT Course_ID, Score FROM course_grades
WHERE STUDENT_ID = p_StudentID;
CURSOR c_GPAPerTerm IS
SELECT DISTINCT Term, Student_ID
FROM course_grades
WHERE STUDENT_ID = p_StudentID;
CURSOR c_GetScores (p_Term VARCHAR2, p_StudentID NUMBER) IS
SELECT Score
FROM course_grades
WHERE Term = p_Term AND StudentID = p_StudentID;
/*FUNCTIONS*/
FUNCTION convert_grade(p_GradeNumber IN NUMBER)
RETURN CHAR IS
BEGIN
/* GET NUMERIC GRADE AND CONVERT TO LETTER */
CASE
WHEN p_GradeNumber < 60 THEN RETURN 'F';
WHEN (p_GradeNumber > 59 AND p_GradeNumber < 70) THEN RETURN 'D';
WHEN (p_GradeNumber > 69 AND p_GradeNumber < 80) THEN RETURN 'C';
WHEN (p_GradeNumber > 79 AND p_GradeNumber < 90) THEN RETURN 'B';
WHEN (p_GradeNumber > 89 AND p_GradeNumber < 101) THEN RETURN 'A';
ELSE RETURN 'Z';
END CASE;
END convert_grade;
FUNCTION calculate_gpa(p_TotalHourPoints IN NUMBER, p_TotalHours IN NUMBER)
RETURN NUMBER IS
/*CREATE VARIABLE TO HOLD GPA*/
v_GPA NUMBER;
BEGIN
/*CALCULATE AND OUTPUT GPA*/
v_GPA := p_TotalHourPoints/p_TotalHours;
RETURN v_GPA;
END calculate_gpa;
FUNCTION calculate_point (p_Grade IN CHAR)
RETURN NUMBER IS
BEGIN
/* GET LETTER GRADE AND CONVERT TO NUMBER */
CASE
WHEN p_Grade = 'A' THEN RETURN 4;
WHEN p_Grade = 'B' THEN RETURN 3;
WHEN p_Grade = 'C' THEN RETURN 2;
WHEN p_Grade = 'D' THEN RETURN 1;
WHEN p_Grade = 'F' THEN RETURN 0;
ELSE RETURN 0;
END CASE;
END calculate_point ;
/****BEGIN MAIN BLOCK********/
BEGIN
DBMS_OUTPUT.PUT_LINE('**********TERMS**********');
OPEN c_GetTerms;
LOOP
FETCH c_GetTerms INTO v_Terms;
DBMS_OUTPUT.PUT_LINE('Term: ' || v_Terms);
EXIT WHEN c_GetTerms%NOTFOUND;
END LOOP;
CLOSE c_GetTerms;
DBMS_OUTPUT.PUT_LINE('**********COURSES AND GRADES**********');
OPEN c_GetCourseAndGrade;
LOOP
FETCH c_GetCourseAndGrade INTO v_Courses, v_Scores;
v_Grade := convert_grade(v_Scores);
DBMS_OUTPUT.PUT_LINE('Course: ' || v_Courses || ' Grade: ' || v_Grade);
EXIT WHEN c_GetCourseAndGrade%NOTFOUND;
END LOOP;
CLOSE c_GetCourseAndGrade;
DBMS_OUTPUT.PUT_LINE('**********GPA PER TERM**********');
OPEN c_GPAPerTerm;
LOOP
FETCH c_GPAPerTerm INTO v_Terms,v_StudentID;
/*NEW CURSOR LOOP WILL GO HERE*/
v_ScoresTotal := v_ScoresTotal + v_Scores;
v_GPA := calculate_gpa(v_ScoresTotal, 3);
v_ScoresTotal :=0;
DBMS_OUTPUT.PUT_LINE('Term: ' || v_Terms || ' GPA: ' || v_GPA);
EXIT WHEN c_GPAPerTerm%NOTFOUND;
END LOOP;
CLOSE c_GPAPerTerm;
END get_Student_GPA;
/ -
JDBC Sender update SQL Statement Question.
I was wondering if there is a way to have the update SQL statement line in the JDBC sender update by time stamp, this would be very helpful. Does anyone know a method of doing this?
In the SAP documentation of the adapter it has this example for using the update SQL statement after the query statement:
SQL statement for query: SELECT * FROM table WHERE processed = 0;
SQL statement for update: UPDATE table SET processed = 1 WHERE processed = 0;
What I want is to be able to put processed = (the current date) instead of processed =1 in the update statement, like this example:
SQL statement for query: SELECT * FROM table WHERE processed = 0;
SQL statement for update: UPDATE table SET processed = (the current date) WHERE processed = ' ';
I seems like you can only use a fixed value for the update statements in the JDBC Sender though, I would like to know if you can use a time stamp or variable there. -
Hi expert,
I have following sql statement, function 'hiroc_get_delta_amount1' and 'hiroc_get_delta_amount2' are separately used in select and where subclause. these two function are exactly same, except that there is a inserting log statement inside. for function 'hiroc_get_delta_amount1' , logs are supposed to write into log table1, whereas for function 'hiroc_get_delta_amount2' , logs are supposed to write into log table2. after running this sql, I got data loaded into log table2, however, there is no data loaded into log table1.
could you please tell me why there is no data in log table2 for function
1. sql statement;
select
pp.policy_premium_pk,
pp.policy_fk,
pp.policy_term_fk,
pp.risk_fk,
pp.coverage_fk,
pp.transaction_log_fk,
pp.coverage_component_code,
hiroc_rpt_user.hiroc_get_delta_amount1(pp.policy_fk, pp.policy_term_fk, pp.risk_fk, pp.coverage_fk, pp.transaction_log_fk, pp.coverage_component_code),
pp.rate_period_from_date
from PRODBKUPDW_MART.rmv_policy_premium pp
where pp.rate_period_type_code = 'TERM_COVG'
and pp.coverage_component_code 'NETPREM'
and hiroc_rpt_user.hiroc_get_delta_amount2(pp.policy_fk, pp.policy_term_fk, pp.risk_fk, pp.coverage_fk, pp.transaction_log_fk, pp.coverage_component_code) != 0
group by pp.policy_premium_pk,
pp.policy_premium_pk,
pp.policy_fk,
pp.policy_term_fk,
pp.risk_fk,
pp.coverage_fk,
pp.transaction_log_fk,
pp.coverage_component_code,
pp.rate_period_from_date;
2. log inserting statement used for both functions:
(1) function 'hiroc_get_delta_amount1'
insert into HIROC_RPT_USER.LOG_TEST1 values (v_start, sysdate,
p_policy_fk,p_policy_term_history_fk,p_risk_fk,p_coverage_fk,p_transaction_log_fk,p_comp_code);
COMMIT;
(2) function 'HIROC_GET_DELTA_AMOUNT_1'
insert into HIROC_RPT_USER.LOG_ZB_TEST_1 values (v_start, sysdate,
p_policy_fk,p_policy_term_history_fk,p_risk_fk,p_coverage_fk,p_transaction_log_fk,p_comp_code);
COMMIT;Are your functions using autonomous transactions?
We also need more information about the log tables etc. as we cannot tell what the problem would be from just that query, and no data. -
Question about reconciliation, by using SQL statement
Dear All,
Does any know how to print out A/R invoice which are internally recon, by using SQL statement. It seems like GL report.
For example:
InvoiceNo Recon
INV222000001 Yes
INV222000002 No
INV222000003 No
From SamsonDear Samson,
Please try this one:
SELECT T0.DocNum AS 'Invoice No.', CASE WHEN SUM(T1.IntrnMatch)=0 THEN 'NO' ELSE 'YES' END AS Recon
FROM DBO.OINV T0
INNER JOIN DBO.JDT1 T1 ON T1.TransId = T0.TransId
WHERE T0.DocDate BETWEEN [%0\] AND [%1\]
GROUP BY T0.DocNum
Thanks,
Gordon -
SQL statement in servlet giving error
Please let me know if I need to post this on a different forum, but I thought it was applicable to here.
First, let me preface this post by saying I've inserted hardcoded values at the DB (Oracle) level and it worked just fine, so most of the statement is sound. All the values inserted properly when testing it that way. Also, I've printed the SQL statement to the console and all looks ok there, too.
Out of this, I'm getting an error citing the following:
java.lang.ArrayIndexOutOfBoundsException
also occasionally getting the following error:
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
In my servlet, I'm attempting the following:
prior to the insert statement, I'm retrieving the last row number to start the increment from as in:
Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rst = stmt.executeQuery("select CHANGE_CTRL_ID from CHANGE_CONTROL_USER order by CHANGE_CTRL_ID");
rst.last();
int lastRowNum = Integer.valueOf(rst.getString("CHANGE_CTRL_ID")).intValue();
rst.close();
stmt.close();
------------ then ------------------------------------------------
String preparedQuery = "INSERT ALL " +
"INTO CHANGE_CONTROL_USER " +
"(CHANGE_CTRL_ID,REQUESTOR_NAME,REQUESTOR_EMAIL,BUS_CONTACT,DEPT,LOCATION,PHONE_NUM,DATE_REQ," +
"BUSVP,VP_PHONE,VP_DATE,BRANCH,PRIORITY,OPS_MAN_CHG,OPS_MAN_PPCHAP,TRAIN_REQ," +
"EXIST_SYS_FLD_CHG,BUS_RULES_CHG,NEW_CODING,NEW_BUS_RULE,NEW_SYS_FIELD,REQ_TYPE_OTHER,REQ_OTHER_SPECIFY,IMPACT_RE_COLL," +
"IMPACT_DEF_LM,IMPACT_DEF_REC_NRE,IMPACT_AUDIT,IMPACT_PERS_COLL,IMPACT_DEF_FCL,IMPACT_BUS_TECH,IMPACT_LEGAL,IMPACT_PRIV_COLL," +
"IMPACT_DEF_BKRUP_RE,IMPACT_DEC_SUPT,IMPACT_RISK_MGT,IMPACT_DEF_REO,IMPACT_DEF_BKRUP_NRE,IMPACT_QUALSVCS,IMPACT_INTERNAL_CTRL,IMPACT_DEF_WKFL," +
"IMPACT_DEF_WKOUT,IMPACT_TRAIN_TPI,IMPACT_OTHER,IMPACT_DEF_MGT,IMPACT_DEF_TAX,IMPACT_VEND_MGT,IMPACT_DEF_CTRL,IMPACT_DEF_REC_RE," +
"IMPACT_BUS_ADMIN,IMPACT_OTHER_SPECIFY,CHANGE_IN_KPMG,CHANGE_IN_OTS,CHANGE_IN_NFR,CHANGE_IN_ARR,CHANGE_IN_BRR, CHANGE_IN_PROC_IMP," +
"CHANGE_IN_INT_CITI_POL,CHANGE_IN_OTHER,CHANGE_IN_OTHER_SPECIFY, CHANGE_INIT_DETAILS,REQ_INFO_DESCRIPT,REQ_INFO_EXPLAIN_CURRBUS,REQ_INFO_EXPLAIN_PROPOSED,REQ_BEN_PROP_BENEFIT,REQ_BEN_FIN_IMPLEMENT," +
"REQ_BEN_OPS_IMPLEMENT,YES_FORM,VULN_ASSESS, CBA_CHG, RISK_ACCEPT,MARSITEM, GCCRFP, APP_COMPL_QUES,CAP_EXPEND)" +
" VALUES (changecontrol_user_seq.nextval,?,?,?,?,?,?,to_date(?,'YYYY-MON-DD HH:MI:SS'),?,?,to_date(?,'YYYY-MON-DD HH:MI:SS'),?,?," + "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,"
+ "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
+ "INTO CHANGE_CONTROL_ADMIN "
+ "(AID,CHANGE_CTRL_ID,ADMNAME,CLOSEDATE,ACTIVE)"
+ "VALUES (changecontrol_admin_seq.nextval, changecontrol_user_seq.currval,NULL, NULL, -1)"
+ "SELECT object_name AS REQUESTOR_NAME FROM all_objects where rownum <= 1;";
also I've declared all the respective strings for the PreparedQuery statement.
If you need to see those, here they are:
PreparedStatement pstmt = connection.prepareStatement(preparedQuery);
// stmt = connection.stmt("INSERT INTO RMIS_USER VALUES (?,?,?,?,to_date(?,'YYYY-MON-DD HH:MI:SS'),?,?,?,?,to_date(?,'YYYY-MM-DD HH:MI:SS')");
pstmt.setInt(1,++lastRowNum);
pstmt.setString(2,reqName);
pstmt.setString(3,reqemail);
pstmt.setString(4,buscont);
pstmt.setString(5,reqDept);
pstmt.setString(6,reqLocale);
pstmt.setString(7,phone_num);
pstmt.setDate(8,dtreq);
//pstmt.setCalendar(8,rtnow);
pstmt.setString(9,busvp_email);
pstmt.setString(10,vpphone);
pstmt.setDate(11,dt);
pstmt.setString(12,branch);
pstmt.setString(13,priority);
pstmt.setString(14,opsmanchg);
pstmt.setString(15,opsmanppchap);
pstmt.setString(16,train_req);
pstmt.setString(17,reqexist_sys_fld_chg);
pstmt.setString(18,reqbus_rules_chg);
pstmt.setString(19,reqnew_coding);
pstmt.setString(20,reqnewbus_rule );
pstmt.setString(21,reqnew_sys_fld);
pstmt.setString(22,reqother);
pstmt.setString(23,req_other_specify);
pstmt.setString(24,imp_recoll);
pstmt.setString(25,imp_deflm);
pstmt.setString(26,imp_defrecnre);
pstmt.setString(27,imp_audit);
pstmt.setString(28,imppers_coll);
pstmt.setString(29,imp_deffcl);
pstmt.setString(30,imp_bustech);
pstmt.setString(31,imp_legal);
pstmt.setString(32,imp_privcoll);
pstmt.setString(33,imp_defbkre);
pstmt.setString(34,imp_decsupt);
pstmt.setString(35,imp_riskmgt);
pstmt.setString(36,imp_defreo);
pstmt.setString(37,imp_defbknre);
pstmt.setString(38,imp_qualsvc);
pstmt.setString(39,imp_intlctrl);
pstmt.setString(40,imp_defwkfl);
pstmt.setString(41,imp_defwkout);
pstmt.setString(42,imp_trtpi);
pstmt.setString(43,impact_other);
pstmt.setString(44,imp_defmgt);
pstmt.setString(45,imp_deftax);
pstmt.setString(46,imp_vendmgt);
pstmt.setString(47,imp_defctrl);
pstmt.setString(48,imp_defrecre);
pstmt.setString(49,imp_busadm);
pstmt.setString(50,impact_other_specify);
pstmt.setString(51,change_in_kpmg);
pstmt.setString(52,change_in_ots);
pstmt.setString(53,change_in_nfr);
pstmt.setString(54,change_in_arr);
pstmt.setString(55,change_in_brr);
pstmt.setString(56,change_in_proc_imp);
pstmt.setString(57,change_inter_citpol);
pstmt.setString(58,change_in_other);
pstmt.setString(59,change_in_other_specify);
pstmt.setString(60,change_init_details);
pstmt.setString(61,req_info_descript);
pstmt.setString(62,req_info_explain_currbus);
pstmt.setString63,req_info_explain_proposed);
pstmt.setString(64,req_ben_prop_benefit);
pstmt.setString(65,req_ben_fin_implement);
pstmt.setString(66,req_ben_ops_implement);
pstmt.setString(67,projyes);
pstmt.setString(68,vulnass);
pstmt.setString(69,cbachg);
pstmt.setString(70,riskacc);
pstmt.setString(71,marsitem);
pstmt.setString(72,gccrfp);
pstmt.setString(73,applcomp);
pstmt.setString(74,capexpend);
pstmt.executeUpdate();
if anyone sees anything flawed here, please let me know!
Thanks!
Message was edited by:
bpropes20
Message was edited by:
bpropes20
Message was edited by:
bpropes20What a mess. First off, the line pstmt.setInt(1,++lastRowNum); just needs to go away. You're already using a sequence to set the value for the primary keys, you don't need to add a mistake like this.
I then count 73 question marks (you can verify, I'm not counting again.) That would mean that your indices are off by one, and the ArrayIndexOutOfBounds is probably coming from pstmt.setString(74,capexpend); Dump the ++lastRowNum line, change all of your indices (after verifying the bind count!) and try it again.
You can see an inherent weakness in the PreparedStatement clauses - one change means manually rewriting all of the indices. A solution is dumping all of your bind values into a List, then loop through the list to do your setXXX statements. If all binds are not of the same type, you can bind the values to some object that identifies type and use those objects in the list instead of the values. A little more complex, but easier to maintain in my opinion. -
Possible to do "grant" sql statement in Native SQL?
We have a need to do a grant of access from one of our systems out for various applications. In order for this to work we need to run a grant access command on the table and are trying to put a wrapper around this so we can use an abap. Below is the code I am unit testing. Two questions. First, can a grant be done via native SQL in abap? Second, if it can be done, what is the error with the logic where I am trying to put in the table name via a parameter.
REPORT ZLJTEST2.
tables dd02l.
DATA scarr_carrid TYPE dd02l-tabname.
SELECT-OPTIONS s_carrid for dd02l-tabname no intervals.
DATA s_carrid_wa LIKE LINE OF s_carrid.
DATA name TYPE c LENGTH 20.
TRY.
EXEC SQL.
CREATE FUNCTION selfunc( input CHAR(20) )
RETURNING char(20);
DEFINE output char(20);
set schema sapr3;
grant select on table input to group infouser;
RETURN output;
END FUNCTION;
ENDEXEC.
LOOP AT s_carrid INTO s_carrid_wa
WHERE sign = 'I' AND option = 'EQ'.
TRY.
EXEC SQL.
EXECUTE PROCEDURE selfunc( IN :s_carrid_wa-low,
OUT :name )
ENDEXEC.
WRITE: / s_carrid_wa-low, name.
CATCH cx_sy_native_sql_error.
MESSAGE `Error in procedure execution` TYPE 'I'.
ENDTRY.
ENDLOOP.
EXEC SQL.
DROP FUNCTION selfunc;
ENDEXEC.
CATCH cx_sy_native_sql_error.
MESSAGE `Error in procedure handling` TYPE 'I'.
ENDTRY.Hi,
Yes it is posible.
I made one program like you want. But it need very long code.
Here I explain the idea:
1. Create Screen with input TEXT EDIT CONTROL.
This is for input SQL Statement.
2. Get SQL Statement from Text Edit Control using method <b>get_text_as_r3table</b>.
3. Now we need to separate SQL Statement into different table.
We Separate SELECT, FROM, WHERE, GROUP, HAVING, ORDER, etc.
4. We need dynamic internal table to store the data.
5. Select the data according SQL statement.
SELECT (IT_SELECT)
into corresponding fields of table <dyn_table>
FROM (IT_FROM)
WHERE (IT_WHERE)
GROUP BY (IT_GROUP)
HAVING (IT_HAVING)
ORDER BY (IT_ORDER).
6. Display our data using ALV GRID
Hopefully it will help you.
Regards, -
TestStand Open SQL Statement does not support SQL's ORDER BY clause???
TestStand 1.0.3
Windows 2000 SP1
SQL Server 2000 Personal
You've got to be kidding me...
It appears that the built-in TestStand Open SQL Step does NOT support the
"ORDER BY" clause in the SELECT statement, even though the documentation
says it does. Is this true?
I have an Open SQL Statement query:
"SELECT * FROM [MyTable] WHERE ([Batch ID]=1234)"
it works fine, returning a correct record count 120 records. If I change
the Open SQL Statement query simply by adding an ORDER BY clause, such as:
"SELECT * FROM [MyTable] WHERE ([Batch ID]=1234) ORDER BY [MyField] ASC"
it returns a record count of zero. I know that "MyField" exists in the
MyTable table and contains valid data. The
second query works fine in SQL
Server Enterprise Manager.
Am I missing something? Is it true that the TestStand Open SQL Step does
NOT support the "ORDER BY" clause? If not, what &#$!ing good is it and why
does the manual state it is supported? Is there any other way using just
the TestStand steps to order a database recordset on one or more fields?
Any help would be appreciated.
Grrrrr....
Bob Rafuse
Etec Inc.> Bob -
> The database step types do not do anything special to the SQL command
> that you give it. The step just passes the command to the ADO
> provider. I tried a simple query using the step types with the
> following command,
>
> "SELECT UUT_RESULT.* FROM UUT_RESULT WHERE ([UUT_SERIAL_NUMBER] =
> 12345) ORDER BY [EXECUTION_TIME] ASC"
>
> and this return the expected results and the record count parameter
> was as expected. I tried this on TS 1.0.2 and TS 2.0 with MS Access
> 2000 and MS SQL Server 7.0. I do not have MS SQL Server 2000 at this
> time.
>
> It would be surprised if the step types are messing something up.
I've been doing some experimenting over the past couple of days. Simple,
one-table queries seem to handle the ORDER BY clause fine. Th
ings seem to
get messed up when I try multi-table queries with ORDER BY clause with the
TestStand database steps. I get no errors but the returned record counts
are always 0 with the ORDER BY and positive without the ORDER BY. The exact
same queries work fine in Visual Basic/ADO and the SQL Server Query
Analyzer.
> Questions:
> 1. Have you verified whether the data is actually returned even though
> the record count is zero?
Hmmm... yes data IS getting returned (at least on the two instances I just
checked), but the record count is always zero. I was not proceeding with
processing if the record count was 0.
Still... I don't know how to loop through the recordset without knowing how
many records there are an not eventually generate an error by passing EOF.
Is there another way using the TestStand database steps to determine a) the
number of records in the recordset or b) when I'm at EOF?
> 2. Are you using any advanced options on the Opend SQL Statement step
> type, specifically
the cursor type set to forward only? Forward only
> cursors do not allow for record counts.
Everything on the Advanced tab of the Open SQL Statement step is set to "Use
Default".
Bob. -
Please help to tune the below query. I have provided following information
1. Query To be tuned
2. Parameter Relevant to Optimizer
3. Explain Plan and AutoTrace Ouput
4. Query traced at Level 8 and Its Tkprof Ouput
5. EXPLAIN PLAN output of DBMS_XPLAN.DISPLAY
INFORMATION 1. SQL QUERY TO BE TUNED
SELECT DISTINCT C.MAN_WIP_T_IN_TS,
C.RCP_NO,
C.WRK_CTR_ID,
C.WTR_FREE_TST_FLG,
A.COMPANY_ID,
A.PROD_ORDER,
A.PART_NO,
A.CARRIER_QTY,
B.PHY_CARID,
C.WIP_SEQ,
A.RCP_NO "CARRIER_RCP"
FROM dbadmintest.PF2_PROD_ORDER_CARRIER A,
PF2_PHYSICAL_CARRIER B,
WORK_IN_PROCESS C
WHERE C.UNIT_TYPE_CD = RTRIM('TL7')
AND C.UNIT_NM = RTRIM('T41')
AND C.WIP_TYPE_CD = 'HANDHELD'
AND C.PHY_CARRIER_SEQ = A.PHY_CARRIER_SEQ
AND A.PHY_CARRIER_SEQ = B.PHY_CARRIER_SEQ
AND ((A.CARRIER_LD_TS <= C.MAN_WIP_T_IN_TS
AND A.CARRIER_UNLD_TS >= C.MAN_WIP_T_IN_TS)
OR ( A.CARRIER_LD_TS <= C.MAN_WIP_T_IN_TS
AND A.CARRIER_UNLD_TS IS NULL))
AND ((A.CARRIER_UNLD_TS >= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
AND A.CARRIER_UNLD_TS <= TO_DATE('2012-01-12 10:03:00', 'YYYY-MM-DD HH24:MI:SS'))
OR (A.CARRIER_LD_TS >= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
AND A.CARRIER_LD_TS <= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS'))
OR (A.CARRIER_LD_TS <= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
AND A.CARRIER_UNLD_TS IS NULL)
OR (A.CARRIER_LD_TS <= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
AND A.CARRIER_UNLD_TS >= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')))
ORDER BY 6,5,1
INFORMATION 2. PARAMETER RELEVANT TO OPTIMIZER
NAME TYPE VALUE
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 10.2.0.4
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_mode string ALL_ROWS
optimizer_secure_view_merging boolean TRUE
db_file_multiblock_read_count integer 16
cursor_sharing string EXACT
SQL> column sname format a20
column pname format a20
column pval2 format a20
select
sname
, pname
, pval1
, pval2
from sys.aux_stats$;SQL>
SNAME PNAME PVAL1 PVAL2
SYSSTATS_INFO STATUS COMPLETED
SYSSTATS_INFO DSTART 08-25-2009 07:27
SYSSTATS_INFO DSTOP 08-25-2009 07:27
SYSSTATS_INFO FLAGS 1
SYSSTATS_MAIN CPUSPEEDNW 1592.87183
SYSSTATS_MAIN IOSEEKTIM 10
SYSSTATS_MAIN IOTFRSPEED 4096
SYSSTATS_MAIN SREADTIM
SYSSTATS_MAIN MREADTIM
SYSSTATS_MAIN CPUSPEED
SYSSTATS_MAIN MBRC
SYSSTATS_MAIN MAXTHR
SYSSTATS_MAIN SLAVETHR
INFORMATION 3. EXPLAIN PLAN AND AUTOTRACE OUTPUT
Execution Plan
Plan hash value: 850402268
| Id | Operation | Name | Rows | Bytes | Cost (%CPU) | Time |
| 0 | SELECT STATEMENT | | 11 | 1100 | 1568 (1) | 00:00:19 |
| 1 | SORT UNIQUE | | 11 | 1100 | 1567 (1) | 00:00:19 |
|* 2 | HASH JOIN | | 11 | 1100 | 1566 (1) | 00:00:19 |
|* 3 | TABLE ACCESS BY INDEX ROWID | PF2_PROD_ORDER_CARRIER | 5 | 270 | 763 (0) | 00:00:10 |
| 4 | NESTED LOOPS | | 11 | 1001 | 1562 (1) | 00:00:19 |
|* 5 | TABLE ACCESS BY INDEX ROWID | WORK_IN_PROCESS | 2 | 74 | 35 (0) | 00:00:01 |
|* 6 | INDEX RANGE SCAN | WORK_IN_PROCESS_IX2 | 56 | | 3 (0) | 00:00:01 |
|* 7 | INDEX RANGE SCAN | PF2_PROD_ORDER_CARRIER_IX3 | 2361 | | 6 (0) | 00:00:01 |
| 8 | TABLE ACCESS FULL | PF2_PHYSICAL_CARRIER | 1736 | 15624 | 4 (0) | 00:00:01 |
Predicate Information (identified by operation id):
2 - access("A"."PHY_CARRIER_SEQ"="B"."PHY_CARRIER_SEQ")
3 - filter(("A"."CARRIER_UNLD_TS" IS NULL AND "A"."CARRIER_LD_TS"<=TO_DATE(' 2012-01-12 08:03:00',
'syyyy-mm-dd hh24:mi:ss') OR "A"."CARRIER_UNLD_TS">=TO_DATE(' 2012-01-12 08:03:00', 'syyyy-mm-dd
hh24:mi:ss') AND "A"."CARRIER_LD_TS"<=TO_DATE(' 2012-01-12 08:03:00', 'syyyy-mm-dd hh24:mi:ss') OR
"A"."CARRIER_UNLD_TS">=TO_DATE(' 2012-01-12 08:03:00', 'syyyy-mm-dd hh24:mi:ss') AND
"A"."CARRIER_UNLD_TS"<=TO_DATE(' 2012-01-12 10:03:00', 'syyyy-mm-dd hh24:mi:ss') OR
"A"."CARRIER_LD_TS"=TO_DATE(' 2012-01-12 08:03:00', 'syyyy-mm-dd hh24:mi:ss')) AND
("A"."CARRIER_LD_TS"<="C"."MAN_WIP_T_IN_TS" AND "A"."CARRIER_UNLD_TS">="C"."MAN_WIP_T_IN_TS" OR
"A"."CARRIER_UNLD_TS" IS NULL AND "A"."CARRIER_LD_TS"<="C"."MAN_WIP_T_IN_TS"))
5 - filter("C"."WIP_TYPE_CD"='HANDHELD' AND "C"."PHY_CARRIER_SEQ" IS NOT NULL)
6 - access("C"."UNIT_TYPE_CD"='TL7' AND "C"."UNIT_NM"='T41')
7 - access("C"."PHY_CARRIER_SEQ"="A"."PHY_CARRIER_SEQ")
filter("A"."PHY_CARRIER_SEQ" IS NOT NULL)
Statistics
1 recursive calls
0 db block gets
13525998 consistent gets
7024 physical reads
0 redo size
1758 bytes sent via SQL*Net to client
492 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
14 rows processed
INFORMATION 4. QUERY TRACES AT LEVEL 8 AND TKPROF OUTPUT
TKPROF: Release 10.2.0.4.0 - Production on Wed Jan 18 01:48:53 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Trace file: ././ppf2_ora_5439924.trc
Sort options: default
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
SELECT DISTINCT C.MAN_WIP_T_IN_TS,
C.RCP_NO,
C.WRK_CTR_ID,
C.WTR_FREE_TST_FLG,
A.COMPANY_ID,
A.PROD_ORDER,
A.PART_NO,
A.CARRIER_QTY,
B.PHY_CARID,
C.WIP_SEQ,
A.RCP_NO "CARRIER_RCP"
FROM PF2_PROD_ORDER_CARRIER A,
PF2_PHYSICAL_CARRIER B,
WORK_IN_PROCESS C
WHERE C.UNIT_TYPE_CD = RTRIM('TL7')
AND C.UNIT_NM = RTRIM('T41')
AND C.WIP_TYPE_CD = 'HANDHELD'
AND C.PHY_CARRIER_SEQ = A.PHY_CARRIER_SEQ
AND A.PHY_CARRIER_SEQ = B.PHY_CARRIER_SEQ
AND ((A.CARRIER_LD_TS <= C.MAN_WIP_T_IN_TS
AND A.CARRIER_UNLD_TS >= C.MAN_WIP_T_IN_TS)
OR ( A.CARRIER_LD_TS <= C.MAN_WIP_T_IN_TS
AND A.CARRIER_UNLD_TS IS NULL))
AND ((A.CARRIER_UNLD_TS >= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
AND A.CARRIER_UNLD_TS <= TO_DATE('2012-01-12 10:03:00', 'YYYY-MM-DD HH24:MI:SS'))
OR (A.CARRIER_LD_TS >= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
AND A.CARRIER_LD_TS <= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS'))
OR (A.CARRIER_LD_TS <= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
AND A.CARRIER_UNLD_TS IS NULL)
OR (A.CARRIER_LD_TS <= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
AND A.CARRIER_UNLD_TS >= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')))
ORDER BY 6,5,1
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 2 219.55 294.41 14030 13523455 0 14
total 4 219.55 294.41 14030 13523455 0 14
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: SYS
Rows Row Source Operation
14 SORT UNIQUE (cr=13523455 pr=14030 pw=0 time=294417731 us)
14 HASH JOIN (cr=13523455 pr=14030 pw=0 time=294416444 us)
14 TABLE ACCESS BY INDEX ROWID PF2_PROD_ORDER_CARRIER (cr=13523440 pr=14030 pw=0 time=292675360 us)
98184018 NESTED LOOPS (cr=270067 pr=9028 pw=0 time=294901120 us)
12128 TABLE ACCESS BY INDEX ROWID WORK_IN_PROCESS (cr=9842 pr=8788 pw=0 time=20479883 us)
15241 INDEX RANGE SCAN WORK_IN_PROCESS_IX2 (cr=49 pr=48 pw=0 time=54577 us)(object id 65980)
98171889 INDEX RANGE SCAN PF2_PROD_ORDER_CARRIER_IX3 (cr=260225 pr=240 pw=0 time=808956 us)(object id 65990)
1736 TABLE ACCESS FULL PF2_PHYSICAL_CARRIER (cr=15 pr=0 pw=0 time=83 us)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 3 0.00 0.00
SQL*Net message from client 3 0.00 0.00
db file sequential read 14030 0.47 43.56
call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
total 2 0.00 0.00 0 0 0 0
Misses in library cache during parse: 0
Parsing user id: SYS
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 2 0.00 0.00 0 0 0 0
Execute 2 0.00 0.00 0 0 0 0
Fetch 2 219.55 294.41 14030 13523455 0 14
total 6 219.55 294.41 14030 13523455 0 14
Misses in library cache during parse: 0
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 3 0.00 0.00
SQL*Net message from client 3 0.00 0.00
db file sequential read 14030 0.47 43.56
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
Parse 0 0.00 0.00 0 0 0 0
Execute 0 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
total 0 0.00 0.00 0 0 0 0
Misses in library cache during parse: 0
2 user SQL statements in session.
0 internal SQL statements in session.
2 SQL statements in session.
Trace file: ././ppf2_ora_5439924.trc
Trace file compatibility: 10.01.00
Sort options: default
1 session in tracefile.
2 user SQL statements in trace file.
0 internal SQL statements in trace file.
2 SQL statements in trace file.
2 unique SQL statements in trace file.
14137 lines in trace file.
294 elapsed seconds in trace file.
INFORMATION 5. EXPLAIN PLAN OUTPUT OF DBMS_XPLAN.DISPLAY
SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
PLAN_TABLE_OUTPUT
SQL_ID 1z1cccq5kxt11, child number 0
SELECT /*+ gather_plan_statistics */ DISTINCT C.MAN_WIP_T_IN_TS, C.RCP_NO, C.WRK_CTR_ID, C.WTR_FREE_TST_FLG,
A.COMPANY_ID, A.PROD_ORDER, A.PART_NO, A.CARRIER_QTY, B.PHY_CARID, C.WIP_SEQ, A.RCP_NO "CARRIER_RCP"
FROM PF2_PROD_ORDER_CARRIER A, PF2_PHYSICAL_CARRIER B, WORK_IN_PROCESS C
WHERE C.UNIT_TYPE_CD = RTRIM('TL7') AND C.UNIT_NM = RTRIM('T41') AND C.WIP_TYPE_CD ='HANDHELD'
AND C.PHY_CARRIER_SEQ = A.PHY_CARRIER_SEQ AND A.PHY_CARRIER_SEQ = B.PHY_CARRIER_SEQ
AND ((A.CARRIER_LD_TS <=C.MAN_WIP_T_IN_TS AND A.CARRIER_UNLD_TS >= C.MAN_WIP_T_IN_TS) OR
( A.CARRIER_LD_TS <= C.MAN_WIP_T_IN_TS AND A.CARRIER_UNLD_TS IS NULL)) AND ((A.CARRIER_UNLD_TS >= TO_DATE('2012-01-12
08:03:00', 'YYYY-MM-DD HH24:MI:SS') AND A.CARRIER_UNLD_TS<= TO
Plan hash value: 850402268
| Id | Operation | Name | Starts |E-Rows | A-Rows |A-Time | Buffers | Reads |OMem |1Mem | Used-Mem |
| 1 | SORT UNIQUE | | 1 | 11 | 14 |00:05:41.48 | 13M | 6571 | 2048 | 2048 | 2048 (0) |
|* 2 | HASH JOIN | | 1 | 11 | 14 |00:05:41.48 | 13M | 6571 | 807K | 807K | 614K (0) |
|* 3 | TABLE ACCESS BY INDEX ROWID | PF2_PROD_ORDER_CARRIER | 1 | 5 | 14 |00:05:39.89 | 13M | 6571 | | | |
| 4 | NESTED LOOPS | | 1 | 11 | 98M |00:04:55.08 | 270K | 6569 | | | |
|* 5 | TABLE ACCESS BY INDEX ROWID | WORK_IN_PROCESS | 1 | 2 | 12130 |00:00:13.15 | 9845 | 6569 | | | |
|* 6 | INDEX RANGE SCAN | WORK_IN_PROCESS_IX2 | 1 | 56 | 15244 |00:00:00.06 | 49 | 45 | | | |
|* 7 | INDEX RANGE SCAN | PF2_PROD_ORDER_CARRIER_IX3 | 12130 | 2361 | 98M |00:00:00.92 | 260K | 0 | | | |
| 8 | TABLE ACCESS FULL | PF2_PHYSICAL_CARRIER | 1 | 1736 | 1736 |00:00:00.01 | 15 | 0 | | | |
Predicate Information (identified by operation id):
2 - access("A"."PHY_CARRIER_SEQ"="B"."PHY_CARRIER_SEQ")
3 - filter(((("A"."CARRIER_UNLD_TS" IS NULL AND "A"."CARRIER_LD_TS"<=TO_DATE(' 2012-01-12 08:03:00', 'syyyy-mm-dd hh24:mi:ss')) OR
("A"."CARRIER_UNLD_TS">=TO_DATE(' 2012-01-12 08:03:00', 'syyyy-mm-dd hh24:mi:ss') AND "A"."CARRIER_LD_TS"<=TO_DATE(' 2012-01-12 08:03:00',
'syyyy-mm-dd hh24:mi:ss')) OR ("A"."CARRIER_UNLD_TS">=TO_DATE(' 2012-01-12 08:03:00', 'syyyy-mm-dd hh24:mi:ss') AND
"A"."CARRIER_UNLD_TS"<=TO_DATE(' 2012-01-12 10:03:00', 'syyyy-mm-dd hh24:mi:ss')) OR "A"."CARRIER_LD_TS"=TO_DATE(' 2012-01-12 08:03:00',
'syyyy-mm-dd hh24:mi:ss')) AND (("A"."CARRIER_LD_TS"<="C"."MAN_WIP_T_IN_TS" AND "A"."CARRIER_UNLD_TS">="C"."MAN_WIP_T_IN_TS") OR
("A"."CARRIER_UNLD_TS" IS NULL AND "A"."CARRIER_LD_TS"<="C"."MAN_WIP_T_IN_TS"))))
5 - filter(("C"."WIP_TYPE_CD"='HANDHELD' AND "C"."PHY_CARRIER_SEQ" IS NOT NULL))
6 - access("C"."UNIT_TYPE_CD"='TL7' AND "C"."UNIT_NM"='T41')
7 - access("C"."PHY_CARRIER_SEQ"="A"."PHY_CARRIER_SEQ")
filter("A"."PHY_CARRIER_SEQ" IS NOT NULL)
41 rows selected.
Regards
RahulRahul, post your question on the SQL and PL/SQL forum PL/SQL. This forum is for Oracle Berkeley DB not Oracle Database.
Thanks,
Andrei
Maybe you are looking for
-
Can I "re-sync" my phone with iTunes match?
I set my iPhone for iTunes match before my computer was finished uploading files. Now a lot of my library is not showing up on the phone. My playlists are also not displaying on the phone
-
BLOB column will caused large memory consumed ?
our appliation server is AS9.0.4 and We using this Jdev 10g with BC4J and JSP to build some application that contain blob column BC4J entity object, we found the blob column will caused the memory consumed issue , each time the contain blob column ap
-
ISight not working from one user account on MacBook
Hi everyone, It'd be great to get some help with fixing an iSight camera. I've followed the instructions here: http://support.apple.com/kb/HT2090 and have narrowed it down to a particular user account (it has admin permissions). Other user accounts c
-
Syncing google calendar to iPhone 5?
I've got an interesting dilemma when it comes to syncing my google calendars. On my iPhone's calendar in the top left hand corner under "calendars" both of my google calendars show up as options but only one of them actually displays events in my iPh
-
Account merge across 2 parties?
I have an SR open but wanted to get other input. We have a situation where we have 2 valid parties, call them Org A and Org B. Org A has two accounts, Org-A-Account-1 and Org-A-Account-2. Org B also has two accounts, Org-B-Account-1 and Org-B-Account