A book in itself
Trevor, August 16, 2001 - 6:28 am UTC
This posting was a book in itself.
I think the idea explicit cursors are faster stems
from a book which explicit cursors were better because
it said something like, implicit cursors always did an
extra fetch. When it reached the end of a data set
and implicit cursor (I heard) will do another read
to check if it really was the end. whereas an explicit
cursor you can control in you program so when the
no more rows is reached you end things.
Very good, but we want this clarified
abbajaan, August 16, 2001 - 9:34 am UTC
Please give us an example for the following 'explicit cursors are harder to code, slower -- using them only when you have no choice.', what are those situations or situation where we can consider tha we have no choice but to use explicit cursors.
dont leave us in confusion
John Quirk, August 16, 2001 - 9:37 am UTC
Illustrate you statement "by the time you've done that -- you are way worse off then a select into (which
will do the above in C very quickly with minimal round trips)" with examples, that is the only way out of this
Daaler, August 16, 2001 - 10:26 am UTC
Developers have got used to explicit cursor so much , that select into is kind of out of fashion.
Tom, can you think of a way to prove conclusively ( I know you have already done that) to the developers, that select into should be used.
But the arguement against select into is that, so many variables need to be declared, in case the select has multiple columns, and that explicit cursors are convenient to code .
You need to do something Tom.
Daaler, August 16, 2001 - 10:36 am UTC
all these days I thought I was doing the right thing using explicit cursors. I feel as if Iam on crossroads, Iam being very indecisive about this , WHICH WAY TO GO?
more discussion on this
Ason, August 16, 2001 - 10:56 am UTC
Tom
I think this is a very good question, every developer gets this kind of trivial doubts while working, he saves it for later, and forgets about it.
I think you shoud beat the select into and explicit cursors discussion to death, as this is very important, many so called oracle experts out there, will be running out for cover.
A reader, August 16, 2001 - 11:16 am UTC
Damit, after working for 7 years in oracle, and doing so many explicit cursors, I get to hear that select into is better
"O.K., TELL ME THE WHOLE STORY"
MIN/MAX subqueries in implicit cursors
A reader, August 16, 2001 - 10:09 pm UTC
I agree on most points, but how about queries designed to give values on a certain point in time.
If you compare the two statements underneath I would prefer the second one using the explicit cursor. Espacially if I could reuse the cursor again and again.
SELECT .. INTO .. FROM t main WHERE main.version_date = (SELECT MIN(sub.version_date) FROM t sub WHERE .. AND sub.version_date >= l_date)
as compared to
CURSOR c_t .. IS SELECT .. FROM t WHERE .. AND sub.version_date >= b_date ORDER BY t.version_date DESC
and then fetching just one row.
response to previous post
Connor, August 17, 2001 - 5:37 am UTC
Implicit is still the way to go here but your code would be:
select blah
from (
select blah
from table
order by date_col desc )
where rownum = 1
because you are giving Oracle EXTRA information that you only want the highest (or lowest) piece of information. In the explicit cursor case, Oracle doesn't know that you'll only be fetching 1 row.
Is there a scrollable cursor in Oracle?
Shane Hu, April 02, 2002 - 11:05 am UTC
DB2 CLI has scrollable cursors. Just wondering how Oracle do backward fetch with pro*c or OCI?
April 02, 2002 - 1:30 pm UTC
A wee-bit more of clarification wanted!!!!!!!!
AK, April 03, 2002 - 2:13 am UTC
Hi tom,
Admittedly the newsgroup discussion has made it amply clear that select into is to be a preferred choice against an explicit cursor. I desire just one more clarification:
Considering that for each row fetched by a cursor there is explicit processing to be performed, which one of the below is preferable??
1. for crec in (select a,b,c
from <table list>
where <where clauses>
loop
<my processsing>
end loop;
2. Explicit cursors
cursor crec is <select SQl>
open cursor
loop
fetch
exit when crec%notfound
< my processing>
end loop
What i want to know is which has a better performance???
Thanks in advance.
April 03, 2002 - 9:30 am UTC
Just one thing you need to remember:
"implicit cursors rule, they are FASTER, they are easier to code, they are more readable, they cause you to type less characters"
#1 is better. Benchmark it and see!
most of the doubts regarding cursors are clear
srinivasa rao bachina, May 27, 2003 - 5:32 am UTC
Hello Tom
thanks for u r nice explanation
one more doubt regardign cursor declaration
--in the cursor declaration we can use sql statement in the decode satement?
Ex:
select decode(sysdate,sysdate,(Select sysdate+1 from dual),sysdate-1) from dual is working in sqlplus
if i use the same staement in cursor declaration like
declare
cursor c1 is
select decode(sysdate,sysdate,(Select sysdate+1 from dual),sysdate-1) dt from dual
begin
for i in c1
loop
dbms_output.put_line(to_char(i.dt,'DDMMYYYY'));
end loop;
end;
i am getting the error
--
ORA-06550: line 3, column 33:
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
( - + mod not null others <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev sum variance
execute forall time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string>
ORA-06550: line 3, column 60:
PLS-00103: Encountered the symbol "," when expecting one of the following:
; return returning and or
ORA-06550: line 4, column 2:
PLS-00103: Encountered the symbol "BEGIN" when expecting one of the following:
. , @ ; for <an identifier>
<a double-quoted delimited-identifier> group having intersect
minus order partition start subpartition union where connect
--
i am using oracle 8i release 8.1.7.4.0
Can u Please Help me
Thank You in Advance
May 27, 2003 - 7:45 am UTC
in 9i, yes, in 8i no.
in 8i you must hide that construct (and CASE, order by in subquery, group by rollup/cube, analytics and some others) in a DYNAMIC query or in a view.
use ful
srinivasa rao bachina, May 29, 2003 - 7:29 am UTC
Hi tom
Can u explain me this case with some examples,if time permits to you?
thanks in advance
May 29, 2003 - 8:28 am UTC
you mean like
"create view v as select ......"
or
execute immediate open l_cursor for l_query;
it is very much straightforward stuff -- views and native dynamic sql.
One question
VMK, June 27, 2003 - 10:38 pm UTC
Hi tom,
My query
SELECT E.ENAME,E.SAL,E.DEPTNO,
(SELECT DNAME FROM DEPT D WHERE E.DEPTNO = D.DEPTNO)
FROM EMP E;
works fine in sql*plus. But if I want to declare it in cursor, it gives an error
DECLARE
CURSOR CUR_TEMP IS
SELECT E.ENAME,E.SAL,E.DEPTNO,
(SELECT DNAME FROM DEPT D WHERE E.DEPTNO = D.DEPTNO)
FROM EMP E;
BEGIN
NULL;
END;
/
Why it is so?
Thanks in advance.
VMK.
June 28, 2003 - 9:06 am UTC
because you are using 8i and there are some constructs that 8i does not recognize (select of a select, order by in a subquery, cursor() functions, analytics, group by cube/rollup)
solutions:
o use 9i
o use dynamic sql
o use a view.
Command line arguments
a reader, June 29, 2003 - 3:00 pm UTC
How can I pass command line argument to a .sql file
in both of the following situations.
1- Running SQLPLUS from a host prompt.
2- Running .sql file with @ in SQL prompt.
Thanks
June 29, 2003 - 6:26 pm UTC
$ sqlplus user/password @script first_parm second_parm
or
SQL> @script first_parm second_parm
miscelaneous questions
A reader, June 30, 2003 - 2:20 am UTC
As usual excellent and resourceful answers.
Thanks Tom!
Will you please provide a concrete example to handle subselect statement .
onsh, July 06, 2003 - 11:19 pm UTC
Hi Tom,
I want to follow up with you as it would be great to get your assistance to resolve the PLS-00103 error with the following code:
CREATE OR REPLACE
PROCEDURE SPR_REP_VISIT_DETAIL (
v_msched_skey IN NUMBER,
v_start_date IN CHAR,
v_end_date IN CHAR,
v_all_hangarbays IN CHAR,
v_hangarbays IN varchar2,
result_set OUT VVV_REPORTS.vis_det_hangarbay_refcur
)IS
temp_container VVV_REPORTS.vis_det_hangarbay_refcur;
BEGIN
IF ( NVL(v_all_hangarbays, 'FALSE') = 'TRUE') THEN
OPEN temp_container FOR
SELECT (v.base_code||'-'||v.hangar_code||'-'||v.bay_code) hbay ,
(SELECT DISTINCT a.aircraft_serial_num FROM aircraft a WHERE a.item_id = v.item_id) thetail,
(SELECT DISTINCT mp.mntce_project_code|| ' ' ||mp.MNTCE_PROJECT_TITLE FROM MAINTENANCE_PROJECT mp WHERE mp.MNTCE_PROJECT_ID = vmi.MNTCE_PROJECT_ID) projtitle,
(SELECT DISTINCT mp.MNTCE_PROJECT_TYPE_CODE FROM maintenance_project mp WHERE mp.MNTCE_PROJECT_ID = vmi.MNTCE_PROJECT_ID ) checktype,
v.visit_start_date_sched visit_start,
v.visit_end_date_sched visit_end,
(v.visit_end_date_sched - v.visit_start_date_sched ) duration,
(vmi.FORECASTED_START_DATE - v.VISIT_START_DATE_SCHED) slack,
vmi.percent_yield yield,
v.visit_desc comments
FROM visit v,
visit_maint_item vmi
WHERE v.visit_skey = vmi.visit_skey
AND v.msched_skey = v_msched_skey
AND (
( V.VISIT_START_DATE_SCHED >= TO_DATE(v_start_date, 'DD-MON-YYYY')
AND V.VISIT_START_DATE_SCHED <= TO_DATE(v_end_date, 'DD-MON-YYYY')
)
)
ORDER BY 1, 2, 3;
END IF;
END IF;
result_set:= temp_container;
END SPR_REP_VISIT_DETAIL;
I am using Oracle 8.1.7.4 and I realized that PL/SQL engine in 9i is much more smart than in 8i.The code above is running w/o problem in 9i and there are bunch of errors in 8i reffereing to subselect statements. Will you please help me.
Thanks a lot in advance,
onsh
July 07, 2003 - 7:23 am UTC
in 8i, the construct:
select ( select count(*) from dual )
from dual;
is not accepted by PLSQL (in addtition to analytics, case statements, group by rollup/cube, order by in a subquery, and some others I may have forgotten)
The work around is:
open p_cursor for
'SELECT .....' USING <binds>;
(native dynamic sql) OR use a VIEW to hide these constructs from PLSQL.
Thanks a lot for your suggestion
A reader, July 08, 2003 - 7:10 pm UTC
Hi Tom,
I've used a view to hide the subselect with analytic functions.
BTW, is there any reference in Oracle 8i (8.1.7.3) to highlight PL/SQL engine limitations?
Thanks,
onsh
July 09, 2003 - 7:50 am UTC
No, there is not.
OK
R.Chacravarthi, September 10, 2003 - 7:53 am UTC
Dear Sir,
I have a question for you.It is
1)Normally in queries we use column name to restrict rows
for ex.
select * from emp where deptno = 10;
My Question is
Can column values be used for row restriction? Like
select * from emp where 10 ...code goes here.
I expect your reply.
Please provide some examples.
Thanks in advance.
September 10, 2003 - 7:38 pm UTC
sorry, not getting your point. don't understand what you mean
OK
R.Chacravarthi, September 11, 2003 - 1:43 am UTC
Dear Sir,
What I asked you was
'select ename from emp where <condition>;'
condition can be of the column names like ename/deptno/empno.My question is whether column values can
be specified in the condition.?
for ex.
'select ename from emp where 10 (<= -- denotes deptno )
in (...code which tests for
some condition)'
Is this possible?
September 11, 2003 - 8:35 am UTC
if you are asking "can I reference the first column of a table using the number "1" instead of its name"
the answer is NO.
select * from emp where 1 = 'KING';
instead of
select * from emp where enamme = 'KING';
won't work (correctly). where 1='KING' is valid SQL -- but it is using the number 1 in there.
there would be no way to ascertain whether you meant "the number one" or "the first column" in any query -- ever. you would never be able to use a number in a SQL query.
Just great!!!
A reader, September 11, 2003 - 3:35 am UTC
This thread is really going good.
OK
R.Chacravarthi, September 11, 2003 - 9:14 am UTC
Dear Sir,
Received your response and thanks for that.You are saying that numbers cannot be used in sql queries.But certain things behave in a strange manner.Consider the following
queries.
QL> select ename from emp where sal = 3000;
ENAME
----------
SCOTT
FORD
SQL> select ename from emp e where 3000 in(select sal from emp where e.ename = ename);
ENAME
----------
SCOTT
FORD
SQL> select ename from emp where deptno = 20;
ENAME
----------
SMITH
JONES
SCOTT
ADAMS
FORD
SQL> select ename from emp e where 20 in(select deptno from emp where e.ename = ename);
ENAME
----------
SMITH
JONES
SCOTT
ADAMS
FORD
SQL> spool off
Why is this happening?Is this correct?.I should mention that
"I am using column values in queries"
September 11, 2003 - 9:51 am UTC
of course you can use numbers in there -- your question is/was very very unclear.
of COURSE you can use a number.
i had no idea what you meant above.
yes, where <NUMBER> <operator> <something> works just dandy.
OK
R.Chacravarthi, September 12, 2003 - 5:36 am UTC
Thanks for your response.Could you please provide some
"extraordinary" examples for such types of queries.Please do
reply.
September 12, 2003 - 10:16 am UTC
huh? "extraordinary"?? don't know what you are looking for.
Basic questions
Suresh, December 03, 2003 - 6:43 am UTC
Hi
I have SOME basic questions
Basically I am SQL SERVER professional. My current project is using ORACLE
So Please clarify these basic questions.
We are using packages. But inside the procedure (which resides
inside the PACKAGES) we are not doing any
commit or rollback work(transaction related).
Q1) so how these datas will get commit. do we have to COMMIT it explicitly.
Actually we are doing up gradation work. But the database is same(ORACLE 8.1.7). I have to
write some more procedures. In the old package I didnt see any
transaction related (commit, rollback) works?
Q2) My Current project is web based project. For e.g. one person login (using website)
and added/edited some datas. Can other session see that datas. Why I am asking
this question is that, these programs are using packages to edit/add. But we dont have any transaction
controls here.
So other session can see these added/edited data
Q3) I have procedure like following in my package.
There are four insert statement are there.
Suppose if the fourth insert statement fails I dont want first there statements.
Can I use AUTONOMUS TRANSACTION? or what to do?
Please explain what I have to do exactly.
December 03, 2003 - 7:22 am UTC
q1) that is awesome -- the sqlserver model of "transactions" is totally wrong -- they "autocommit" (because having locks in their system is like the kiss of death, everything halts). We do not.
the CLIENT that calls the procedure should commit or rollback -- it is the CLIENTS decision. In that fashion, you can take procedure1 and procedure2 and call them as a single transaction anytime they want!!!
the client should either:
begin procedure; end;
commit or rollback based on the error code (in the event of an error, the rollback of changes is implicit)
or, to call a procedure it can submit this block instead:
begin
procedure;
commit;
exception when others then
rollback;
raise;
end;
in that fashion, the client can later code:
begin
procedure1;
procedure2;
procedure3;
commit;
exception when others then
rollback;
raise;
end;
as a single atomic transaction.
q2) other sessions can see the data as soon as the session modifying the data commits. not before.
q3) if you have my book "expert one on one Oracle" - i cover this topic in huge detail -- huge detail. this is important stuff (not that I'm trying to see a book here but i think you would benefit from the discussions contained therein).
in Oracle -- ACID is important, we pay attention to it. A procedure is considered a STATMENT -- if you call a procedure it either
a) entirely succeeds
b) entirely fails and it is as if it never occured.
a simple test:
ops$tkyte@ORA9IR2> create table t ( x int check (x>0) );
Table created.
ops$tkyte@ORA9IR2>
ops$tkyte@ORA9IR2> create or replace procedure good
2 as
3 begin
4 insert into t values ( 1 );
5 insert into t values ( 2 );
6 insert into t values ( 3 );
7 insert into t values ( 0 );
8 end;
9 /
Procedure created.
ops$tkyte@ORA9IR2>
ops$tkyte@ORA9IR2> create or replace procedure BAD
2 as
3 begin
4 insert into t values ( 1 );
5 insert into t values ( 2 );
6 insert into t values ( 3 );
7 insert into t values ( 0 );
8 exception
9 when others then dbms_output.put_line( 'bummer ' || sqlerrm );
10 end;
11 /
Procedure created.
ops$tkyte@ORA9IR2>
ops$tkyte@ORA9IR2> select * from t;
no rows selected
ops$tkyte@ORA9IR2> exec good;
BEGIN good; END;
*
ERROR at line 1:
ORA-02290: check constraint (OPS$TKYTE.SYS_C002910) violated
ORA-06512: at "OPS$TKYTE.GOOD", line 7
ORA-06512: at line 1
ops$tkyte@ORA9IR2> select * from t;
no rows selected
ops$tkyte@ORA9IR2> exec bad;
bummer ORA-02290: check constraint (OPS$TKYTE.SYS_C002910) violated
PL/SQL procedure successfully completed.
ops$tkyte@ORA9IR2> select * from t;
X
----------
1
2
3
<b>as you can see -- if the procedure "fails" (good does that) and returns the error the client -- lets the exception propagate out -- the work it does is "undone" totally.
as you can also see, if you use the "when others" or any other exception to catch the error and "make it go away" as I did here (eg: what I'm getting at is LET THE EXCEPTIONS PROPAGATE TO THE CLIENT, do not catch them and return return CODES!!!!) then the client is responsible for undoing the work.
Use of commit and rollback in java
suresh, December 03, 2003 - 8:13 am UTC
The application(java) programmers are calling a package. How transactions can be comitted/rolled back using the java programs. If the commit/rollback is implemented in package, does that have a down side.
If commit/rollback is not done in the java & packages both, what will be the consequnces ?
December 03, 2003 - 10:37 am UTC
well, i already stated two ways
a) have the application do it:
conn.commit()
b) submit a block that calls procedure and either commits or rollsback.
I FIRMLY believe transactional control MUST be in the client.
SQLPLUS linesize issue/question
JD, December 28, 2005 - 11:50 am UTC
Tom,
With reference to the very first question (and it's answer) in this thread:
---
9.what is the maxvalue we can give to set line size.
---
I have related problem with linesize.
When I run the following script, sqlplus prints heading for the second select statement.
Please see the sql statement and outputs from two different versions of IBM/AIX OS:
=========================================
---
SQL script (say tmp.sql):
set echo off
set doc off
set pause off
set feedback off
set pagesize 0
set wrap off
set verify off
set head off
set linesize 4000
spool tmp.lis
select 'abcdefg' col1 from dual;
select '12345678901234567890123456789012345678901234567890' --1
||'12345678901234567890123456789012345678901234567890'
||'12345678901234567890123456789012345678901234567890'
||'12345678901234567890123456789012345678901234567890'
||'12345678901234567890123456789012345678901234567890' --5
||'12345678901234567890123456789012345678901234567890'
||'12345678901234567890123456789012345678901234567890'
||'12345678901234567890123456789012345678901234567890'
||'12345678901234567890123456789012345678901234567890'
||'12345678901234567890123456789012345678901234567890' --10
||'12345678901234567890123456789012345678901234567890'
||'12345678901234567890123456789012345678901234567890'
||'12345678901234567890123456789012345678901234567890'
||'12345678901234567890123456789012345678901234567890'
||'12345678901234567890123456789012345678901234567890' --15
||'12345678901234567890123456789012345678901234567890'
||'12345678901234567890123456789012345678901234567890'
||'12345678901234567890123456789012345678901234567890'
||'12345678901234567890123456789012345678901234567890'
||'12345678901234567890123456789012345678901234567890' --20
||'123456789012345678901234' col2
from dual;
/
spool off
exit
---
execute as
sqlplus -s scott/tiger @tmp.sql > tmp.out
---
OUTPUT (tmp.out) on IBM/AIX 4 using SQL*Plus: Release 9.2.0.5.0
abcdefg
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234
OUTPUT (tmp.out) on IBM/AIX 5 using SQL*Plus: Release 9.2.0.4.0
abcdefg
^A^P^SN`À789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234
---
=========================================
- both outputs printed header for second select statement, even though I have both "set head off" and "set pagesize 0"
- Second output printed junk characters (^A^P^SN`À) at the beginning of the header.
Are these known issues? OR am I missing something here??
Any help would be greatly appreciated.
Thanks,
JD
December 28, 2005 - 11:56 am UTC
must be missing something?
I do not see col1 nor col2 in any of the output??
It's not the column header....
JD, December 28, 2005 - 12:29 pm UTC
Sorry, it isn't printing the column headers "col1" and "col2" but it does repeat the value of col2 (from second statement).
I was expecting same output as of first statement (no repetation):
select 'abcdefg' col1 from dual;
>>abcdefg
Hope this is more clear.
Thanks.
December 28, 2005 - 5:45 pm UTC
I don't see any repeats?
I think what JD is asking is...
Kevin, December 28, 2005 - 1:16 pm UTC
He doesn't want to get the line
"OUTPUT (tmp.out) on IBM/AIX 5 using SQL*Plus: Release 9.2.0.4.0"
(i.e., the login banner from sql*plus)
in his output file.
As far as I know, you can't supress the banner -- it happens as you authenticate, so there's no chance to set a parameter to tell it to stop.
But, you're only getting this because you are logging the entire session output to temp.out. The appropriate way to do this (which you seem to be doing in the script file anyway, amusingly -- look at 'spool tmp.lis') is to use the spool command, starting spooling after you've authenticated and set your environment appropriately.
December 28, 2005 - 5:47 pm UTC
I don't think that is what they meant - they wrote that line to tell us which output we were looking at - the and tags were put there by them.
but yes, I too believe they want to use the tmp.lis file, not the redirection
Thanks Kevin... but...
JD, December 28, 2005 - 1:34 pm UTC
Thanks Kevin for the review, BUT the line
"OUTPUT (tmp.out) on IBM/AIX 5 using SQL*Plus: Release 9.2.0.4.0"
is not from the output. I have copied and pasted the output as it is after that/those lines.
Just FYI, you can supress the banner using -s option (also mentioned in the question): sqlplus -s scott/tiger @tmp.sql > tmp.out
Thanks anyway.
Please see the output... seperated in paragraphs
JD, December 28, 2005 - 5:53 pm UTC
Length of the string (of col2) in sql is only 1024 characters, but output, in both cases, is 2048.
--- This is the first line (should not appear)
^A^P^SN`À789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234
--- This is actual column value of col2 (only expected)
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234
Thanks.
December 28, 2005 - 6:13 pm UTC
Oh, that is easy, you ran the query twice:
from dual;
/
spool off
either use the ; to end the query and run it OR the / - but not both.
Even .lis (spool) does the same thing
JD, December 28, 2005 - 5:57 pm UTC
<quote> but yes, I too believe they want to use the tmp.lis file, not the redirection <quote>
Spool output (.lis) also has repeated values. The only difference is there are no junk characters.
Thanks,
JD
December 28, 2005 - 6:13 pm UTC
(you are running the query twice :)
Got it! I think...
Chris Poole, December 28, 2005 - 6:16 pm UTC
to JD from VA
Its because you have a slash AND a semicolon!!
select 'some junk'
from dual;
/
Run that in SQL*Plus, yet get the same staement executed twice. The slash just says 'run whats in the buffer', whats in the buffer? The select from dual you just ran because you put a semicolon on the end!
Drat and double drat, not quick enough!
Chris Poole, December 28, 2005 - 6:41 pm UTC
Tom you have a slight advantage when you post your replies,
it makes us look like we are just repeating you, but I know I got there first! ;)
Happy New Year to you
Got it... Thanks... BUT
JD, December 29, 2005 - 12:07 pm UTC
Thanks.. thanks... thanks...
I got the fact about getting result twice. In fact, I keep advising same thing to others :(
BUT the main issue we are having is JUNK characters in redirect file. Now, if I run the same sql (without ;) and redirect to the file, I see junk character at beginning (in .out file) but the spool file (.lis) does not show any of those. This happens only on the combination of "on IBM/AIX 5 and SQL*Plus: Release 9.2.0.4.0"
--- Part of output
abcdefg
^A^P^SN`À789012345678901.....
---
Is this a known bug or do I need to check some settings in the database?
Also, is/was there any limit on spool file size?
(Thanks to Chris from toasty NORTH [?] Sydney. Happy new year to you and hope you will enjoy the fire works
)
.. JD
December 29, 2005 - 1:17 pm UTC
I don't know, as I don't track every bug on all platforms (that would be handled via support)
Could be control characters of some sort.
but the lis file is what you want - The screen output isn't what you want to use.
32bit tools might have file size limits, yes. But if you are 64bit, they should not.
Thanks...
JD, December 29, 2005 - 2:28 pm UTC
Thanks Tom.
Wish you and everyone a Very Happy New Year.
.. JD
SQL Question
bc, January 26, 2006 - 1:29 pm UTC
Tom,
What does the (+) symbol in the following cursor do ?
cursor c1 is
select col_a,
col_b
from table_a
where col_a (+) is null;
Thanks
January 27, 2006 - 8:13 am UTC
nothing. it is rather meaningless in that context.
Thanks
BC, January 27, 2006 - 10:26 am UTC
Tom,
Thank you very much, I apprecitate it.