Escolar Documentos
Profissional Documentos
Cultura Documentos
In a procedure i used below given methods to drop a table and both are
working, but what is the difference between 'execute immediate' and
'DBMS_SQL.PARSE' package...which is faster in execution, please suggest.
OR
cr number:=DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(cr, vsql ,DBMS_SQL.V7);
--- which command is better to use in PLSQL as im using oracle9i Re1.
Thanks in advance
http://www.stanford.edu/dept/itss/docs/oracle/10g/appdev.101/b10795/adf
ns_dy.htm
Because native dynamic SQL is integrated with SQL, you can use it in
the same way that you use static SQL within PL/SQL code. Native dynamic
SQL code is typically more compact and readable than equivalent code
that uses the DBMS_SQL package.
With the DBMS_SQL package you must call many procedures and functions
in a strict sequence, making even simple operations require a lot of
code. You can avoid this complexity by using native dynamic SQL instead.
Native dynamic SQL supports all of the types supported by static SQL in
PL/SQL, including user-defined types such as user-defined objects,
collections, and REFs. The DBMS_SQL package does not support these
user-defined types.
Native dynamic SQL and static SQL both support fetching into records,
but the DBMS_SQL package does not. With native dynamic SQL, the rows
resulting from a query can be directly fetched into PL/SQL records.
In the following example, the rows from a query are fetched into the
emp_rec record:
DECLARE
TYPE EmpCurTyp IS REF CURSOR;
c EmpCurTyp;
emp_rec emp%ROWTYPE;
stmt_str VARCHAR2(200);
e_job emp.job%TYPE;
BEGIN
stmt_str := 'SELECT * FROM emp WHERE job = :1';
-- in a multi-row query
OPEN c FOR stmt_str USING 'MANAGER';
LOOP
FETCH c INTO emp_rec;
EXIT WHEN c%NOTFOUND;
END LOOP;
CLOSE c;
-- in a single-row query
EXECUTE IMMEDIATE stmt_str INTO emp_rec USING 'PRESIDENT';
END;
/
The DBMS_SQL package supports SQL statements larger than 32KB; native
dynamic SQL does not.
Native dynamic SQL prepares a SQL statement each time the statement is
used, which typically involves parsing, optimization, and plan
generation. Although the extra prepare operations incur a small
performance penalty, the slowdown is typically outweighed by the
performance benefits of native dynamic SQL.
technically, under the covers, at the most "basic level", they are the
same.
Declare
type rc is ref cursor;
cursor c is select * from dual;
l_cursor rc;
begin
if ( to_char(sysdate,'dd') = 30 ) then
open l_cursor for 'select * from emp';
elsif ( to_char(sysdate,'dd') = 29 ) then
open l_cursor for select * from dept;
else
open l_cursor for select * from dual;
end if;
open c;
end;
/
Given that block of code -- you see perhaps the most "salient"
difference -- no matter how many times you run that block -- cursor C
will always be
select * from dual. The ref cursor can be anything.
Another difference is that static sql (not using a ref cursor) is much
more
efficient then using ref cursors and that use of ref cursors should be
limited to
- returning result sets to clients
- when there is NO other efficient/effective means of achieving the goal
that is, you want to use static SQL (with implicit cursors really)
first and use a ref cursor only when you absolutely have to
Then sit back and say "anything else you wanted to know about them"
ENAME SAL R
---------- ---------- ----------
MILLER 1300 6
http://www.akadia.com/services/ora_analytic_functions.html
http://www.quest-pipelines.com/newsletter-v3/0402_D.htm
Another Method: 1
select * FROM emp where sal = (select max(sal) from emp where sal <
(select max(sal) from temp));
Another Method: 2
Select * from emp where 1 = ( select count(*) from emp e
where salary > emp.salary)
Initial position
The initial position of the high water mark is extent 0 block 0 for
tables and extent 0 block 1 for indexes.
Rank:
1
2<--2nd position
2<--3rd position
4
5
Dense Rank:
1
2<--2nd position
2<--3rd position
3
4
http://asktom.oracle.com/pls/asktom/f?
p=100:11:0::::P11_QUESTION_ID:30011178429375
a) how much do you want to assign to your buffer cache for maximum
performance
b) how big is your shared/java pool (a function of how much
sql/plsql/java you run in
your database, no magical number for all to use)
c) do you run in shared server (than the large pool is used and will be
large -- that is
part of the sga) or in dedicated server -- then you need to leave OS
memory for dynamic
allocations
d) what else is going on in the machine.
basically, Oracle will setup reasonable initial sized pools (if you
know how to peek at _
parameters, you'll see them:
__java_pool_size 4194304
__large_pool_size 4194304
__shared_pool_size 247463936
) and will put the rest in the buffer cache. Over time, if the pools
need more, it'll steal from
the buffer cache and increase them.
* Data buffer cache - cache data and index blocks for faster access.
* Shared pool - cache parsed SQL and PL/SQL statements.
* Dictionary Cache - information about data dictionary objects.
* Redo Log Buffer - committed transactions that are not yet written to
the redo log files.
* JAVA pool - caching parsed Java programs.
* Streams pool - cache Oracle Streams objects.
* Large pool - used for backups, UGAs, etc.
PGA (Program or Process Global Area) is a memory area (RAM) that stores
data and control
information for a single process. For example, it typically contains a
sort area, hash area,
session cursor cache, etc.