首页 > 数据库 > 数据库开发技术 > PLSQL questions
here are some general questions
PL/SQL Questions:
A function must return a value while a procedure doesn’t have to. Functions can be called from SQL.
anonymous pl/sql block begins with a DECLARE statement.
[@more@]
%TYPE associates a variable with a single column type.
%ROWTYPE associates a variable with an entire table row.
% TYPE is used to declare a field with the same type as that of a specified table’s column.
% ROWTYPE is used to declare a record with the same types as found in the specified database table, view and cursor.
Oracle provides the DBMS_ series of packages. There are many which developers should be aware of such as DBMS_SQL, DBMS_OUTPUT, DBMS_DDL, DBMS_PIPE, DBMS_TRANSACTION, DBMS_LOCK, DBMS_ALERT, DBMS_JOB, DBMS_UTILITY, UTL_FILE.
PL/SQL tables are scalar arrays that can be referenced by a binary integer. They can be used to hold values for use in later queries or calculations.
SQLCODE returns the value of the error number for the last error encountered. The SQLERRM returns the actual error message for the last error encountered.
Use the %ISOPEN cursor status variable.
Use the DBMS_OUTPUT package. Another possible method is to just use the SHOW ERROR command, but this only shows errors. The DBMS_OUTPUT package can be used to show intermediate results from loops and the status of variables as the procedure is executed. The new package UTL_FILE can also be used.
There are 12 types of triggers in PL/SQL that consist of combinations of the BEFORE, AFTER, ROW, TABLE, INSERT, UPDATE, DELETE and ALL key words:
Ø BEFORE ALL ROW INSERT
Ø AFTER ALL ROW INSERT
Ø BEFORE INSERT
Ø AFTER INSERT etc.
DBA:
The user is assigned the SYSTEM tablespace as a default and temporary tablespace. This is bad because it causes user objects and temporary segments to be placed into the SYSTEM tablespace resulting in fragmentation and improper table placement
(only data dictionary objects and the system rollback segment should be in SYSTEM).
By checking the status column of the DBA_, ALL_ or USER_OBJECTS views, depending upon whether you own or only have permission on the view or are using a DBA account.
The best way is to analyze the table and then use the data provided in the DBA_TABLES view to get the average row length and other pertinent data for the calculation. The quick and dirty way is to look at the number of blocks the table is actually using and ratio the number of rows in the table to its number of blocks against the number of expected rows.
There are several ways. One is to look at the v$session or v$process views. Another way is to check the current_logins parameter in the v$sysstat view. Another if you are on UNIX is to do a "ps -ef|grep oracle|wc -l? command, but this only works against a single instance installation.
Run the ANALYZE INDEX command on the index to validate its structure and then calculate the ratio of LF_BLK_LEN/LF_BLK_LEN+BR_BLK_LEN and if it isn?t near 1.0 (i.e. greater than 0.7 or so) then the index should be rebuilt. Or if the ratio
BR_BLK_LEN/ LF_BLK_LEN+BR_BLK_LEN is nearing 0.3.
The COST based system allows the use of HINT to control the optimizer path selection.
A Cartesian product is the result of an unrestricted join of two or more tables. The result set of a three table Cartesian product will have x * y * z number of rows where x, y, z correspond to the number of rows in each table involved in the join.
By use of the SPOOL command
Increase the size of the shared pool.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/14377/viewspace-1060086/ ,如需转载,请注明出处,否则将追究法律责任。