Overview
This chapter describes concurrent processing APIs you can use in your PL/SQL procedures. It also includes example PL/SQL code using these concurrent processing APIs.
The following concurrent processing packages are covered:
FND_CONC_GLOBAL.REQUEST_DATA: Sub–request Submission
FND_CONCURRENT: Information on Submitted Requests
FND_FILE: PL/SQL: File I/O
FND_PROGRAM: Concurrent Program Loader
FND_SET: Request Set Creation
FND_REQUEST: Concurrent Program Submission
FND_REQUEST_INFO: Request Information
FND_SUBMIT: Request Set Submission
This package is used for submitting sub-requests from PL/SQL concurrent programs.
FND_CONC_GLOBAL.REQUEST_DATAVariable | Description |
---|---|
Summary |
|
Variable | Description |
---|---|
Description | FND_CONC_GLOBAL.REQUEST_DATA retrieves the value of the REQUEST_DATA global. |
Variable | Description |
---|---|
Summary |
|
Variable | Description |
---|---|
Description | FND_CONC_GLOBAL .SET_REQ_GLOBALS sets the values for special globals. |
/* * This is sample PL/SQL concurrent program submits 10 * sub-requests. The sub-requests are submitted one at a * time. Each time a sub-request is submitted, the parent * exits to the Running/Paused state, so that it does not * consume any resources while waiting for the child * request, to complete. When the child completes the * parent is restarted. */create or replace procedure parent (errbuf out varchar2, retcode out number) is i number; req_data varchar2(10); r number;begin -- -- Read the value from REQUEST_DATA. If this is the -- first run of the program, then this value will be -- null. -- Otherwise, this will be the value that we passed to -- SET_REQ_GLOBALS on the previous run. -- req_data := fnd_conc_global.request_data; -- -- If this is the first run, we‘ll set i = 1. -- Otherwise, we‘ll set i = request_data + 1, and we‘ll -- exit if we‘re done. -- if (req_data is not null) then i := to_number(req_data); i := i + 1; if (i < 11 ) then errbuf := ‘Done!‘; retcode := 0 ; return; end if; else i := 1; end if; -- -- Submit the child request. The sub_request parameter -- must be set to ‘Y‘. -- r := fnd_request.submit_request(‘FND‘, ‘CHILD‘, ‘Child ‘ || to_char(i), NULL, TRUE, fnd_conc_global.printer); if r = 0 then -- -- If request submission failed, exit with error. -- errbuf := fnd_message.get; retcode := 2; else -- -- Here we set the globals to put the program into the -- PAUSED status on exit, and to save the state in -- request_data. -- fnd_conc_global.set_req_globals(conc_status => ‘PAUSED‘, request_data => to_char(i)); errbuf := ‘Sub-Request submitted!‘; retcode := 0 ; end if; return;end;
FND_CONCURRENT PackageFND_CONCURRENT.AF_COMMITVariable | Description |
---|---|
Summary |
|
Description | FND_CONCURRENT.AF_COMMIT is used by concurrent programs that use a particular rollback segment. This rollback segment must be defined in the Define Concurrent Program form. |
FND_CONCURRENT.AF_COMMIT executes the COMMIT command for the specified rollback segment.
FND_CONCURRENT.AF_COMMIT has no arguments.
FND_CONCURRENT.AF_ROLLBACKVariable | Description |
---|---|
Summary |
|
Description | FND_CONCURRENT.AF_ROLLBACK is used by concurrent programs that use a particular rollback segment. This rollback segment must be defined in the Define Concurrent Program form.FND_CONCURRENT.AF_ROLLBACK executes the ROLLBACK command for the specified rollback segment.FND_CONCURRENT.AF_ROLLBACK has no arguments. |
Variable | Description |
---|---|
Summary |
|
Description | Returns the status of a concurrent request. If the request has already completed, also returns a completion message.FND_CONCURRENT.GET_REQUEST_STATUS returns the "developer" phase and status values that can drive program logic. |
Variable | Description |
---|---|
request_id | The request ID of the program to be checked. |
application | Short name of the application associated with the concurrent program. This parameter is necessary only when the request_id is not specified. |
program | Short name of the concurrent program (not the executable). This parameter is necessary only when the request_id is not specified. When application and program are provided, the request ID of the last request for this program is returned in request_id. |
Variable | Description |
---|---|
phase | The user-friendly request phase from FND_LOOKUPS. |
status | The user-friendly request status from FND_LOOKUPS. |
dev_phase | The request phase as a constant string that can be used for program logic comparisons. |
dev_status | The request status as a constant string that can be used for program logic comparisons. |
message | The completion message supplied if the request has completed. |
Example
call_status boolean; rphase varchar2(80); rstatus varchar2(80); dphase varchar2(30); dstatus varchar2(30); message varchar2(240); call_status := FND_CONCURRENT.GET_REQUEST_STATUS(<Request_ID>, ‘‘, ‘‘, rphase,rstatus,dphase,dstatus, message); end;
In the above example, rphase and rstatus receive the same phase and status values as are displayed on the Concurrent Requests form. The completion text of a completed request returns in a message.
Any developer who wishes to control the flow of a program based on a request‘s outcome should use the following values to compare the request‘s phase and status.
Possible values for dev_phase and dev_status are listed and described in the following table:
dev_phase | dev_status | Description |
---|---|---|
PENDING | NORMAL | Request is waiting for the next available manager. |
PENDING | STANDBY | A constrained request (i.e. incompatible with currently running or actively pending programs) is waiting for the Internal concurrent manager to release it. |
PENDING | SCHEDULED | Request is scheduled to start at a future time or date. |
PENDING | PAUSED | Child request is waiting for its Parent request to mark it ready to run. For example, a report in a report set that runs sequentially must wait for a prior report to complete. |
RUNNING | NORMAL | Request is being processed. |
RUNNING | PAUSED | Parent request is waiting for its sub-requests to complete. |
RUNNING | RESUMING | Parent request is waiting to restart after its sub-requests have completed. |
RUNNING | TERMINATING | A user has requested to terminate this running request. |
COMPLETE | NORMAL | Request completed successfully. |
COMPLETE | ERROR | Request failed to complete successfully. |
COMPLETE | WARNING | Request completed with warnings. For example, a report is generated successfully but failed to print. |
COMPLETE | CANCELLED | Pending or Inactive request was cancelled. |
COMPLETE | TERMINATED | Running request was terminated. |
INACTIVE | DISABLED | Concurrent program associated with the request is disabled. |
INACTIVE | ON_HOLD | Pending request placed on hold. |
INACTIVE | NO_ MANAGER | No manager is defined to run the request. |
INACTIVE | SUSPENDED | This value is included for upward compatibility. It indicates that a user has paused the request at the OS level. |
Variable | Description |
---|---|
Summary |
|
Description | Waits for request completion, then returns the request phase/status and completion message to the caller. Goes to sleep between checks for request completion. |
Variable | Description |
---|---|
request_id | The request ID of the request to wait on. |
interval | Number of seconds to wait between checks (i.e., number of seconds to sleep.) |
max_wait | The maximum time in seconds to wait for the request‘s completion. |
Variable | Description |
---|---|
phase | The user-friendly request phase from the FND_LOOKUPS table. |
status | The user-friendly request status from the FND_LOOKUPS table. |
dev_phase | The request phase as a constant string that can be used for program logic comparisons. |
dev_status | The request status as a constant string that can be used for program logic comparisons. |
message | The completion message supplied if the request has already completed. |
Variable | Description |
---|---|
Summary |
|
Description | Call SET_COMPLETION_STATUS from a concurrent program to set its completion status. The function returns TRUE on success, otherwise FALSE. |
Variable | Description |
---|---|
status | The status to set the concurrent program to. Either NORMAL, WARNING, or ERROR. |
message | An optional message. |
The FND_FILE package contains procedures to write text to log and output files. These procedures are supported in all types of concurrent programs.
For testing and debugging, you can use the procedures FND_FILE.PUT_NAMES and FND_FILE.CLOSE. Note that these two procedures should not be called from a concurrent program.
FND_FILE supports a maximum buffer line size of 32K for both log and output files.
Tip: This package is not designed for generic PL/SQL text I/O, but rather only for writing to request log and output files.
See: PL/SQL File I/O Processing
FND_FILE.PUTVariable | Description |
---|---|
Summary |
|
Description | Use this procedure to write text to a file (without a new line character). Multiple calls to FND_FILE.PUT will produce concatenated text. Typically used with FND_FILE.NEW_LINE. |
Variable | Description |
---|---|
which | Log file or output file. Use either FND_FILE.LOG or FND_FILE.OUTPUT. |
buff | Text to write. |
Variable | Description |
---|---|
Summary |
|
Description | Use this procedure to write a line of text to a file (followed by a new line character). You will use this utility most often. |
Variable | Description |
---|---|
which | Log file or output file. Use either FND_FILE.LOG or FND_FILE.OUTPUT. |
buff | Text to write. |
Using Message Dictionary to retrieve a message already set up on the server and putting it in the log file (allows the log file to contain a translated message):
FND_FILE.PUT_LINE( FND_FILE.LOG, fnd_message.get );
Putting a line of text in the log file directly (message cannot be translated because it is hardcoded in English; not recommended):
fnd_file.put_line(FND_FILE.LOG,‘Warning: Employee ‘|| l_log_employee_name||‘ (‘|| l_log_employee_num || ‘) does not have a manager.‘);
FND_FILE.NEW_LINEVariable | Description |
---|---|
Summary |
|
Description | Use this procedure to write line terminators (new line characters) to a file. |
Variable | Description |
---|---|
which | Log file or output file. Use either FND_FILE.LOG or FND_FILE.OUTPUT. |
lines | Number of line terminators to write. |
To write two new line characters:
fnd_file.new_line(FND_FILE.LOG,2);
FND_FILE.PUT_NAMESVariable | Description |
---|---|
Summary |
|
Description | Sets the temporary log and out filenames and the temp directory to the user-specified values. DIR must be a directory to which the database can write. FND_FILE.PUT_NAMES should be called before calling any other FND_FILE function, and only once per session. |
Tip: FND_FILE.PUT_NAMES is meant for testing and debugging from SQL*Plus; it does nothing if called from a concurrent program.
BEGINfnd_file.put_names(‘test.log‘, ‘test.out‘,‘/local/db/8.0.4/db-temp-dir/‘); fnd_file.put_line(fnd_file.output,‘Called stored procedure‘); /* Some logic here... */ fnd_file.put_line(fnd_file.output, ‘Reached point A‘); /* More logic, etc... */ fnd_file.close;END;
Variable | Description |
---|---|
p_log | Temporary log filename. |
p_out | Temporary output filename. |
p_dir | Temporary directory name. |
BEGIN fnd_file.put_names(‘test.log‘, ‘test.out‘, ‘/local/db/8.0.4/db-temp-dir/‘); fnd_file.put_line(fnd_file.output,‘Called stored procedure‘); /* Some logic here... */ fnd_file.put_line(fnd_file.output, ‘Reached point A‘); /* More logic, etc... */ fnd_file.close;END;
FND_FILE.CLOSEVariable | Description |
---|---|
Summary |
|
Description | Use this procedure to close open files.
Tip: Use FND_FILE.CLOSE only in command lines sessions. FND_FILE.CLOSE should not be called from a concurrent program.
|
BEGIN fnd_file.put_names(‘test.log‘, ‘test.out‘, ‘/local/db/8.0.4/db-temp-dir/‘); fnd_file.put_line(fnd_file.output,‘Called stored procedure‘); /* Some logic here... */ fnd_file.put_line(fnd_file.output, ‘Reached point A‘); /* More logic, etc... */ fnd_file.close;END;
Error HandlingThe FND_FILE package can raise one exception, FND_FILE.UTL_FILE_ERROR, which is raised to indicate an UTL_FILE error condition. Specifically, the procedures FND_FILE.PUT, FND_FILE.PUT_LINE and FND_FILE.NEW_LINE can raise FND_FILE.UTL_FILE_ERROR if there is an error. In addition to this package exception, FND_FILE can also raise predefined PL/SQL exceptions such as NO_DATA_FOUND or VALUE_ERROR.
FND_FILE will raise a UTL_FILE_ERROR if it is not able to open or write to a temporary file. It is up to the concurrent program to error out or complete normally, after the FND_FILE.UTL_FILE_ERROR exception is raised. FND_FILE keeps the translated message in the message stack before raising the UTL_FILE_ERROR exception. Developers can get the message for FND_FILE errors and use it as a Request Completion text. It is up to the caller to get the message from the message stack by using the FND_MESSAGE routine within an exception handler.
The concurrent manager will keep all the temporary file creation errors in the request log file.
FND_PROGRAM: Concurrent Program LoadersThe FND_PROGRAM package includes procedures for creating concurrent program executables, concurrent programs with parameters and incompatibility rules, request sets, and request groups. The FND_PROGRAM package also contains functions you can use to check for the existence of concurrent programs, executables, parameters, and incompatibility rules.
The arguments passed to the procedures correspond to the fields in the Oracle Application Object Library forms, with minor exceptions. In general, first enter the parameters to these procedures into the forms for validation and debugging.
If an error is detected, ORA-06501: PL/SQL: internal error is raised. The error message can be retrieved by a call to the function fnd_program.message().
Some errors are not trapped by the package, notably "duplicate value on index".
Note that an exception is raised if bad foreign key information is provided. For example, delete_program() does not fail if the program does not exist, but does fail if given a bad application name.
FND_PROGRAM.MESSAGEVariable | Description |
---|---|
Summary |
|
Description | Use the message function to return an error message. Messages are set when any validation (program) errors occur. |
Variable | Description |
---|---|
Summary |
|
Description | Use this procedure to define a concurrent program executable. This procedure corresponds to the "Concurrent Program Executable" window accessible from the System Administrator and Application Developer responsibilities. |
Variable | Description |
---|---|
executable | Name of executable (for example, ‘FNDSCRMT‘). |
application | The short name of the executable‘s application, for example, ‘FND‘. |
description | Optional description of the executable. |
execution_ method | The type of program this executable uses. Possible values are ‘Host‘, ‘Immediate‘, ‘Oracle Reports‘, ‘PL/SQL Stored Procedure‘, ‘Spawned‘, ‘SQL*Loader‘, ‘SQL*Plus‘. |
execution_ file_name | The operating system name of the file. Required for all but Immediate programs. This file name should not include spaces or periods unless the file is a PL/SQL stored procedure. |
subroutine_name | Used only by Immediate programs. Cannot contain spaces or periods. |
icon_name | Reserved for future use by internal developers only. Specify NULL. |
language_code | Language code for the name and description, for example, ‘US‘. |
Variable | Description |
---|---|
Summary |
|
Variable | Description |
---|---|
Description | Use this procedure to delete a concurrent program executable. An executable that is assigned to a concurrent program cannot be deleted. |
Variable | Description |
---|---|
executable | The short name of the executable to delete. |
application | The short name of the executable‘s application, for example ‘FND‘. |
Variable | Description |
---|---|
Summary |
|
Description | Use this procedure to define a concurrent program. This procedure corresponds to the "Concurrent Program" window accessible from the System Administrator and Application Developer responsibilities. |
Variable | Description |
---|---|
program | The user-visible program name, for example ‘Menu Report‘. |
application | The short name of the application that owns the program. The program application determines the Oracle user name used by the program. |
enabled | Specify either "Y" or "N". |
short_name | The internal developer program name. |
description | An optional description of the program. |
executable_name | The short name of the registered concurrent program executable. |
executable_ application | The short name of the application under which the executable is registered. |
execution_ options | Any special option string, used by certain executables such as Oracle Reports. |
priority | An optional program level priority. |
save_output | Indicate with "Y" or "N" whether to save the output. |
Allow printing by specifying "Y", otherwise "N". | |
cols | The page width of report columns. |
rows | The page length of report rows. |
style | The default print style name. |
style_required | Specify whether to allow changing the default print style from the Submit Requests window. |
printer | Force output to the specified printer. |
request_type | A user-defined request type. |
request_type_ application | The short name of the application owning the request type. |
use_in_srs | Specify "Y" to allow users to submit the program from the Submit Requests window, otherwise "N". |
allow_ disabled_values | Specify "Y" to allow parameters based on outdated value sets to validate anyway. Specify "N" to require current values. |
run_alone | Program must have the whole system to itself. ("Y" or "N") |
output_type | The type of output generated by the concurrent program. Either "HTML", "PS", "TEXT" or "PDF". |
enable_trace | Specify "Y" if you want to always enable SQL trace for this program, "N" if not. |
nls_compliant | Reserved for use by internal developers only. Use "N". |
icon_name | Reserved for use by internal developers only. Use NULL. |
language_code | Language code for the name and description. |
mls_function_ short_name | The name of the registered MLS function. |
mls_function_ application | The short name of the application under which the MLS function is registered. |
incrementor | The incrementor PL/SQL function name. |
Variable | Description |
---|---|
Summary |
|
Description | Use this procedure to delete a concurrent program. All references to the program are deleted as well. |
Variable | Description |
---|---|
program_short_ name | The short name used as the developer name of the concurrent program. |
application | The application that owns the concurrent program. |
Variable | Description |
---|---|
Summary |
|
Description | Creates a new parameter for a specified concurrent program. This procedure corresponds to the "Concurrent Program Parameters" window accessible from the System Administrator and Application Developer responsibilities. |
Tip: A newly added parameter does not show up in the SRS form until the descriptive flexfields are compiled. The program $FND_TOP/$APPLBIN/fdfcmp compiles the descriptive flexfields.
Variable | Description |
---|---|
program_short_ name | The short name used as the developer name of the concurrent program. |
application | The short name of the application that owns the concurrent program. |
sequence | The parameter sequence number that determines the order of the parameters. |
parameter | The parameter name. |
description | An optional parameter description. |
enabled | "Y" for enabled parameters; "N" for disabled parameters. |
value_set | The value set to use with this parameter. |
default_type | An optional default type. Possible values are ‘Constant‘, ‘Profile‘, ‘SQL Statement‘, or ‘Segment‘. |
default_value | Only required if the default_type is not NULL. |
required | "Y" for required parameters, "N" for optional ones. |
enable_security | "Y" enables value security if the value set permits it. "N" prevents value security from operating on this parameter. |
range | Optionally specify "High", "Low", or "Pair". |
display | "Y" to display the parameter, "N" to hide it. |
display_size | The length of the item in the parameter window. |
description_size | The length of the item‘s description in the parameter window. |
concatenated_ description_size | The Length of the description in the concatenated parameters field. |
prompt | The item prompt in the parameter window. |
token | The Oracle Reports token (only used with Oracle Reports programs). |
Variable | Description |
---|---|
Summary |
|
Description | Call this procedure to remove a parameter from a concurrent program. |
Variable | Description |
---|---|
program_short_ name | The short name used as the developer name of the concurrent program. |
application | The application that owns the concurrent program. |
parameter | The parameter to delete. |
Variable | Description |
---|---|
Summary |
|
Description | Use this procedure to register an incompatibility for a specified concurrent program. This procedure corresponds to the "Incompatible Programs" window accessible from the System Administrator and Application Developer responsibilities. |
Variable | Description |
---|---|
program_short_ name | The short name used as the developer name of the concurrent program. |
application | The short name of the application that owns the concurrent program |
inc_prog_ short_name | The short name of the incompatible program. |
inc_prog_ application | Application that owns the incompatible program. |
scope | Either "Set" or "Program Only" |
Variable | Description |
---|---|
Summary |
|
Description | Use this procedure to delete a concurrent program incompatibility rule. |
Variable | Description |
---|---|
program_short_ name | The short name used as the developer name of the concurrent program. |
application | Application that owns the concurrent program |
inc_prog_ short_name | Short name of the incompatible program to delete. |
inc_prog_ application | Application that owns the incompatible program. |
Variable | Description |
---|---|
Summary |
|
Description | Use this procedure to create a new request group. This procedure corresponds to the master region of the "Request Groups" window in the System Administration responsibility. |
Variable | Description |
---|---|
request_group | The name of the request group |
application | The application that owns the request group. |
code | An optional code for the request group. |
description | An optional description of the request group. |
Variable | Description |
---|---|
Summary |
|
Description | Use this procedure to delete a request group. |
Variable | Description |
---|---|
request_group | The name of the request group to delete. |
application | The application that owns the request group. |
Variable | Description |
---|---|
Summary |
|
Description | Use this procedure to add a concurrent program to a request group. This procedure corresponds to the "Requests" region in the "Request Groups" window in System Administration. |
Variable | Description |
---|---|
program_short_ name | The short name used as the developer name of the concurrent program. |
program_ application | The application that owns the concurrent program. |
request_group | The request group to which to add the concurrent program. |
group_ application | The application that owns the request group. |
Variable | Description |
---|---|
Summary |
|
Description | Use this procedure to remove a concurrent program from a request group. |
Variable | Description |
---|---|
program_short_ name | The short name used as the developer name of the concurrent program. |
program_ application | The application that owns the concurrent program. |
request_group | The request group from which to delete the concurrent program. |
group_ application | The application that owns the request group. |
Variable | Description |
---|---|
Summary |
|
Description | Returns TRUE if a concurrent program exists. |
Variable | Description |
---|---|
program | The short name of the program |
application | Application short name of the program. |
Variable | Description |
---|---|
Summary |
|
Variable | Description |
---|---|
Description | Returns TRUE if a program parameter exists. |
Variable | Description |
---|---|
program | The short name of the program |
application | Application short name of the program. |
parameter | Name of the parameter. |
Variable | Description |
---|---|
Summary |
|
Description | Returns TRUE if a program incompatibility exists. |
Variable | Description |
---|---|
program | The short name of the first program |
application | Application short name of the program. |
inc_prog_short_ name | Short name of the incompatible program. |
inc_prog_ applicatoin | Application short name of the incompatible program. |
Variable | Description |
---|---|
Summary |
|
Description | Returns TRUE if program executable exists. |
Variable | Description |
---|---|
program | The name of the executable. |
application | Application short name of the executable. |
Variable | Description |
---|---|
Summary |
|
Description | Returns TRUE if request group exists. |
Variable | Description |
---|---|
program | The name of the executable. |
application | Application short name of the request group. |
Variable | Description |
---|---|
Summary |
|
Description | Returns TRUE if a program is in a request group. |
Variable | Description |
---|---|
program | The short name of the first program. |
application | Application short name of the program. |
request_group | Name of the request group. |
group_ application | Application short name of the request group. |
Variable | Description |
---|---|
Syntax |
|
Variable | Description |
---|---|
Description | Use this procedure to enable or disable a concurrent program. |
Variable | Description |
---|---|
short_name | The shortname of the program. |
application | Application short name of the program. |
enabled | Specify ‘Y‘ to enable the program and ‘N‘ to disable the program. |
Variable | Description |
---|---|
Syntax |
|
Description | Optionally call before submitting a concurrent request to set request options. Returns TRUE on successful completion, and FALSE otherwise. |
Variable | Description小编还为您整理了以下内容,可能对您也有帮助: plsql查询中'%%'是模糊查询吗?为什么查不出来呢? plsql查询中'%%'是模糊查询,操作方法如下: 1、首先在sql中选择一个表,检索数据,比如按orderNum进行模糊查询。 2、用like语句模糊查询,百分号之间的是模糊值。 3、执行以后就查出了包含模糊值的数据。 4、当后面的百分号不要,代表的是以模糊值结尾。 5、最后前面百分号不要证明,是查以模糊值开始的数据。 6、还可以使用mysql的模糊查询like,基本也是需要用到通配符_的,它的作用是:表示任意单个字符。匹配单个任意字符,它常用来表达式的字符长度语句。 怎么看 oracle 执行计划结果 显示结果 一、通过PL/SQL Dev工具 1、直接File->New->Explain Plan Window,在窗口中执行sql可以查看计划结果。其中,Cost表示cpu的消耗,单位为n%,Cardinality表示执行的行数,等价Rows。 2、先执行 EXPLAIN PLAN FOR select * from tableA where paraA=1,再 select * from table(DBMS_XPLAN.DISPLAY)便可以看到oracle的执行计划了,看到的结果和1中的一样,所以使用工具的时候推荐使用1方法。 注意:PL/SQL Dev工具的Command window中不支持set autotrance on的命令。还有使用工具方法查看计划看到的信息不全,有些时候我们需要sqlplus的支持。 二、通过sqlplus 1.最简单的办法 Sql> set autotrace on Sql> select * from al; 执行完语句后,会显示explain plan 与 统计信息。 这个语句的优点就是它的缺点,这样在用该方法查看执行时间较长的sql语句时,需要等待该语句执行成功后,才返回执行计划,使优化的周期大大增长。如果不想执行语句而只是想得到执行计划可以采用: Sql> set autotrace traceonly 这样,就只会列出执行计划,而不会真正的执行语句,大大减少了优化时间。虽然也列出了统计信息,但是因为没有执行语句,所以该统计信息没有用处,如果执行该语句时遇到错误,解决方法为: (1)在要分析的用户下: Sqlplus > @ ? dbmsadminutlxplan.sql (2) 用sys用户登陆 Sqlplus > @ ?sqlplusadminplustrce.sql Sqlplus > grant plustrace to user_name; - - user_name是上面所说的分析用户 2.用explain plan命令 (1) sqlplus > explain plan for select * from testdb.myuser (2) sqlplus > select * from table(dbms_xplan.display); 上面这2种方法只能为在本会话中正在运行的语句产生执行计划,即我们需要已经知道了哪条语句运行的效率很差,我们是有目的只对这条SQL语句去优化。其实,在很多情况下,我们只会听一个客户抱怨说现在系统运行很慢,而我们不知道是哪个SQL引起的。此时有许多现成的语句可以找出耗费资源比较多的语句,如: SELECT ADDRESS, substr(SQL_TEXT,1,20) Text, buffer_gets, executions, buffer_gets/executions AVG FROM v$sqlarea WHERE executions>0 AND buffer_gets > 100000 ORDER BY 5; ADDRESS TEXT BUFFER_GETS EXECUTIONS AVG -------- ---------------------------------------- ----------- ---------- ------------------------------------------------------------ 66D83D64 select t.name, (sel 421531 60104 7.01336017 66D9E8AC select t.schema, t.n 1141739 2732 417.913250 66B82BCC select s.synonym_nam 441261 6 73543.5 从而对找出的语句进行进一步优化。当然我们还可以为一个正在运行的会话中运行的所有SQL语句生成执行计划,这需要对该会话进行跟踪,产生trace文件,然后对该文件用tkprof程序格式化一下,这种得到执行计划的方式很有用,因为它包含其它额外信息,如SQL语句执行的每个阶段(如Parse、Execute、Fetch)分别耗费的各个资源情况(如CPU、DISK、elapsed等)。 3、启用SQL_TRACE跟踪所有后台进程活动: 全局参数设置: .OracleHome/admin/SID/pfile中指定: SQL_TRACE = true (10g) 当前session中设置: SQL> alter session set SQL_TRACE=true; SQL> select * from al; SQL> alter session set SQL_TRACE=false; 对其他用户进行跟踪设置: SQL> select sid,serial#,username from v$session where username='XXX'; SID SERIAL# USERNAME ------ ---------- ------------------ 127 31923 A 128 54521 B 开启跟踪:SQL> exec dbms_system.set_SQL_TRACE_in_session(127,31923,true); 关闭跟踪:SQL> exec dbms_system.set_SQL_TRACE_in_session(127,31923,false); 然后使用oracle自带的tkprof命令行工具格式化跟踪文件。 4、使用10046事件进行查询: 10046事件级别: Lv1 - 启用标准的SQL_TRACE功能,等价于SQL_TRACE Lv4 - Level 1 + 绑定值(bind values) Lv8 - Level 1 + 等待事件跟踪 Lv12 - Level 1 + Level 4 + Level 8 全局设定: OracleHome/admin/SID/pfile中指定: EVENT="10046 trace name context forever,level 12" 当前session设定: 开启:SQL> alter session set events '10046 trace name context forever, level 8'; 关闭:SQL> alter session set events '10046 trace name context off'; 对其他用户进行设置: SQL> select sid,serial#,username from v$session where username='XXX'; SID SERIAL# USERNAME ------ ---------- ------------------ 127 31923 A SQL> exec dbms_system.set_ev(127,31923,10046,8,'A'); 5、使用tkprof格式化跟踪文件: (根据下面SQL语句得到的文件都不存在该目录下,郁闷啊,懵懂啊...) 一般,一次跟踪可以分为以下几步: 1、界定需要跟踪的目标范围,并使用适当的命令启用所需跟踪。 2、经过一段时间后,停止跟踪。此时应该产生了一个跟踪结果文件。 3、找到跟踪文件,并对其进行格式化,然后阅读或分析。 --使用一下SQL找到当前session的跟踪文件: SELECT d.value|| '/' ||lower(rtrim(i.instance, chr( 0 )))|| '_ora_' ||p.spid|| '.trc' trace_file_namefrom( select p.spid from v$mystat m,v$session s, v$process pwhere m.statistic# = 1 and s.sid = m.sid and p.addr = s.paddr) p,( select t.instance from v$thread t,v$parameter vwhere v.name = 'thread' and (v.value = 0 or t.thread# = to_number(v.value))) i,( select value from v$parameter where name = 'user_mp_dest' ) d;-- 其它用户的 session SELECT d.value|| '/' ||lower(rtrim(i.instance, chr( 0 )))|| '_ora_' ||p.spid|| '.trc' trace_file_name from ( select p.spid from v$session s, v$process p where s.sid= '27' and s. SERIAL#= '30' and p.addr = s.paddr) p, ( select t.instance from v$thread t,v$parameter v where v.name = 'thread' and (v.value = 0 or t.thread# = to_number(v.value))) i, ( select value from v$parameter where name = 'user_mp_dest' ) d; --查找后使用tkprof命令,将TRACE文件格式为到D盘的explain_format.txt文件中 SQL> $tkprof d:/oracle/admin/FZLGFM/ump/fzlgfm_ora_3468.trc d:/explain_format.txt 文件内容大致如下(看不太懂....懵懂啊.....天啊....神啊.....过几时就懂了/////////////) TKPROF: Release 9.2.0.1.0 - Proction on 星期二 4月 20 13:59:20 2010 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. Trace file: d:/oracle/admin/FZLGFM/ump/fzlgfm_ora_3468.trc Sort options: default ******************************************************************************** count = number of times OCI procere 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******************************************************************************** alter session set events '10046 trace name context forever, level 8' call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 0 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 1 0.00 0.00 0 0 0 0 Misses in library cache ring parse: 0 Misses in library cache ring execute: 1 Optimizer goal: CHOOSE Parsing user id: SYS 在oracle中 PL/sql程序块必须包括哪几部分? oracle中 PL/sql程序块必须包括声明部分,可执行部分,异常处理部分。 PL/SQL程序都是以块(block)为基本单位。整个PL/SQL块分三部分:声明部分(用declare开头)、执行部分(以 begin开头)和异常处理部分(以exception开头)。 其中执行部分是必须的,其他两个部分可选。无论PL/SQL程序段的代码量有多大,其基本结构就是由这三部分组成。而且每条语句均由分号隔开。 哪位高手可以推荐几款通用的数据库管理工具 1、MySQL Workbench MySQL Workbench是一款专为MySQL设计的ER/数据库建模工具。它是著名的数据库设计工具DBDesigner4的继任者。你可以用MySQL Workbench设计和创建新的数据库图示,建立数据库文档,以及进行复杂的MySQL 迁移 MySQL Workbench是下一代的可视化数据库设计、管理的工具,它同时有开源和商业化的两个版本。该软件支持Windows和Linux系统,下面是一些该软件运行的界面截图: 2、数据库管理工具 Navicat Lite NavicatTM是一套快速、可靠并价格相宜的资料库管理工具,大可使用来简化资料库的管理及降低系统管理成本。它的设计符合资料库管理员、开发人员及中小企业的需求。 Navicat是以直觉化的使用者图形介面所而建的,让你可以以安全且简单的方式建立、组织、存取并共用资讯。 界面如下图所示: Navicat 提供商业版Navicat Premium 和免费的版本 Navicat Lite 。免费版本的功能已经足够强大了。 Navicat 支持的数据库包括MySQL、Oracle、SQLite、PostgreSQL和SQL Server 等。 3、开源ETL工具Kettle Kettle是一款国外开源的etl工具,纯java编写,绿色无需安装,数据抽取高效稳定(数据迁移工具)。Kettle中有两种脚本文件,transformation和job,transformation完成针对数据的基础转换,job则完成整个工作流的控制。 ·授权协议:LGPL ·开发语言: Java ·操作系统: 跨平台 4、Eclipse SQLExplorer SQLExplorer是Eclipse集成开发环境的一种插件,它可以被用来从Eclipse连接到一个数据库。 SQLExplorer插件提供了一个使用SQL语句访问数据库的图形用户接口(GUI)。通过使用SQLExplorer,你能够显示表格、表格结构和表格中的数据,以及提取、添加、更新或删除表格数据。 SQLExplorer同样能够生成SQL脚本来创建和查询表格。所以,与命令行客户端相比,使用SQLExplorer可能是更优越的选择,下图是运行中的界面,很好很强大。 l授权协议: 未知 l开发语言: Java l操作系统: 跨平台 5、MySQL管理工具phpMyAdmin phpMyAdmin是一个非常受欢迎的基于web的MySQL数据库管理工具。它能够创建和删除数据库,创建/删除/修改表格,删除/编辑/新增字段,执行SQL脚本等。 l授权协议:GPL l开发语言:PHP l操作系统:跨平台 6、Mongodb 管理工具Mongodb Studio Mongodb是一款性能优良,功能丰富的文档型非关系型数据库。由于该数据库是开源项目并且还在不断更新中,目前为止在任何平台上都不能找到功能相对完整的客户端数据库管理工具。而越来越多的项目中使用了Mongodb,使得管理起来十分麻烦.如果点点鼠标就搞定了.那该有多好。 基于如上背景,我们制作了此MongoDB管理工具,在DBA/开发/管理员三个维度提供一定层次的管理功能。 Mongodb Management Studio功能如下: l服务器管理功能 添加服务器,删除服务器 l服务器,数据库,表,列,索引,树形显示和状态信息查看 l查询分析器功能. 支持select,insert,Delete,update 支持自定义分页函 数 $rowid(1,5)查询第一条到第五条,需放在select后面. l索引管理功能 支持列名的显示,索引的创建,查看,删除. l数据库Profile管理. 可以设置Profile开关,查看Profile信息.自定义分页大小. lmaster/slave信息显示 7、MySQL监控小工具mycheckpoint mycheckpoint是一个开源的 MySQL监控工具,主要用来监控数据。通过视图方式提供监控数据报表。mycheckpoint支持以的Web服务器来运行。 例如:SELECTinnodb_read_hit_percent, DML FROM sv_report_chart_sample; 查看详细报表示例。 安装手册:http://code.openark.org/forge/mycheckpoint/documentation/installation 8、SQL SERVER 数据库发布向导 Microsoft SQL Server DatabasePublishing Wizard (微软SQLServer数据库发布向导) 是微软发布的一个开源工具,使用该工具可以帮你将SQLSERVER 数据库导出成一个 SQL脚本,类似 MySQL 的 mysqlmp工具。 官方说明:SQLServer数据库发布向导提供了一种将数据库发布到 T-SQL 脚本或者直接发布到支持宿主服务提供程序的方法。 9、Eclipse 的Oracle插件jOra jOra是一个为 Oracle开发者和管理员提供的 Eclipse 插件,可轻松的对Oracle进行开发和管理。 安装地址:http://jora.luenasoft.de/updatesite 插件截图 l授权协议:免费,非开源 l开发语言:Java l操作系统:跨平台 10、免费PostgreSQL监控工具pgwatch pgwatch 是一个简单易用的PostgreSQL的监控工具,支持PostgreSQL 9.0 以及更新的版本。 主要特性: - 配置简单 - 大量的监控图表 - 快速系统检查面板 - 自动收集统计信息 - 交互式的 Flash 图表 - 集成 SQL worksheet l授权协议: Artistic l开发语言:PHP l操作系统: Linux 11、MySQL Browser MySQL的客户端工具MySQL Browser的优点是简单,及其的简单,安装之后能够立刻上手,马上就能使用的那种,布局也很简陋,功能也很简陋,简单使用没有问题,尤其是刚开始学习mysql的同学,可以尝试一下。 ·授权协议:未知 ·操作系统: Windows 12、MySQL客户端软件HeidiSQL HeidiSQL是一个功能非常强大的 MySQL 客户端软件,采用Delphi 开发,支持 Windows 操作系统。 l授权协议:GPL l开发语言:Delphi/Pascal l操作系统: Windows 13、SQLite管理工具SQLiteStudio SQLiteStudio 是一个跨平台的 SQLite数据库的管理工具,采用 Tcl语言开发。 l授权协议:未知 l操作系统:跨平台 14、SQL客户端工具SQLyog SQLyog 是一个易于使用的、快速而简洁的图形化管理MYSQL数据库的工具,它能够在任何地点有效地管理你的数据库。 功能: l快速备份和恢复数据; l以GRID/ TEXT格式显示结果; l支持客户端挑选、过滤数据; l批量执行很大的SQL脚本文件; l快速执行多重查询并能够返回每页超过1000条的记录集,而这种操作是直接生成在内存中的; l程序本身非常短小精悍!压缩后只有348 KB ; l完全使用MySQLC APIs程序接口; l以直观的表格界面建立或编辑数据表; l以直观的表格界面编辑数据; l进行索引管理; l创建或删除数据库; l操纵数据库的各种权限:库、表、字段; l编辑BLOB类型的字段,支持Bitmap/GIF/JPEG格式; l输出数据表结构/数据为SQL脚本; l支持输入/输出数据为CSV文件; l可以输出数据库清单为HTML文件; l为所有操作建立日志; l个人收藏管理操作语句; l支持语法加亮显示; l可以保存记录集为CSV、HTML、XML格式的文件; l21、99% 的操作都可以通过快捷键完成; l支持对数据表的各种高级属性修改; l查看数据服务器的各种状态、参数等; l支持更改数据表类型为ISAM, MYISAM, MERGE, HEAP, InnoDB, BDB; l刷新数据服务器、日志、权限、表格等; l诊断数据表:检查、压缩、修补、分析。 l授权协议:GPLv2 l开发语言:C/C++ l操作系统: Windows 15、数据挖掘工具RapidMiner RapidMiner是世界领先的数据挖掘解决方案,在一个非常大的程度上有着先进技术。它数据挖掘任务涉及范围广泛,包括各种数据艺术,能简化数据挖掘过程的设计和评价。 功能和特点 l免费提供数据挖掘技术和库; l100%用Java代码(可运行在操作系统); l数据挖掘过程简单,强大和直观; l内部XML保证了标准化的格式来表示交换数据挖掘过程; l可以用简单脚本语言自动进行大规模进程; l多层次的数据视图,确保有效和透明的数据; l图形用户界面的互动原型; l命令行(批处理模式)自动大规模应用; lJava API(应用编程接口); l简单的插件和推广机制; l强大的可视化引擎,许多尖端的高维数据的可视化建模; l400多个数据挖掘运营商支持; l耶鲁大学已成功地应用在许多不同的应用领域,包括文本挖掘,多媒体挖掘,功能设计,数据流挖掘,集成开发的方法和分布式数据挖掘。 l授权协议:未知 l开发语言:Java l操作系统:跨平台 16、Oracle 数据库开发工具Oracle SQL Developer Oracle SQL Developer 是一个免费非开源的用以开发数据库应用程序的图形化工具,使用SQLDeveloper 可以浏览数据库对象、运行 SQL 语句和脚本、编辑和调试 PL/SQL语句。另外还可以创建执行和保存报表。该工具可以连接任何 Oracle 9.2.0.1 或者以上版本的 Oracle 数据库,支持Windows、Linux 和 Mac OS X 系统。 ·授权协议:免费,非开源 ·开发语言:Java ·操作系统:Windows Linux MacOS 17、EMS SQL Manager for MySQL EMS SQL Manager for MySQL是一款高性能MySQL数据库服务器系统的管理和开发工具。它支持从MySQL 3.23到6.0的任一版本,并支持最新版本的MySQL的特点,包括:查看、存储规程和函数、InnoDB外部键字和其他特点。它提供了大量工具以满足富有经验的用户的所有要求。添加了精心设计的操作向导系统,以及SQL Manager for MySQL那富有艺术感的图形用户界面,即使新手也可以不会为如何使用而感到困扰。 l授权协议:商业软件 l开发语言:C/C++ l操作系统: Windows 18、数据库管理工具CoolSQL CoolSQL是一个数据库客户端管理工具。 ·支持大部分数据库包括:DB2、oracle、mysql、MS SQL Server、Derby、HSQL、Informix、Sybase、PostgresSQL等。 ·为用户提供友好和漂亮UI,其整体框架由视图组成类似于Eclipse。支持直接修改SQL查询结果。 ·支持将表格数据导出成文本文件,EXCEL和HTML。 ·拥有一个支持SQL语法着色显示,智能提示,文本编辑和查找的SQL编辑器。 ·能够展示数据库大部分元数据包括:版本,数据类型、函数,连接信息等。 ·支持导出数据对象信息包括对象数据(INSERT SQL语句),生成创建/删除脚本(create script/drop script)。 ·所有SQL脚本都可以以批量的模式执行。 ·能够搜索所有数据包括数据库列,表/视图和其他表格型。 ·支持i18n,当前提供两种语言(中文和英文)。 ·提供收藏功能,管理由用户收集的文本信息。 ·支持通过插件扩展其功能。 ll 授权协议:未知 l开发语言:Java l操作系统:跨平台 19、SQLite Manager 这是一款方便firefox对任何SQLite数据库操作的扩展。使用这款扩展,可以在firefox下很容易的创建表格、建立索引、浏览搜索等操作。此外它还具有一个语法检查功能的下拉式菜单,从而保证用户的操作不会出错。 20、MySQL GUI Tools 这是MySQL官方专业的数据库管理工具,同时支持多种操作系统。该工具包括下面三个产品: ·MySQL Administrator 1.2 ·MySQL Query Browser 1.2 ·MySQL MigrationToolkit 1.1 21、SQL客户端管理工具SQuirreL SQL Client SQuirreL SQL Client是一个SQL客户端管理工具。它允许你查看一个兼容JDBC的数据库的结构,浏览表格中的数据,运行SQL命令, 可连接的数据库有ORCAL,MS SQLSERVER, DB2 等, 它还允许用户安装和创建用于补充应用程序基本功能的插件。 功能和特点: l柱状图显示对像; l自动完成; l语句提示; l标记; l自动纠正; l编辑查询结果; l关系图; l分页打印。 l授权协议:未知 l语言:Java l操作系统:跨平台 22、Tomcat管理工具EasyTomcat EasyTomcat是一个用来帮助简化 Tomcat和 MySQL管理的系统,你可以启动、停止和配置Tomcat和MySQL服务器,同时也提供了监控的功能。 l授权协议:未知 l开发语言:Java l操作系统:跨平台 23、SQL Server管理工具sqlBuddy SqlBuddy是C#编写的一款用于Microsoft SQLServer和MSDE的开源工具,使用它可以很容易的编写SQL脚本。SqlBuddy提供的功能和查询分析器的目的有些微不同,它倾向于帮助使用者编写SQL。 l授权协议:未知 l开发语言:C# l操作系统: Windows 24、数据库开发工具GSQL GSQL 是 Gnome 下的一个集成数据库开发工具。数据库结构显示在下图左边的树状结构中,支持SQL的语法着色。 l授权协议:未知 l操作系统:Linux 25、SQLite数据库管理SQLiteSpy sqlitespy是一个快速和紧凑的数据库SQLite的GUI管理软件 。它的图形用户界面使得它很容易探讨,分析和操纵sqlite3数据库。 l授权协议:未知 l开发语言:Delphi/Pascal l操作系统:Windows 26、数据库开发工具Aqua Data Studio Aqua DataStudio 是一个为数据库开发人员准备的集成开发环境,可以对数据库做查询、管理,提供大量的数据库工具,例如数据库比较、源码控制等,目前支持的数据库包括:Oracle, DB2iSeries, DB2 LUW, MS SQL Server, Sybase ASE, Sybase Anywhere, Sybase IQ, Informix,PostgreSQL, MySQL, Apache Derby, JDBC, and ODBC. l授权协议:未知 l开发语言:C/C++ l操作系统:跨平台 27、MySQL 架构管理工具MySQL MMM MySQL Master-Master 架构常被用在 SQLquery 相依性低的情况,像是 counter常使用的INSERT INTO ... ON DUPLICATEKEY UPDATE a = a + 1不会因为out-of-order而造成问题。而 MySQL MMM算是其中一套写得比较好的 MySQLMaster-Master架构管理工具。 l授权协议:未知 l开发语言:Python l操作系统: Linux 28、MySQL Client MySQL的客户端工具,主界面如下: l授权协议:未知 l操作系统:Windows
|
---|