<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
>

<channel>
	<title>Oracle SQL</title>
	<atom:link href="http://www.kods.net/feed/category/oracle-sql/" rel="self" type="application/rss+xml" />
	<link>http://www.kods.netwww.kods.net/</link>
	<description>Oracle SQL</description>
	<pubDate>Fri, 12 Mar 2010 22:53:35+0000</pubDate>
	<generator>http://www.kods.netwww.kods.net/</generator>
	<language>en</language>
		<item>
		<title>ORACLE SQL Performance Tuning Series</title>
		<link>http://www.kods.netwww.kods.net/oracle-sql-performance-tuning-series/</link>
		<comments>http://www.kods.netwww.kods.net/oracle-sql-performance-tuning-series/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 23:53:32+0000</pubDate>
		<dc:creator>kods.net</dc:creator>
		<category><![CDATA[Oracle SQL]]></category>
		<category><![CDATA[oracle]]></category>
<category><![CDATA[oracle sql]]></category>
<category><![CDATA[performance optimization]]></category>
<category><![CDATA[oracle performance]]></category>
<category><![CDATA[sql performance tuning]]></category>
		<guid isPermaLink="true">http://www.kods.netwww.kods.net/oracle-sql-performance-tuning-series/</guid>
		<description><![CDATA[File: Oracle performance optimization. Chm Size: 106KB Download: Download]]></description>
		<content:encoded><![CDATA[<table bordercolor=#dddddd cellspacing=0 cellpadding=0 width=360 align=center border=1><tbody><tr height=60><td align=middle width=60></td><td><table cellspacing=0 cellpadding=0 width="100%" border=0><tbody><tr height=20><td align=middle width=40> File: </td><td> Oracle performance optimization. Chm </td></tr><tr height=20><td align=middle width=40> Size: </td><td> 106KB </td></tr><tr height=20><td align=middle width=40> Download: </td><td> Download </td></tr></tbody></table></td></tr></tbody></table>				<h5>Related Posts</h5>
		<div id="smilar">
		<ul>
					<li><a href="http://www.kods.netwww.kods.net/sga-extended-the-principle-of-32bit-oracle/" title="SGA extended the principle of 32bit oracle">SGA extended the principle of 32bit oracle</a> 2009-03-31 09:48:01</li>
					<li><a href="http://www.kods.netwww.kods.net/high-availability-oracle-flashback/" title="High Availability Oracle Flashback">High Availability Oracle Flashback</a> 2009-02-26 17:23:02</li>
					<li><a href="http://www.kods.netwww.kods.net/an-example-of-the-use-of-tkprof/" title="An example of the use of TKPROF">An example of the use of TKPROF</a> 2009-02-26 01:38:19</li>
					<li><a href="http://www.kods.netwww.kods.net/diagnosis-and-principles-of-order/" title="Diagnosis and principles of order">Diagnosis and principles of order</a> 2009-02-25 20:27:28</li>
					<li><a href="http://www.kods.netwww.kods.net/oracle-10g-dataguard-configuration-step-by-step/" title="ORACLE 10G dataguard configuration Step by Step">ORACLE 10G dataguard configuration Step by Step</a> 2009-02-16 01:13:55</li>
				</ul>
		</div>
		        ]]></content:encoded>
		<wfw:commentRss>http://www.kods.netwww.kods.net/oracle-sql-performance-tuning-series/</wfw:commentRss>
	</item>
		<item>
		<title>Oracle SQL * PLUS based</title>
		<link>http://www.kods.netwww.kods.net/oracle-sql-plus-based/</link>
		<comments>http://www.kods.netwww.kods.net/oracle-sql-plus-based/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 21:40:03+0000</pubDate>
		<dc:creator>kods.net</dc:creator>
		<category><![CDATA[Oracle SQL]]></category>
		<category><![CDATA[relational database system]]></category>
<category><![CDATA[data integrity]]></category>
<category><![CDATA[oracle sql]]></category>
<category><![CDATA[rdbms oracle]]></category>
<category><![CDATA[oracle applications]]></category>
<category><![CDATA[relational table]]></category>
<category><![CDATA[relational model]]></category>
<category><![CDATA[two elements]]></category>
<category><![CDATA[network database]]></category>
<category><![CDATA[database task]]></category>
<category><![CDATA[physical integrity]]></category>
<category><![CDATA[consistent feature]]></category>
<category><![CDATA[desktop database]]></category>
<category><![CDATA[mathematical concept]]></category>
<category><![CDATA[robust system]]></category>
<category><![CDATA[system language]]></category>
<category><![CDATA[entity integrity]]></category>
<category><![CDATA[performance system]]></category>
<category><![CDATA[application systems]]></category>
<category><![CDATA[group database]]></category>
		<guid isPermaLink="true">http://www.kods.netwww.kods.net/oracle-sql-plus-based/</guid>
		<description><![CDATA[rn Oracle&#39;s SQL * PLUS is the design of the basic tools of all application systems. To be applied as a robust system design, superior performance system. The key is to understand the true meaning  ...]]></description>
		<content:encoded><![CDATA[rn <br /> Oracle&#39;s SQL * PLUS is the design of the basic tools of all application systems. To be applied as a robust system design, superior performance system. The key is to understand the true meaning and structure of the RDBMS, Oracle SQL * PLUS to understand the characteristics and the core of the relational database and the desktop database to ascertain the difference. For example to understand data integrity, consistency, indexes, views, and so on. The only way to design a consistent feature of Oracle applications. In order to ensure the system after use does not appear in the provision of consistency, performance and other issues. <BR> § 1.1 to understand relational database system (RDBMS) <BR> CODASYL (Data System Language Association) is the Database Task Group (Database Task Group, DBTG) created a database standard, which is a COBOL-based network database standard. <br /> rn <br /> § 1.1.1 relational model a description of how the two elements of the collection or how to contact one correspondence between the mathematical concept of the database, the relationship has only one table with some special properties. So, are: <br /> rn <br /> l is the relationship between the basis of data entry <BR> l In these tables, the operation produced only on the relationship between a relational table must meet certain conditions in order to become a part of the relational model <BR> l The data stored in the unit must be atomic. Each unit can store a data, called the principle of information (Information Principle). If the store is in breach of the principle of more than one. Te Shu circumstances may require in breach of the principle. <BR> l stored in the data under the column must have the same data type. <BR> l each row is unique (not exactly the same lines). <BR> l there is no order of the column. <BR> l line is not the order of <BR> l contains a unique name. <br /> rn <br /> The other is the integrity of the relationship between the principles of the model. It includes the physical integrity of the principle of (Entity integrity rule), and the principle of referential integrity (Referential integrity rule), such as: <BR> l primary key (Primary key) is to be able to uniquely identify a row or a group of a collection of columns. <BR> l by a number of columns constitute the primary key is called Connect button (Concatenated key), combination of keys (Compound key), also known as a composite key (Composity key). <br /> rn <br /> The other is the external keys (Foreign key) is a table in one or a group of columns, they are in other tables as the primary key exists. A table in the foreign key is considered to be the primary key in another table references. Physical integrity of the principle that the primary key can not be concise manner whole or in part, vacant or empty, the principle of referential integrity succinctly that a foreign key must be null or it refers to the primary key value that currently exists is consistent. <br /> rn <br /> Rule 12 § 1.1.2 Codd <BR> Oracle database system is a perfect database technology in full compliance with the relationship between the database system. In order for your application design principles in accordance with the database to carry out, the most important is to understand the structure of Oracle, statements and orders. Codd&#39;s 12 rules proposed in the Oracle system can be found at: <br /> rn <br /> 1) Information rules. <BR> 2) authorize the storage rule, each data item through a &quot;line of table name + primary key + one of the&quot; combination of the formation of access. <BR> 3) must be consistent ways to use null values. <BR> 4) an active, on-line data dictionary should be stored as a relational table <BR> 5) It must provide access to data access language access. <BR> 6) All that can be updated view should be updated. <BR> 7) There must be a collection-level insert, update, and delete. <BR> 8) physical data independence. That applications are not dependent on physical structure. <BR> 9) logical data independence. If a table is divided into two parts, then the application view are connected so as not to impact on the application. <BR> 10) the integrity of independence. Integrity of the rule should be stored in the data dictionary. <BR> 11) the distribution of independence. A database, even if they are distributed, it should be able to work. <BR> 12) the principle of non-destructive. If you allow low-level access, must not bypass the security and integrity of the principles. <br /> rn <br /> § 1.2 relational database system (RDBMS) the composition of the <BR> RDBMS consists of two parts, namely, the kernel database system (software) and data dictionary (the kernel database system used to manage the data structure) in two parts. <br /> rn <br /> § 1.2.1 RDBMS kernel <BR> RDBMS is used to control data access operating system. Its mission is to store data according to certain rules, retrieve data and protect data. <br /> rn <br /> § 1.2.2 the concept of data dictionary data is automatically stored in the database of all objects (such as tables, indexes, views, etc.) the required information. The data dictionary is the Oracle 8i database systems store information in a set of tables from the data dictionary information in the data objects can be identified in the database of basic information and store locations. <br /> rn <br /> § 1.3 SQL, SQL * Plus and PL / SQL <BR> The following simple language to explain the commonly used Oracle products contain SQL * PLUS and PL / SQL relationship. <BR> § 1.3.1 SQL and SQL * PLUS the difference between <BR> SQL is a standard structured query language, SQL * PLUS is actually include standard SQL and Oracle, the product composition of a number of commands, thus its name to Oracle&#39;s SQL * PLUS. The following is their explanation. <br /> rn <br /> 1. SQL (Structured Query Language) <br /> rn <br /> There are many SQL keywords, the following statement is commonly used in the beginning of the statement: <BR> Alter Insert <BR> Audit Lock <BR> Commit Noaudit <BR> Comment Rename <BR> Create Revoke <BR> Delete Select <BR> Drop Update <BR> Grant Validate <br /> rn<br /> Note: <BR> 1.Oracle of the SQL buffer can only store a SQL command; <BR> 2.Validate (to force) in the oracle used in conjunction with the Enable, but eliminated, Validate, so much of the information is not introduced Validate usage. The syntax such as: <BR> Enable ([Validate] [Novalidate]) ([UNIQUE] [PRIMARY KEY] ...) ... <br /> rn <br /> 2. SQL * PLUS <br /> rn <br /> In addition to SQL outside, SQL * PLUS also known as SQL * PLUS command additional commands that is mainly used for the formation of complex reports, edit SQL commands, to provide help to safeguard systems. SQL * PLUS, including the command is as follows: <br /> rn <br /> @ Connect <BR> Host Set <BR> # Copy <BR> Input Show <BR> $ Define <BR> List Spool <BR> / Del <BR> Newpage Sqlplus <BR> Accept Describe <BR> Pause Start <BR> Append Disconnect <BR> Quit Timing <BR> Break Document <BR> Remark Ttitle <BR> Btitle Edit <BR> Prompt Undefine <BR> Chang Execute <BR> Print Save <BR> Clear Exit <BR> Run Column <BR> Get Runform <BR> Compute Help <br /> rn <br /> 3. DDL (Data Define Language) <br /> rn <br /> For the structured query language (sometimes called SQL command), they can be divided into two groups, one group of data definition language (DDL); the other group is the data manipulation language (DML). Data definition language which is used as follows: <br /> rn <br /> Alter procedure re-compilation process <BR> Alter table modify the properties of the table <BR> Analyze the value of statistical properties of database objects <BR> Alter table add Constraint on the table plus the existing constraints <BR> Create table table structure established <BR> Create index index <BR> Drop table drop table entities and the related index <BR> Drop index Remove index <BR> Grant authorization to the user or role <BR> Truncate to delete all the rows in the table <BR> Revoke permissions from the user or role to recover <br /> rn <br /> 4. DML (Data Manipulation Language) <br /> rn <br /> For the structured query language, another group of data manipulation language (DML). DML for data manipulation commands of which are as follows: <br /> rn <br /> Insert <BR> Delete <BR> Update <BR> Select <BR> Commit work <BR> Rollback <br /> rn <br /> § 1.3.2 PL / SQL Language <BR> PL / SQL is Oracle RDBMS (Oracle 6 or later) is an integral part of, PL is a &quot;process-oriented language (Procedure Language)&quot; acronym. PL / SQL language is a combination of the SQL language structure, language composition process the quasi-fourth-generation language. <br /> rn <br /> Using the PL / SQL purpose: <BR> Since most of PL / SQL is a server to run, this could reduce the client needed to run the program when the network data traffic. <BR> You can use PL / SQL places: <BR> l PL / SQL you can write a separate program to complete the general processing functions; <BR> l in the high-level language that can be embedded in PL / SQL block; <BR> l In the 4GL can be embedded in PL / SQL block; <BR> l In the PL / SQL programs can be embedded in HTML and XML. <br /> rn <br /> § 1.4 Log on to SQL * PLUS <BR> We create any object, such as creating tables, indexes and so on need to connect to Oracle, here, with the &quot;Sign in&quot; interface is mainly provided by Oracle is the Login name for this. In fact, the meaning is the connection. In the Client / Server structure, Oracle provides two ways to connect SQL * PLUS, including SQL * NET V2.x version (the current version no longer use SQL * NET V2.x) provides character mode to connect to SQL * PLUS, SQL * NET V2. x version provides the graphics mode (Window) to use, the current version of ORACLE8/8i use NET8 connection. (NET8 no longer supports character terminals) <br /> rn <br /> § 1.4.1 UNIX environment in UNIX, we should ensure that the client or server side to connect with the Oracle server system, we must ensure that the two parameters tnsnames.ora and the listener.ora file is configured correctly. The configuration explained in detail in the chapter explains DBA. Here is the file tnsnames.ora and listener.ora displays the contents of the two parameters. <br /> rn <br /> 1. Tnsnames.ora parameter file: <BR> INST1_HTTP = <BR> (DESCRIPTION = <BR> (ADDRESS_LIST = <BR> (ADDRESS = (PROTOCOL = TCP) (HOST = dbsvr) (PORT = 1521)) <BR> ) <BR> (CONNECT_DATA = <BR> (SERVER = SHARED) <BR> (SERVICE_NAME = s450) <BR> (PRESENTATION = http://admin) <BR> ) <BR> ) <br /> rn <br /> EXTPROC_CONNECTION_DATA = <BR> (DESCRIPTION = <BR> (ADDRESS_LIST = <BR> (ADDRESS = (PROTOCOL = IPC) (KEY = EXTPROC)) <BR> ) <BR> (CONNECT_DATA = <BR> (SID = PLSExtProc) <BR> (PRESENTATION = RO) <BR> ) <BR> ) <br /> rn <br /> S450 = <BR> (DESCRIPTION = <BR> (ADDRESS_LIST = <BR> (ADDRESS = (PROTOCOL = TCP) (HOST = dbsvr) (PORT = 1521)) <BR> ) <BR> (CONNECT_DATA = <BR> (SERVICE_NAME = s450) <BR> ) <BR> ) <br /> rn <br /> 2. Listener.ora parameter file: <BR> LISTENER = <BR> (DESCRIPTION_LIST = <BR> (DESCRIPTION = <BR> (ADDRESS_LIST = <BR> (ADDRESS = (PROTOCOL = TCP) (HOST = dbsvr) (PORT = 1521)) <BR> ) <BR> (ADDRESS_LIST = <BR> (ADDRESS = (PROTOCOL = IPC) (KEY = EXTPROC)) <BR> ) <BR> ) <BR> ) <br /> rn <br /> SID_LIST_LISTENER = <BR> (SID_LIST = <BR> (SID_DESC = <BR> (SID_NAME = PLSExtProc) <BR> (ORACLE_HOME = / home/oracle/app/oracle/product/8.1.7) <BR> (PROGRAM = extproc) <BR> ) <BR> (SID_DESC = <BR> (GLOBAL_DBNAME = s450) <BR> (ORACLE_HOME = / home/oracle/app/oracle/product/8.1.7) <BR> (SID_NAME = s450) <BR> ) <BR> ) <br /> rn <br /> If the installation has been correctly on the above two parameters, configuration files, you can follow the steps below to log in: <br /> rn <br /> 1) First start the server-side listener: <BR> lsnrctl start <br /> rn <br /> 2) Use the following command to explicitly log on to SQL * PLUS: <BR> $ sqlplus username / password <BR> Or <BR> $ SQLPLUS username / password @ connect_string <br /> rn<br /> 3) implicitly with the following command to log on to SQL * PLUS: <BR> $ sqlplus [enter] <BR> Enter user name: scott <BR> Enter password :****** <br /> rn <br /> § 1.4.2 Windows NT and WINDOWS/2000 environment in the NT/2000 environment, to make the client connect with the Oracle server, tnsnames.ora, and listener.ora file configuration parameters are as follows: <br /> rn <br /> 1. Tnsnames.ora parameter file: <br /> rn <br /> ORA816.TAIJI.COM.CN = <BR> (DESCRIPTION = <BR> (ADDRESS_LIST = <BR> (ADDRESS = (PROTOCOL = TCP) (HOST = zhao) (PORT = 1521)) <BR> ) <BR> (CONNECT_DATA = <BR> (SERVICE_NAME = ora816) <BR> ) <BR> ) <br /> rn <br /> EXTPROC_CONNECTION_DATA.TAIJI.COM.CN = <BR> (DESCRIPTION = <BR> (ADDRESS_LIST = <BR> (ADDRESS = (PROTOCOL = IPC) (KEY = EXTPROC1)) <BR> ) <BR> (CONNECT_DATA = <BR> (SID = PLSExtProc) <BR> (PRESENTATION = RO) <BR> ) <BR> ) <BR> S450 = <BR> (DESCRIPTION = <BR> (ADDRESS_LIST = <BR> (ADDRESS = (PROTOCOL = TCP) (HOST = dbsvr) (PORT = 1521)) <BR> ) <BR> (CONNECT_DATA = <BR> (SERVICE_NAME = s450) <BR> ) <BR> ) <br /> rn <br /> 2. Listener.ora parameter file: <br /> rn <br /> LISTENER = <BR> (DESCRIPTION_LIST = <BR> (DESCRIPTION = <BR> (ADDRESS_LIST = <BR> (ADDRESS = (PROTOCOL = IPC) (KEY = EXTPROC1)) <BR> ) <BR> (ADDRESS_LIST = <BR> (ADDRESS = (PROTOCOL = TCP) (HOST = zhao) (PORT = 1521)) <BR> ) <BR> ) <BR> (DESCRIPTION = <BR> (PROTOCOL_STACK = <BR> (PRESENTATION = GIOP) <BR> (SESSION = RAW) <BR> ) <BR> (ADDRESS = (PROTOCOL = TCP) (HOST = zhao) (PORT = 2481)) <BR> ) <BR> ) <br /> rn <br /> SID_LIST_LISTENER = <BR> (SID_LIST = <BR> (SID_DESC = <BR> (SID_NAME = PLSExtProc) <BR> (ORACLE_HOME = D: \ oracle) <BR> (PROGRAM = extproc) <BR> ) <BR> (SID_DESC = <BR> (GLOBAL_DBNAME = ora816) <BR> (ORACLE_HOME = D: \ oracle) <BR> (SID_NAME = ora816) <BR> ) <BR> ) <br /> rn <br /> Windows NT/2000 character to log steps: <BR> 1) First start the server-side listener: <BR> lsnrctl start <br /> rn <br /> 2) Use the following command to explicitly log on to SQL * PLUS: <BR> $ sqlplus username / password <BR> Or <BR> $ SQLPLUS username / password @ connect_string <br /> rn <br /> Windows NT/2000 graphical login steps: <BR> 1) Click &quot;Start&quot; = &quot;&quot; program &quot;=&quot; &quot;Oracle-OraHome81&quot; = &quot;&quot; Application on Development &quot;=&quot; &quot;SQL Plus&quot; to enter the following screen: <br /> rn <br /> In the WINDOWS NT/98/2000 on the login screen (sqlplus Map) <br /> rn <br /> In the User Name box enter the user, password and host string; also be entered separately. <br /> rn <br /> § 1.5 Additional commands commonly used SQL * PLUS Introduction <BR> Oracle provides additional statement (or command), to meet program staff and administrators of some special operational requirements. For example, records showed that more than hundreds of lines of information, you can use each screen &quot;pause&quot; to achieve. To achieve this objective, we have in the SQL&gt; issued a set pause on the command. Because SQL * PLUS commands more, the following are given only the most commonly used description of a few commands in detail please refer to Appendix. <BR> § 1.5.1 Log on to SQL * PLUS <br /> rn <br /> Can use the following command to log on to SQL * PLUS, SQL * PLUS commands a simple syntax is as follows: <br /> rn <br /> SQLPLUS [[logon] | [start]] <br /> rn <br /> logon can be: <BR> (username [/ password] [@ connect_identifier] | /) [AS (SYSOPER | SYSDBA)] <BR> | / NOLOG <br /> rn <br /> Note 1: SQLPLUS is mainly used in the command mode, in the NT, WINDOWS/2000, UNIX usage are the same. <BR> Note 2: If the UNIX under, SQLPLUS command is not to be identified (not exist), then the problem in the environment variable PATH is not set correctly, or not set. SQLPLUS executable program in $ ORACLE_HOME / bin directory. <br /> rn <br /> § 1.5.2 EXIT and QUIT <br /> rn <br /> Can use exit or quit to terminate the operation of SQL * PLUS (session). Syntax is as follows: <br /> rn <br /> (EXIT | QUIT) [SUCCESS | FAILURE | WARNING] <br /> rn <br /> (EXIT | QUIT) can use exit or quit, they are currently functioning. <br /> rn <br /> SUCCESS normal exit <br /> rn <br /> FAILURE error code with a prompt withdrawal of <br /> rn <br /> WARNING exit code with prompt warnings <br /> rn <br /> COMMIT out to save not submitted before the <br /> rn <br /> For example: <BR> SQL&gt; exit <br /> rn <br /> § 1.5.3 DESCRIBE (display tables, views, structures) <BR> DESCRIBE can use (as long as you can with the DESC) to display the table, view the definition of the column, you can also display a synonym for a function or stored procedure instructions. Syntax is as follows: <br /> rn <br /> DESC [RIBE] ([schema.] Object [@ connect_identifier]) <br /> rn <br /> Schema: user name, if omitted, for the owner of an object. <br /> rn <br /> object <BR> Can be a table (table), view (view), type (type), stored procedure (procedure), the function (function), package (package) or synonyms (synonym) <br /> rn <br /> @ connect_identifier <BR> Database connection string <br /> rn <br /> Example: Display the structure of emp table: <br /> rn <br /> SQL&gt; desc emp <br /> rn <br /> § 1.5.4 LIST (list) command can use LIST command to list the current SQL buffer in one or more lines in the command statement. <br /> rn <br /> L [IST] [n | nm | n * | n LAST | * | * n | * LAST | LAST] <br /> rn <br /> n the first n rows listed <BR> nm are listed in rows n to m <BR> n * are listed in the first n rows to the current row <BR> n LAST lists the first line to last line n <BR> * List of all rows <BR> * N lists the current line to the first n rows <BR> * LAST lists the current line to the last row <BR> LAST lists the last line of <br /> rn <br /> Example: <BR> SQL&gt; LIST <BR> 1 SELECT ENAME, DEPTNO, JOB <BR> 2 FROM EMP <BR> 3 WHERE JOB = &#39;CLERK&#39; <BR> 4 * ORDER BY DEPTNO <br /> rn<br /> § 1.5.5 Change (replace string) command <br /> rn <br /> Change the command can be used to change the string (ie replace the string). Syntax is as follows: <br /> rn <br /> C [HANGE] sepchar old [sepchar [new [sepchar]]] <br /> rn <br /> Sepchar as separator, which can be &quot;/&quot; or &quot;!&quot; - Asking the users to pay special attention <br /> rn <br /> Old Old string <br /> rn <br /> New new string <br /> rn <br /> Example: In addition to number (/) to multiplication sign (*), you need to command c !/!*!. Namely: <BR> SQL&gt; l <BR> 1 * select sal, sal/100 from emp <BR> SQL&gt; c !/!*! <br /> rn <br /> Reminder: For Modify / characters can only be used! To make separators (the cases). <br /> rn <br /> Example: The multiplication sign (*) to a plus sign (+), you need to command c !/!*!. Namely: <BR> SQL&gt; l <BR> 1 * select sal, sal * 100 from emp <BR> SQL&gt; c /*/+/ <BR> 1 * select sal, sal +100 from emp <BR> SQL&gt; <br /> rn <br /> § 1.5.6 Append (append string) command <br /> rn <br /> Can be completed with the Append command to append the string at the end of the current row. Syntax is as follows: <br /> rn <br /> A [PPEND] text <br /> rn <br /> Text string of the requested additional <br /> rn <br /> Example: In the current row select sal, sal +100 from emp added where sal&gt; = 2000, then: <br /> rn <br /> SQL&gt; l <BR> 1 * select sal, sal +100 from emp <BR> SQL&gt; a where sal&gt; = 2000 <BR> 1 * select sal, sal +100 from emp where sal&gt; = 2000 <BR> SQL&gt; <br /> rn <br /> § 1.5.7 Save command to save the current buffer to file <br /> rn <br /> Can use SAVE command to save the current command line to the operating system file. Syntax is as follows: <br /> rn <br /> SAV [E] filename [. Ext] [CRE [ATE] | REP [LACE] | APP [END]] <br /> rn <br /> Of which: <BR> filename: You will buffer the contents of the deposit to the operating system directory file name. <BR> ext: If you use the file suffix, the default file extension for SQL. <br /> rn <br /> Example: <BR> SQL&gt; select table_name from dict where table_name like &#39;% ROLE%&#39;; <BR> SQL&gt; save c: \ get_role <br /> rn <br /> § 1.5.8 GET command file will be read with the GET command buffer can be the operating system directory under the command file to read the buffer (but not executed). Syntax is as follows: <br /> rn <br /> GET filename [. Ext] [LIS [T] | NOL [IST]] <BR> Of which: <BR> filename: want to load into the SQL buffer file name <BR> ext: extension of the file, the default for SQL. <br /> rn <br /> Example: <br /> rn <br /> SQL&gt; get c: \ get_role <br /> rn <br /> § 1.5.9 SPOOL log information to a file <BR> Oracle&#39;s SPOOL command allows the screen all the information arising from the paper records into the operating system up until the SPOOL OFF. Syntax is as follows: <br /> rn <br /> SPO [OL] [filename [. Ext] | OFF | OUT] <BR> Of which: <BR> filename: you want to output (spool) file name. <BR> ext: file suffix. The default suffix is the LST (or LIS). <br /> rn <br /> SQL&gt; col table_name for a20 <BR> SQL&gt; col comments for a80 <BR> SQL&gt; set linesize 110 <BR> SQL&gt; SPOOl c: \ all_dict <BR> SQL&gt; select table_name, comments from dict; <BR> ...... (System query information) <br /> rn <br /> SQL&gt; SPOOL OFF <br /> rn <br /> § 1.5.10 to run the current buffer command in SQL&gt; mode, if you want to run the current command, can be Run (or R) or with / to achieve, such as: <br /> rn <br /> SQL&gt; set lin 120 <BR> SQL&gt; select table_name from dict where table_name like &#39;% ROLE%&#39;; <br /> rn <br /> TABLE_NAME <BR> ------------------------------ <BR> DBA_ROLES <BR> DBA_ROLE_PRIVS <BR> USER_ROLE_PRIVS <BR> ROLE_ROLE_PRIVS <BR> ROLE_SYS_PRIVS <BR> ROLE_TAB_PRIVS <BR> SESSION_ROLES <br /> rn <br /> Have chosen 7 rows. <br /> rn <br /> SQL&gt; l <BR> 1 * select table_name from dict where table_name like &#39;% ROLE%&#39; <BR> SQL&gt; / <br /> rn <br /> TABLE_NAME <BR> ------------------------------ <BR> DBA_ROLES <BR> DBA_ROLE_PRIVS <BR> USER_ROLE_PRIVS <BR> ROLE_ROLE_PRIVS <BR> ROLE_SYS_PRIVS <BR> ROLE_TAB_PRIVS <BR> SESSION_ROLES <br /> rn <br /> Have chosen 7 rows. <br /> rn <br /> § 1.6 Common Data Dictionary Overview <BR> ORACLE provides a number of internal data dictionary for a variety of information management systems and parameters (ie, database objects), the following are a few common data dictionary for beginners and reference, other aspects of the data dictionary will be described in the DBA management. <br /> rn <br /> ORACLE data dictionary named Description: <br /> rn <br /> USER record for the prefix ---- all objects the user information <BR> ALL for the prefix USER ---- records, including records and delegation of authority to PUBLIC for all objects or the user&#39;s information. <BR> DBA for the official records of the database objects ---- prefix (non-user object) information. <BR> Dynamic view V $ public system, for system optimization and adjustment of reference. <BR> V_ $ dynamic performance views, you can create a dynamic view of the establishment of the script CATALOG.SQL synonyms. <BR> GV $ new (oracle 8) a fixed view of the additional (Global V $). In the parallel environment, the reaction is <BR> V $ view information. Such as: <br /> rn <br /> SELECT * FROM GV $ LOCK WHERE INST_ID = 2 OR INST_ID = 5; <br /> rn <br /> Returns instances 2 and 5 of the V $ information. Therefore, GV $ response to a group of Instances of parameters. GV $ view restriction is PARALLEL_MAX_SERVERS parameter must be greater than 0. <BR> See Oracle Enterprise Manager Administrator&#39;s Guide. <br /> rn <br /> Note: Please note that the following summary: <BR> l General DBA_ view content that contains USER_ and ALL_ for the prefix view; <BR> l DBA_ To view the contents of the prefix is basically capitalized; <BR> l to V $ _ as a prefix of the view contents are basically the lowercase. <br /> rn<br /> 1. USER_TABLEs (= TABS) all of the user tables. <BR> 2. USER_TAB_COLUMNS (= COLS) the relevant table columns (fields) of information <BR> 3. USER_VIEWS users all views <BR> 4. USER_SYNONYMS (= SYN) User synonymous <BR> 5. USER_SEQUENCES (= SEQ) the user sequence <BR> 6. USER_CONSTRAINTS records to create the table structure of the building restrictions. <BR> 7. USER_TAB_COMMENTS table notes. Such as: <br /> rn <br /> Comment on table emp is &#39;employee table&#39;; <br /> rn <br /> 8. USER_COL_COMMENTS column (field) notes. Such as: <br /> rn <br /> Comment on column emp.ename is &#39;Name&#39;; <br /> rn <br /> 9. USER_INDEXES (= IND) brief information on the user index <BR> 10. USER_IND_COLUMNS user index column information <BR> 11. USER_TRIGGERS the user triggers the information <BR> 12. USER_SOURCE user stored procedure <BR> 13. USER_TABLESPACE users can use the table space information <BR> 14. USER_TS_QUOTAS users of information system resources <BR> 15. USER_SEGMENTS spatial information used by the user object <BR> 16. USER_EXTENTS the user&#39;s extended segment information <BR> 17. USER_OBJECTS User Object <BR> = USER_TABLES + USER_VIEWS + USER_INDEXES + <BR> USER_SOURCE + USER_TRIGGERS + USER_JAVA <br /> rn <br /> 18. USER_PART_TABLES user partition information <BR> 19. USER_TAB_PARTITIONS <BR> 20. USER_PART_COL_STATISTICS <BR> 21. USER_IND_PARTITIONS <BR> 22. USER_FREE_SPACE <BR> 23. CAT (= USER_CATALOG) users can access all of the base tables. <BR> 24. TAB users to create all the base tables, views, synonyms and so on. <BR> 25. DICT (= DICTIONARY) constitute a data dictionary for all tables. <br /> rn <br /> Tip: Although Oracle provides can Comment on column tablename.column is &#39;xxxx&#39;; and so to achieve the right table or column comments, but is not recommended in such a way designers work. The proposed notes is more intuitive to write the script. <br /> rn <br /> § 1.7 ORACLE Data Type <BR> Oracle Database data types when compared with other database systems, which limited the type of data, Oracle said the data in the database than other systems that want to save a number of keywords. Oracle only NUMBER (m, n) can represent any complex digital data. Others, such as date type, etc. are also much simpler, says that only the DATE the date and time. Given below in tabular form the various versions of the Oracle system data type of representation. Here are the old version of the Oracle data types aim is to enable readers to understand the changes in Oracle, the other is the old version you are upgrading or data conversion should pay attention to the various versions of the difference. <br /> rn <br /> ORACLE5, ORACLE6 data type <br /> rn <br /> Data Type Description <BR> Char variable length character, ≤ 254 <BR> Varchar2 variable length character, ≤ 2000 <BR> Number (m, n) number of types, including integers, decimals, etc. <BR> Date date type, with time, default format is mmm-dd-yyyy hh: mi: ss (total 7 bytes) <BR> Long storage of large variable-length strings, ≤ 2GB <BR> Raw storage short binary strings, ≤ 2GB <BR> Long raw storage length binary strings, ≤ 2GB <br /> rn <br /> ORACLE7 data type <br /> rn <br /> Data Type Description <BR> Char fixed-length character, ≤ 255 characters <BR> Varchar variable-length character, ≤ 2000 characters <BR> Varchar2 variable-length character, ≤ 2000 characters <BR> Number (m, n) number of types, including integer, floating point, double precision, etc. <BR> Long storage of large variable-length strings, ≤ 2GB <BR> Raw storage variable short binary, ≤ 2000 <BR> Long raw storage of large variable-length binary, ≤ 2GB <br /> rn <br /> ORACLE8/8i data type <br /> rn <br /> Data Type Description <BR> Char fixed-length character, ≤ 2000 characters <BR> Varchar (with Varchar2) variable characters, ≤ 4000 characters <BR> Varchar2 variable-length character, ≤ 4000 characters <BR> Date fixed length (7 bytes) of the date type <BR> Number numeric can store real-and integer <BR> Long variable character, ≤ 2GB characters <BR> Raw binary data variable, ≤ 4000 bytes <BR> Variable Long raw binary data, ≤ 2GB <BR> MLSLABEL using Trusted Oracle only 2 to 5 bytes in length between the <BR> Blob large binary objects, ≤ 4GB <BR> Clob large string objects, ≤ 4GB <BR> Nclob multi-byte character set Clob, ≤ 4GB <BR> Bfile an external binary file, the size of the decision by the OS <br /> rn <br /> CHAR () <BR> Fixed-length character (in the Oracle5, Oracle6 is a variable length), the character length is not enough spaces automatically sign on the right. When the length exceeds 2000 characters in an error. Do not specify the size of the default is 1. <br /> rn <br /> VARCHAR () <BR> Variable character, the current and VARCHAR2 () the same. <br /> rn <br /> VARCHAR2 () <BR> Variable character, the current and VARCHAR () the same. VARCHAR2 types of fields (columns) can store 4000 characters; but the VARCHAR2 variable can store 32,767 characters. Size must be specified. <br /> rn <br /> NCHAR (), and NVARCHAR2 () <BR> NCHAR and NVARCHAR2 respectively CHAR and VARCHAR2 have the same size. And used in the store National Language Support (NLS) data, Oracle allows storage of data in local languages and query data. <BR> If the column name of the statement into NCHAR, NVARCHAR2 such a type, then the insert, and select the specific values such as statements preceded by N, can not directly operate in accordance with common character type. See the following examples: <br /> rn <br /> SQL&gt; create table nchar_tst (name nchar (6), addr nvarchar2 (16), sal number (9,2)); <br /> rn <br /> The table has been created. <br /> rn <br /> SQL&gt; insert into nchar_tst values (N &#39;ZHAO Yuan-jie&#39;, N &#39;, Beijing Haidian District&#39;, 9999.99); <br /> rn <br /> Have created a row. <br /> rn<br /> SQL&gt; select * from nchar_tst where name like N &#39;Zhao%&#39;; <br /> rn <br /> NAME ADDR SAL <BR> ------ ---------------- ---------- <BR> ZHAO Yuan-jie, Beijing Haidian District 9999.99 <br /> rn <br /> SQL&gt; select * from nchar_tst where name like &#39;Zhao%&#39;; <BR> select * from nchar_tst where name like &#39;Zhao%&#39; <BR> * <BR> ERROR at line 1: <BR> ORA-12704: character set mismatch. <br /> rn <br /> Tip: Although Oracle can use the nchar, nvarchar2 type to store character data, but recommends that designers do not use the NCHAR and NVARCHAR2. Because the CHAR and VARCHAR2 can store characters. <br /> rn <br /> NUMBER ( <BR> ,) <br /> rn <br /> Is the integer part of the data, the accuracy of the data (ie fractional) part, note that some can be expressed as a negative precision. Can be expressed with a decimal point right or left from the number of bits reserved. The following table: <br /> rn <br /> Data type stores the value of the actual value <BR> 1234567.89 Number 1234567.89 <BR> 1234567.89 Number (8) 1234568 <BR> 1234567.89 Number (6) error <BR> 1234567.89 Number (9,1) 1234567.9 <BR> 1234567.89 Number (9,3) error <BR> 1234567.89 Number (7,2) error <BR> 1234567.89 Number (5, -2) 1234600 <BR> 1234511.89 Number (5, -2) 1234500 <BR> 1234567.89 Number (5, -4) 1230000 <BR> 1234567.89 Number (*, 1) 1234567.9 <br /> rn <br /> Sal number (7,2), - said the 5 integers and 2 decimal places. <br /> rn <br /> DATE <BR> Oracle date type with 7 bytes, each date type that contains the following: <BR> l Century (century) <BR> l Year (years) <BR> l Month (month) <BR> l Day (days) <BR> l Hour (hours) <BR> l Minute (min) <BR> l Second (sec) <br /> rn <br /> Date-type field has the following characteristics: <br /> rn <br /> l date-type field insert and update data type or character, and with to_date function description can be. <BR> l The default date format NLS_DATE_FORMAT parameter control, it is the default format DD-MON-YY. <BR> l The default time is 00:00:00 at night (ie, 0:00:00). <BR> l sysdate returns the server&#39;s time, see the following example. <BR> l date format display can be set, see the following examples. <BR> Date l-type can be operations, see the following examples. See the following examples. <BR> l century, said that with the cc; years, said with yyyy, month to use mm, said daily dd said hours with hh24 said the split-mi said that seconds with ss said. <br /> rn <br /> Example: <BR> SQL&gt; create table save_info (per_id varchar2 (20), name varchar2 (20), tran_date date, <BR> 2 tran_val number (12,2)); <br /> rn <br /> The table has been created. <br /> rn <br /> SQL&gt; insert into save_info values (&#39;110105540609811 &#39;,&#39; ZHAO Yuan-jie &#39;, <BR> 2 to_date (&#39;2001 .06.18 &#39;,&#39; yyyy.mm.dd &#39;), 12345.66); <br /> rn <br /> Have created a row. <br /> rn <br /> SQL&gt; select * from save_info; <br /> rn <br /> PER_ID NAME TRAN_DATE TRAN_VAL <BR> -------------------- -------------------- ---------- ---------- <BR> 110105540609811 ZHAO Yuan-jie 18-6 months -01 1234.66 <br /> rn <br /> SQL&gt; select per_id, name, to_char (tran_date, &#39;yyyy / mm / dd&#39;), tran_val from save_info; <br /> rn <br /> PER_ID NAME TO_CHAR (TR TRAN_VAL <BR> -------------------- -------------------- ---------- ---------- <BR> 110105540609811 ZHAO Yuan-jie 2001/06/18 12,345.66 <br /> rn <br /> SQL&gt; show parameter nls_date_format <br /> rn <br /> NAME TYPE VALUE <BR> ------------------------------------ ------- ------- ----------------------- <BR> nls_date_format string <br /> rn <br /> SQL&gt; alter session set nls_date_format = <BR> 2 &#39; &quot;Year&quot; yyyy &quot;Year&quot; mm &quot;on&quot; dd &quot;days&quot;&#39;; <br /> rn <br /> Conversation has changed. <br /> rn <br /> SQL&gt; select sysdate from dual; <br /> rn <br /> SYSDATE <BR> ------------------ <BR> AD May 18, 2001 <br /> rn <br /> SQL&gt; select to_char (sysdate, &#39;cc yyyy.mm.dd&#39;) from dual; <br /> rn <br /> TO_CHAR (SYSDA <BR> ------------- <BR> 21 2001.05.18 <br /> rn <br /> Type of use on the date details please refer to &quot;Oracle8i National Language Support Guide&quot;. <br /> rn <br /> BLOB <BR> Large binary objects, each record can store up to 4GB of data, see the following sections in detail. <br /> rn <br /> CLOB <BR> Large character objects, each record can store up to 4GB of data, see the following sections in detail. <br /> rn <br /> BFILE <BR> External binary file, each record can store up to 4GB of data (with the OS-related), see the following chapters in detail. <br /> rn <br /> RAW <BR> Unstructured binary data, which database system is not explained. RAW can store up to 2,000 bytes. <br /> rn <br /> LONGRAW <BR> Large binary type data, LONGRAW non-binary data structure, these data are database systems are not explained. LONGRAW can store up to 2GB bytes. LONGRAW can not be indexed, but RAW can be indexed. <br /> rn <br /> ROWID <BR> ROWID in Oracle database is a virtual column, that is, the system uses a special column, the column is not our building. Used in the database to locate each record. Details, see &quot;Rowid the use of&quot; section. <br /> rn <br /> UROWID <BR> UROWID is a Universal ROWID meaning. The Global ROWID, it supports logical and physical ROWID, but also as an external table (through getway access to non-Oracle tables) of the ROWID. UROWID type can store all of the ROWID types of data. <br /> rn <br /> % TYPE type of match: <BR> books_printed number (6); <BR> books_sold books_printed% TYPE; <BR> books_sold data types and book_printed types of the same; <BR> (% TYPE type in PL / SQL in the introduction). <br /> rn<br /> Null values and character, the digital-based computing: <BR> null + &lt;number&gt; = null (empty value + figure is still empty value) <BR> null&gt; &lt;number&gt; = null (null value compared with the results of an empty value) <BR> null | | &#39;string&#39; = string <br /> rn <br /> number type and the following types have the same range: <BR> DEC <BR> Decimal <BR> Double PREcision <BR> Float <BR> Integer <BR> Int <BR> Numeric <BR> Real <BR> Smallint <br /> rn <br /> Tip: Although you can use the above sub-Oracle data types, but the proposal was adopted NUMBER (n, m) is better. Because if the data type definitions using the sub-field type of improper operation may cause data problems. <br /> rn <br /> Long data type restrictions: <BR> l select can be used long; <BR> l update can be used in select clause; <BR> l insert can be used Valus clause; <BR> l Each table can only allow a long column; <BR> l long columns can not list integrity constraints (null, not null exception); <BR> l long columns can not be indexed; <BR> l procedure or stored function can not receive long-type function; <BR> l stored function can not return long-type value. <br /> rn <br /> long is not currently appear in the following situations: <BR> l select the Where, Group by, order by, Connect by, distinct; <BR> l can not long classified as substr, instr; <BR> l expression or condition; <BR> l sub-query or the collection can not be long; <BR> l Create table ... as select can not be used long; <br /> rn <br /> § 1.8 SQL statement is the basis of the following SQL statement is given a basic introduction, a more detailed description see the following chapters. <BR> § 1.8.1 SQL statements used in symbolic <br /> rn <br /> Examples of Operator Use <BR> + - Indicates positive or negative, positive, can be avoided + -1234.56 <BR> + Will be the sum of two numbers or expressions A = c + b <BR> - The two numbers or expressions subtract 34-12 <BR> * To multiply two numbers or expressions 12 * 34 <BR> / Divided by a number or expression 18 * 11 <BR> NULL null value judgments Where name is null; <BR> | | String to connect &#39;101-&#39;| | tel_num <BR> = Equal to test Select * from emp where name = &#39;ZHAO Yuan-jie&#39;; <BR> ! = Or &quot;&quot; or ^ = not equal to test Select * from emp where name! = &#39;ZHAO Yuan-jie&#39;; <BR> &quot;Less than the Test Select * from emp Where sal &lt;5000; <BR> &quot;Greater than the Test Select * from emp Where sal&gt; 5000; <BR> &quot;= Less than or equal test Select * from emp Where sal &lt;= 5000; <BR> &quot;= Greater than or equal test Select * from emp Where sal&gt; = 5000; <BR> Not in testing whether a particular value of a specified result set Select name, addr from expertwhere local not in ( &#39;Beijing&#39;, &#39;Shanghai&#39;); <BR> ANY would be a value compared with a group of values, return to meet the criteria. Must follow !=,&lt;,&gt;,&lt;=,&gt;= select ename, sal from emp where sal &lt;= any (select sal from emp where deptno = 10) <BR> SOME with ANY, must follow !=,&lt;,&gt;,&lt;=,&gt;= <BR> ALL will be a value with a set of value, to return all the column values to meet the conditions. Must follow !=,&lt;,&gt;,&lt;=,&gt;= Select name, sal from empWhere sal &lt;= all (500,800,1200); <BR> Not betweenA and B to determine whether a value in between. Select name, sal from emp Where sal between 500 and 1200; <BR> [not] exists to determine whether a column exists in a set of values. select dname, deptno from dept where exists (select * from emp where dept.deptno = emp.deptno) <BR> A [not] like b [Escape &#39;char&#39;] compare the two models is similar, like statements when using Oracle not to access the index. Select * from empWhere ename like &#39;TH%&#39;; <BR> Is [not] null test value is empty. Select ename, deptno from empWhere comm. Is null or comm .= 0; <BR> Not the negative results. Select * from empWhere sal not (sal &lt;1000); equivalent to select ename, sal from emp where sal&gt; = 1000; <BR> AND is used to determine both the two conditions are met. Select * from emp where Ename = &#39;SIMTH&#39; and sal&gt; = 1000; <BR> OR is used to determine whether there are two conditions to satisfy one. Select * from emp where Ename = &#39;SIMTH&#39; or ename = &#39;SCOTT&#39;; <BR> UNION is used to return (combination) of all the only two rows in the query. Select ename from emp unionSelect ename from emp; <BR> UNION ALL is used to return (combination) of all two check all the rows. <BR> INTERSECT is used to return two query the same row. Select ename from emp1 intersect select ename from emp2; <BR> MINUS query used to return two different lines. <br /> rn <br /> § 1.8.2 Simple select query if we can use SQL * PLUS to log on to SQL&gt; Next, we can use DESC show the structure of a table, you can also use a simple select statement to query the table some of the column content. <br /> rn <br /> Example: To query the table EMP employee&#39;s name, salary and date of birth, then: <br /> rn <br /> SQL&gt; select ename, sal, hiredate from emp; <br /> rn <br /> § 1.9 Pseudo-out and pseudo-table <BR> Oracle systems in order to achieve a complete relational database capabilities, the system provides a set of special pseudo-columns (Pseudocolumn) of the database column, these columns are not in the establishment of an object (such as the construction of the table) is done by us, but we build objects automatically done by the Oracle. Oracle currently has the following pseudo-columns: <br /> rn <br /> l CURRVAL and NEXTVAL the use of the serial number of the reserved words <BR> l LEVEL query data corresponding to class <BR> l ROWID to uniquely identify records <BR> l ROWNUM limit the number of query result sets <br /> rn <br /> A detailed explanation of the pseudo-column and use, see the relevant sections. <br /> rn<br /> Oracle also provides a pseudo-DUAL table, which main purpose is to ensure that the use of SELECT statement provided the integrity of statements, such as: we have to query the current system date and time, and the system date and time, and is putting the in a specified table. Therefore, from statement after the table name is not given. In order to use from the table after a name, we will use DUAL to replace. Such as: <br /> rn <br /> Example 1: Query Oracle system date and time: <BR> SQL&gt; select to_char (sysdate, &#39;yyyy.mm.dd hh24: mi: ss&#39;) from DUAL; <br /> rn <br /> TO_CHAR (SYSDATE, &#39;YY <BR> ------------------- <BR> 2001.06.02 07:28:09 <br /> rn <br /> Example 2: calculate the results of 5000 +5000 * 0.1 What is, then: <BR> SQL&gt; select 5000 +5000 * 0.1 from DUAL; <br /> rn <br /> 5000 +5000 * 0.1 <BR> ------------------- <BR> 5500 <br /> rn <br /><br /> rn <br /> This article comes from CSDN blog, reproduced please indicate source: http://blog.csdn.net/jack_rao/archive/2009/05/11/4168359.aspx				<h5>Related Posts</h5>
		<div id="smilar">
		<ul>
					<li><a href="http://www.kods.netwww.kods.net/oracle-sql-statement-based-on/" title="oracle sql statement based on">oracle sql statement based on</a> 2009-05-20 15:41:25</li>
					<li><a href="http://www.kods.netwww.kods.net/oracle-sql-optimization-principles-pick/" title="Oracle SQL optimization principles (pick)">Oracle SQL optimization principles (pick)</a> 2009-05-20 02:43:26</li>
					<li><a href="http://www.kods.netwww.kods.net/shell-script-examples-of-the-implementation-of-oracle-sql-script/" title="shell script examples of the implementation of Oracle SQL script">shell script examples of the implementation of Oracle SQL script</a> 2009-04-14 06:08:39</li>
					<li><a href="http://www.kods.netwww.kods.net/foreign-key-fields-to-build-the-index-is-not-caused-by-deadlock/" title="Foreign key fields to build the index is not caused by deadlock">Foreign key fields to build the index is not caused by deadlock</a> 2009-04-09 17:55:59</li>
					<li><a href="http://www.kods.netwww.kods.net/oracle-basic-concepts-and-terminology/" title="oracle basic concepts and terminology">oracle basic concepts and terminology</a> 2009-04-06 22:17:39</li>
				</ul>
		</div>
		        ]]></content:encoded>
		<wfw:commentRss>http://www.kods.netwww.kods.net/oracle-sql-plus-based/</wfw:commentRss>
	</item>
		<item>
		<title>Oracle SQL * PLUS basic and sqlplus command Xiangjie -2</title>
		<link>http://www.kods.netwww.kods.net/oracle-sql-plus-basic-and-sqlplus-command-xiangjie-2/</link>
		<comments>http://www.kods.netwww.kods.net/oracle-sql-plus-basic-and-sqlplus-command-xiangjie-2/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 19:55:02+0000</pubDate>
		<dc:creator>kods.net</dc:creator>
		<category><![CDATA[Oracle SQL]]></category>
		<category><![CDATA[operating system]]></category>
<category><![CDATA[oracle]]></category>
<category><![CDATA[implementation]]></category>
<category><![CDATA[inconvenience]]></category>
<category><![CDATA[database connection]]></category>
<category><![CDATA[oracle enterprise manager]]></category>
<category><![CDATA[functional description]]></category>
<category><![CDATA[oracle sql]]></category>
<category><![CDATA[database administration]]></category>
<category><![CDATA[connection string]]></category>
<category><![CDATA[current version]]></category>
<category><![CDATA[figure 1]]></category>
<category><![CDATA[sal]]></category>
<category><![CDATA[sql worksheet]]></category>
<category><![CDATA[cursor icon]]></category>
<category><![CDATA[graphical manner]]></category>
<category><![CDATA[query command]]></category>
<category><![CDATA[working environment]]></category>
		<guid isPermaLink="true">http://www.kods.netwww.kods.net/oracle-sql-plus-basic-and-sqlplus-command-xiangjie-2/</guid>
		<description><![CDATA[§ 1.10 using the SQL Worksheet in the new version of Oracle, the system provides a graphical SQL called SQL Worksheet working environment, which is part of the ORACLE Enterprise Manager. Use it can be ...]]></description>
		<content:encoded><![CDATA[<BR> § 1.10 using the SQL Worksheet in the new version of Oracle, the system provides a graphical SQL called SQL Worksheet working environment, which is part of the ORACLE Enterprise Manager. Use it can be removed from the SQL&gt; edit the line under the command of inconvenience. It is completely in a graphical manner. It starts with the following methods: <BR> l start from the ORACLE Enterprise Manager <BR> l start from the Administrtor Tools <BR> l from the operating system to start <br /> rn <br /> Here&#39;s the operating system to start the SQL Worksheet tool to work these steps: <BR> 1) Click on the SQL Worksheet icon, choose Start - &quot;programs -&gt; Oracle-OraHome81-&gt; database Administration-&gt; SQLPLUS Worksheet. SQLPLUS Worksheet is selected after the following screen: <br /> rn <br /> Figure 1.10-1 login screen using the SQL Worksheet <br /> rn <br /> In the user name, password and imports of services ORACLE valid user name, password and connection string and then click OK after entering the picture as shown in Figure 1.10-2. <br /> rn <br /> 2) When entered after the screen shown in Figure 1.10-2. You can work. The current version is in the top of the screen enter the command, the bottom of the screen is the system displays the results. <br /> rn <br /> 3) We will click the cursor to the top of the screen, enter the SQL commands, such as the type: <BR> select ename, sal from scott.emp; <BR> Enter the completion of command, with the implementation of the cursor icon to click on the left side, Oracle will be the results displayed in the screen below: <br /> rn <br /> Figure 1. 10-2 after a successful login screen <br /> rn <br /> Figure 1.10-3 query command and display the results of the screen <br /> rn <br /> From the SQL Worksheet tool can be seen, the tool provides a very rich functionality. The following gives a brief functional description: <br /> rn <br /> 1. File: <BR> l change the database connection: you can connect to another user and database up; <BR> l Open: You can open an existing file; <BR> l will enter the Save As: save the current command to a file; <BR> l will be displayed below the result saved as a file. <BR> 2. Editor: <BR> l Cut: The characters in the currently selected shear; <BR> l Copy: Cut the selected characters; <BR> l Paste: The paste buffer characters; <BR> l Select: all the characters on the current screen Select All; <BR> l All Clear: Clear all the contents of the current. <br /> rn <br /> 3. Worksheet: <BR> l Execution: execution of the current order; <BR> l run a local script: run an operating system. SQL file (when clicked, prompts the input file name); <BR> l Command history: view the command history; <BR> l at a command: Display on a command. <br /> rn <br /> Tip: If your SQL Worksheet are not shown in Chinese characters (which appears chaotic character), you NT/2000/98 your environment variable settings of Chinese characters the same as with the server just fine. Chinese characters in the WINDOWS NT environment variables to set these steps: <br /> rn <br /> Using regedit to modify the registry of all ORACLE character set items, such as: <BR> 1) Click on: Start = &quot;Run =&quot; type regedit; <BR> 2) Click &quot;HEY_LOCAL_MACHINE&quot; the left &quot;+&quot; to expand the directory; <BR> 3) Click on the &quot;SOFTWARE&quot; the left &quot;+&quot; to expand the directory; <BR> 4) Click on the &quot;ORACLE&quot; item; <BR> 5) Revise the ORACLE under the tree for all &quot;NLS&quot; variables and props $ in agreement. <br /> rn <br /> On the Chinese environment variable settings, please refer to the &quot;Oracle8i/9I the primary database management.&quot; <br /> rn <br /> ----------------------------------------------- <br /> rn <br /> 1, Oracle startup and shutdown <BR> 1, in the stand-alone environment, in order to start or shut down ORACLE system must first switch to the ORACLE user, as follows <BR> su - oracle <br /> rn <br /> a, start the ORACLE system <BR> oracle&gt; svrmgrl <BR> SVRMGR&gt; connect internal <BR> SVRMGR&gt; startup <BR> SVRMGR&gt; quit <br /> rn <br /> b, shut down ORACLE system <BR> oracle&gt; svrmgrl <BR> SVRMGR&gt; connect internal <BR> SVRMGR&gt; shutdown <BR> SVRMGR&gt; quit <br /> rn <br /> Start oracle9i database command: <BR> $ Sqlplus / nolog <br /> rn <br /> SQL * Plus: Release 9.2.0.1.0 - ProdUCtion on Fri Oct 31 13:53:53 2003 <br /> rn <br /> Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. <br /> rn <br /> SQL&gt; connect / as sysdba <BR> Connected to an idle instance. <BR> SQL&gt; startup ^ C <br /> rn <br /> SQL&gt; startup <BR> ORACLE instance started. <br /> rn <br /> 2, in the two-plane environment, in order to start or shut down ORACLE system must first switch to root user, as follows <BR> su - root <br /> rn <br /> a, start the ORACLE system <BR> hareg-y oracle <br /> rn <br /> b, shut down ORACLE system <BR> hareg-n oracle <br /> rn <br /> What are a few to start Oracle database method <br /> rn <br /> Description: <br /> rn <br /> There are several ways to start: <BR> 1, startup nomount <BR> Non-installation start, in this way to launch the next executable: rebuild control file, rebuild the database <br /> rn <br /> Read init.ora file to start the instance, that launched SGA and background processes, which started just init.ora file. <br /> rn <br /> 2, startup mount dbname <BR> Installation starts, this approach to launch the next executable: <BR> Database log archiving, <BR> Database media recovery, <BR> The data file online or offline, <BR> To re-locate data files, redo log files. <br /> rn<br /> Implementation of the &quot;nomount&quot;, then open the control file, confirm data files and online log file location, <BR> But this time not data files and log files and checks. <br /> rn <br /> 3, startup open dbname <BR> The first implementation of the &quot;nomount&quot;, then run the &quot;mount&quot;, then open the Redo log file, including all databases, including documents, <BR> This way can access data in the database. <br /> rn <br /> 4, startup, equivalent to the following three commands <BR> startup nomount <BR> alter database mount <BR> alter database open <br /> rn <br /> 5, startup restrict <BR> Constrained in this way can be activated to start the database, but only allowed to have a certain privileged users to access non-privileged user access, the following tips: <BR> ERROR: <BR> ORA-01035: ORACLE only allows users with the RESTRICTED SESSION privileges to use <br /> rn <br /> 6, startup force <BR> Forced to start way when you can not close the database, you can use startup force to complete the closure of the database to close the database, then the normal database commands to start <br /> rn <br /> 7, startup pfile = parameter file names start with initialization parameter file means the first to read parameter file, and then set the parameter file to start the database in the cases of: startup pfile = E: Oracleadminoradbpfileinit.ora <br /> rn <br /> 8, startup EXCLUSIVE <BR> 2, the user how to effectively use of ORACLE data dictionary data dictionary is an important part of the database, which arise as a database created with the database and change, <BR> Reflected in sys user at some of the tables and views. Data dictionary name is uppercase English characters. <br /> rn <br /> The data dictionary, there is user information, the user&#39;s access information, all data objects information, table constraints, such as statistical analysis of the database view. <BR> We can not manually modify the data dictionary information. <br /> rn <br /> In many cases, the general ORACLE users do not know how to effectively use it. <br /> rn <br /> dictionary all the data dictionary table names and explanations, it has a synonym dict <BR> dict_column all the data dictionary table field names and explanations <br /> rn <br /> If we want to query the data dictionary with the index, you can this with the following SQL statement: <br /> rn <br /> SQL&gt; select * from dictionary where instr (comments, &#39;index&#39;)&gt; 0; <br /> rn <br /> If we want to know user_indexes table details the meaning of each field name, you can use the following clause in SQL statement: <br /> rn <br /> SQL&gt; select column_name, comments from dict_columns where table_name = &#39;USER_INDEXES&#39;; <br /> rn <br /> And so on, you can easily know the details of the name of the data dictionary and explanation do not see the other documentation of ORACLE. <br /> rn <br /> The following are listed by category of some commonly used ORACLE user queries the data dictionary to use. <br /> rn <br /> 1, the user <br /> rn <br /> View the current user&#39;s default tablespace <br /> rn <br /> SQL&gt; select username, default_tablespace from user_users; <br /> rn <br /> View the current user&#39;s role <BR> SQL&gt; select * from user_role_privs; <br /> rn <br /> View the current user&#39;s system privileges, and table-level permissions <BR> SQL&gt; select * from user_sys_privs; <BR> SQL&gt; select * from user_tab_privs; <br /> rn <br /> 2, Table <br /> rn <br /> See the table of all users <BR> SQL&gt; select * from user_tables; <br /> rn <br /> See the table name contains characters log <BR> SQL&gt; select object_name, object_id from user_objects <BR> where instr (object_name, &#39;LOG&#39;)&gt; 0; <br /> rn <br /> View of a table creation time <BR> SQL&gt; select object_name, created from user_objects where object_name = upper ( &#39;&amp; table_name&#39;); <br /> rn <br /> See the size of a table <BR> SQL&gt; select sum (bytes) / (1024 * 1024) as &quot;size (M)&quot; from user_segments <BR> where segment_name = upper ( &#39;&amp; table_name&#39;); <br /> rn <br /> View on the ORACLE table in the memory area where <BR> SQL&gt; select table_name, cache from user_tables where instr (cache, &#39;Y&#39;)&gt; 0; <br /> rn <br /> 3, index <br /> rn <br /> View the index number and type of <BR> SQL&gt; select index_name, index_type, table_name from user_indexes order by table_name; <br /> rn <br /> View the index fields have been indexed <BR> SQL&gt; select * from user_ind_columns where index_name = upper ( &#39;&amp; index_name&#39;); <br /> rn <br /> View the index size of the <BR> SQL&gt; select sum (bytes) / (1024 * 1024) as &quot;size (M)&quot; from user_segments <BR> where segment_name = upper ( &#39;&amp; index_name&#39;); <br /> rn <br /> 4, serial number <br /> rn <br /> View serial number, last_number is the current value of <BR> SQL&gt; select * from user_sequences; <br /> rn <br /> 5, view <br /> rn <br /> View the name of the view <BR> SQL&gt; select view_name from user_views; <br /> rn <br /> View of the select statement to create the view <BR> SQL&gt; set view_name, text_length from user_views; <BR> SQL&gt; set long 2000; Note: You can view text_length value is set according to set long the size of the <BR> SQL&gt; select text from user_views where view_name = upper ( &#39;&amp; view_name&#39;); <br /> rn <br /> 6, synonyms <br /> rn <br /> See the name of the synonym <BR> SQL&gt; select * from user_synonyms; <br /> rn <br /> 7, constraints <br /> rn <br /> View the constraints of a table <BR> SQL&gt; select constraint_name, constraint_type, search_condition, r_constraint_name <BR> from user_constraints where table_name = upper ( &#39;&amp; table_name&#39;); <br /> rn<br /> SQL&gt; select c.constraint_name, c.constraint_type, cc.column_name <BR> from user_constraints c, user_cons_columns cc <BR> where c.owner = upper ( &#39;&amp; table_owner&#39;) and c.table_name = upper ( &#39;&amp; table_name&#39;) <BR> and c.owner = cc.owner and c.constraint_name = cc.constraint_name <BR> order by cc.position; <br /> rn <br /> 8, stored functions and procedures <br /> rn <br /> View the status of functions and procedures <BR> SQL&gt; select object_name, status from user_objects where object_type = &#39;FUNCTION&#39;; <BR> SQL&gt; select object_name, status from user_objects where object_type = &#39;PROCEDURE&#39;; <br /> rn <br /> View the source code for functions and procedures <BR> SQL&gt; select text from all_source where owner = user and name = upper ( &#39;&amp; plsql_name&#39;); <br /> rn <br /> 3, view database, SQL <BR> 1, view the table space name and size of the <br /> rn <br /> select t.tablespace_name, round (sum (bytes / (1024 * 1024)), 0) ts_size <BR> from dba_tablespaces t, dba_data_files d <BR> where t.tablespace_name = d.tablespace_name <BR> group by t.tablespace_name; <br /> rn <br /> 2, view tablespace physical file name and size of the <br /> rn <br /> select tablespace_name, file_id, file_name, <BR> round (bytes / (1024 * 1024), 0) total_space <BR> from dba_data_files <BR> order by tablespace_name; <br /> rn <br /> 3, view the name and size of rollback segments <br /> rn <br /> select segment_name, tablespace_name, r.status, <BR> (initial_extent/1024) InitialExtent, (next_extent/1024) NextExtent, <BR> max_extents, v.curext CurExtent <BR> From dba_rollback_segs r, v $ rollstat v <BR> Where r.segment_id = v.usn (+) <BR> order by segment_name; <br /> rn <br /> 4, view control files <br /> rn <br /> select name from v $ controlfile; <br /> rn <br /> 5, view the log file <br /> rn <br /> select member from v $ logfile; <br /> rn <br /> 6, view the table space is being used <br /> rn <br /> select sum (bytes) / (1024 * 1024) as free_space, tablespace_name <BR> from dba_free_space <BR> group by tablespace_name; <br /> rn <br /> SELECT A. TABLESPACE_NAME, A. BYTES TOTAL, B. BYTES USED, C. BYTES FREE, <br /> rn <br /> (B. BYTES * 100) / A. BYTES &quot;% USED&quot;, (C. BYTES * 100) / A. BYTES &quot;% FREE&quot; <BR> FROM SYS.SM $ TS_AVAIL A, SYS.SM $ TS_USED B, SYS.SM $ TS_FREE C <BR> WHERE A. TABLESPACE_NAME = B. TABLESPACE_NAME AND A. TABLESPACE_NAME = C. TABLESPACE_NAME; <br /> rn <br /> 7, view the database object library <br /> rn <br /> select owner, object_type, status, count (*) count # from all_objects group by owner, object_type, status; <br /> rn <br /> 8, view the version of the database <br /> rn <br /> Select version FROM Product_component_version <BR> Where SUBSTR (PRODUCT, 1,6) = &#39;Oracle&#39;; <br /> rn <br /> 9, see the database creation date and archiving methods <br /> rn <br /> Select Created, Log_Mode, Log_Mode From V $ Database; 4, ORACLE management of user connections <br /> rn <br /> With the system administrator to see the current database, there are several user connections: <br /> rn <br /> SQL&gt; select username, sid, serial # from v $ session; <br /> rn <br /> If you want to stop a connection with the <br /> rn <br /> SQL&gt; alter system kill session &#39;sid, serial #&#39;; <br /> rn <br /> If this command not work, find its UNIX process number <br /> rn <br /> SQL&gt; select pro.spid from v $ session ses, v $ process pro where ses.sid = 21 and ses.paddr = pro.addr; <br /> rn <br /> Note: 21 is the number of a connection sid <br /> rn <br /> Then use the kill command to kill this process ID. <br /> rn <br /> 5, SQL * PLUS using the <BR> a, almost into the SQL * Plus <BR> $ sqlplus username / password <br /> rn <br /> Exit SQL * Plus <BR> SQL&gt; exit <br /> rn <br /> b, In sqlplus under the help information lists all the SQL commands and SQL * Plus commands <BR> SQL&gt; help <BR> Commands are listed in a specific information <BR> SQL&gt; help command name <br /> rn <br /> c, shows the table structure of the command DESCRIBE <BR> SQL&gt; DESC table name <br /> rn <br /> d, SQL * Plus editing commands shown in the SQL buffer commands <BR> SQL&gt; L <br /> rn <br /> First of all you want to modify the SQL command line becomes the current line to be corrected <BR> SQL&gt; n <BR> Modify the contents of the command with the CHANGE <BR> SQL&gt; c / old / new re-verify that the correct <BR> SQL&gt; L <br /> rn <br /> Using the INPUT command in the SQL buffer to add one or more rows <BR> SQL&gt; i <BR> SQL&gt; input <br /> rn <br /> e, call the external system editor <BR> SQL&gt; edit the file name you can use the DEFINE command to set system variable EDITOR to change the type of text editor in the file are defined as follows login.sql row <BR> DEFINE_EDITOR = vi <br /> rn <br /> f, run the command file <BR> SQL&gt; START test <BR> SQL&gt; @ test <br /> rn <br /> Common SQL * Plus Statements <BR> a, the table to create, modify, delete command to create the table the following format: <BR> create table table name (column description list); <br /> rn <br /> As the base table to add a new column command is as follows: <BR> ALTER TABLE table ADD (column description list) <BR> Example: In order to test the table to increase an Age, used to store the age <BR> sql&gt; alter table test <BR> add (Age number (3)); <br /> rn <br /> Modify the base table column definition command is as follows: <BR> ALTER TABLE table name <BR> MODIFY (column name data type) <BR> Example: The test table in the Count column width extended to 10 characters <BR> sql&gt; alter atble test <BR> modify (County char (10)); <br /> rn <br /> b, will be a table delete statement the following format: <BR> DORP TABLE table name; <BR> Example: Table to delete will also delete the table data and table definitions <BR> sql&gt; drop table test <br /> rn<br /> c, table space, create, delete 6, ORACLE logical backup of the SH file <br /> rn <br /> Full backup of the SH file: eXP_comp.sh <br /> rn <br /> rq = `date +&quot;% m% d &quot;` <br /> rn <br /> su - oracle-c &quot;exp system / manager full = y inctype = complete file = / oracle / export / db_comp $ rq.dmp&quot; <br /> rn <br /> SH cumulative backup file: exp_cumu.sh <br /> rn <br /> rq = `date +&quot;% m% d &quot;` <br /> rn <br /> su - oracle-c &quot;exp system / manager full = y inctype = cumulative file = / oracle / export / db_cumu $ rq.dmp&quot; <br /> rn <br /> SH incremental backup files: exp_incr.sh <br /> rn <br /> rq = `date +&quot;% m% d &quot;` <br /> rn <br /> su - oracle-c &quot;exp system / manager full = y inctype = incremental file = / oracle / export / db_incr $ rq.dmp&quot; <br /> rn <br /> root user crontab file <BR> / var / spool / cron / crontabs / root to add the following content <br /> rn <br /> 0 2 1 * * / oracle / exp_comp.sh <br /> rn <br /> 30 2 * * 0-5 / oracle / exp_incr.sh <br /> rn <br /> 45 2 * * 6 / oracle / exp_cumu.sh <br /> rn <br /> Of course, this timetable can be changed according to different needs, and this is just one example. <br /> rn <br /> 7, ORACLE commonly used in SQL syntax and data objects <br /> rn <br /> 1. Data control statements (DML) part of the <br /> rn <br /> 1.INSERT (insert record to the data table statement) <br /> rn <br /> INSERT INTO table (field name 1, field name 2, ... ...) VALUES (value 1, the value 2, ... ...); <BR> INSERT INTO table (field name 1, field name 2, ... ...) SELECT (field name 1, field name 2, ... ...) FROM another table name; <br /> rn <br /> String type field values must be enclosed in single quotation marks, for example: &#39;GOOD DAY&#39; <BR> If the field value contains a single quote inside &#39;the need for a string conversion, we replace it into two single quotation marks&#39;&#39;. <BR> String type field value exceeds the length of the definition of an error, preferably inserted before the length of the checksum. <br /> rn <br /> The date field the field value can be a database system time with the current SYSDATE, accurate to seconds, or use string to date type function TO_DATE (&#39;2001-08-01 &#39;,&#39; YYYY-MM-DD &#39;) <BR> TO_DATE () There are many date formats, you can see ORACLE DOC. <BR> Year - month - day hours: minutes: seconds format YYYY-MM-DD HH24: MI: SS <br /> rn <br /> INSERT maximum operational length of the string is less than equal to 4000 single-byte, if you want to insert a longer string, please consider using CLOB field type, <BR> Way to use ORACLE Lane comes DBMS_LOB package. <br /> rn <br /> If you use the INSERT, when starting from an automatic increase in the serial number, it should first establish a serial number <BR> CREATE SEQUENCE serial number of the name (preferably the table name + serial number tag) INCREMENT BY 1 START WITH 1 <BR> MAXVALUE 99999 CYCLE NOCACHE; <BR> One of the biggest values determined by the length of the field, if the definition of automatic increase in the serial number NUMBER (6), max 999999 <BR> INSERT statement inserts the value of this field: the name of the serial number. NEXTVAL <br /> rn <br /> 2.DELETE (delete data table records statement) <br /> rn <br /> DELETE FROM table WHERE conditions; <br /> rn <br /> Note: does not delete the record and the release of ORACLE data block inside the occupied table space. Only those who have been deleted data blocks marked as unused. <br /> rn <br /> If you really want to delete all the records of a large table, you can use TRUNCATE command, it can block the release of the data table space occupied by <BR> TRUNCATE TABLE table; <BR> This action can not be rollback. <br /> rn <br /> 3.UPDATE (modify data table records statement) <br /> rn <br /> UPDATE table SET field name 1 = value 1, field name 2 = value 2, ... ... WHERE condition; <br /> rn <br /> If you modify the value of N is not an assignment or definition, will clear the contents of the original record of NULL, preferably before modifying non-empty calibration; <BR> Over the definition of the length of the value of N would be an error, it is best inserted before the length of the check .. <br /> rn <br /> Note: <BR> A. above SQL statement is added to the tables are row-level locks, <BR> Upon completion, must be added the end of the command COMMIT transaction processing in order to come into force, <BR> Otherwise, change is not necessarily written to the database. <BR> If you want to withdraw these operations, you can use the command ROLLBACK recovery. <br /> rn <br /> B. run the INSERT, DELETE, and UPDATE statements before the best estimates of what the record may be operating range, <BR> It should be limited to small (10000 records) within the framework. Or ORACLE uses a great deal with this thing rollback segment. <BR> Procedures to respond to slow or even loss of response. If the number of records on the hundreds of thousands of these operations, these SQL statements can be sub-sub-sub-complete, <BR> Together with confirmation of things during COMMIT processing. 2. Data definition (DDL) part of the <br /> rn <br /> 1.CREATE (to create tables, indexes, views, synonyms, procedures, functions, database links, etc.) <br /> rn <br /> ORACLE common field types are <BR> CHAR fixed-length strings <BR> VARCHAR2 variable-length strings <BR> NUMBER (M, N) number of type M is the median total length, N is the length of the decimal <BR> DATE date type <br /> rn <br /> When we are young to create the table is not empty field on the front of the field may be empty on the back <br /> rn <br /> Can be used to create the table field names in Chinese, but the best of the field names in English <br /> rn <br /> To create the table fields can be added to the default value, for example, DEFAULT SYSDATE <BR> So each insertion and modification, do not have access to procedures for operation of this field action time <br /> rn <br /> Create a table can be added to the field, for example, the constraints do not allow duplicate UNIQUE, keyword PRIMARY KEY <br /> rn <br /> 2.ALTER (changing tables, indexes, views, etc.) <br /> rn <br /> To change the name of the table <BR> ALTER TABLE table 1 TO table 2; <br /> rn<br /> In the table behind the increase in a field <BR> ALTER TABLE table name ADD name of the field names described in paragraph; <br /> rn <br /> Modify the definition of the field description table <BR> ALTER TABLE table MODIFY field name field name description; <br /> rn <br /> Field to the table with constraint <BR> ALTER TABLE table name ADD CONSTRAINT constraint name PRIMARY KEY (field name); <br /> rn <br /> ALTER TABLE table name ADD CONSTRAINT constraint name UNIQUE (field names); <br /> rn <br /> Put the table on the database, or remove the memory area <BR> ALTER TABLE table name CACHE; <BR> ALTER TABLE table name NOCACHE; <br /> rn <br /> 3.DROP (delete tables, indexes, views, synonyms, procedures, functions, database links, etc.) <br /> rn <br /> Remove the table and all its constraints <BR> DROP TABLE table CASCADE CONSTRAINTS; <br /> rn <br /> 4.TRUNCATE (empty table all the records, retaining the table structure) <br /> rn <br /> TRUNCATE table; <br /> rn <br /> 3. Query (SELECT) part of the <br /> rn <br /> SELECT field name 1, field name 2, ... ... FROM table 1, [table 2, ... ...] WHERE conditions; <br /> rn <br /> Field names can be brought into the functions such as: COUNT (*), MIN (field names), MAX (field names), AVG (field names), DISTINCT (field names), <BR> TO_CHAR (DATE field names, &#39;YYYY-MM-DD HH24: MI: SS&#39;) <br /> rn <br /> NVL (EXPR1, EXPR2) function is explained: <BR> IF EXPR1 = NULL <BR> RETURN EXPR2 <BR> ELSE <BR> RETURN EXPR1 <br /> rn <br /> DECODE (AA, V1, R1, V2, R2 ....) function, explained: <BR> IF AA = V1 THEN RETURN R1 <BR> IF AA = V2 THEN RETURN R2 <BR> .. ... ELSE <BR> RETURN NULL <br /> rn <br /> LPAD (char1, n, char2) function is explained: <BR> Character char1 according to the number of bits n to develop shows, less than the number of bits to replace the string with the left side of the space char2 <br /> rn <br /> Field names can be between the arithmetic such as: (a field name field name * 1) / 3 <br /> rn <br /> For example, can be nested query: SELECT ... ... FROM <BR> (SELECT ... ... FROM table 1, [table 2, ... ...] WHERE condition) WHERE condition 2; <br /> rn <br /> 2 the results of query operations such as the collection can be done: and set UNION (remove duplicate records), and set UNION ALL (do not remove duplicate records), and poor collection MINUS, intersection INTERSECT <br /> rn <br /> Group Inquiries <BR> SELECT field name 1, field name 2, ... ... FROM table 1, [table 2, ... ...] GROUP BY field name 1 <BR> [HAVING conditions]; <br /> rn <br /> The connection between two or more tables query <br /> rn <br /> SELECT field name 1, field name 2, ... ... FROM table 1, [table 2, ... ...] WHERE <BR> Table 1. Field name = table name 2. Field name [AND ... ...]; <br /> rn <br /> SELECT field name 1, field name 2, ... ... FROM table 1, [table 2, ... ...] WHERE <BR> Table 1. Field name = table name 2. Field name (+) [AND ... ...]; <br /> rn <br /> With (+) of the field position auto-fill empty value <br /> rn <br /> Query result set sorting operation, the default sort is ascending ASC, descending order is DESC <br /> rn <br /> SELECT field name 1, field name 2, ... ... FROM table 1, [table 2, ... ...] <BR> ORDER BY field name 1, field name 2 DESC; <br /> rn <br /> String comparison method of fuzzy <br /> rn <br /> INSTR (field name, &#39;string&#39;) &quot;0 <BR> Field Name LIKE &#39;string%&#39; [ &#39;% string%&#39;] <br /> rn <br /> Each table has a hidden field ROWID, which marks the uniqueness of records. <br /> rn <br /> 4. ORACLE where commonly used data objects (SCHEMA) <br /> rn <br /> 1. Index (INDEX) <br /> rn <br /> CREATE INDEX index name ON table (field 1, [field 2, ... ...]); <BR> ALTER INDEX index name REBUILD; <br /> rn <br /> The best index of a table should not exceed three (except for special big table), the best single-field index, combined with an analysis of the implementation of the SQL statement, <BR> Can also be a combination of a multi-field index and function-based index <br /> rn <br /> ORACLE8.1.7 string can index the maximum length of 1578 single-byte <BR> ORACLE8.0.6 string can index the maximum length of 758 single-byte <br /> rn <br /> 2. The view (VIEW) <br /> rn <br /> CREATE VIEW view name AS SELECT .... FROM ... ..; <BR> ALTER VIEW view name COMPILE; <br /> rn <br /> The view is only one SQL query, which can form complex relationship between the simplicity of. <br /> rn <br /> 3. Synonym (SYNONMY) <BR> CREATE SYNONYM synonym name FOR table; <BR> CREATE SYNONYM synonym name FOR table @ database link name; <br /> rn <br /> 4. Database link (DATABASE LINK) <BR> CREATE DATABASE LINK database link name CONNECT TO username IDENTIFIED BY password USING &#39;database connection string&#39;; <br /> rn <br /> Database connection string can be NET8 EASY CONFIG or directly modify the TNSNAMES.ORA where defined. <br /> rn <br /> Database Parameters global_name = true to request the database link name with the same remote database name <br /> rn <br /> Database global name can be found using the following command <BR> SELECT * FROM GLOBAL_NAME; <br /> rn <br /> Queries the remote database table <BR> SELECT ... ... FROM table @ database link name; <br /> rn <br /> 5. Rights Management (DCL) statements <br /> rn <br /> 1.GRANT the system assigns permissions to access a collection of commonly used has the following three: <BR> CONNECT (basic connectivity), RESOURCE (Programming), DBA (database management) <br /> rn <br /> Commonly used data objects have the following five rights: <BR> ALL ON data object names, SELECT ON data object names, UPDATE ON data object names, <BR> DELETE ON data object name, INSERT ON data object name, ALTER ON data object name <br /> rn <br /> GRANT CONNECT, RESOURCE TO username; <BR> GRANT SELECT ON table TO user name; <BR> GRANT SELECT, INSERT, DELETE ON table TO user name one, user name 2; <br /> rn<br /> 2.REVOKE recovery Permissions <br /> rn <br /> REVOKE CONNECT, RESOURCE FROM username; <BR> REVOKE SELECT ON table FROM user name; <BR> REVOKE SELECT, INSERT, DELETE ON table FROM user name one, user name 2; <br /> rn <br /> Query the database Error No. 63: <BR> select orgaddr, destaddr from sm_histable0116 where error_code = &#39;63 &#39;; <br /> rn <br /> Query the database user accounts and the largest issued to submit the largest number: select MSISDN, TCOS, OCOS from ms_usertable; <br /> rn <br /> Query the database in the sum of the various error codes: <BR> select error_code, count (*) from sm_histable0513 group by error_code order <BR> by error_code; <br /> rn <br /> Query statements in the database, then a single statistical types of queries. <BR> select sum (Successcount) from tbl_MiddleMt0411 where ServiceType2 = 111 <BR> select sum (successcount), servicetype from tbl_middlemt0411 group by servicetype <br /> rn <br /><BR> This article comes from CSDN blog, reproduced please indicate source: http://blog.csdn.net/jack_rao/archive/2009/05/11/4168371.aspx				<h5>Related Posts</h5>
		<div id="smilar">
		<ul>
					<li><a href="http://www.kods.netwww.kods.net/sga-extended-the-principle-of-32bit-oracle/" title="SGA extended the principle of 32bit oracle">SGA extended the principle of 32bit oracle</a> 2009-03-31 09:48:01</li>
					<li><a href="http://www.kods.netwww.kods.net/diagnosis-and-principles-of-order/" title="Diagnosis and principles of order">Diagnosis and principles of order</a> 2009-02-25 20:27:28</li>
					<li><a href="http://www.kods.netwww.kods.net/oracle-10g-dataguard-configuration-step-by-step/" title="ORACLE 10G dataguard configuration Step by Step">ORACLE 10G dataguard configuration Step by Step</a> 2009-02-16 01:13:55</li>
				</ul>
		</div>
		        ]]></content:encoded>
		<wfw:commentRss>http://www.kods.netwww.kods.net/oracle-sql-plus-basic-and-sqlplus-command-xiangjie-2/</wfw:commentRss>
	</item>
		<item>
		<title>oracle sql outer join predicates the application of a time when the order will affect the outcome of</title>
		<link>http://www.kods.netwww.kods.net/oracle-sql-outer-join-predicates-the-application-of-a-time-when-the-order-will-affect-the-outcome-of/</link>
		<comments>http://www.kods.netwww.kods.net/oracle-sql-outer-join-predicates-the-application-of-a-time-when-the-order-will-affect-the-outcome-of/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 17:53:08+0000</pubDate>
		<dc:creator>kods.net</dc:creator>
		<category><![CDATA[Oracle SQL]]></category>
		<category><![CDATA[oracle]]></category>
<category><![CDATA[relationship]]></category>
<category><![CDATA[lt]]></category>
<category><![CDATA[yyyy]]></category>
<category><![CDATA[dd]]></category>
<category><![CDATA[ss]]></category>
<category><![CDATA[oracle sql]]></category>
<category><![CDATA[nvl]]></category>
<category><![CDATA[company id]]></category>
<category><![CDATA[bas tab]]></category>
<category><![CDATA[c pause]]></category>
<category><![CDATA[b company]]></category>
<category><![CDATA[c company]]></category>
<category><![CDATA[unreg]]></category>
		<guid isPermaLink="true">http://www.kods.netwww.kods.net/oracle-sql-outer-join-predicates-the-application-of-a-time-when-the-order-will-affect-the-outcome-of/</guid>
		<description><![CDATA[oracle sql outer join predicates the application of a time when the order will affect the outcome, there is no relationship between the non-outer join, but the oracle so because, although the understa ...]]></description>
		<content:encoded><![CDATA[oracle sql outer join predicates the application of a time when the order will affect the outcome, there is no relationship between the non-outer join, but the oracle so because, although the understanding that a bit strange, it should also have their reasons. <br /><br /> SELECT COUNT (DISTINCT B. COMPANY_ID) <br /> FROM (SELECT * <br /> FROM ODS.BAS_TAB_EMPLOYEE_FJYD C <br /> WHERE C. END_DATE = TO_DATE (&#39;3000-12-31 &#39;,&#39; YYYY-MM-DD &#39;) <br /> AND C. REG_DATE &lt;TO_DATE (&#39;2010-01-24 00:00:00 &#39;/ *: v_end_dt * /, <br /> &#39;YYYY-MM-DD HH24: MI: SS&#39;) <br /> AND (C. EMPLOYEE_STATUS = 1 OR <br /> C. EMPLOYEE_STATUS = 0 AND <br /> C. PAUSE_DATE&gt; = <br /> TO_DATE (&#39;2010-01-23 00:00:00 &#39;/ *: v_start_dt * /, <br /> &#39;YYYY-MM-DD HH24: MI: SS&#39;) OR <br /> NVL (C. PAUSE_DATE, C. UNREG_DATE)&gt; = <br /> TO_DATE (&#39;2010-01-23 00:00:00 &#39;/ *: v_start_dt * /, <br /> &#39;YYYY-MM-DD HH24: MI: SS&#39;))) C, <br /> ODS.BAS_TAB_COMPANY_FJYD B <br /> WHERE B. COMPANY_ID = C. COMPANY_ID <br /><br /> AND B. END_DATE = TO_DATE (&#39;3000-12-31 &#39;,&#39; YYYY-MM-DD &#39;) <br /> AND B. REG_DATE &lt; <br /> TO_DATE (&#39;2010-01-24 00:00:00 &#39;/ *: v_end_dt * /,&#39; YYYY-MM-DD HH24: MI: SS &#39;) <br /> AND (B. COMPANY_STATUS = 1 OR <br /> B. COMPANY_STATUS = 0 AND <br /> B. PAUSE_DATE&gt; = TO_DATE (&#39;2010-01-23 00:00:00 &#39;/ *: v_start_dt * /, <br /> &#39;YYYY-MM-DD HH24: MI: SS&#39;) OR <br /> NVL (B. PAUSE_DATE, B. UNREG_DATE)&gt; = <br /> TO_DATE (&#39;2010-01-23 00:00:00 &#39;/ *: v_start_dt * /, <br /> &#39;YYYY-MM-DD HH24: MI: SS&#39;)) <br /><br /> 4813 --- OK <br /><br /> SELECT COUNT (DISTINCT B. COMPANY_ID) <br /> FROM ODS.BAS_TAB_COMPANY_FJYD B, ODS.BAS_TAB_EMPLOYEE_FJYD C <br /> WHERE C. COMPANY_ID = B. COMPANY_ID <br /><br /> AND B. END_DATE = TO_DATE (&#39;3000-12-31 &#39;,&#39; YYYY-MM-DD &#39;) <br /> AND B. REG_DATE &lt; <br /> TO_DATE (&#39;2010-01-24 00:00:00 &#39;/ *: v_end_dt * /,&#39; YYYY-MM-DD HH24: MI: SS &#39;) <br /> AND (B. COMPANY_STATUS = 1 OR <br /> B. COMPANY_STATUS = 0 AND <br /> B. PAUSE_DATE&gt; = TO_DATE (&#39;2010-01-23 00:00:00 &#39;/ *: v_start_dt * /, <br /> &#39;YYYY-MM-DD HH24: MI: SS&#39;) OR <br /> NVL (B. PAUSE_DATE, B. UNREG_DATE)&gt; = <br /> TO_DATE (&#39;2010-01-23 00:00:00 &#39;/ *: v_start_dt * /, <br /> &#39;YYYY-MM-DD HH24: MI: SS&#39;)) <br /><br /> AND C. END_DATE = TO_DATE (&#39;3000-12-31 &#39;,&#39; YYYY-MM-DD &#39;) <br /> AND C. REG_DATE &lt; <br /> TO_DATE (&#39;2010-01-24 00:00:00 &#39;/ *: v_end_dt * /,&#39; YYYY-MM-DD HH24: MI: SS &#39;) <br /> AND (C. EMPLOYEE_STATUS = 1 OR <br /> C. EMPLOYEE_STATUS = 0 AND <br /> C. PAUSE_DATE&gt; = TO_DATE (&#39;2010-01-23 00:00:00 &#39;/ *: v_start_dt * /, <br /> &#39;YYYY-MM-DD HH24: MI: SS&#39;) OR <br /> NVL (C. PAUSE_DATE, C. UNREG_DATE)&gt; = <br /> TO_DATE (&#39;2010-01-23 00:00:00 &#39;/ *: v_start_dt * /, <br /> &#39;YYYY-MM-DD HH24: MI: SS&#39;)); <br /><br /> - 4813 line. <br /><br /> SELECT COUNT (DISTINCT B. COMPANY_ID) <br /> FROM (SELECT * <br /> FROM ODS.BAS_TAB_EMPLOYEE_FJYD C <br /> WHERE C. END_DATE = TO_DATE (&#39;3000-12-31 &#39;,&#39; YYYY-MM-DD &#39;) <br /> AND C. REG_DATE &lt;TO_DATE (&#39;2010-01-24 00:00:00 &#39;/ *: v_end_dt * /, <br /> &#39;YYYY-MM-DD HH24: MI: SS&#39;) <br /> AND (C. EMPLOYEE_STATUS = 1 OR <br /> C. EMPLOYEE_STATUS = 0 AND <br /> C. PAUSE_DATE&gt; = <br /> TO_DATE (&#39;2010-01-23 00:00:00 &#39;/ *: v_start_dt * /, <br /> &#39;YYYY-MM-DD HH24: MI: SS&#39;) OR <br /> NVL (C. PAUSE_DATE, C. UNREG_DATE)&gt; = <br /> TO_DATE (&#39;2010-01-23 00:00:00 &#39;/ *: v_start_dt * /, <br /> &#39;YYYY-MM-DD HH24: MI: SS&#39;))) C, <br /> ODS.BAS_TAB_COMPANY_FJYD B <br /> WHERE B. COMPANY_ID = C. COMPANY_ID (+) <br /><br /> AND B. END_DATE = TO_DATE (&#39;3000-12-31 &#39;,&#39; YYYY-MM-DD &#39;) <br /> AND B. REG_DATE &lt; <br /> TO_DATE (&#39;2010-01-24 00:00:00 &#39;/ *: v_end_dt * /,&#39; YYYY-MM-DD HH24: MI: SS &#39;) <br /> AND (B. COMPANY_STATUS = 1 OR <br /> B. COMPANY_STATUS = 0 AND <br /> B. PAUSE_DATE&gt; = TO_DATE (&#39;2010-01-23 00:00:00 &#39;/ *: v_start_dt * /, <br /> &#39;YYYY-MM-DD HH24: MI: SS&#39;) OR <br /> NVL (B. PAUSE_DATE, B. UNREG_DATE)&gt; = <br /> TO_DATE (&#39;2010-01-23 00:00:00 &#39;/ *: v_start_dt * /, <br /> &#39;YYYY-MM-DD HH24: MI: SS&#39;)) <br /><br /> - 8441 Line <br /><br /> SELECT COUNT (DISTINCT B. COMPANY_ID) <br /> FROM ODS.BAS_TAB_COMPANY_FJYD B, ODS.BAS_TAB_EMPLOYEE_FJYD C <br /> WHERE C. COMPANY_ID (+) = B. COMPANY_ID <br /><br /> AND B. END_DATE = TO_DATE (&#39;3000-12-31 &#39;,&#39; YYYY-MM-DD &#39;) <br /> AND B. REG_DATE &lt; <br /> TO_DATE (&#39;2010-01-24 00:00:00 &#39;/ *: v_end_dt * /,&#39; YYYY-MM-DD HH24: MI: SS &#39;) <br /> AND (B. COMPANY_STATUS = 1 OR <br /> B. COMPANY_STATUS = 0 AND <br /> B. PAUSE_DATE&gt; = TO_DATE (&#39;2010-01-23 00:00:00 &#39;/ *: v_start_dt * /, <br /> &#39;YYYY-MM-DD HH24: MI: SS&#39;) OR <br /> NVL (B. PAUSE_DATE, B. UNREG_DATE)&gt; = <br /> TO_DATE (&#39;2010-01-23 00:00:00 &#39;/ *: v_start_dt * /,<br /> &#39;YYYY-MM-DD HH24: MI: SS&#39;)) <br /><br /> AND C. END_DATE = TO_DATE (&#39;3000-12-31 &#39;,&#39; YYYY-MM-DD &#39;) <br /> AND C. REG_DATE &lt; <br /> TO_DATE (&#39;2010-01-24 00:00:00 &#39;/ *: v_end_dt * /,&#39; YYYY-MM-DD HH24: MI: SS &#39;) <br /> AND (C. EMPLOYEE_STATUS = 1 OR <br /> C. EMPLOYEE_STATUS = 0 AND <br /> C. PAUSE_DATE&gt; = TO_DATE (&#39;2010-01-23 00:00:00 &#39;/ *: v_start_dt * /, <br /> &#39;YYYY-MM-DD HH24: MI: SS&#39;) OR <br /> NVL (C. PAUSE_DATE, C. UNREG_DATE)&gt; = <br /> TO_DATE (&#39;2010-01-23 00:00:00 &#39;/ *: v_start_dt * /, <br /> &#39;YYYY-MM-DD HH24: MI: SS&#39;)); <br /> - 4813 lines, and non-outer join the same result set.				<h5>Related Posts</h5>
		<div id="smilar">
		<ul>
					<li><a href="http://www.kods.netwww.kods.net/sga-extended-the-principle-of-32bit-oracle/" title="SGA extended the principle of 32bit oracle">SGA extended the principle of 32bit oracle</a> 2009-03-31 09:48:01</li>
					<li><a href="http://www.kods.netwww.kods.net/high-availability-oracle-flashback/" title="High Availability Oracle Flashback">High Availability Oracle Flashback</a> 2009-02-26 17:23:02</li>
					<li><a href="http://www.kods.netwww.kods.net/an-example-of-the-use-of-tkprof/" title="An example of the use of TKPROF">An example of the use of TKPROF</a> 2009-02-26 01:38:19</li>
					<li><a href="http://www.kods.netwww.kods.net/diagnosis-and-principles-of-order/" title="Diagnosis and principles of order">Diagnosis and principles of order</a> 2009-02-25 20:27:28</li>
					<li><a href="http://www.kods.netwww.kods.net/oracle-10g-dataguard-configuration-step-by-step/" title="ORACLE 10G dataguard configuration Step by Step">ORACLE 10G dataguard configuration Step by Step</a> 2009-02-16 01:13:55</li>
				</ul>
		</div>
		        ]]></content:encoded>
		<wfw:commentRss>http://www.kods.netwww.kods.net/oracle-sql-outer-join-predicates-the-application-of-a-time-when-the-order-will-affect-the-outcome-of/</wfw:commentRss>
	</item>
		<item>
		<title>Oracle SQL exquisite SQL (Reprinted)</title>
		<link>http://www.kods.netwww.kods.net/oracle-sql-exquisite-sql-reprinted/</link>
		<comments>http://www.kods.netwww.kods.net/oracle-sql-exquisite-sql-reprinted/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 03:30:03+0000</pubDate>
		<dc:creator>kods.net</dc:creator>
		<category><![CDATA[Oracle SQL]]></category>
		<category><![CDATA[oracle]]></category>
<category><![CDATA[rownum]]></category>
<category><![CDATA[lt]]></category>
<category><![CDATA[partition]]></category>
<category><![CDATA[code 39]]></category>
<category><![CDATA[oracle sql]]></category>
<category><![CDATA[merger]]></category>
<category><![CDATA[conversion]]></category>
<category><![CDATA[random value]]></category>
<category><![CDATA[code substr]]></category>
<category><![CDATA[column switch]]></category>
<category><![CDATA[code switch]]></category>
<category><![CDATA[t card]]></category>
<category><![CDATA[aq]]></category>
<category><![CDATA[q4]]></category>
<category><![CDATA[comma]]></category>
<category><![CDATA[q1]]></category>
<category><![CDATA[q3]]></category>
<category><![CDATA[q2]]></category>
<category><![CDATA[painstaking research]]></category>
		<guid isPermaLink="true">http://www.kods.netwww.kods.net/oracle-sql-exquisite-sql-reprinted/</guid>
		<description><![CDATA[rn Recently due to the reasons of work, in the painstaking research Oracle. Just found the article to this vote, reproduced over. Convert row to switch out the ranks of DROP TABLE t_change_lc; CREATE  ...]]></description>
		<content:encoded><![CDATA[rn <font face="arial, sans-serif"><br /> <font size="4">Recently due to the reasons of work, in the painstaking research Oracle. Just found the article to this vote, reproduced over.</font> <br /><br /> <font size="4"><br /></font> <br /> Convert row to switch out the ranks of <br /> DROP TABLE t_change_lc; <br /></font> <br /> <font face="arial, sans-serif">CREATE TABLE t_change_lc (card_code VARCHAR2 (3), q NUMBER, bal NUMBER); <br /> INSERT INTO t_change_lc <br /> SELECT &#39;001 &#39;card_code, ROWNUM q, trunc (dbms_random.VALUE * 100) bal FROM dual CONNECT BY ROWNUM &lt;= 4 <br /> UNION <br /> SELECT &#39;002 &#39;card_code, ROWNUM q, trunc (dbms_random.VALUE * 100) bal FROM dual CONNECT BY ROWNUM &lt;= 4; <br /><br /> SELECT * FROM t_change_lc; <br /><br /> SELECT a.card_code, <br /> SUM (decode (aq, 1, a.bal, 0)) q1, <br /> SUM (decode (aq, 2, a.bal, 0)) q2, <br /> SUM (decode (aq, 3, a.bal, 0)) q3, <br /> SUM (decode (aq, 4, a.bal, 0)) q4 <br /> FROM t_change_lc a <br /> GROUP BY a.card_code <br /> ORDER BY 1; <br /><br /> - Convert the ranks of the column switch <br /> DROP TABLE t_change_cl; <br /> CREATE TABLE t_change_cl AS <br /> SELECT a.card_code, <br /> SUM (decode (aq, 1, a.bal, 0)) q1, <br /> SUM (decode (aq, 2, a.bal, 0)) q2, <br /> SUM (decode (aq, 3, a.bal, 0)) q3, <br /> SUM (decode (aq, 4, a.bal, 0)) q4 <br /> FROM t_change_lc a <br /> GROUP BY a.card_code <br /> ORDER BY 1; <br /><br /> SELECT * FROM t_change_cl; <br /><br /> SELECT t.card_code, <br /> t.rn q, <br /> decode (t.rn, 1, t.q1, 2, t.q2, 3, t.q3, 4, t.q4) bal <br /> FROM (SELECT a. *, b.rn <br /> FROM t_change_cl a, <br /> (SELECT ROWNUM rn FROM dual CONNECT BY ROWNUM &lt;= 4) b) t <br /> ORDER BY 1, 2; <br /><br /> - Convert line to switch out the ranks of the merger <br /> DROP TABLE t_change_lc_comma; <br /> CREATE TABLE t_change_lc_comma AS SELECT card_code, &#39;quarter_&#39; | | q AS q FROM t_change_lc; <br /><br /> SELECT * FROM t_change_lc_comma; <br /><br /> SELECT t1.card_code, substr (MAX (sys_connect_by_path (t1.q,&#39;;&#39;)), 2) q <br /> FROM (SELECT a.card_code, <br /> aq, <br /> row_number () over (PARTITION BY a.card_code ORDER BY aq) rn <br /> FROM t_change_lc_comma a) t1 <br /> START WITH t1.rn = 1 <br /> CONNECT BY t1.card_code = PRIOR t1.card_code <br /> AND t1.rn - 1 = PRIOR t1.rn <br /> GROUP BY t1.card_code; <br /><br /> - Switch to split the ranks of Conversion Columns <br /> DROP TABLE t_change_cl_comma; <br /> CREATE TABLE t_change_cl_comma AS <br /> SELECT t1.card_code, substr (MAX (sys_connect_by_path (t1.q,&#39;;&#39;)), 2) q <br /> FROM (SELECT a.card_code, <br /> aq, <br /> row_number () over (PARTITION BY a.card_code ORDER BY aq) rn <br /> FROM t_change_lc_comma a) t1 <br /> START WITH t1.rn = 1 <br /> CONNECT BY t1.card_code = PRIOR t1.card_code <br /> AND t1.rn - 1 = PRIOR t1.rn <br /> GROUP BY t1.card_code; <br /><br /> SELECT * FROM t_change_cl_comma; <br /><br /> SELECT t.card_code, <br /> substr (tq, <br /> instr ( &#39;;&#39; | | tq, &#39;;&#39;, 1, rn), <br /> instr (tq | | &#39;;&#39;, &#39;;&#39;, 1, rn) - instr ( &#39;;&#39; | | tq, &#39;;&#39;, 1, rn)) q <br /> FROM (SELECT a.card_code, aq, b.rn <br /> FROM t_change_cl_comma a, <br /> (SELECT ROWNUM rn FROM dual CONNECT BY ROWNUM &lt;= 100) b <br /> WHERE instr ( &#39;;&#39; | | aq, &#39;;&#39;, 1, rn)&gt; 0) t <br /> ORDER BY 1, 2; <br /><br /> - To achieve a record under the conditions of multi-table insert <br /> DROP TABLE t_ia_src; <br /> CREATE TABLE t_ia_src AS SELECT &#39;a&#39; | | ROWNUM c1, &#39;b&#39; | | ROWNUM c2 FROM dual CONNECT BY ROWNUM &lt;= 5; <br /> DROP TABLE t_ia_dest_1; <br /> CREATE TABLE t_ia_dest_1 (flag VARCHAR2 (10), c VARCHAR2 (10)); <br /> DROP TABLE t_ia_dest_2; <br /> CREATE TABLE t_ia_dest_2 (flag VARCHAR2 (10), c VARCHAR2 (10)); <br /> DROP TABLE t_ia_dest_3; <br /> CREATE TABLE t_ia_dest_3 (flag VARCHAR2 (10), c VARCHAR2 (10)); <br /><br /> SELECT * FROM t_ia_src; <br /> SELECT * FROM t_ia_dest_1; <br /> SELECT * FROM t_ia_dest_2; <br /> SELECT * FROM t_ia_dest_3; <br /><br /> INSERT ALL <br /> WHEN (c1 IN ( &#39;a1&#39;, &#39;a3&#39;)) THEN <br /> INTO t_ia_dest_1 (flag, c) VALUES (flag1, c2) <br /> WHEN (c1 IN ( &#39;a2&#39;, &#39;a4&#39;)) THEN <br /> INTO t_ia_dest_2 (flag, c) VALUES (flag2, c2) <br /> ELSE <br /> INTO t_ia_dest_3 (flag, c) VALUES (flag1 | | flag2, c1 | | c2) <br /> SELECT c1, c2, &#39;f1&#39; flag1, &#39;f2&#39; flag2 FROM t_ia_src; <br /><br /> - If there is on the update, there is no insert with a statement on the implementation <br /> DROP TABLE t_mg; <br /> CREATE TABLE t_mg (code VARCHAR2 (10), NAME VARCHAR2 (10)); <br /><br /> SELECT * FROM t_mg; <br /><br /> MERGE INTO t_mg a <br /> USING (SELECT &#39;the code&#39; code, &#39;the name&#39; NAME FROM dual) b <br /> ON (a.code = b.code) <br /> WHEN MATCHED THEN <br /> UPDATE SET a.NAME = b.NAME <br /> WHEN NOT MATCHED THEN <br /> INSERT (code, NAME) VALUES (b.code, b.NAME); <br /><br /> - Extract / delete duplicate records <br /> DROP TABLE t_dup; <br /> CREATE TABLE t_dup AS SELECT &#39;code_&#39; | | ROWNUM code, dbms_random.string ( &#39;z&#39;, 5) NAME FROM dual CONNECT BY ROWNUM &lt;= 10; <br /> INSERT INTO t_dup SELECT &#39;code_&#39; | | ROWNUM code, dbms_random.string ( &#39;z&#39;, 5) NAME FROM dual CONNECT BY ROWNUM &lt;= 2; <br /><br /> SELECT * FROM t_dup; <br /><br /> SELECT * FROM t_dup a WHERE a.ROWID &lt;&gt; (SELECT MIN (b.ROWID) FROM t_dup b WHERE a.code = b.code); <br /><br /> SELECT b.code, b.NAME <br /> FROM (SELECT a.code, <br /> a.NAME, <br /> row_number () over (PARTITION BY a.code ORDER BY a.ROWID) rn <br /> FROM t_dup a) b</font><br /> WHERE b.rn&gt; 1; <br /><br /> - IN / EXISTS different from the application of environmental <br /> - T_orders.customer_id an index <br /> SELECT a. * <br /> FROM t_employees a <br /> WHERE a.employee_id IN <br /> (SELECT b.sales_rep_id FROM t_orders b WHERE b.customer_id = 12); <br /><br /> SELECT a. * <br /> FROM t_employees a <br /> WHERE EXISTS (SELECT 1 <br /> FROM t_orders b <br /> WHERE b.customer_id = 12 <br /> AND a.employee_id = b.sales_rep_id); <br /><br /> - T_employees.department_id an index <br /> SELECT a. * <br /> FROM t_employees a <br /> WHERE a.department_id = 10 <br /> AND EXISTS <br /> (SELECT 1 FROM t_orders b WHERE a.employee_id = b.sales_rep_id); <br /><br /> SELECT a. * <br /> FROM t_employees a <br /> WHERE a.department_id = 10 <br /> AND a.employee_id IN (SELECT b.sales_rep_id FROM t_orders b); <br /><br /> - FBI <br /> DROP TABLE t_fbi; <br /> CREATE TABLE t_fbi AS <br /> SELECT ROWNUM rn, dbms_random.STRING ( &#39;z&#39;, 10) NAME, SYSDATE + dbms_random.VALUE * 10 dt FROM dual <br /> CONNECT BY ROWNUM &lt;= 10; <br /><br /> CREATE INDEX idx_nonfbi ON t_fbi (dt); <br /><br /> DROP INDEX idx_fbi_1; <br /> CREATE INDEX idx_fbi_1 ON t_fbi (trunc (dt)); <br /><br /> SELECT * FROM t_fbi WHERE trunc (dt) = to_date (&#39;2006-09-21 &#39;,&#39; yyyy-mm-dd &#39;); <br /><br /> - Do not recommend the use of <br /> SELECT * FROM t_fbi WHERE to_char (dt, &#39;yyyy-mm-dd&#39;) = &#39;2006-09-21 &#39;; <br /><br /> - LOOP in the COMMIT / ROLLBACK <br /> DROP TABLE t_loop PURGE; <br /> create TABLE t_loop AS SELECT * FROM user_objects WHERE 1 = 2; <br /><br /> SELECT * FROM t_loop; <br /><br /> - Progressive author <br /> DECLARE <br /> BEGIN <br /> FOR cur IN (SELECT * FROM user_objects) LOOP <br /> INSERT INTO t_loop VALUES cur; <br /> COMMIT; <br /> END LOOP; <br /> END; <br /><br /> - Simulation of bulk submitted to http://blog.knowsky.com/ <br /> DECLARE <br /> v_count NUMBER; <br /> BEGIN <br /> FOR cur IN (SELECT * FROM user_objects) LOOP <br /> INSERT INTO t_loop VALUES cur; <br /> v_count: = v_count + 1; <br /> IF v_count&gt; = 100 THEN <br /> COMMIT; <br /> END IF; <br /> END LOOP; <br /> COMMIT; <br /> END; <br /><br /> - The real bulk submission <br /> DECLARE <br /> CURSOR cur IS <br /> SELECT * FROM user_objects; <br /> TYPE rec IS TABLE OF user_objects% ROWTYPE; <br /> recs rec; <br /> BEGIN <br /> OPEN cur; <br /> WHILE (TRUE) LOOP <br /> FETCH cur BULK COLLECT <br /> INTO recs LIMIT 100; <br /> - Forall to realize a fixed <br /> FORALL i IN 1 .. recs.COUNT <br /> INSERT INTO t_loop VALUES recs (i); <br /> COMMIT; <br /> EXIT WHEN cur% NOTFOUND; <br /> END LOOP; <br /> CLOSE cur; <br /> END; <br /><br /> - Pessimistic locking / optimistic locking <br /> DROP TABLE t_lock PURGE; <br /> CREATE TABLE t_lock AS SELECT 1 ID FROM dual; <br /><br /> SELECT * FROM t_lock; <br /><br /> - The realization of common logic, hidden bug <br /> DECLARE <br /> v_cnt NUMBER; <br /> BEGIN <br /> - There is a bug concurrency <br /> SELECT MAX (ID) INTO v_cnt FROM t_lock; <br /><br /> - Here for other operation <br /> v_cnt: = v_cnt + 1; <br /> INSERT INTO t_lock (ID) VALUES (v_cnt); <br /> COMMIT; <br /> END; <br /><br /> - High-concurrency environment, security, realization of the logic <br /> DECLARE <br /> v_cnt NUMBER; <br /> BEGIN <br /> - Obtained lock on the specified line <br /> SELECT ID INTO v_cnt FROM t_lock WHERE <br /> - In the case of a lock to continue the operation of the following <br /> SELECT MAX (ID) INTO v_cnt FROM t_lock; <br /><br /> - Here for other operation <br /> v_cnt: = v_cnt + 1; <br /> INSERT INTO t_lock (ID) VALUES (v_cnt); <br /> COMMIT; - submission and release the lock <br /> END; <br /><br /> - Hard parse / soft parse <br /> DROP TABLE t_hard PURGE; <br /> CREATE TABLE t_hard (ID INT); <br /><br /> SELECT * FROM t_hard; <br /><br /> DECLARE <br /> sql_1 VARCHAR2 (200); <br /> BEGIN <br /> - Hard parse <br /> - Java in the same statement is Statement.execute () <br /> FOR i IN 1 .. 1000 LOOP <br /> sql_1: = &#39;insert into t_hard (id) values (&#39; | | i | | &#39;)&#39;; <br /> EXECUTE IMMEDIATE sql_1; <br /> END LOOP; <br /> COMMIT; <br /><br /> - Soft parse <br /> - java in the same statement is PreparedStatement.execute () <br /> sql_1: = &#39;insert into t_hard (id) values (: id)&#39;; <br /> FOR i IN 1 .. 1000 LOOP <br /> EXECUTE IMMEDIATE sql_1 <br /> USING i; <br /> END LOOP; <br /> COMMIT; <br /> END; <br /><br /> - The correct paging algorithm <br /> SELECT * <br /> FROM (SELECT a. *, ROWNUM rn <br /> FROM (SELECT * FROM t_employees ORDER BY first_name) a <br /> WHERE ROWNUM &lt;= 500) <br /> WHERE rn&gt; 480; <br /><br /> - Paging algorithm (why not this one) <br /> SELECT a. *, ROWNUM rn <br /> FROM (SELECT * FROM t_employees ORDER BY first_name) a <br /> WHERE ROWNUM &lt;= 500 AND ROWNUM&gt; 480; <br /><br /> - Paging algorithm (why not this one) <br /> SELECT b. * <br /> FROM (SELECT a. *, ROWNUM rn <br /> FROM t_employees a <br /> WHERE ROWNUM &lt;= 500 <br /> ORDER BY first_name) b <br /> WHERE b.rn&gt; 480; <br /><br /> - OLAP <br /> - Subtotal Total <br /> SELECT CASE <br /> WHEN a.deptno IS NULL THEN <br /> &#39;Total&#39; <br /> WHEN a.deptno IS NOT NULL AND a.empno IS NULL THEN <br /> &#39;Subtotal&#39; <br /> ELSE <br /> &#39;&#39;| | A.deptno <br /> END deptno, <br /> a.empno, <br /> a.ename, <br /> SUM (a.sal) total_sal <br /> FROM scott.emp a <br /> GROUP BY GROUPING SETS ((a.deptno), (a.deptno, a.empno, a.ename ),()); <br /><br /> - Packet Sorting <br /> SELECT a.deptno, <br /> a.empno, <br /> a.ename, <br /> a.sal,<br /> - May be jumping rank <br /> rank () over (PARTITION BY a.deptno ORDER BY a.sal DESC) r1, <br /> - Intensive rank <br /> dense_rank () over (PARTITION BY a.deptno ORDER BY a.sal DESC) r2, <br /> - No group sorting <br /> rank () over (ORDER BY sal DESC) r3 <br /> FROM scott.emp a <br /> ORDER BY a.deptno, a.sal DESC; <br /><br /> - The current row of data and before / after n rows of data comparison <br /> SELECT a.empno, <br /> a.ename, <br /> a.sal, <br /> - Above the line <br /> lag (a.sal) over (ORDER BY a.sal DESC) lag_1, <br /> - The following three lines of <br /> lead (a.sal, 3) over (ORDER BY a.sal DESC) lead_3 <br /> FROM scott.emp a <br /> ORDER BY a.sal DESC; <br /><br /><br /> rn rn rn rn rn rn				<h5>Related Posts</h5>
		<div id="smilar">
		<ul>
					<li><a href="http://www.kods.netwww.kods.net/sga-extended-the-principle-of-32bit-oracle/" title="SGA extended the principle of 32bit oracle">SGA extended the principle of 32bit oracle</a> 2009-03-31 09:48:01</li>
					<li><a href="http://www.kods.netwww.kods.net/high-availability-oracle-flashback/" title="High Availability Oracle Flashback">High Availability Oracle Flashback</a> 2009-02-26 17:23:02</li>
					<li><a href="http://www.kods.netwww.kods.net/an-example-of-the-use-of-tkprof/" title="An example of the use of TKPROF">An example of the use of TKPROF</a> 2009-02-26 01:38:19</li>
					<li><a href="http://www.kods.netwww.kods.net/diagnosis-and-principles-of-order/" title="Diagnosis and principles of order">Diagnosis and principles of order</a> 2009-02-25 20:27:28</li>
					<li><a href="http://www.kods.netwww.kods.net/oracle-10g-dataguard-configuration-step-by-step/" title="ORACLE 10G dataguard configuration Step by Step">ORACLE 10G dataguard configuration Step by Step</a> 2009-02-16 01:13:55</li>
				</ul>
		</div>
		        ]]></content:encoded>
		<wfw:commentRss>http://www.kods.netwww.kods.net/oracle-sql-exquisite-sql-reprinted/</wfw:commentRss>
	</item>
		<item>
		<title>Oracle SQL exquisite SQL statement to explain</title>
		<link>http://www.kods.netwww.kods.net/oracle-sql-exquisite-sql-statement-to-explain/</link>
		<comments>http://www.kods.netwww.kods.net/oracle-sql-exquisite-sql-statement-to-explain/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 04:38:31+0000</pubDate>
		<dc:creator>kods.net</dc:creator>
		<category><![CDATA[Oracle SQL]]></category>
		<category><![CDATA[rownum]]></category>
<category><![CDATA[sql statement]]></category>
<category><![CDATA[lt]]></category>
<category><![CDATA[partition]]></category>
<category><![CDATA[oracle sql]]></category>
<category><![CDATA[amp]]></category>
<category><![CDATA[rn]]></category>
<category><![CDATA[merger]]></category>
<category><![CDATA[random value]]></category>
<category><![CDATA[code substr]]></category>
<category><![CDATA[favorites bar]]></category>
<category><![CDATA[column switch]]></category>
<category><![CDATA[code switch]]></category>
<category><![CDATA[t card]]></category>
<category><![CDATA[aq]]></category>
<category><![CDATA[q4]]></category>
<category><![CDATA[comma]]></category>
<category><![CDATA[q1]]></category>
<category><![CDATA[q3]]></category>
<category><![CDATA[q2]]></category>
		<guid isPermaLink="true">http://www.kods.netwww.kods.net/oracle-sql-exquisite-sql-statement-to-explain/</guid>
		<description><![CDATA[Good things, we hastened to Favorites Bar ~ ~ ~ - The ranks of conversion lines turn out DROP TABLE t_change_lc; CREATE TABLE t_change_lc (card_code VARCHAR2 (3), q NUMBER, bal NUMBER); INSERT INTO t_ ...]]></description>
		<content:encoded><![CDATA[Good things, we hastened to Favorites Bar ~ ~ ~ <br /><br /> - The ranks of conversion lines turn out <br /> DROP TABLE t_change_lc; <br /> CREATE TABLE t_change_lc (card_code VARCHAR2 (3), q NUMBER, bal NUMBER); <br /><br /> INSERT INTO t_change_lc <br /> SELECT &#39;001 &#39;card_code, ROWNUM q, trunc (dbms_random.VALUE * 100) bal FROM dual CONNECT BY ROWNUM &lt;= 4 <br /> UNION <br /> SELECT &#39;002 &#39;card_code, ROWNUM q, trunc (dbms_random.VALUE * 100) bal FROM dual CONNECT BY ROWNUM &lt;= 4; <br /><br /> SELECT * FROM t_change_lc; <br /><br /> SELECT a.card_code, <br /> SUM (decode (aq, 1, a.bal, 0)) q1, <br /> SUM (decode (aq, 2, a.bal, 0)) q2, <br /> SUM (decode (aq, 3, a.bal, 0)) q3, <br /> SUM (decode (aq, 4, a.bal, 0)) q4 <br /> FROM t_change_lc a <br /> GROUP BY a.card_code <br /> ORDER BY 1; <br /><br /> - Convert the ranks of the column switch <br /> DROP TABLE t_change_cl; <br /> CREATE TABLE t_change_cl AS <br /> SELECT a.card_code, <br /> SUM (decode (aq, 1, a.bal, 0)) q1, <br /> SUM (decode (aq, 2, a.bal, 0)) q2, <br /> SUM (decode (aq, 3, a.bal, 0)) q3, <br /> SUM (decode (aq, 4, a.bal, 0)) q4 <br /> FROM t_change_lc a <br /> GROUP BY a.card_code <br /> ORDER BY 1; <br /><br /> SELECT * FROM t_change_cl; <br /><br /> SELECT t.card_code, <br /> t.rn q, <br /> decode (t.rn, 1, t.q1, 2, t.q2, 3, t.q3, 4, t.q4) bal <br /> FROM (SELECT a. *, b.rn <br /> FROM t_change_cl a, <br /> (SELECT ROWNUM rn FROM dual CONNECT BY ROWNUM &lt;= 4) b) t <br /> ORDER BY 1, 2; <br /><br /> - Convert line to switch out the ranks of the merger <br /> DROP TABLE t_change_lc_comma; <br /> CREATE TABLE t_change_lc_comma AS SELECT card_code, &#39;quarter_&#39; | | q AS q FROM t_change_lc; <br /><br /> SELECT * FROM t_change_lc_comma; <br /><br /> SELECT t1.card_code, substr (MAX (sys_connect_by_path (t1.q,&#39;;&#39;)), 2) q <br /> FROM (SELECT a.card_code, <br /> aq, <br /> row_number () over (PARTITION BY a.card_code ORDER BY aq) rn <br /> FROM t_change_lc_comma a) t1 <br /> START WITH t1.rn = 1 <br /> CONNECT BY t1.card_code = PRIOR t1.card_code <br /> AND t1.rn - 1 = PRIOR t1.rn <br /> GROUP BY t1.card_code; <br /><br /> - Switch to split the ranks of Conversion Columns <br /> DROP TABLE t_change_cl_comma; <br /> CREATE TABLE t_change_cl_comma AS <br /> SELECT t1.card_code, substr (MAX (sys_connect_by_path (t1.q,&#39;;&#39;)), 2) q <br /> FROM (SELECT a.card_code, <br /> aq, <br /> row_number () over (PARTITION BY a.card_code ORDER BY aq) rn <br /> FROM t_change_lc_comma a) t1 <br /> START WITH t1.rn = 1 <br /> CONNECT BY t1.card_code = PRIOR t1.card_code <br /> AND t1.rn - 1 = PRIOR t1.rn <br /> GROUP BY t1.card_code; <br /><br /> SELECT * FROM t_change_cl_comma; <br /><br /> SELECT t.card_code, <br /> substr (tq, <br /> instr ( &#39;;&#39; | | tq, &#39;;&#39;, 1, rn), <br /> instr (tq | | &#39;;&#39;, &#39;;&#39;, 1, rn) - instr ( &#39;;&#39; | | tq, &#39;;&#39;, 1, rn)) q <br /> FROM (SELECT a.card_code, aq, b.rn <br /> FROM t_change_cl_comma a, <br /> (SELECT ROWNUM rn FROM dual CONNECT BY ROWNUM &lt;= 100) b <br /> WHERE instr ( &#39;;&#39; | | aq, &#39;;&#39;, 1, rn)&gt; 0) t <br /> ORDER BY 1, 2; <br /><br /> - To achieve a record under the conditions of multi-table insert <br /> DROP TABLE t_ia_src; <br /> CREATE TABLE t_ia_src AS SELECT &#39;a&#39; | | ROWNUM c1, &#39;b&#39; | | ROWNUM c2 FROM dual CONNECT BY ROWNUM &lt;= 5; <br /> DROP TABLE t_ia_dest_1; <br /> CREATE TABLE t_ia_dest_1 (flag VARCHAR2 (10), c VARCHAR2 (10)); <br /> DROP TABLE t_ia_dest_2; <br /> CREATE TABLE t_ia_dest_2 (flag VARCHAR2 (10), c VARCHAR2 (10)); <br /> DROP TABLE t_ia_dest_3; <br /> CREATE TABLE t_ia_dest_3 (flag VARCHAR2 (10), c VARCHAR2 (10)); <br /><br /> SELECT * FROM t_ia_src; <br /> SELECT * FROM t_ia_dest_1; <br /> SELECT * FROM t_ia_dest_2; <br /> SELECT * FROM t_ia_dest_3; <br /><br /> INSERT ALL <br /> WHEN (c1 IN ( &#39;a1&#39;, &#39;a3&#39;)) THEN <br /> INTO t_ia_dest_1 (flag, c) VALUES (flag1, c2) <br /> WHEN (c1 IN ( &#39;a2&#39;, &#39;a4&#39;)) THEN <br /> INTO t_ia_dest_2 (flag, c) VALUES (flag2, c2) <br /> ELSE <br /> INTO t_ia_dest_3 (flag, c) VALUES (flag1 | | flag2, c1 | | c2) <br /> SELECT c1, c2, &#39;f1&#39; flag1, &#39;f2&#39; flag2 FROM t_ia_src; <br /><br /> - If there is on the update, there is no insert with a statement on the implementation <br /> DROP TABLE t_mg; <br /> CREATE TABLE t_mg (code VARCHAR2 (10), NAME VARCHAR2 (10)); <br /><br /> SELECT * FROM t_mg; <br /><br /> MERGE INTO t_mg a <br /> USING (SELECT &#39;the code&#39; code, &#39;the name&#39; NAME FROM dual) b <br /> ON (a.code = b.code) <br /> WHEN MATCHED THEN <br /> UPDATE SET a.NAME = b.NAME <br /> WHEN NOT MATCHED THEN <br /> INSERT (code, NAME) VALUES (b.code, b.NAME); <br /><br /> - Extract / delete duplicate records <br /> DROP TABLE t_dup; <br /> CREATE TABLE t_dup AS SELECT &#39;code_&#39; | | ROWNUM code, dbms_random.string ( &#39;z&#39;, 5) NAME FROM dual CONNECT BY ROWNUM &lt;= 10; <br /> INSERT INTO t_dup SELECT &#39;code_&#39; | | ROWNUM code, dbms_random.string ( &#39;z&#39;, 5) NAME FROM dual CONNECT BY ROWNUM &lt;= 2; <br /><br /> SELECT * FROM t_dup; <br /><br /> SELECT * FROM t_dup a WHERE a.ROWID &lt;&gt; (SELECT MIN (b.ROWID) FROM t_dup b WHERE a.code = b.code); <br /><br /> SELECT b.code, b.NAME <br /> FROM (SELECT a.code, <br /> a.NAME,<br /> row_number () over (PARTITION BY a.code ORDER BY a.ROWID) rn <br /> FROM t_dup a) b <br /> WHERE b.rn&gt; 1; <br /><br /> - IN / EXISTS different from the application of environmental <br /> - T_orders.customer_id an index <br /> SELECT a. * <br /> FROM t_employees a <br /> WHERE a.employee_id IN <br /> (SELECT b.sales_rep_id FROM t_orders b WHERE b.customer_id = 12); <br /><br /> SELECT a. * <br /> FROM t_employees a <br /> WHERE EXISTS (SELECT 1 <br /> FROM t_orders b <br /> WHERE b.customer_id = 12 <br /> AND a.employee_id = b.sales_rep_id); <br /><br /> - T_employees.department_id an index <br /> SELECT a. * <br /> FROM t_employees a <br /> WHERE a.department_id = 10 <br /> AND EXISTS <br /> (SELECT 1 FROM t_orders b WHERE a.employee_id = b.sales_rep_id); <br /><br /> SELECT a. * <br /> FROM t_employees a <br /> WHERE a.department_id = 10 <br /> AND a.employee_id IN (SELECT b.sales_rep_id FROM t_orders b); <br /><br /> - FBI <br /> DROP TABLE t_fbi; <br /> CREATE TABLE t_fbi AS <br /> SELECT ROWNUM rn, dbms_random.STRING ( &#39;z&#39;, 10) NAME, SYSDATE + dbms_random.VALUE * 10 dt FROM dual <br /> CONNECT BY ROWNUM &lt;= 10; <br /><br /> CREATE INDEX idx_nonfbi ON t_fbi (dt); <br /><br /> DROP INDEX idx_fbi_1; <br /> CREATE INDEX idx_fbi_1 ON t_fbi (trunc (dt)); <br /><br /> SELECT * FROM t_fbi WHERE trunc (dt) = to_date (&#39;2006-09-21 &#39;,&#39; yyyy-mm-dd &#39;); <br /><br /> - Do not recommend the use of <br /> SELECT * FROM t_fbi WHERE to_char (dt, &#39;yyyy-mm-dd&#39;) = &#39;2006-09-21 &#39;; <br /><br /> - LOOP in the COMMIT / ROLLBACK <br /> DROP TABLE t_loop PURGE; <br /> create TABLE t_loop AS SELECT * FROM user_objects WHERE 1 = 2; <br /><br /> SELECT * FROM t_loop; <br /><br /> - Progressive author <br /> DECLARE <br /> BEGIN <br /> FOR cur IN (SELECT * FROM user_objects) LOOP <br /> INSERT INTO t_loop VALUES cur; <br /> COMMIT; <br /> END LOOP; <br /> END; <br /><br /> - Simulation of bulk submitted to <br /> DECLARE <br /> v_count NUMBER; <br /> BEGIN <br /> FOR cur IN (SELECT * FROM user_objects) LOOP <br /> INSERT INTO t_loop VALUES cur; <br /> v_count: = v_count + 1; <br /> IF v_count&gt; = 100 THEN <br /> COMMIT; <br /> END IF; <br /> END LOOP; <br /> COMMIT; <br /> END; <br /><br /> - The real bulk submission <br /> DECLARE <br /> CURSOR cur IS <br /> SELECT * FROM user_objects; <br /> TYPE rec IS TABLE OF user_objects% ROWTYPE; <br /> recs rec; <br /> BEGIN <br /> OPEN cur; <br /> WHILE (TRUE) LOOP <br /> FETCH cur BULK COLLECT <br /> INTO recs LIMIT 100; <br /> - Forall to realize a fixed <br /> FORALL i IN 1 .. recs.COUNT <br /> INSERT INTO t_loop VALUES recs (i); <br /> COMMIT; <br /> EXIT WHEN cur% NOTFOUND; <br /> END LOOP; <br /> CLOSE cur; <br /> END; <br /><br /> - Pessimistic locking / optimistic locking <br /> DROP TABLE t_lock PURGE; <br /> CREATE TABLE t_lock AS SELECT 1 ID FROM dual; <br /><br /> SELECT * FROM t_lock; <br /><br /> - The realization of common logic, hidden bug <br /> DECLARE <br /> v_cnt NUMBER; <br /> BEGIN <br /> - There is a bug concurrency <br /> SELECT MAX (ID) INTO v_cnt FROM t_lock; <br /><br /> - Here for other operation <br /> v_cnt: = v_cnt + 1; <br /> INSERT INTO t_lock (ID) VALUES (v_cnt); <br /> COMMIT; <br /> END; <br /><br /> - High-concurrency environment, security, realization of the logic <br /> DECLARE <br /> v_cnt NUMBER; <br /> BEGIN <br /> - Obtained lock on the specified line <br /> SELECT ID INTO v_cnt FROM t_lock WHERE <br /> - In the case of a lock to continue the operation of the following <br /> SELECT MAX (ID) INTO v_cnt FROM t_lock; <br /><br /> - Here for other operation <br /> v_cnt: = v_cnt + 1; <br /> INSERT INTO t_lock (ID) VALUES (v_cnt); <br /> COMMIT; - submission and release the lock <br /> END; <br /><br /> - Hard parse / soft parse <br /> DROP TABLE t_hard PURGE; <br /> CREATE TABLE t_hard (ID INT); <br /><br /> SELECT * FROM t_hard; <br /><br /> DECLARE <br /> sql_1 VARCHAR2 (200); <br /> BEGIN <br /> - Hard parse <br /> - <font color=#0000ff><strong><u>Java</u></strong></font> in the same statement is Statement.execute () <br /> FOR i IN 1 .. 1000 LOOP <br /> sql_1: = &#39;insert into t_hard (id) values (&#39; | | i | | &#39;)&#39;; <br /> EXECUTE IMMEDIATE sql_1; <br /> END LOOP; <br /> COMMIT; <br /><br /> - Soft parse <br /> - java in the same statement is PreparedStatement.execute () <br /> sql_1: = &#39;insert into t_hard (id) values (: id)&#39;; <br /> FOR i IN 1 .. 1000 LOOP <br /> EXECUTE IMMEDIATE sql_1 <br /> USING i; <br /> END LOOP; <br /> COMMIT; <br /> END; <br /><br /> - The correct paging algorithm <br /> SELECT * <br /> FROM (SELECT a. *, ROWNUM rn <br /> FROM (SELECT * FROM t_employees ORDER BY first_name) a <br /> WHERE ROWNUM &lt;= 500) <br /> WHERE rn&gt; 480; <br /><br /> - Paging algorithm (why not this one) <br /> SELECT a. *, ROWNUM rn <br /> FROM (SELECT * FROM t_employees ORDER BY first_name) a <br /> WHERE ROWNUM &lt;= 500 AND ROWNUM&gt; 480; <br /><br /> - Paging algorithm (why not this one) <br /> SELECT b. * <br /> FROM (SELECT a. *, ROWNUM rn <br /> FROM t_employees a <br /> WHERE ROWNUM &lt;= 500 <br /> ORDER BY first_name) b <br /> WHERE b.rn&gt; 480; <br /><br /> - OLAP <br /> - Subtotal Total <br /> SELECT CASE<br /> WHEN a.deptno IS NULL THEN <br /> &#39;Total&#39; <br /> WHEN a.deptno IS NOT NULL AND a.empno IS NULL THEN <br /> &#39;Subtotal&#39; <br /> ELSE <br /> &#39;&#39;| | A.deptno <br /> END deptno, <br /> a.empno, <br /> a.ename, <br /> SUM (a.sal) total_sal <br /> FROM scott.emp a <br /> GROUP BY GROUPING SETS ((a.deptno), (a.deptno, a.empno, a.ename ),()); <br /><br /> - Packet Sorting <br /> SELECT a.deptno, <br /> a.empno, <br /> a.ename, <br /> a.sal, <br /> - May be jumping rank <br /> rank () over (PARTITION BY a.deptno ORDER BY a.sal DESC) r1, <br /> - Intensive rank <br /> dense_rank () over (PARTITION BY a.deptno ORDER BY a.sal DESC) r2, <br /> - No group sorting <br /> rank () over (ORDER BY sal DESC) r3 <br /> FROM scott.emp a <br /> ORDER BY a.deptno, a.sal DESC; <br /><br /> - The current row of data and before / after n rows of data comparison <br /> SELECT a.empno, <br /> a.ename, <br /> a.sal, <br /> - Above the line <br /> lag (a.sal) over (ORDER BY a.sal DESC) lag_1, <br /> - The following three lines of <br /> lead (a.sal, 3) over (ORDER BY a.sal DESC) lead_3 <br /> FROM scott.emp a <br /> ORDER BY a.sal DESC;				<h5>Related Posts</h5>
		<div id="smilar">
		<ul>
					<li><a href="http://www.kods.netwww.kods.net/rman-created-physical-standby/" title="RMAN created physical standby">RMAN created physical standby</a> 2009-03-30 22:49:29</li>
					<li><a href="http://www.kods.netwww.kods.net/proc-will-select-the-data-on-the-two-dimensional-array/" title="ProC will select the data on the two-dimensional array">ProC will select the data on the two-dimensional array</a> 2009-03-30 11:50:27</li>
					<li><a href="http://www.kods.netwww.kods.net/sql-optimization-1-full-table-scan-and-index-the-test/" title="SQL optimization (1) - full table scan and index the test">SQL optimization (1) - full table scan and index the test</a> 2009-03-28 09:02:39</li>
					<li><a href="http://www.kods.netwww.kods.net/oracle-locking-mechanism-reprint/" title="Oracle locking mechanism (reprint)">Oracle locking mechanism (reprint)</a> 2009-03-28 05:20:43</li>
				</ul>
		</div>
		        ]]></content:encoded>
		<wfw:commentRss>http://www.kods.netwww.kods.net/oracle-sql-exquisite-sql-statement-to-explain/</wfw:commentRss>
	</item>
		<item>
		<title>Oracle SQL Loader Data Import</title>
		<link>http://www.kods.netwww.kods.net/oracle-sql-loader-data-import/</link>
		<comments>http://www.kods.netwww.kods.net/oracle-sql-loader-data-import/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 05:55:02+0000</pubDate>
		<dc:creator>kods.net</dc:creator>
		<category><![CDATA[Oracle SQL]]></category>
		<category><![CDATA[oracle]]></category>
<category><![CDATA[oracle database]]></category>
<category><![CDATA[indexes]]></category>
<category><![CDATA[oracle data]]></category>
<category><![CDATA[array]]></category>
<category><![CDATA[database sql]]></category>
<category><![CDATA[stream buffer]]></category>
<category><![CDATA[oracle sql]]></category>
<category><![CDATA[data warehouse]]></category>
<category><![CDATA[bind]]></category>
<category><![CDATA[sqlldr]]></category>
<category><![CDATA[logical records]]></category>
<category><![CDATA[valid keywords]]></category>
<category><![CDATA[parallel load]]></category>
<category><![CDATA[index maintenance]]></category>
<category><![CDATA[loading tools]]></category>
<category><![CDATA[path data]]></category>
<category><![CDATA[data loading]]></category>
<category><![CDATA[parameter specifications]]></category>
<category><![CDATA[discards]]></category>
		<guid isPermaLink="true">http://www.kods.netwww.kods.net/oracle-sql-loader-data-import/</guid>
		<description><![CDATA[rn 1, SQL LOADER is the ORACLE data loading tools normally used to operating system files to migrate to ORACLE database. SQL * LOADER is the option of using a large data warehouse loading, because it  ...]]></description>
		<content:encoded><![CDATA[rn <br /> 1, SQL LOADER is the ORACLE data loading tools normally used to operating system files to migrate to ORACLE database. SQL * LOADER is the option of using a large data warehouse loading, because it provides the fastest route (DIRECT, PARALLEL). <br /><br /> rn <br /><br /> rn <br /> It uses the command as follows: In the NT,, SQL LOADER command for SQLLDR, under the UNIX, compared with sqlldr / sqlload. <br /><br /> rn <br /><br /> rn <br /> 2, the general usage <br /><br /> rn <pre>sqlldr scott/tiger control=control_file.ctl log=logFile.log direct=true</pre> rn <br /><br /> rn <br /><br /> rn <br /> Other parameters in the type sqlldr command appears: <br /><br /> rn <br /> Usage: SQLLDR keyword = value [, keyword = value ,...] <br /><br /> rn <br /> Valid keywords: <br /><br /> rn <br /> userid - ORACLE username / password <br /> control - Control file name <br /> log - Log file name <br /> bad - Bad file name <br /> data - Data file name <br /> discard - Discard file name <br /> discardmax - Number of discards to allow (all default) <br /> skip - Number of logical records to skip (Default 0) <br /> load - Number of logical records to load (all default) <br /> errors - Number of errors to allow (Default 50) <br /> rows - Number of rows in conventional path bind array or between direct path data saves (Default: Conventional path 64, all direct paths) <br /> bindsize - Size of conventional path bind array in bytes (default 256,000) <br /> silent - Suppress messages during run (header, feedback, errors, discards, partitions) <br /> direct - use direct path (Default FALSE) <br /> parfile - parameter file: name of file that contains parameter specifications <br /> parallel - do parallel load (Default FALSE) <br /> file - File to allocate extents from <br /> skip_unusable_indexes - disallow / allow unusable indexes or index partitions (Default FALSE) <br /> skip_index_maintenance - do not maintain indexes, mark affected indexes as unusable (Default FALSE) <br /> readsize - Size of Read buffer (Default 1048576) <br /> external_table - use external table for load; NOT_USED, GENERATE_ONLY, EXECUTE (Default NOT_USED) <br /> columnarrayrows - Number of rows for direct path column array (default 5000) <br /> streamsize - Size of direct path stream buffer in bytes (default 256,000) <br /> multithreading - use multithreading in direct path <br /> resumable - enable or disable resumable for current session (Default FALSE) <br /> resumable_name - text string to help identify resumable statement <br /> resumable_timeout - wait time (in seconds) for RESUMABLE (default 7200) <br /> date_cache - size (in entries) of date conversion cache (Default 1000) <br /><br /> rn <br /> PLEASE NOTE: command-line parameters can be specified by a location or keyword. Examples of the former &#39;sqlload scott / tiger foo&#39;; an example of the latter situation is&#39; sqlldr control = foo <br /> userid = scott / tiger &#39;. location of the specified parameters of time must be earlier but not later than the parameters specified by the keyword. For example, the <br /> Allow &#39;sqlldr scott / tiger control = foo logfile = log&#39;, but is not allowed &#39;sqlldr scott / tiger control = foo log&#39;, even if the parameter &#39;log&#39; of the correct location. <br /><br /> rn <br /><br /> rn <br /> 3, control document to develop <br /><br /> rn <br /> LOAD DATA <br /> INFILE &#39;input_File.csv&#39; <br /> INTO TABLE tableName <br /> FIELDS TERMINATED BY &quot;,&quot; <br /><br /> rn <br /> (field1, field2, field3, field4) <br /><br /> rn <br /><br /> rn <br /><br /> rn <br /> Explained: <br /><br /> rn <br /> infile refers to the data source file where we omitted the default discardfile result.dsc badfile result.bad <br /> into table tableName default is INSERT, you can APPEND into table tableName as an additional way, or REPLACE <br /><br /> rn <br /> Note: <br /><br /> rn <br /> 1, insert, as the default way of loading the beginning of the data requirements table is empty <br /> 2, append, append a new record in the table <br /> 3, replace, delete the old records, replace the load into a new record <br /> 4, truncate, ibid <br /><br /> rn <br /> terminated by &#39;,&#39; refers to a comma-separated <br /> terminated by whitespace at the end separated by a space <br /><br /> rn <br /> fields terminated by X&#39;09 &#39;fields terminated at X&#39;09&#39;, is a tab (TAB) <br /><br /> rn <br /> tableName: Data Sheet <br /><br /> rn <br /> (field1, field2, field3, field4): Data Sheet Import Fields <br /><br /> rn <br /><br /> rn <br /> Note: When infile *, the import data in the control file ..... <br /><br /> rn <br /> Such as: <br /><br /> rn <br /><br /> rn <br /><br /> rn <br /> LOAD DATA <br /> INFILE * <br /> APPEND INTO TABLE tableName <br /> FIELDS TERMINATED BY &quot;,&quot; Optionally enclosed by &#39; &quot;&#39; <br /> (field1, field2, field3, field4) <br /><br /> rn <br /><br /> rn <br /> BEGINDATA <br /><br /> rn <br /><br /> rn <br /> field1_data, field2_data, field3_data, field4_data <br /><br /> rn <br /> field1_data, field2_data, field3_data, field4_data <br /><br /> rn <br /> field1_data, field2_data, field3_data, field4_data <br /><br /> rn <br /><br /> rn <br /><br /> rn<br /> Note: &quot;*&quot; represents the data file with this file the same name, that is behind the use of BEGINDATA segment to identify the data <br /><br /> rn <br /><br /> rn <br /> 4, concurrent operation <br /><br /> rn <br /><br /> rn <pre>sqlldr scott/tiger control=control_file.ctl log=logFile.log direct=true parallel=true </pre> rn <br /><br /> rn <br /><br /> rn <br /> 5, derived rules of data <br /><br /> rn <br /><br /> rn <pre>Oracle 没有提供将数据导出到一个文件的工具。但是，我们可以用SQL*Plus的select 及 format 数据来输出到一个文件</pre> rn <pre>    set echo off newpage 0 space 0 pagesize 0 feed off head off trimspool on<br />　　spool oradata.txt<br />　　select col1 || ',' || col2 || ',' || col3<br />　　from tab1<br />　　where col2 = 'XYZ';<br />　　spool off<br /></pre> rn <br /><br /> rn <br /><br /> rn <br /> In addition, you can use use the UTL_FILE PL / SQL packet processing: <br /> rem Remember to update initSID.ora, utl_file_dir = &#39;c: \ oradata&#39; parameter <br /> declare <br /> fp utl_file.file_type; <br /> begin <br /> fp: = utl_file.fopen ( &#39;c: \ oradata&#39;, &#39;tab1.txt&#39;, &#39;w&#39;); <br /> utl_file.putf (fp, &#39;% s,% s \ n&#39;, &#39;TextField&#39;, 55); <br /> utl_file.fclose (fp); <br /> end; <br /><br /> rn <br /><br /> rn <br /> Of course, you can also use third-party tools, such as SQLWays, TOAD for Quest and so on. <br /> Load variable length or a specified length of records such as: <br /> LOAD DATA <br /> INFILE * <br /> INTO TABLE load_delimited_data <br /> FIELDS TERMINATED BY &quot;,&quot; OPTIONALLY ENCLOSED BY &#39; &quot;&#39; <br /> TRAILING NULLCOLS <br /> (Data1, <br /> data2 <br /> ) <br /> BEGINDATA <br /> 11111, AAAAAAAAAA <br /> 22222, &quot;A, B, C, D,&quot; <br /> The following is to import a fixed position (fixed length) data Example: <br /> LOAD DATA <br /> INFILE * <br /> INTO TABLE load_positional_data <br /> (Data1 POSITION (1:5), <br /> data2 POSITION (6:15) <br /> ) <br /> BEGINDATA <br /> 11111AAAAAAAAAA <br /> 22222BBBBBBBBBB <br /> Skip data rows: <br /> Can be &quot;SKIP n&quot; keyword to specify the number of rows to import the data can be skipped. Such as: <br /> LOAD DATA <br /> INFILE * <br /> INTO TABLE load_positional_data <br /> SKIP 5 <br /> (Data1 POSITION (1:5), <br /> data2 POSITION (6:15) <br /> ) <br /> BEGINDATA <br /> 11111AAAAAAAAAA <br /> 22222BBBBBBBBBB <br /> Importing data to modify data: <br /> When you import the data into the database, you can modify the data. Note that this is only suitable for regular import, is not suitable for direct import method. <br /><br /> rn <br /> rn rn rn				<h5>Related Posts</h5>
		<div id="smilar">
		<ul>
					<li><a href="http://www.kods.netwww.kods.net/sga-extended-the-principle-of-32bit-oracle/" title="SGA extended the principle of 32bit oracle">SGA extended the principle of 32bit oracle</a> 2009-03-31 09:48:01</li>
					<li><a href="http://www.kods.netwww.kods.net/an-example-of-the-use-of-tkprof/" title="An example of the use of TKPROF">An example of the use of TKPROF</a> 2009-02-26 01:38:19</li>
					<li><a href="http://www.kods.netwww.kods.net/diagnosis-and-principles-of-order/" title="Diagnosis and principles of order">Diagnosis and principles of order</a> 2009-02-25 20:27:28</li>
					<li><a href="http://www.kods.netwww.kods.net/oracle-10g-dataguard-configuration-step-by-step/" title="ORACLE 10G dataguard configuration Step by Step">ORACLE 10G dataguard configuration Step by Step</a> 2009-02-16 01:13:55</li>
				</ul>
		</div>
		        ]]></content:encoded>
		<wfw:commentRss>http://www.kods.netwww.kods.net/oracle-sql-loader-data-import/</wfw:commentRss>
	</item>
		<item>
		<title>oracle sql date comparison</title>
		<link>http://www.kods.netwww.kods.net/oracle-sql-date-comparison/</link>
		<comments>http://www.kods.netwww.kods.net/oracle-sql-date-comparison/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 12:15:02+0000</pubDate>
		<dc:creator>kods.net</dc:creator>
		<category><![CDATA[Oracle SQL]]></category>
		<category><![CDATA[oracle]]></category>
<category><![CDATA[lt]]></category>
<category><![CDATA[yyyy]]></category>
<category><![CDATA[dd]]></category>
<category><![CDATA[ss]]></category>
<category><![CDATA[oracle sql]]></category>
<category><![CDATA[sql date]]></category>
		<guid isPermaLink="true">http://www.kods.netwww.kods.net/oracle-sql-date-comparison/</guid>
		<description><![CDATA[oracle sql date comparison]]></description>
		<content:encoded><![CDATA[<PRE>oracle sql日期比较:<BR>在今天之前:<br /><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->select * from up_date where update &lt; to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')<BR>select * from up_date where update &lt;= to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')<br /><BR>在今天只后:<br /><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->select * from up_date where update &gt; to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')<BR>select * from up_date where update &gt;= to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')<br /><BR>精确时间:<br /><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->select * from up_date where update = to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')<br /><BR>在某段时间内:<br /><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->select * from up_date where update between to_date('2007-07-07 00:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')<BR>select * from up_date where update &lt; to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss') and update &gt; to_date('2007-07-07 00:00:00','yyyy-mm-dd hh24:mi:ss')<BR>select * from up_date where update &lt;= to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss') and update &gt;= to_date('2007-07-07 00:00:00','yyyy-mm-dd hh24:mi:ss')<br /></PRE>				<h5>Related Posts</h5>
		<div id="smilar">
		<ul>
					<li><a href="http://www.kods.netwww.kods.net/sga-extended-the-principle-of-32bit-oracle/" title="SGA extended the principle of 32bit oracle">SGA extended the principle of 32bit oracle</a> 2009-03-31 09:48:01</li>
					<li><a href="http://www.kods.netwww.kods.net/high-availability-oracle-flashback/" title="High Availability Oracle Flashback">High Availability Oracle Flashback</a> 2009-02-26 17:23:02</li>
					<li><a href="http://www.kods.netwww.kods.net/an-example-of-the-use-of-tkprof/" title="An example of the use of TKPROF">An example of the use of TKPROF</a> 2009-02-26 01:38:19</li>
					<li><a href="http://www.kods.netwww.kods.net/diagnosis-and-principles-of-order/" title="Diagnosis and principles of order">Diagnosis and principles of order</a> 2009-02-25 20:27:28</li>
					<li><a href="http://www.kods.netwww.kods.net/oracle-10g-dataguard-configuration-step-by-step/" title="ORACLE 10G dataguard configuration Step by Step">ORACLE 10G dataguard configuration Step by Step</a> 2009-02-16 01:13:55</li>
				</ul>
		</div>
		        ]]></content:encoded>
		<wfw:commentRss>http://www.kods.netwww.kods.net/oracle-sql-date-comparison/</wfw:commentRss>
	</item>
		<item>
		<title>Encyclopedia of common command oracle sqlplus</title>
		<link>http://www.kods.netwww.kods.net/encyclopedia-of-common-command-oracle-sqlplus/</link>
		<comments>http://www.kods.netwww.kods.net/encyclopedia-of-common-command-oracle-sqlplus/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 14:17:23+0000</pubDate>
		<dc:creator>kods.net</dc:creator>
		<category><![CDATA[Oracle SQL]]></category>
		<category><![CDATA[quot]]></category>
<category><![CDATA[data dictionary]]></category>
<category><![CDATA[null value]]></category>
<category><![CDATA[sql statements]]></category>
<category><![CDATA[database user]]></category>
<category><![CDATA[desc]]></category>
<category><![CDATA[error error]]></category>
<category><![CDATA[oracle sqlplus]]></category>
<category><![CDATA[prohibition]]></category>
<category><![CDATA[amp]]></category>
<category><![CDATA[system variables]]></category>
<category><![CDATA[value defaults]]></category>
<category><![CDATA[connection users]]></category>
<category><![CDATA[suspension settings]]></category>
<category><![CDATA[autocommit]]></category>
<category><![CDATA[execution time]]></category>
<category><![CDATA[current connection]]></category>
<category><![CDATA[query time]]></category>
<category><![CDATA[column header]]></category>
<category><![CDATA[time consuming]]></category>
		<guid isPermaLink="true">http://www.kods.netwww.kods.net/encyclopedia-of-common-command-oracle-sqlplus/</guid>
		<description><![CDATA[show and the set command is used for the maintenance of the two SQL * Plus system variables in order SQL&gt; show all - View all 68 values of system variables SQL&gt; show user - shows the current con ...]]></description>
		<content:encoded><![CDATA[show and the set command is used for the maintenance of the two SQL * Plus system variables in order <br /> SQL&gt; show all - View all 68 values of system variables <br /> SQL&gt; show user - shows the current connection users <br /> SQL&gt; show error - error <br /> SQL&gt; set heading off - to prohibit the output column header, default is ON <br /> SQL&gt; set feedback off - the prohibition of the count showed that the last line of feedback, the default value of &quot;six or more of the records, loopback ON&quot; <br /> SQL&gt; set timing on - default is OFF, set the query time-consuming, can be used to estimate the execution time of SQL statements to test the performance <br /> SQL&gt; set sqlprompt &quot;SQL&gt;&quot; - set the default prompt, default value is &quot;SQL&gt;&quot; <br /> SQL&gt; set linesize 1000 - set the screen display line width, default 100 <br /> SQL&gt; set autocommit ON - settings are automatically submitted, it will default to OFF <br /> SQL&gt; set pause on - default is OFF, the suspension settings, the screen will show the stop and wait for pressing the ENTER key, and then show the next page <br /> SQL&gt; set arraysize 1 - default is 15 <br /> SQL&gt; set long 1000 - the default is 80 <br /> Description: <br /> long value defaults to 80, 1000 is set to show more content, because many data dictionary views used in a long data type, such as: <br /> SQL&gt; desc user_views <br /> Names can be any type of null value <br /> ------------------------------- -------- ---- <br /> VIEW_NAME NOT NULL VARCHAR2 (30) <br /> TEXT_LENGTH NUMBER <br /> TEXT LONG <br /> SQL&gt; define a =&#39;&#39;&#39;20000101 12:01:01&#39;&#39; &#39;- the definition of local variables, if you want to use a similar display in a variety of return included in the kind of constant, <br /> - Can be used to define the command set <br /> SQL&gt; select &amp; a from dual; <br /> Original value of 1: select &amp; a from dual <br /> New value 1: select&#39;20000101 12:01:01 &#39;from dual <br /> &#39;2000010112: 01:01 <br /> ----------------- <br /> 20000101 12:01:01 <br /> Issues: <br /> 1, users need the database user under the table each have the same implementation of a SQL operation, then, again, again, type the SQL statement is a very cumbersome method: <br /> SQL&gt; set heading off - to prohibit the output column headings <br /> SQL&gt; set feedback off - the prohibition of the count showed that the last line of the current user feedback information listed under the definition of all the synonyms can be used to test the actual existence of synonyms <br /> select &#39;desc&#39; | | tname from tab where tabtype = &#39;SYNONYM&#39;; <br /> Under the current user query the number of records in all tables <br /> select &#39;select&#39;&#39;&#39;|| tname ||&#39;&#39;&#39;, count (*) from&#39; | | tname ||&#39;;&#39; from tab where tabtype = &#39;TABLE&#39;; <br /> To all eligible grant select the table for the public <br /> select &#39;grant select on&#39; | | table_name | | &#39;to public;&#39; from user_tables where &quot;conditions&quot;; <br /> Under a variety of objects to delete user <br /> select &#39;drop&#39; | | tabtype | | &#39;&#39; | | tname from tab; <br /> Eligible users to delete <br /> select &#39;drop user&#39; | | username | | &#39;cascade;&#39; from all_users where user_id&gt; 25; <br /> Quickly compile all views <br /> ---- When the database into the new server after the (database reconstruction), the need to recompile the view again, <br /> ---- View of the tablespace to other tablespace of the table will have problems connecting, you can use PL / SQL language features, fast compiler. <br /> SQL&gt; SPOOL ON.SQL <br /> SQL&gt; SELECT&#39;ALTER VIEW &#39;| | TNAME | |&#39; COMPILE; &#39;FROM TAB; <br /> SQL&gt; SPOOL OFF <br /> ON.SQL can then implement. <br /> SQL&gt; @ ON.SQL <br /> Of course, the mandate and the creation of synonyms can be quickly, such as: <br /> SQL&gt; SELECT &#39;GRANT SELECT ON&#39; | | TNAME | | &#39;TO username;&#39; FROM TAB; <br /> SQL&gt; SELECT &#39;CREATE SYNONYM&#39; | | TNAME | | &#39;FOR user name.&#39; | | TNAME ||&#39;;&#39; FROM TAB; <br /> Command list: <br /> The assumption that the current implementation of an order for: select * from tab; <br /> (a) ppend add text to the current end-of-line buffer a order by tname results: select * from tab order by tname; <br /> (Note: a followed by two spaces) <br /> (c) hange / old / new line in the current text with new text to replace the old c / * / tname results: select tname from tab; <br /> (c) hange / text to delete text from the current line c / tab results: select tname from; <br /> del to delete the current row <br /> del n delete the first n lines <br /> (i) nput text after the current line add a line <br /> (l) ist all line display buffer <br /> (l) ist n display buffer in the first n lines <br /> (l) ist mn display buffer lines m to n <br /> the implementation of the current run of the command buffer <br /> / Implementation of the current command buffer <br /> r the implementation of the current command buffer <br /> @ File name to run the sql files transferred to memory, such as: <br /> SQL&gt; edit s &lt;Enter&gt; <br /> If the current directory does not exist s.sql document, the system automatically s.sql documents <br /> In which the importation of &quot;select * from tab;&quot;, from the disk. <br /> SQL&gt; @ s &lt;Enter&gt; <br /> The system will automatically query the current user all tables, views, synonyms. <br /> @ @ The file name in the. Sql file to make a call. Sql file using the<br /> save the buffer&#39;s file of papers in order to save, the default file name extension is. sql <br /> Save the file name get transferred to the sql file <br /> start the file name to run the sql files transferred to memory <br /> spool file name after this operation and the implementation of the outcome of a variety of &quot;spool&quot; that is, save to disk file, the default file extension. lst <br /> Displays the current spool of &quot;spool&quot; state <br /> spool off to stop the output example: <br /> SQL&gt; spool a <br /> SQL&gt; spool <br /> Is the spool A. LST <br /> SQL&gt; spool off <br /> SQL&gt; spool <br /> No current spool <br /> exit from the SQL * PLUS <br /> desc table shows the structure <br /> show user displays the current connection users <br /> show error error <br /> show all show all 68 values of system variables <br /> edit to open the default editor, Windows system default notepad.exe, to buffer the last SQL statement afiedt.buf transferred document to edit <br /> edit the file name specified in the current directory. sql file editor to edit transferred <br /> Clear the screen clear screen shows the current second. Oracle sqlplus command to edit the first statement we enter such a command: <br /> SELECT emp_id, emp_name <br /> FROM Employees <br /> Then input the command to add a directive statement, such as in the above statement is running enter: <br /> input WHERE emp_age&gt; 30 <br /> Instructions can be as follows: <br /> SELECT emp_id, emp_name <br /> FROM Employees <br /> WHERE emp_age&gt; 30 <br /> ln command is used to specify the first n input line statement to operate, such as in the above statement is running enter: <br /> l1 statement is the current row is selected <br /> SELECT emp_id, emp_name <br /> (Statement before the &quot;*&quot; means) <br /> a command is used directly in the line added at the end of the current characters, such as in the above statement is running enter: <br /> a, emp_dept <br /> The implementation of the Directive is to: <br /> SELECT emp_id, emp_name, emp_dept <br /> FROM Employees <br /> WHERE emp_age&gt; 30 <br /> c command is used to modify the current statement of the characters, such as in the above statement is running enter: <br /> c / emp_name / emp_age / is the implementation of the directive to: <br /> SELECT emp_id, emp_age, emp_dept <br /> FROM Employees <br /> WHERE emp_age&gt; 30 <br /> del n command is used to delete the first n command line, such as in the above statement is running enter: <br /> DEL 3 <br /> The implementation of the Directive is to: <br /> SELECT emp_id, emp_age, emp_dept <br /> FROM Employees				<h5>Related Posts</h5>
		<div id="smilar">
		<ul>
					<li><a href="http://www.kods.netwww.kods.net/char-varchar2-difference/" title="char, varchar2 difference">char, varchar2 difference</a> 2009-04-06 22:10:03</li>
					<li><a href="http://www.kods.netwww.kods.net/sql-optimization-5-commonly-used-test-hints/" title="SQL optimization (5) - commonly used test hints">SQL optimization (5) - commonly used test hints</a> 2009-03-29 08:39:54</li>
					<li><a href="http://www.kods.netwww.kods.net/oracle-locking-mechanism-reprint/" title="Oracle locking mechanism (reprint)">Oracle locking mechanism (reprint)</a> 2009-03-28 05:20:43</li>
					<li><a href="http://www.kods.netwww.kods.net/oracle10g-with-cross-platform-endian-transfer/" title="Oracle10g with cross-platform endian transfer">Oracle10g with cross-platform endian transfer</a> 2009-03-14 22:09:48</li>
					<li><a href="http://www.kods.netwww.kods.net/diagnosis-and-principles-of-order/" title="Diagnosis and principles of order">Diagnosis and principles of order</a> 2009-02-25 20:27:28</li>
				</ul>
		</div>
		        ]]></content:encoded>
		<wfw:commentRss>http://www.kods.netwww.kods.net/encyclopedia-of-common-command-oracle-sqlplus/</wfw:commentRss>
	</item>
		<item>
		<title>oracle sql statement based on</title>
		<link>http://www.kods.netwww.kods.net/oracle-sql-statement-based-on/</link>
		<comments>http://www.kods.netwww.kods.net/oracle-sql-statement-based-on/#comments</comments>
		<pubDate>Wed, 20 May 2009 15:41:25+0000</pubDate>
		<dc:creator>kods.net</dc:creator>
		<category><![CDATA[Oracle SQL]]></category>
		<category><![CDATA[dml statements]]></category>
<category><![CDATA[sql statement]]></category>
<category><![CDATA[database object]]></category>
<category><![CDATA[oracle sql]]></category>
<category><![CDATA[data manipulation language]]></category>
<category><![CDATA[data definition language]]></category>
<category><![CDATA[set transaction]]></category>
<category><![CDATA[control language]]></category>
<category><![CDATA[structured query language]]></category>
<category><![CDATA[execution plan]]></category>
<category><![CDATA[audit database]]></category>
<category><![CDATA[annual salary]]></category>
<category><![CDATA[session properties]]></category>
<category><![CDATA[language query]]></category>
<category><![CDATA[transaction control]]></category>
<category><![CDATA[savepoint]]></category>
<category><![CDATA[language data]]></category>
<category><![CDATA[control session]]></category>
<category><![CDATA[session control]]></category>
<category><![CDATA[control statements]]></category>
		<guid isPermaLink="true">http://www.kods.netwww.kods.net/oracle-sql-statement-based-on/</guid>
		<description><![CDATA[- sql structured query language - DML - Data Manipulation Language - Data Manipulation Language query information (SELECT), add new rows (INSERT), modify existing rows (UPDATE), delete existing rows ( ...]]></description>
		<content:encoded><![CDATA[- sql structured query language <br /><br /> - DML - Data Manipulation Language - Data Manipulation Language <br /><br /> query information (SELECT), <br /> add new rows (INSERT), <br /> modify existing rows (UPDATE), <br /> delete existing rows (DELETE), <br /> perform a conditional update or insert operation (MERGE), <br /> see an execution plan of SQL (EXPLAIN PLAN), <br /> and lock a table to restrict access (LOCK TABLE). <br /><br /> - DDL - Data Definition Language - Data Definition Language <br /> create, modify, drop, or rename objects (CREATE, ALTER, DROP, RENAME), <br /> remove all rows from a database object without dropping the structure (TRUNCATE), <br /> manage access privileges (GRANT, REVOKE), <br /> audit database use (AUDIT, NOAUDIT) <br /> and add a description about an object to the dictionary (COMMENT). <br /><br /> - Transaction Control Transaction Control statement <br /> save the changes (COMMIT) <br /> or discard the changes (ROLLBACK) made by DML statements. <br /> Also included in the transaction-control statements are statements to set a point or marker in the transaction for possible rollback (SAVEPOINT) <br /> and to define the properties for the transaction (SET TRANSACTION). <br /> Used to manage the properties of the database. <br /> There isonly one statement in this category (ALTER SYSTEM). <br /><br /> - DCL - Data Control Language - with development of the relationship is not very close, for the distribution of authority and recycling <br /> grant, revoke, data control <br /><br /> - Session Control <br /> control the session properties (ALTER SESSION) <br /> and to enable / disable roles (SET ROLE). <br /><br /> - System Control <br /><br /> -------------------------------------------------- ------ <br /> select the usage of <br /><br /> - Every employee all the information <br /> select * from emp <br /> - Everyone&#39;s department number, name, salary <br /> select deptno, ename, sal from emp; <br /> - Each person&#39;s annual salary <br /> select ename, sal * 12 from emp; <br /> - Calculating the value 2 * 3 <br /> select 2 * 3 from emp; <br /> <br /> select 2 * 3 from dual; <br /> select * from dual; <br /> - Get current time <br /> select sysdate from dual <br /> - Can give out from the alias, such as the annual salary for each person <br /> select ename, sal * 12 salperyear from emp; <br /> - If an alias in the space, need to use double quotes <br /> select ename, sal * 12 &quot;sal per year&quot; from emp; <br /> - If there is no content, compared with empty <br /> select comm from emp; <br /> - When the air field to participate in the calculation, the result is null <br /> - For example: the year of each person&#39;s income, including monthly and year-end awards <br /> select ename, sal * 12 + comm from emp; <br /> - Can be more than string together fight. For example: the salary for each person, the format for the smith-sal-123 <br /> select ename | | &#39;-sal-&#39; | | sal from emp; <br /> - If the string in single quotation marks, need to escape a single quote, for example: a string: he&#39;s friend <br /> select ename ||&#39;&#39;&#39; s sal is&#39; | | sal from emp; <br /><br /> -------------------------------------------------- ------ <br /> - distinct usage of words <br /> - What are the departments for <br /> select distinct deptno from emp <br /> - Modified a number of fields can be used. For example: What are the order of a combination of departments and job <br /> select distinct deptno, job from emp <br /><br /> -------------------------------------------------- ------ <br /> where the usage of words <br /> - Value types can be judged equivalent. For example: 10 for all employees in this sector <br /> select * from emp where deptno = 20 <br /> - String type can be judged equivalent. For example: KING called for the information of the person <br /> select * from emp where ename = &#39;KING&#39; <br /> - Can not be judged equivalent. For example: for salaries of less than 2000 employees <br /> select * from emp where sal &lt;2000; <br /> - The string can be equivalent to do not to judge, such as: for all ename than &#39;CBA&#39; of employee information. <br /> select * from emp where ename&gt; &#39;CBA&#39;; <br /> - Instead of 10 for department staff <br /> select * from emp where deptno &lt;&gt; 10; <br /> - In order to pay between 800 and 1500 employees <br /> select * from emp where sal&gt; = 800 and sal &lt;= 1500; <br /> - Can also be written <br /> select * from emp where sal between 800 and 1500 <br /> - Can not be written like this <br /> ----------------------------- select * from emp where 800 &lt;= sal &lt;= 1500 <br /> - where ... in .. the usage. For example: is the salary for 1500 or 800 or 2000 employees <br /> select * from emp where sal = 800 or sal = 1500 or sal = 2000 <br /> - The equivalent of writing this <br /> select * from emp where sal in (1500,800,2000,1500,1500,1500,1500); <br /> - Another example is the name for KING, SMITH, AA staff information <br /> select * from emp where ename in ( &#39;KING&#39;, &#39;SMITH&#39;, &#39;AA&#39;) <br /> - Order entry time -81 months after the 20-2 staff information <br /> select * from emp where hiredate &lt;&#39;23-5 on -87 &#39;; <br /><br /> -------------------------------------------------- ------ <br /> - and or not the use of <br /> - For salaries, or greater than 1000 in 20 employees in this sector <br /> select * from emp where sal&gt; 1000 and deptno = 20 <br /> - Not for salaries instead of 800 or 1500 or 3000 rather than employees<br /> select * from emp where sal not in (800,1500,3000) <br /> - We can also write <br /> select * from emp where sal &lt;&gt; 800 and sal &lt;&gt; 1500 and sal &lt;&gt; 3000 <br /><br /> -------------------------------------------------- ------ <br /> - like the use of <br /> - Seek to include the names of the three characters ALL employees <br /> select * from emp where ename like &#39;% E%&#39;; <br /> - For the name of the second letter is A staff <br /> select * from emp where ename like &#39;_A%&#39;; <br /> - The need to escape special characters. For example: the staff in order to contain special characters% of employees <br /> select * from emp where ename like &#39;% \%%&#39; escape &#39;\&#39; <br /><br /> -------------------------------------------------- ------ <br /> - null usage <br /> - Not the end of the year award for staff <br /> select * from emp where comm is null <br /> - Award for a financial year-end staff <br /> select * from emp where comm is not null <br /><br /> -------------------------------------------------- ------ <br /> - order by the use of <br /> - The names of employees in accordance with the positive sequence with <br /> select * from emp order by ename asc; <br /> - Employees with information in accordance with the flashback <br /> select * from emp order by ename desc; <br /> - It could be a portfolio with a number of fields. For example: employees with positive sequence in accordance with the sector, and in accordance with the order of the names of flashback <br /> select * from emp order by deptno asc, ename desc <br /><br /> -------------------------------------------------- ------ <br /> - function usage <br /> - All the names into lower case <br /> select lower (ename) from emp; <br /> - All the names into upper case <br /> select upper (ename) from emp; <br /> - For all were included in &#39;a&#39; of the employees are not case-sensitive <br /> select * from emp where lower (ename) like &#39;% a%&#39; <br /> - Interception of sub-string, such as for part of Hello <br /> select substr ( &#39;hello&#39;, 2,2) from dual; <br /> select substr (ename, 2,2) from emp; <br /> - For part of Hello and specify the length of <br /><br /> - Ascii code for the corresponding characters <br /> select chr (65) from dual <br /> - For the corresponding ascii character code <br /> select ascii ( &#39;in&#39;) from dual <br /> - Rounding <br /> select round (12.456,2) from dual <br /> select round (12.456, -1) from dual <br /> - The number of places after the decimal point rounding <br /><br /> - Rounded to the nearest decimal point in front of the number of those who <br /><br /> -------------------------------------------------- ------ <br /> - important! the date of transfer function <br /> -------------------------------------------------- ------ <br /> - Will be converted to the current date 1981-03-12 12:00:00 This form of string <br /> select to_char (sysdate, &#39;YYYY-MM-DD HH24: MI: SS&#39;) from dual; <br /><br /> - 1981-03-12 12:00:00 would convert the date string <br /> select to_date (&#39;1981-03-12 12:00:00 &#39;,&#39; YYYY-MM-DD HH24: MI: SS &#39;) from dual; <br /><br /> - Everyone&#39;s salary will be converted into a fixed format string <br /> select to_char (sal, &#39;$ 999,999,999.99&#39;) from emp; <br /> - Fixed format string will be converted into numerical <br /> select to_number ( &#39;$ 8,000.00&#39;, &#39;$ 999,999,999.99&#39;) from dual; <br /><br /> - When calculating the time to participate in null, nvl this function can be used. For example, each year for a total income <br /> select ename, sal * 12 + comm from emp <br /><br /> -------------------------------------------------- ------ <br /> - group function group function <br /> - For the sum of all salaries, average, maximum, minimum <br /> select sum (sal), avg (sal), max (sal), min (sal) from emp; <br /> - For the total number of rows <br /> select count (*) from emp; <br /> - The total for the tree line, (you can specify a specific field) but if the field have null values need to be careful with the use of time <br /> select count (comm) from emp; <br /><br /> - Also can filter out duplicate rows after the visit statistics <br /><br /> select count (distinct deptno) from emp <br /> - Can specify which fields in accordance with the group. For example; sub-sectors the highest salary statistics <br /> select deptno, max (sal) from emp where deptno is not null group by deptno <br /> - Can also be grouped in accordance with the number of field statistics, such as: sub-sectors and jobs, the highest salary statistics and the number of rows <br /> select deptno, job, max (sal), count (*) from emp group by deptno, job <br /><br /> -------------------------------------------------- ------ <br /> - Important: appear in the select field list, if there is no function in the group, it must appear in the group by clause. <br /> -------------------------------------------------- ------ <br /> select ename, deptno, job, max (sal), count (*) from emp group by deptno, job <br /><br /> - The highest salaries for employees of the name <br /> select * from emp where sal = (select max (sal) from emp); <br /> delete from emp where ename = &#39;TEST2&#39; <br /> update emp set deptno = 10 where deptno = 99 <br /> select * from dept <br /> insert into dept (deptno, dname, loc) values (&#39;10 &#39;,&#39; ACCOUNTING &#39;,&#39; NEW YORK &#39;); <br /> - having clause is used <br /> - For the average salary is more than 2000 departments <br /> select deptno, avg (sal) as avg_sal from emp group by deptno <br /> having avg (sal)&gt; 2000 <br /> -------------------------------------------------- ------ <br /> - Select syntax summary <br /> select <br /> from <br /> where <br /> group by <br /> having <br /> order by<br /> -------------------------------------------------- ------ <br /> - The implementation of the order of very important! <br /> - First implementation of the original record of statement where filtration; <br /> - The implementation of the second group by group; <br /> - The implementation of having a third sub-filter; <br /> - And then select the field values in the elected; <br /> - The last sort order by the Executive; <br /><br /> -------------------------------------------------- ------ <br /> / * <br /> Group are in accordance with the department, and the highest salaries, average salary is only 1200 more than salary to be involved in statistical and subgroup results only include the average salary of more than 1,500 department and arranged in accordance with the average salary flashback <br /> * / <br /> select max (sal), avg (sal) from emp <br /> where sal&gt; 1200 <br /> group by deptno <br /> having avg (sal)&gt; 1500 <br /> order by avg (sal) desc <br /><br /> -------------------------------------------------- ------ <br /> / * <br /> The employees grouped by department, <br /> Seek the highest salary, department number, <br /> Filter out the second letter in the name of the &#39;A&#39; and <br /> Claim the average salary after&gt; 1500, <br /> Reverse order in accordance with the sector number <br /> * / <br /> select max (sal), deptno from emp where ename not like &#39;_A%&#39; group by deptno <br /> having avg (sal)&gt; 1500 <br /> order by deptno desc <br /><br /> / * Very very important! * / <br /> select ename, deptno from emp; <br /> select deptno, dname from dept; <br /> -------------------------------------------------- ------------------------------------ <br /> - Old syntax :--------------------------------------------- ------------------------------- <br /> -------------------------------------------------- ------------------------------------ <br /> - Equivalent to connect: for employees, as well as the names of the names of department employees at the same time show <br /> select ename, emp.deptno, dname, dept.deptno from emp, dept <br /> where emp.deptno = dept.deptno <br /><br /> select ename, e.deptno, dname, d.deptno from emp e, dept d <br /> where e.deptno = d.deptno <br /><br /> - Non-equivalent connections: for each employee&#39;s salary grade <br /> select * from salgrade <br /> select ename, sal, grade, losal, hisal from emp, salgrade <br /> where sal&gt; = losal and sal &lt;= hisal <br /> - Inter-Table 3: jobs for the &#39;PRESIDENT&#39; employee name, department name and salary grade <br /> select ename, dname, grade from emp, dept, salgrade <br /> where emp.deptno = dept.deptno <br /> and sal&gt; = losal and sal &lt;= hisal <br /> and job = &#39;PRESIDENT&#39; <br /><br /> - Can also be a table with cross-table connections: for each employee&#39;s name, and its parent manager&#39;s name <br /><br /> select e1.ename, e2.ename from emp e1, emp e2 <br /> where e1.mgr = e2.empno <br /><br /> -------------------------------------------------- ------------------------------------ <br /> - New syntax ---------------------------------------------- -------------------------------- <br /> - In the SQL1992 syntax rules, statement table filters to connect the conditions and the conditions have been placed on the where clause, when the conditions too much, it is easy to cause confusion, <br /> - SQL1999 to amend the shortcomings of the conditions and data will be connected to separate filters, <br /> -------------------------------------------------- ------------------------------------ <br /><br /> - Cross-Connect <br /> - The results of the two tables will have the Cartesian product <br /><br /> select * from emp cross join dept <br /> - To use as the equivalent connection deptno conditions, we can write <br /> select * from emp join dept using (deptno) <br /> select ename, dname from emp join dept using (deptno); <br /> - The equivalent of <br /> select ename, dname from emp join dept on emp.deptno = dept.deptno <br /> - Can also be written in such <br /><br /> - Can also be used to connect non-equivalent <br /> - For each employee&#39;s salary grade <br /> select * from emp join salgrade on (sal&gt; = losal and sal &lt;= hisal) <br /><br /> - A number of join, where used in combination <br /> - (For jobs is&#39; PRESIDENT &#39;employee name, department name and salary grade) <br /><br /> select * from emp join dept on emp.deptno = dept.deptno <br /> join salgrade on (sal&gt; = losal and sal &lt;= hisal) <br /> where job = &#39;PRESIDENT&#39; <br /><br /> - Outer Join - Remove the table not connected with the need for redundant data <br /> - Not wholly within the connection, there is no right in connection <br /><br /> - Which can also omit the outer, short for the left join, right join, full join <br /> - left inner join can be abbreviated into a inner join can also be the initials into a join, within the meaning of the left. <br /> - update emp set deptno = 20 where ename = &#39;SMITH&#39;; <br /> - commit; <br /> select * from emp; <br /> select * from dept; <br /> delete from dept where deptno = 99; <br /> - Left inside, looking from left to right, matching the records do not show <br /> select ename, emp.deptno from emp join dept on emp.deptno = dept.deptno; <br /> select ename, emp.deptno from emp inner join dept on emp.deptno = dept.deptno; <br /> - There is no such syntax: select ename, emp.deptno from emp left inner join dept on emp.deptno = dept.deptno; <br /> - Left outer join, right from the left to find, match the record does not show his <br /> select ename, dept.deptno from emp left / * outer * / join dept on emp.deptno = dept.deptno; <br /><br /> - Right outer join, right to the left to find the records do not match, it also shows his <br /> select ename, dept.deptno from emp right / * outer * / join dept on emp.deptno = dept.deptno; <br /> - There is no right to connect with: select ename, dept.deptno from emp right inner join dept on emp.deptno = dept.deptno; <br /><br /> - Full outer join <br /> select ename, dept.deptno from emp full / * outer * / join dept on emp.deptno = dept.deptno; <br /><br /> - Left, right outside the distinction between <br /><br /> - When connecting them with outside? For example, leading to you to a list of all students, the way to their classes are also listed, on the need to connect <br /><br /> - Where language used in subquery <br /> -------------------------------------------------- --------------- <br /> - Employees in the name of the highest staff salary <br /> - 1, to derive the maximum salary <br /> - 2, then the maximum salary for employees in the name of the staff <br /> select ename from emp where sal = (select max (sal) from emp) <br /><br /> - What are the salary is the average salary of the employees on <br /> select ename, sal from emp where sal&gt; (select avg (sal) from emp) <br /><br /> -------------------------------------------------- --------------- <br /> - Employees who are managers <br /> - 1, first of all, what inquiries mgr number <br /> - 2, look at what number of personnel in this emerging <br /> select distinct mgr from emp where mgr is not null order by mgr <br /><br /> select ename <br /> from emp <br /> where empno in (select distinct mgr from emp where mgr is not null) <br /> - where in China and not to write orderby <br /> select ename <br /> from emp <br /> where empno in (select distinct mgr from emp where mgr is not null order by mgr) <br /><br /> -------------------------------------------------- --------------- <br /> - Used in the From clause subquery <br /> -------------------------------------------------- ---------------- <br /><br /> - The level of average salary <br /> - 1, first of all, each department will be seeking out the average salary <br /> - 2, and then the results as a table, and then the results of this table and table do salgrade connected to salary grades obtained <br /> select deptno, avg (sal) from emp group by deptno <br /> select * from (select deptno, avg (sal) avg_sal from emp group by deptno) t join salgrade <br /> on avg_sal between losal and hisal; <br /><br /> -------------------------------------------------- --------------- <br /> - The highest salary in each department the name of the staff <br /> - 1, first of all, each department will be seeking out the highest salaries <br /> - 2, and then the results as a table, and then the results of emp table and do this connection in order to achieve the highest salaries in each department the name of the staff <br /><br /> select deptno, max (sal) from emp where deptno is not null group by deptno <br /><br /> select ename from emp e join <br /> (select deptno, max (sal) max_sal from emp where deptno is not null group by deptno) t <br /> on sal = max_sal and e.deptno = t.deptno <br /><br /> -------------------------------------------------- --------------- <br /> - What are the salary of the average salary in the sector on <br /> - 1, first of all, each department will be seeking out the average salary <br /> - 2, and then the results as a table, and then the results of emp table and do this connection, as the salaries of those who seek in the department&#39;s average salary over <br /> select deptno, avg (sal) avg_sal from emp group by deptno <br /><br /> select * from emp join (select deptno, avg (sal) avg_sal from emp group by deptno) t <br /> on (sal&gt; avg_sal and emp.deptno = t.deptno) <br /> -------------------------------------------------- --------------- <br /> - For sector (all of) the average salary level, forms such as: <br /> - Deptno avg_grade <br /> - 10 3.67 <br /> - 20 2.8 <br /> - 30 2.5 <br /> - 1, first for each person&#39;s salary level <br /> - 2, and then grouped according to sector, and the average <br /> select deptno, sal, grade from emp join salgrade on sal between losal and hisal <br /> select deptno, avg (grade) from (select deptno, sal, grade from emp join salgrade on sal between losal and hisal) t group by deptno <br /><br /> -------------------------------------------------- ---------------------------------------- <br /> - The use of pseudo-field: rownum ,---------------------- <br /> -------------------------------------------------- ---------------------------------------- <br /> - Used to identify each record line number, line number starting at 1 for each incremental 1 <br /> select rownum, emp .* from emp; <br /> - oracle only under rownum &lt;&lt;=, can not be used =&gt;&gt; = comparison operator, <br /> select rownum, emp .* from emp where rownum &lt;5; <br /> - Rownum and order by when used together, it will first elect a record of compliance with the conditions rownum, and then sort <br /> - (Wrong wording) For example, when we asked for the maximum salary of the top 5 individuals, the most direct way of thinking can be written: <br /> select * from emp where rownum &lt;5 order by sal desc <br /> - (Correct wording) can be written <br /><br /> select * from <br /> (select * from emp order by sal desc) t <br /> where rownum &lt;= 5 <br /><br /> -------------------------------------------------- ------ <br /> - Not allowed to use group function (ie, MAX ()), for the highest salary values (surface test) <br /> - The first solution:<br /> - 1, first of all salaries in accordance with the reverse order <br /> - 2, and then take the first line of <br /> select * from <br /> (select sal from emp order by sal desc) t <br /> where rownum = 1 <br /><br /> - The second solution: <br /> - 1, their first inter-table query, first the results obtained, e1.sal maximum number will not happen <br /> - 2, and then not in <br /> select e2.sal from emp e1, emp e2 where e1.sal&gt; e2.sal <br /> select sal from emp where sal not in (select e2.sal from emp e1, emp e2 where e1.sal&gt; e2.sal) <br /><br /> -------------------------------------------------- --------------- <br /> - The average salary for the highest number of departmental <br /> - The first solution: <br /> - 1, first calculated the average salary of each department, <br /> select deptno, avg (sal) avg_sal from emp group by deptno <br /> - 2, then for each sector the average salary of the highest value, <br /> select max (avg_sal) from (1111111111111111111111111) <br /> - 3, then the results for the first step avg_sal = highest salary records. <br /><br /> select deptno from (111111111111) where avg_sal = (22222222) <br /><br /> select deptno <br /> from (select deptno, avg (sal) avg_sal from emp group by deptno) <br /> where avg_sal = <br /> (select max (avg_sal) <br /> from (select deptno, avg (sal) avg_sal from emp group by deptno)) <br /><br /> - Can not consider the case of a tie for first <br /> select deptno from <br /> (select deptno, avg (sal) avg_sal from emp group by deptno order by avg (sal) desc) <br /> where rownum &lt;= 1 <br /><br /> - The second solution: <br /> - 1, will be the first step above the second step merger, first for the highest average salary, with max (avg (sal)) approach <br /> - Can not be written in select deptno, max (avg (sal)) from emp group by deptno <br /> select max (avg (sal)) from emp group by deptno <br /> - 2, find the average salary of each department <br /> select deptno, avg (sal) avg_sal from emp group by deptno <br /> - 3, then the results for the second step (that is, the average salary of each department), avg_sal = (first results) records. Avg_sal = highest salary that is the record. <br /> select deptno from (select deptno, avg (sal) avg_sal from emp group by deptno) <br /> where avg_sal = (select max (avg (sal)) from emp group by deptno) <br /><br /> - The third solution: <br /> - 1, first calculated the average salary of each department, <br /> select avg (sal) avg_sal from emp group by deptno <br /> - 2, and the highest average salary, with max (avg (sal)) approach <br /> select max (avg (sal)) from emp group by deptno <br /> - 3, and then having to use words, avg (sal) = the second step the results Note: for the group since the alias function can not be used in having <br /><br /> select deptno from emp group by deptno <br /> having avg (sal) = (select max (avg (sal)) from emp group by deptno) <br /><br /> -------------------------------------------------- --------------- <br /> - The highest average salary for the department the name of the department <br /> - 1, the highest average salary <br /> - 2, be a list of department numbers, paying attention to use group by deptno <br /> - 3, and then having the application clause, having avg (sal) = (first results) <br /> - 4, the highest average salary that the number of departments <br /> - 5, and then get the name of the department <br /><br /> select dname from dept where deptno in <br /><br /> ( <br /> select deptno <br /> from (select deptno, avg (sal) avg_sal from emp group by deptno) <br /> where avg_sal = <br /> (select max (avg_sal) <br /> from (select deptno, avg (sal) avg_sal from emp group by deptno)) <br /><br /> ) <br /><br /> -------------------------------------------------- --------------- <br /> - The average salary for the lowest level of the name of the department of the sector <br /> - The first step: the level of average salary, divided into two small steps, the first step is the average salary for department <br /><br /> select * from <br /> (select deptno, avg (sal) avg_sal from emp group by deptno) t <br /> join salgrade on avg_sal between losal and hisal <br /><br /> - Step two: the lowest level of the value of <br /><br /> select min (grade) from (1111111111111111111111111) <br /><br /> - The third step: the value equivalent to the minimum number of sectors <br /> ------------ A mistake, should be grade = <br /> select deptno from (111111111111) where grade = (22222222222222) <br /> - Step four: for the name of <br /> select dname from dept where deptno in (33333333333) <br /><br /> select dname <br /> from dept <br /> where deptno in <br /> ( <br /><br /> select deptno <br /> from (select * <br /> from (select deptno, avg (sal) avg_sal <br /> from emp <br /> group by deptno) t <br /> join salgrade on avg_sal between losal and hisal) <br /> where grade = <br /> (select min (grade) <br /> from (select * <br /> from (select deptno, avg (sal) avg_sal <br /> from emp <br /> group by deptno) t <br /> join salgrade on avg_sal between losal and hisal))) <br /><br /> - Views can also be used to solve <br /> - conn sys / bjsxt as sysdba <br /> - grant create table, create view, create sequence to scott <br /> - According to the results of the first step in the establishment of a view <br /><br /> create or replace view v1 as <br /> - Must be a clear definition of out <br /> select deptno, avg_sal, grade from <br /> (select deptno, avg (sal) avg_sal from emp group by deptno) t <br /> join salgrade on avg_sal between losal and hisal <br /><br /> - Check <br /> select * from v1 <br /> - Inquiries about <br /><br /> - Into the view <br /><br /> select dname from dept where deptno in <br /> (select deptno from (v1) where grade = (select min (grade) from v1)) <br /><br /> -------------------------------------------------- ----------- <br /> - Why in the back can not order by? <br /><br /> -------------------------------------------------- ------------- <br /> - For department managers the lowest average salary in the name of the department (thinking title) <br /> The first step, and the employee ID Manager <br /> select distinct mgr from emp where mgr is not null <br /> The second step, according to department statistics, and the average salary manager <br /> select deptno, avg (sal) avg_sal from emp where empno in (select distinct mgr from emp where mgr is not null) group by deptno <br /> The third step, and the minimum value <br /> select min (avg (sal)) from emp where empno in (select distinct mgr from emp where mgr is not null) group by deptno <br /> The fourth step, and department managers the lowest average salary in the name of the department <br /> select deptno from (2222222222222) where avg_sal = (333333333333333333333333) <br /><br /> select dname from dept where deptno in (select deptno from (select deptno, avg (sal) avg_sal from emp where empno in (select distinct mgr from emp where mgr is not null) group by deptno) where avg_sal = (select min (avg ( sal)) from emp where empno in (select distinct mgr from emp where mgr is not null) group by deptno)) <br /> -------------------------------------------------- -------------------------- <br /> - For the highest than that of ordinary employees with high salaries but also the name of the manager <br /> - 1, and the number of all managers <br /> create or replace view v1 as <br /> select distinct mgr from emp where mgr is not null <br /> select * from v1 <br /> - 2, the general staff of the highest salaries <br /> select max (sal) from emp where empno not in (select distinct mgr from emp where mgr is not null) <br /> - 3, <br /><br /> select ename from emp where empno in (select * from v1) <br /> and sal&gt; (select max (sal) from emp where empno not in (select distinct mgr from emp where mgr is not null)) <br /><br /> - That is: <br /><br /> select ename from emp where empno in (select distinct mgr from emp where mgr is not null) <br /> and sal&gt; (select max (sal) from emp where empno not in (select distinct mgr from emp where mgr is not null)) <br /><br /> -------------------------------------------------- ---------------------------- <br /> - The highest salary for the first 5 employees <br /> - 1, first look <br /><br /> - 2, take a look at the role of rownum <br /><br /> - 3, not the result we want <br /> select ename, sal from emp where rownum &lt;= 5 order by sal desc <br /> - 4, the first order by, then rownum <br /> select * from <br /> (select ename, sal from emp order by sal desc) t <br /> where rownum &lt;= 5 <br /><br /> -------------------------------------------------- ------------------------------ <br /> - The highest salary for the first 6 to 10 employees (master key) <br /> - Can not achieve this, oracle can only be used under rownum &lt;&lt;=, can not be used =&gt;&gt; = comparison operator, etc. <br /> - Rownum attention inside and outside the difference between rownum, outside to inside access rownum, must obtain an alias. <br /><br /> select * from <br /> (select ename, sal from emp order by sal desc) t <br /> where rownum&gt; = 5 <br /> and rownum &lt;= 10 <br /><br /> - So select a layer of re-sets <br /> select * from <br /> (select t. *, rownum r from <br /> (select ename, sal from emp order by sal desc) t <br /> ) <br /> where r&gt; = 5 <br /> and r &lt;= 10 <br /><br /> - There is also a way to sort <br /> select * from <br /> (select * from emp order by sal desc) where rownum &lt;= 10 <br /> minus <br /> select * from <br /> (select * from emp order by sal desc) where rownum &lt;= 5 <br /> -------------------------------------------------- ------------------ <br /> - Practice: the final entry for the five staff <br /> - 1, each time the entry <br /><br /> - 2, take the top 5 lines <br /><br /> -------------------------------------------------- --------------- <br /> - Demand the highest salaries in each department in the top two employees <br /><br /> - 1, each employee&#39;s name, department, salary and wages by sector (reverse) with <br /> select ename, deptno, sal from emp order by deptno, sal desc <br /> - 2, sets of one, coupled with a r <br /> select ename, deptno, sal, rownum r from <br /> (select ename, deptno, sal from emp order by deptno, sal desc) t <br /> - 3, the creation of an attempt <br /> create or replace view v1 <br /> as <br /> select ename, deptno, sal, rownum r from <br /> (select ename, deptno, sal from emp order by deptno, sal desc) t <br /> - Look <br /> select * from v1 <br /><br /> - For each sector, the first line of the highest salaries and the creation of an attempt <br /> create or replace view v2 as <br /> select deptno, min (r) min_r from v1 group by deptno <br /><br /> - Two cross-table view connected to the maximum salary is greater than the number of rows, the maximum number of rows is less than +1, and sector number to match <br /> select ename from v1 join v2 <br /> on (v1.deptno = v2.deptno and v1.r&gt; = v2.min_r and v1.r &lt;= v2.min_r +1) <br /><br /> -------------------------------------------------- ----------------------------- <br /> - Face the questions: To compare the efficiency of <br /> select * from emp where deptno = 10 and ename like &#39;% A%&#39;; <br /> select * from emp where ename like &#39;% A%&#39; and deptno = 10; <br /><br /> -------------------------------------------------- ------- <br /> - The use of union, minus <br /><br /> - The use of union, minus the result set can be used to achieve the merger and to remove (can be interpreted as a plus and minus), such as: <br /> select * from emp where deptno = 10 <br /> union <br /> select * from emp where deptno = 20; <br /><br /> - The equivalent of <br /> select * from emp where deptno = 10 or deptno = 20 <br /><br /> - The following statement <br /> select * from emp where deptno in (10,20) <br /> minus <br /> select * from emp where sal &lt;1500; <br /> - The equivalent of <br /> select * from emp where deptno in (10,20) and sal&gt; = 1500 <br /><br /> - Show the salaries for the number of sub - <br /><br /> Such as: <br /> scale total <br /> &lt;800 0 <br /> 801-1000 2 <br /> 1001-2000 3 <br /> 2001-5000 6 <br /> &gt; 50,008 <br /><br /> select &#39;&lt;800&#39; as scale, count (*) as total from emp where sal &lt;800 <br /> union <br /> select &#39;&lt;801-1000&#39; as scale, count (*) as total from emp where sal &lt;= 1000 and sal&gt; = 801 <br /><br /> - Or display as a <br /> - Note: the use of between .. and .. the time, including the largest and the minimum value. <br /> 800-1000 1001 -2000 2001-5000 <br /> 2 3 6 <br /> select * from <br /> (select count (*) as &quot;800-1000&quot; from emp where sal&gt; = 800 and sal &lt;= 1000), <br /> (select count (*) as &quot;1001-2000&quot; from emp where sal&gt; = 1001 and sal &lt;= 2000), <br /> (select count (*) as &quot;2001-5000&quot; from emp where sal&gt; = 2001 and sal &lt;= 5000) <br /><br /> - Or display as a <br /> DEPTNO 800-2000 2001 -5000 <br /> ------ ---------- ---------- <br /> 30 5 1 <br /> 20 2 3 <br /> 10 1 2 <br /> select t.deptno, &quot;800-2000&quot;, &quot;2001-5000&quot; from <br /> (select deptno, count (*) as &quot;800-2000&quot; from emp where sal between 800 and 2000 group by deptno) t <br /> join <br /> (select deptno, count (*) as &quot;2001-5000&quot; from emp where sal between 2001 and 5000 group by deptno) t1 <br /> on t.deptno = t1.deptno				<h5>Related Posts</h5>
		<div id="smilar">
		<ul>
					<li><a href="http://www.kods.netwww.kods.net/rman-created-physical-standby/" title="RMAN created physical standby">RMAN created physical standby</a> 2009-03-30 22:49:29</li>
					<li><a href="http://www.kods.netwww.kods.net/proc-will-select-the-data-on-the-two-dimensional-array/" title="ProC will select the data on the two-dimensional array">ProC will select the data on the two-dimensional array</a> 2009-03-30 11:50:27</li>
					<li><a href="http://www.kods.netwww.kods.net/oracle-locking-mechanism-reprint/" title="Oracle locking mechanism (reprint)">Oracle locking mechanism (reprint)</a> 2009-03-28 05:20:43</li>
					<li><a href="http://www.kods.netwww.kods.net/turning-optimization-oracle-article/" title="Turning optimization oracle article">Turning optimization oracle article</a> 2009-03-26 21:39:35</li>
					<li><a href="http://www.kods.netwww.kods.net/using-sql-trace-and-tkprof/" title="Using SQL TRACE and TKPROF">Using SQL TRACE and TKPROF</a> 2009-02-26 21:36:37</li>
				</ul>
		</div>
		        ]]></content:encoded>
		<wfw:commentRss>http://www.kods.netwww.kods.net/oracle-sql-statement-based-on/</wfw:commentRss>
	</item>
		<item>
		<title>ORACLE SQL and SQL * PLUS (1)</title>
		<link>http://www.kods.netwww.kods.net/oracle-sql-and-sql-plus-1/</link>
		<comments>http://www.kods.netwww.kods.net/oracle-sql-and-sql-plus-1/#comments</comments>
		<pubDate>Wed, 20 May 2009 12:05:34+0000</pubDate>
		<dc:creator>kods.net</dc:creator>
		<category><![CDATA[Oracle SQL]]></category>
		<category><![CDATA[oracle rdbms]]></category>
<category><![CDATA[sql statement]]></category>
<category><![CDATA[oracle server]]></category>
<category><![CDATA[oracle corporation]]></category>
<category><![CDATA[sql commands]]></category>
<category><![CDATA[oracle sql syntax]]></category>
<category><![CDATA[pl sql oracle]]></category>
<category><![CDATA[relational database model]]></category>
<category><![CDATA[relational database management]]></category>
<category><![CDATA[sql plus oracle]]></category>
<category><![CDATA[relational database management system]]></category>
<category><![CDATA[database management system]]></category>
<category><![CDATA[field arithmetic]]></category>
<category><![CDATA[arithmetic operations]]></category>
<category><![CDATA[fuzzy query]]></category>
<category><![CDATA[query conditions]]></category>
<category><![CDATA[language sql]]></category>
<category><![CDATA[undefined variables]]></category>
<category><![CDATA[distinct field]]></category>
<category><![CDATA[space 39]]></category>
		<guid isPermaLink="true">http://www.kods.netwww.kods.net/oracle-sql-and-sql-plus-1/</guid>
		<description><![CDATA[Preface: a brief introduction of relational database 1970.Dr.EFcodded created a relational database model (similar to the now commonly used two-dimensional form) Relational database composed of a numb ...]]></description>
		<content:encoded><![CDATA[Preface: a brief introduction of relational database <br /> 1970.Dr.EFcodded created a relational database model (similar to the now commonly used two-dimensional form) <br /> Relational database composed of a number of data objects, the relationship between the operation of the management of SQL commands, and data integrity between the constraints. <br /> RDBMS (relational database management system) <br /> ORDBMS (object relational database management system) <br /> ORACLE RDBMS often called ORACLE SERVER <br /> Its core is written in C language. <br /><br /> A simple introduction to ORACLE <br /> ORACLE Corporation is the leading provider of integrated technology products, programs, services, database company <br /> ORACLE database designed to be a large number of stored data, rapid query data, ensure data security and consistency, <br /> Distributed inter-network management and customers - such as server configuration. <br /> ORACLE SQL syntax in line with the ANSI 1986 standard <br /> SQL and databases in order to exchange language <br /> SQL * PLUS ORACLE a tool to run SQL and PL / SQL statement <br /> PL / SQL ORACLE process of programming language <br /><br /> First, choose line <br /> 1. A simple SELECT statement <br /> SELECT [DISTINCT] (*, COLUMN [ALIAS], ... ...) FROM table_name; <br /> Field of non-unique set of results <br /> DISTINCT field name 1 [, field names 2] <br /> Between the number of types of field arithmetic operations can be carried out <br /> + - * /, Such as for example: (1 * Field Name Field Name 2) / 3 <br /> Connect the content of the combined field of characters | | <br /> Field Name 1 | | Field Name 2 <br /> Field can have an alias <br /> SELECT fieldname 1 [AS] &#39;explained a field name&#39; FROM table; <br /><br /> 2. To deal with NULL <br /> NULL is not defined, not allowed to operate, nothing is <br /> NULL! = 0 NULL! = &#39;Space&#39; <br /> And any operator NULL return NULL <br /> Undefined variables in ORACLE for NULL values <br /> NVL function can be NULL converted to other types of symbols <br /> NVL (EXPR1, EXPR2) Function explanation: IF EXPR1 = NULL RETURN EXPR2 <br /> ELSE RETURN EXPR1 <br /> Programming skills: NVL function in a multi-fuzzy query conditions more useful when <br /> nvl ( &#39;+ input_value +&#39;,&#39;0 &#39;) =&#39;0&#39; or filed_name like &#39;% + input_value +%&#39; <br /> NVL function can return a variety of data types: <br /> Return date NVL (start_date,&#39;2002-02-01 &#39;) <br /> Return string NVL (title, &#39;no title&#39;) <br /> Return the number of NVL (salary, 1000) <br /><br /> 3. The use of SQL * PLUS (1) <br /> Log in SQL * PLUS method user names, passwords, database connection string the database connection string can be used to establish net8 easy configuration of the local network service configuration, <br /> Can also manually edit the $ ORACLE_HOME / network / admin / tnsnames.ora file. <br /> In UNIX systems do not use <br /> $ sqlplus username / password @ dbname <br /> So other users can use $ ps command to see the user&#39;s password <br /> SQL&gt; desc table; display table structure <br /> SQL&gt; select * from tab; See the table of all users <br /> SQL&gt; set pause on; can result set in a large number of users by &quot;Enter&quot; (carriage return) after the page <br /> SQL&gt; set pagesize 100; settings SQL statement to return a result set number of rows 100, the default value is 14 <br /> SQL&gt; set linesize 100; settings SQL statements to return result sets the width of line 100, the default value is 80 <br /><br /> 3. The use of SQL * PLUS (2) SQL * PLUS command recent editorial in a statement the existence of SQL command ORACLE memory (sql buffer), the SQL * PLUS command but does not keep into account. <br /> SQL * PLUS editor in the command: <br /> A [PPEND] text to the text after the current row <br /> C [HANGE] / old / new / the old symbol to replace the current line into a new symbol, new is empty, delete the old symbol <br /> CL [EAR] BUFF [ER] from the sql buffer to remove all the lines in <br /> DEL n delete sql buffer line in the first n <br /> I [NPUT] text in the text insert sql buffer <br /> L [IST] n show sql buffer line in the first n <br /> n so that the first acts of the current line n <br /> n text article text replaced by n line <br /> 0 text inserted in the first row in front of his <br /><br /> 3. The use of SQL * PLUS (3) SQL * PLUS command in the document: <br /> SAV [E] filename [REP [LACE] | APP [END]] <br /> The sql buffer kept in the SQL command to the OS under a file filename, the default file name suffix to. Sql. <br /> REP [LACE] replace the filename in the SQL command <br /> APP [END] to SQL in the sql buffer added to the filename after the command <br /> GET filename from the filename in the SQL command to read sql buffer <br /> STA [RT] filename running last saved to a file filename in the SQL command <br /> @ filename to run the last saved to the file filename in the SQL command <br /> EDIT to open the edit window, edit the sql buffer in SQL command <br /> EDIT filename to open the edit window, edit the document filename in the SQL command <br /> SPO [OL] filename [OFF | OUT] the results of the SQL command output to a file under OS end filename OFF the output to a file, OUT the end of the output to a file and print documents <br /><table width="72%" border=0><tbody><tr><td width="3%" bgcolor=#ffffff height=17></td><td"97%"><table cellspacing=0 cellpadding=0 width="87%" border=0><tbody><tr><td><br /> 4. SQL * PLUS in the field provides the number of the display format of the display format provides <br /> SQL&gt; column field names format 99999999999; <br /> SQL&gt; column field names format 999,999,999,999; <br /> The provisions of the display width of string <br /> SQL&gt; column name format a number of fields [word_wrapped];<br /> Description: his only show the length of the number of places over the length of fold line, plus word_wrapped, the word line will not be provided for folding the display width of characters long <br /> SQL&gt; set long 200; <br /> The provisions of the display field names <br /> SQL&gt; column field name heading &#39;field names display content&#39;; <br /> SQL&gt; set heading off; query field names do not show the provisions of the alignment field direction <br /> SQL&gt; column field names justify [left | right | center]; <br /> Clear the form fields <br /> SQL&gt; column field names clear; <br /><br /> 5. SQL * PLUS in the field provides an example of the display format <br /> SQL&gt; column last_name heading &#39;Employee | Name&#39; format a15; <br /> SQL&gt; column salary justify right format $ 99,999.99; <br /> SQL&gt; column start_date format a10 null &#39;Not Hired&#39;; <br /> Note: If start_date is null, show the string &#39;Not Hired&#39; <br /><br /> 6. To determine questions (T / F) <br /> (1). SQL command are always held in sql buffer. [T] <br /> (2). SQL * PLUS command assit with query data. [T] <br /> SQL * PLUS command SELECT result set to control only the display and control file format. Only SQL commands to access the database. <br /><br /> Second, restrictions on choice of line <br /> 1. In accordance with the rules specified in order <br /> SELECT expr FROM table [ORDER BY (column, expr) [ASC | DESC]]; <br /> ASC default is ascending order (from small to big) <br /> ORDER BY can also be the location of field names [1] | [2] ASC | DESC; <br /> Very complicated when the field names or field arithmetic expression used to sort of show is very convenient location. <br /><br /> 2. With restrictions on choice of WHERE line (1) <br /> Comparison Operators =&gt; &lt;&gt; = &lt;=! = &lt;&gt; ^ = NULL comparison with the above comparison can not use ANY SOME ALL operator <br /> SQL Operator BETWEEN ... AND ... IN LIKE IS NULL <br /> NOT BETWEEN ... AND ... NOT IN NOT LIKE IS NOT NULL <br /> Logical Operators AND OR NOT <br /><br /> 3. With restrictions on choice of WHERE line (2) <br /> Comparison of the order (in brackets can be used to change their order) <br /> (1). = &lt;&gt;&gt; = &lt;= In like is null between <br /> (2). And <br /> (3). Or <br /> Note: char and varchar2 different comparison rules: <br /> char string comparison will ignore the spaces behind. varchar2 string will be taken into account the space behind <br /><br /> 4. LIKE operation <br /> % Zero to any number of characters _ a character such as: field names like &#39;M%&#39; field names like &#39;% m%&#39; field names like &#39;job_&#39; <br /> If you are looking for characters with an underscore, it is necessary to add a backslash For example: field names like &#39;% X / _Y%&#39; escape &#39;/&#39; <br /><br /> 5. Comparison of date fields, for example: <br /> Date fields between to_date (&#39;2001-12-12 &#39;,&#39; YYYY-MM-DD &#39;) and to_date (&#39;2002-02-01&#39;, &#39;YYYY-MM-DD&#39;) <br /> Date field&gt; to_date (&#39;2001-12-12 &#39;,&#39; YYYY-MM-DD &#39;) and the date field &lt;= to_date (&#39;2002-02-01&#39;, &#39;YYYY-MM-DD&#39;); <br /><br /> 6. Can not be used for comparison of the index operator <br /> IS NULL <br /> IS NOT NULL <br /> LIKE &#39;% m%&#39; <br /><br /> Third, one-way function <br /> 1. The number of function <br /> POWER absolute involution ABS check for LN 10 base exponentiation <br /> SQRT square root of n times EXP e involution LOG (m, n) m for the base n exponentiation arithmetic functions: ACOS ATAN ATAN2 COS COSH SIGN SIN SINH TAN TANH <br /> CEIL take an integer greater than or equal to <br /> FLOOR integer less than or equal to check <br /> MOD take more than a few <br /> ROUND (n, m) according to the median m value check if rounding round (date): at 12 after the date will be tomorrow. Round (sysdate, &#39;Y&#39;) is the first day of the year <br /> TRUNC (n, m) by m in front of the median value check if trunc (date), there is removed from the province of the time <br /><br /> 2. Characters function <br /> CHR by the database character set to return by the number of characters <br /> CONCAT (c1, c2) of the two characters c1, c2 as a combination of characters, and | | the same <br /> REPLACE (c, s, r) the character c in s character appears to replace into r, the return of new characters <br /> SUBSTR (c, m, n) m&gt; 0, m characters c from the start in front of n-bit characters check, m is equal to 0 and 1, the <br /> small m and 0, m characters c Department from behind and started to admit n-bit characters <br /> TRANSLATE (c, f1, t1) character c in accordance with the rules of f1 to t1 into a new string <br /> The first letter capitalized INITCAP characters, other characters lowercase <br /> All lowercase characters LOWER <br /> All uppercase characters UPPER <br /> LTRIM (c1, c2) characters removed c1 characters left c2 <br /> RTRIM (c1, c2) <br /> TRIM (c1, c2) characters removed c1 about the characters on both sides of c2 <br /> LPAD (c1, n, c2) in accordance with the development of characters c1 show n less than the median of the median c2 string with the replacement of the left side of the space <br /> RPAD (c1, n, c2) <br /><br /> 3. Date function <br /> ADD_MONTHS (d, n) the date on the value of n increases <br /> LAST_DAY (d) the last day of the month to return date <br /> MONTHS_BETWEEN (d1, d2) between the two dates the value of the month, d1 &lt;d2 return negative <br /> NEXT_DAY (d) the date the return value of the date of the next day <br /> SYSDATE The current system time <br /> DUAL is the SYS user of an empty table, it is only one dummy field <br /> 4. Transfer function (1) <br /> TO_CHAR (date, &#39;date format&#39;) <br /> TO_CHAR (number) used to display or report format aligned <br /> TO_DATE (char, &#39;date format&#39;) <br /> Long field TO_LOB to lob into the field <br /> TO_NUMBER (char) used to calculate or compare the size of <br /><br /> 4. Transfer function (2) <br /> to_date date in display format <br /> YYYY-year YEAR YYY YY Y <br /> Q quarter <br /> MM on MONTH MON <br /> W week (week of month) WW, IW (week of year)<br /> (Note: weeks are based on ISO standards, from January 1 after the number of weeks to seven days to one week, may not necessarily be from Monday to Sunday) <br /> DD on DAY DY <br /> HH12 HH-hour HH24 <br /> MI-minute <br /> SS seconds if you want a fixed date display format parameter can be in the database in the new document to write his initorasid.ora parameter NLS_DATE_FORMAT = yyyy-mm-dd hh24: mi: ss in the NT or UNIX environment variable settings in the registry NLS_DATE_FORMAT = yyyy-mm-dd hh24: mi: ss <br /><br /> 4. Transfer function (3) <br /> If you want a fixed date display format can be used alter session command to change <br /> SQL&gt; alter session set nls_date_format = &#39;yyyy-mm-dd hh24: mi: ss&#39;; <br /> Its role in the following order: <br /> initialization parameter <br /> Environment variable <br /> ALTER SESSION command <br /><br /> 4. Transfer function (4) <br /> to_char (number) in the number display format <br /> 9 the number of spaces <br /> 0 the number of front fill 0 to_char (-1200,&#39;00000 .00 &#39;) <br /> . Decimal point position <br /> , Marking the location of the comma format used in the figures of the left <br /> L according to the database character set plus the currency symbol to_char (-1200, &#39;L9999.99&#39;) <br /> B shows the number of 0 for the space, the figures used in the right format <br /><br /> MI negative tags right to_char (-1200,&#39;9999 .99 MI &#39;) <br /> The negative PR enclose to_char (-1200,&#39;9999 .99 PR &#39;) <br /> EEEE index expressed by to_char (-1200,&#39;9999 .99 EEEE &#39;) <br /><br /> 5. Enter the characters, the return of the number of function <br /> instr (c1, c2) characters appear in the c2 position c1, there is no return to 0, commonly used in the fuzzy query <br /> length? by the database character set, calculate the length of characters c, with the database character set, and a length of 1 character <br /><br /> 6. Logical comparison function NVL (EXPR1, EXPR2) Function explanation: IF EXPR1 = NULL RETURN EXPR2 <br /> ELSE RETURN EXPR1 <br /> DECODE (AA, V1, R1, V2, R2 ....) interpretation function: IF AA = V1 THEN RETURN R1 <br /> IF AA = V2 THEN RETURN R2 <br /> .. ... <br /> ELSE <br /> RETURN NULL <br /> For example: decode (id, 1, &#39;dept sale&#39;, 2, &#39;dept tech&#39; <br /><br /> ////////////////////////////////////////////////// ////// <br /><br /><table cellspacing=0 cellpadding=0 width="87%" border=0><tbody><tr><td> <font face=黑体,sans-serif>Fourth, select the data from multiple table records <br /> 1. The connection between data tables connected simple syntax: <br /> SELECT fields of 1, Field Name 2, ... ... FROM table 1, [table 2, ... ...] <br /> WHERE table 1. Field name = table name 2. Fieldname [AND ... ...]; <br /> SELECT fields of 1, Field Name 2, ... ... FROM table 1, [table 2, ... ...] <br /> WHERE table 1. Field name = table name 2. Field Name (+) [AND ... ...]; <br /> There are (+)</font> of <font face=黑体,sans-serif>the field-position auto-fill empty value <br /><br /> Connect with the classification: <br /> Equivalent to the connection = <br /> The connection does not mean that! = BETWEEN ... AND ... IN attention with IN and OR can not be connected with a field outside of (+), does not meet the conditions for space-fill value from a table to connect with their own connections with their own example to find duplicate records <br /><br /> 2. Datasheets example to delete the link between the exterior field names table_name duplicate records email: <br /> SQL&gt; delete from table_name t1 <br /> where t1.rowid&gt; <br /> (select min (rowid) from table_name t2 <br /> where</font> t1.email <font face=黑体,sans-serif>= t2.email <br /> group by email <br /> having count (email)&gt; 1); <br /><br /> Mobile phone users to find the service area: <br /> SQL&gt; select a.handphoneno,</font> nvl <font face=黑体,sans-serif>(c.name, &#39;null&#39;), a.totalscore <br /> from topscore a,</font> chargeoperator <font face=黑体,sans-serif>cc,</font> chargeoperatorinfo <font face=黑体,sans-serif>c <br /> where substr (a.handphoneno, 1,7) = cc.hpnohead (+) <br /> and</font> cc.chargetype <font face=黑体,sans-serif>= c.chargetype (+) <br /> order by</font> a.totalscore <font face=黑体,sans-serif>desc; <br /><br /> 3. Datasheets skills to connect the link between the N tables, the need for N-1 connections table are connected to operate the best characters to build a single alias, field names with the single character before the alias <br /> BETWEEN .. AND .. than&gt; = AND &lt;= is better to connect the field of operation should be the best index of the field operation to connect the best type by an integer number of things connected, can not be used OR or IN comparison operator <br /><br /> 4. How to analyze and implement multi-table SQL statement to connect write SQL statements to know that its analysis of implementation of the plan. <br /> Sys users run @ / ORACLE_HOME / sqlplus / admin / plustrce.sql <br /> Plustrace have a role <br /> Sys users given this role under the general user SQL&gt; grant plustrace to</font> &amp;username; <font face=黑体,sans-serif><br /> Run under the general user @ / ORACLE_HOME / rdbms / admin / utlxplan.sql <br /> Have plan_table <br /> SQL&gt; set time on; Description: Open the time display <br /> SQL&gt; set autotrace on; Description: Open the automatic analysis of statistics, SQL statement and display the results <br /> SQL&gt; set autotrace traceonly; Description: Open the automatic analysis of statistics, do not show the results of SQL statements to run the next test you run SQL statements, see the results of its analysis. <br /> In general, the SQL statement that we should avoid large table full table scan. <br /> SQL&gt; set autotrace off; Description: turn off the automatic analysis of statistics</font> </td></tr></tbody></table><br /><br /> <font face=黑体,sans-serif>Fifth, the collection function and group by together with the regular use of <br /> 1. Collection function list <br /> AVG (DISTINCT | ALL | N) averaged <br /> COUNT (DISTINCT | ALL | N | expr | *) statistics on the number of</font><br /> MAX (DISTINCT | ALL | N) from the maximum <br /> MIN (DISTINCT | ALL | N) from the minimum <br /> SUM (DISTINCT | ALL | N) from the total value of <br /> STDDEV (DISTINCT | ALL | N) deviation from the value, if the group have the same choice of content, the result is 0 <br /> VARIANCE (DISTINCT | ALL | N) from the square deviation <br /><br /> 2. The use of a collection of grammatical function <br /> SELECT column, group_function FROM table <br /> WHERE condition GROUP BY group_by_expression <br /> HAVING group_condition ORDER BY column; <br /><br /> 3. The use of count Notes <br /> SELECT COUNT (*) FROM table; <br /> SELECT COUNT (constant) FROM table; <br /><br /> Are recorded in the number of tables, if there is no better than some of the latter PK <br /> SELECT COUNT (all field names) FROM table; <br /> SELECT COUNT (fieldname) FROM table; <br /><br /> Not the field statistics for the number of NULL <br /> SUM, AVG will be ignored when the field is NULL <br /><br /> 4. With the group by time constraints <br /> SELECT field names can not be, to be included in the field in the GROUP BY <br /> ORDER BY after the GROUP BY can not be used when the alias restrictions on the location of symbols and display the results of GROUP BY, and HAVING conditions <br /><br /> 5. Examples of <br /> SQL&gt; select title, sum (salary) payroll from s_emp <br /> where title like &#39;VP%&#39; group by title <br /> having sum (salary)&gt; 5000 order by sum (salary) desc; <br /><br /> Exterior field to identify a number of duplicate records, and display <br /> SQL&gt; select (duplicate field names) from table_name <br /> group by (list out fields) having count (*)&gt; 1; <br /><br /> 6. To determine questions (T / F) <br /> (1) Group functions include nulls in calculations [F] <br /> (2) Using the having clause to exclude rows from a group calculation [F] <br /> Explained: <br /> Group function are neglected NULL values NULL If you want to calculate value, using NVL function <br /> Where in the Group By statement before the result set Having excluded in the Group By statement after the result set to exclude <br /><br /> 7. SQL * PLUS can be used in other command: <br /><br /> Ctrl ^ C to terminate the SQL statement is running <br /> remark /*...*/ - Note symbol <br /> HOST executable command under the operating system can use some unix! <br /><br /> BREAK ON column_name SKIP n [ON column_name SKIP n] <br /> According to the name field separated by column_name show more clearly, SKIP n Department in the blank lines to separate the number of n <br /> BREAK ON ROW SKIP n between each line is put a blank line n <br /><br /> COMPUTE collection OF field operator 1 ON field 2 field 2 on the field by a collection of operations carried out <br /> COMPUTE back to work with a collection of operators: <br /> SUM MINIMUM MAXIMUM AVG STD VARIANCE COUNT NUMBER <br /><br /> 8. In SQL * PLUS can be used in other commands, for example: (scott users) <br /><br /> BREAK ON REPORT <br /> COMPUTE SUM LABEL TOTAL OF SAL ON REPORT behind in the count all the result sets together <br /> select ename, sal from emp where job = &#39;SALESMAN&#39;; <br /><br /> COMPUTE AVG LABEL avg OF SAL ON REPORT in all the result set back the average balance <br /> / Re-implementation of the last sql statement <br /><br /> break on DEPTNO skip 2 on JOB skip 1 fields in the result set back BREAK total count <br /> COMPUTE SUM OF SAL ON DEPTNO <br /> SELECT DEPTNO, JOB, ENAME, SAL FROM EMP ORDER BY DEPTNO, JOB; <br /><br /> SQL&gt; CLEAR BREAKS; clear conditions set BREAK <br /> SQL&gt; CLEAR COMPUTES; clear conditions set COMPUTE <br /><br /> <font face=黑体,sans-serif>VI subquery <br /> 1. For example, can be nested query: SELECT ... ... FROM (SELECT ... ... FROM table 1, [table 2, ... ...] WHERE conditions) WHERE condition 2; <br /><br /> 2. Subquery can be used where? <br /> When the query is uncertain conditions <br /> DML (insert, update, delete) statement can also be used in subquery <br /> HAVING can also be used in subquery <br /><br /> 3. The results of two query set operation can be done such as: <br /> And set UNION (removing duplicate records) <br /> And set UNION ALL (do not remove duplicate records) <br /> Difference Sets MINUS, <br /> Intersection INTERSECT <br /><br /> 4. Subquery matters to the attention of the implementation of the SQL statement inside the brackets, the outside layers to the implementation of an internal inquiry only if the inner layer of the result set to return to a number, can not be used =&gt; &lt;&gt; = &lt;= comparison site to use, such as IN . <br /><br /> 5. Subquery examples of (1) <br /> SQL&gt; select title, avg (salary) from</font> s_emp <font face=黑体,sans-serif><br /> group by title Having avg (salary) = <br /> (select min (avg (salary)) from</font> s_emp <font face=黑体,sans-serif><br /> group by title); <br /> Find the minimum average wage of job titles and wages <br /><br /> 5. Subquery examples (2) <br /> Subquery can query the parent table in the SQL statement that is correct: <br /> SQL&gt; select</font> cty_name <font face=黑体,sans-serif>from city where</font> st_code <font face=黑体,sans-serif>in <br /> (select</font> st_code <font face=黑体,sans-serif>from state where</font> st_name <font face=黑体,sans-serif>= &#39;TENNESSEE&#39; and <br /> city.cnt_code = state.cnt_code); <br /> Note: For inquiries, call the parent subquery only once. <br /><br /> 6. Sets out the results of 8-10&#39;s SQL statement <br /> ORACLE to deal with each set of results indicate that there is only one field ROWNUM the logic of its position, <br /> And can only be used ROWNUM &lt;100, can not be used ROWNUM&gt; 80. <br /> The following is an analysis of two ORACLE better results</font> 80-100 <font face=黑体,sans-serif>sets the SQL statement (ID is the only keyword field names): <br /> Written statement: <br /> SQL&gt; select * from ( <br /> (Select rownum as numrow, c. * from (</font><br /> select [field_name ,...] from table_name where condition 1 order by conditions 2) c) <br /> where numrow&gt; 80 and numrow &lt;= 100) <br /> order by the conditions of 3; <br /><br /> Seven, in the implementation of SQL statements to bind variables when <br /> 1. To receive and the definition of variables SQL * PLUS command <br /> ACCEPT <br /> DEFINE UNDEFINE <br /> &amp; <br /><br /> 2. Bind variable SQL statement examples (1) <br /> SQL&gt; select id, last_name, salary from s_emp where dept_id = &amp; department_number; <br /> Enter value for department_number: 10 <br /> old 1: select id, last_name, salary from s_emp where dept_id = &amp; department_number; <br /> new 1: select id, last_name, salary from s_emp where dept_id = 10 <br /> SQL&gt; SET VERIFY OFF | ON; can close and open the confirmation prompt old 1 and new 1&#39;s shows. <br /><br /> 3. Bind variable SQL statement examples (2) <br /> SQL&gt; select id, last_name, salary <br /> from s_emp <br /> where title = &#39;&amp; job_title&#39;; <br /> Enter value for job_title: Stock Clerk <br /><br /> SQL&gt; select id, last_name, salary <br /> from s_emp <br /> where hiredate&gt; to_date ( &#39;&amp; start_hire_date&#39;, &#39;YYYY-MM-DD&#39;); <br /> Enter value for start_hire_date: 2001-01-01 <br /><br /> To bind the type of string and date variables, the variables to be added outside the single quotation marks can also bind variables to query the different fields of input variables when the value will not increase; and other symbols <br /><br /> 4. ACCEPT syntax and examples <br /> SQL&gt; ACCEPT variable [datatype] [FORMAT] [PROMPT text] [HIDE] <br /> Note: variable variable name refers to the type of datatype refers to variables such as number, char variables, such as display format format means prompt text can be customized pop-up prompt hidden text hide the contents of the user&#39;s input ACCEPT examples of the use of symbols: <br /> ACCEPT p_dname PROMPT &#39;Provide the department name:&#39; <br /> ACCEPT p_salary NUMBER PROMPT &#39;Salary amount:&#39; <br /> ACCEPT pswd CHAR PROMPT &#39;Password:&#39; HIDE <br /> ACCEPT low_date date format &#39;YYYY-MM-DD&#39; PROMPT &quot;Enter the low date range ( &#39;YYYY-MM-DD&#39;):&quot; <br /><br /> 4. DEFINE syntax and examples <br /> SQL&gt; DEFINE variable = value <br /> Note: variable variable name refers to the variable value means the value of the variable definition of a good good value, the implementation of the SQL statements to bind variables when the variables are no longer prompted to enter examples of the use of DEFINE: <br /> SQL&gt; DEFINE dname = sales <br /> SQL&gt; DEFINE dname <br /> DEFINE dname = &quot;sales&quot; (CHAR) <br /> SQL&gt; select name from dept where lower (name) = &#39;&amp; dname&#39;; <br /> NAME <br /> ------------------------- <br /> sales <br /> sales <br /> SQL&gt; UNDEFINE dname <br /> SQL&gt; DEFINE dname <br /> Symbol dname is UNDEFINED <br /><br /> 5. SQL * PLUS in passing parameters to the preservation of good *. sql file <br /> SQL&gt; @ / path name / filename argument to name 1 [, parameter name 2, ....] <br /> SQL&gt; start / path name / filename argument to name 1 [, parameter name 2, ....] <br /><br /> Note: <br /> Can only obtain a maximum of 9 &amp; variable, the variable name can only be from the &amp; 1, &amp; 2 to &amp; 9 <br /> Variable name will not increase after the end of special symbols in to SQL * PLUS Lane &amp; symbols stored in the ORACLE database, it is necessary to amend the sql * plus environment variables define <br /> SQL&gt; set define off; <br /><br /> <font face=黑体,sans-serif>8, an overview of the data model and database design <br /> 1. The stage of system development: <br /> Strategy and Analysis <br /> Design <br /> Build and Document <br /> Transition <br /> Production <br /><br /> 2. Data Model <br /> Model of system in client&#39;s mind <br /> Entity model of client&#39;s model <br /> Table model of entity model <br /> Tables on disk <br /><br /> 3. Entity Relationship Model (ERM) concept <br /> ERM (entity relationship modeling) <br /> Entities have the objective of specific information and events such as: customers, orders and other attributes to describe the attributes of entities such as: name, phone number, such as the relationship between the relationship between two entities such as: order and product model entity-relationship diagrams,</font> etc. <font face=黑体,sans-serif>in the agreement <br /> Dashed line (dotted line) optional parameters &quot;may be&quot; <br /> Solid line (solid line) will be selected parameters &quot;must be&quot; <br /> Crow&#39;s foot (multi-line) the level of the parameters &quot;one or more&quot; <br /> Single line (one-way) the extent of the parameters &quot;one and only one&quot; <br /><br /> 4. Entity relationship model examples of each order must have one or a few customers each customer may be one or more orders of the applicant <br /><br /> 5. The relationship between the type of entity <br /> 1:1 one-to-one example: the taxi and drivers <br /> M: 1 many-to-one for example: passenger and aircraft <br /> 1: M one-to-many example: staff and skills <br /><br /> 6. Correction entities of the principle of the relationship between a single attribute value, there will be no duplication of attributes must be dependent on entities, should be marked not only the sole property of non-dependent on another non-unique attributes <br /> 7. The definition of the structure of Notes to reduce data redundancy to reduce the problem of integrity constraints have omitted to confirm the entities, relations and attributes <br /><br /> 8. The requirements of integrity constraints <br /> Primary key primary key the only non-NULL <br /> Foreign key foreign key depends on a Primary key, may be NULL <br /> Column field names in line with the definition of the type and length of <br /> Constraint constraint bound user-defined conditions,</font> it is necessary <font face=黑体,sans-serif>to meet the requirements of workflow</font><br /> For example: a sales force which can not exceed the percentage of basic salary <br /> Candidate primary key Candidate key field names can be composed of a number of candidates for the main keyword, its portfolio is the only non-NULL and the <br /><br /> 9. The relationship between entities is mapped to the object-relational database approach to a simple entity is mapped to the database table mapped to the attribute table database fields, marked with the type and the Notes to the only tag is mapped to the database only a key word to the relationship between entities is mapped to the database of the foreign key <br /><br /> Other considerations: <br /> The design of the index, so that the establishment of the view query faster, so that the presentation of information have different surface, the SQL statements to reduce the complexity of storage space allocation plans to redefine the conditions of integrity constraints <br /><br /> 10. Entity relationship diagram in the meaning of symbols <br /> PK field is the only keyword <br /> FK a foreign key field <br /> FK1, FK2 a table with two different foreign key <br /> FK1, FK1 two fields together to form a foreign key <br /> NN non-null fields <br /> The only field U <br /> U1, U1 to form two fields a unique field <br /><br /></td></tr></tbody></table></td></tr></tbody></table>				<h5>Related Posts</h5>
		<div id="smilar">
		<ul>
					<li><a href="http://www.kods.netwww.kods.net/rman-created-physical-standby/" title="RMAN created physical standby">RMAN created physical standby</a> 2009-03-30 22:49:29</li>
					<li><a href="http://www.kods.netwww.kods.net/proc-will-select-the-data-on-the-two-dimensional-array/" title="ProC will select the data on the two-dimensional array">ProC will select the data on the two-dimensional array</a> 2009-03-30 11:50:27</li>
					<li><a href="http://www.kods.netwww.kods.net/oracle-locking-mechanism-reprint/" title="Oracle locking mechanism (reprint)">Oracle locking mechanism (reprint)</a> 2009-03-28 05:20:43</li>
					<li><a href="http://www.kods.netwww.kods.net/turning-optimization-oracle-article/" title="Turning optimization oracle article">Turning optimization oracle article</a> 2009-03-26 21:39:35</li>
				</ul>
		</div>
		        ]]></content:encoded>
		<wfw:commentRss>http://www.kods.netwww.kods.net/oracle-sql-and-sql-plus-1/</wfw:commentRss>
	</item>
		<item>
		<title>oracle sql query principle</title>
		<link>http://www.kods.netwww.kods.net/oracle-sql-query-principle/</link>
		<comments>http://www.kods.netwww.kods.net/oracle-sql-query-principle/#comments</comments>
		<pubDate>Wed, 20 May 2009 03:46:59+0000</pubDate>
		<dc:creator>kods.net</dc:creator>
		<category><![CDATA[Oracle SQL]]></category>
		<category><![CDATA[quot]]></category>
<category><![CDATA[implementation plan]]></category>
<category><![CDATA[statement 1]]></category>
<category><![CDATA[syntax analysis]]></category>
<category><![CDATA[index table]]></category>
<category><![CDATA[buffer pool]]></category>
<category><![CDATA[database objects]]></category>
<category><![CDATA[sql statements]]></category>
<category><![CDATA[oracle sql]]></category>
<category><![CDATA[oracle connection]]></category>
<category><![CDATA[memory pool]]></category>
<category><![CDATA[expression 2]]></category>
<category><![CDATA[select connection]]></category>
<category><![CDATA[source table]]></category>
<category><![CDATA[semantic analysis]]></category>
<category><![CDATA[search path]]></category>
<category><![CDATA[data search]]></category>
<category><![CDATA[two tables]]></category>
<category><![CDATA[first high efficiency]]></category>
<category><![CDATA[sql query]]></category>
		<guid isPermaLink="true">http://www.kods.netwww.kods.net/oracle-sql-query-principle/</guid>
		<description><![CDATA[A step in the implementation of sql statement 1) Syntax analysis syntax statement with the norms, measured statement of the meaning of the expression. 2) semantic analysis, to check all statements rel ...]]></description>
		<content:encoded><![CDATA[A step in the implementation of sql statement <br /> 1) Syntax analysis syntax statement with the norms, measured statement of the meaning of the expression. <br /> 2) semantic analysis, to check all statements relating to the existence of database objects, and users have the appropriate permissions. <br /> 3) view of conversion, will involve the view query is converted to the corresponding base form of the query. <br /> 4) The expression of conversion, complex SQL expression is converted to a simpler expression equivalent connection. <br /> 5) Select Optimizer, Optimizer different in general have a different &quot;implementation plan&quot; <br /> 6) Select connection, ORACLE there are three connections on the multi-table connection ORACLE way to choose the appropriate connection. <br /> 7) Select the order to connect to multi-table select which ORACLE connection to connect to the table, select the two tables in which the source table as a data table. <br /> 8) Select the data search path, select the appropriate conditions for the basis of the above data search path, in the case of selection or use of the entire search index table or in other ways. <br /> 9) run &quot;implementation plan&quot; <br /><br /> Second, the principle of shared oracle <br /> ORACLE will be implemented over the SQL statements stored in the shared memory pool (shared buffer pool), you can by all users to share the database when you implement a SQL statement (sometimes called a cursor), if it is before carried out exactly the same statement, ORACLE has been able to quickly resolve the statement, as well as the implementation of the best path. This feature greatly enhance the performance of the SQL and save the use of memory to improve query efficiency statement oracle approach <br /> .1: .. Where column in (select * from ... where ...); <br /> 2: ... where exists (select &#39;X&#39; from ... where ...); <br /> The second format to a format than the first high efficiency. Oracle can be in almost all of the IN operator subquery rewritten to use the EXISTS subquery use EXIST, Oracle will first check the system operator, and then run until it subquery to find the first match, which saves time <br /> Oracle system in the implementation of IN subquery, the first implementation of sub-queries, and results in a list stored in a temporary increase in the index table <br /><br /> Avoid the use of words to avoid having to use HAVING clause, HAVING retrieved only after all records should filter the result set. This sort to deal with the need for a total of such operations. If the WHERE clause can limit the number of records that can be reduced spending in this area				<h5>Related Posts</h5>
		<div id="smilar">
		<ul>
					<li><a href="http://www.kods.netwww.kods.net/sql-optimization-1-full-table-scan-and-index-the-test/" title="SQL optimization (1) - full table scan and index the test">SQL optimization (1) - full table scan and index the test</a> 2009-03-28 09:02:39</li>
					<li><a href="http://www.kods.netwww.kods.net/oracle-locking-mechanism-reprint/" title="Oracle locking mechanism (reprint)">Oracle locking mechanism (reprint)</a> 2009-03-28 05:20:43</li>
					<li><a href="http://www.kods.netwww.kods.net/oracle10g-with-cross-platform-endian-transfer/" title="Oracle10g with cross-platform endian transfer">Oracle10g with cross-platform endian transfer</a> 2009-03-14 22:09:48</li>
					<li><a href="http://www.kods.netwww.kods.net/diagnosis-and-principles-of-order/" title="Diagnosis and principles of order">Diagnosis and principles of order</a> 2009-02-25 20:27:28</li>
				</ul>
		</div>
		        ]]></content:encoded>
		<wfw:commentRss>http://www.kods.netwww.kods.net/oracle-sql-query-principle/</wfw:commentRss>
	</item>
		<item>
		<title>Oracle SQL optimization principles (pick)</title>
		<link>http://www.kods.netwww.kods.net/oracle-sql-optimization-principles-pick/</link>
		<comments>http://www.kods.netwww.kods.net/oracle-sql-optimization-principles-pick/#comments</comments>
		<pubDate>Wed, 20 May 2009 02:43:26+0000</pubDate>
		<dc:creator>kods.net</dc:creator>
		<category><![CDATA[Oracle SQL]]></category>
		<category><![CDATA[oracle]]></category>
<category><![CDATA[select count]]></category>
<category><![CDATA[lt]]></category>
<category><![CDATA[circumstances]]></category>
<category><![CDATA[sql command]]></category>
<category><![CDATA[database environment]]></category>
<category><![CDATA[realization]]></category>
<category><![CDATA[sql optimization]]></category>
<category><![CDATA[oracle sql]]></category>
<category><![CDATA[optimization principles]]></category>
<category><![CDATA[proper optimization]]></category>
<category><![CDATA[sql analysis]]></category>
<category><![CDATA[sql 1]]></category>
<category><![CDATA[index design]]></category>
<category><![CDATA[oltp]]></category>
<category><![CDATA[complex system]]></category>
<category><![CDATA[transaction processing]]></category>
<category><![CDATA[misunderstanding]]></category>
<category><![CDATA[neglect]]></category>
<category><![CDATA[excerpts]]></category>
		<guid isPermaLink="true">http://www.kods.netwww.kods.net/oracle-sql-optimization-principles-pick/</guid>
		<description><![CDATA[When people in the use of SQL in a misunderstanding sometimes, that is too much focus on the result SQL is correct, the neglect of the realization of the different methods that may exist between the d ...]]></description>
		<content:encoded><![CDATA[When people in the use of SQL in a misunderstanding sometimes, that is too much focus on the result SQL is correct, the neglect of the realization of the different methods that may exist between the differences in performance, in particular the statements of Web more complex system used Select the command of the complex or large database environment (such as online transaction processing OLTP) has been particularly evident after the application of the relevant SQL analysis and related data collection, we find that bad from the SQL Command is often inappropriate index design, the connection is not fully optimized conditions and not where clause. in their proper optimization, its speed has improved! The following is a summary and excerpts of some optimization principles. <br /><br /> When people in the use of SQL in a misunderstanding sometimes, that is too much focus on the result SQL is correct, the neglect of the realization of the different methods that may exist between the differences in performance, in particular the statements of Web more complex system used Select the command of the complex or large database environment (such as online transaction processing OLTP) has been particularly evident after the application of the relevant SQL analysis and related data collection, we find that bad from the SQL Command is often inappropriate index design, the connection is not fully optimized conditions and not where clause. in their proper optimization, its speed has improved! The following is a summary and excerpts of some optimization principles: <br /><br /> <strong>A. Index unreasonable design</strong> <br /><br /> Example: Table 620,000 recorded in the record line, take a look at the index in different circumstances, following the operation of SQL: <br /><br /> 1. In the field has a date on a non-clustered index <br /><br /> Select count (*) from record where date&gt;&#39;19991201 &#39;and date &lt;&#39;19991214&#39; and amount&gt; 2000 (25 seconds) <br /><br /> Select date, sum (amount) from record group by date (55 seconds) Select count (*) from record where date&gt;&#39;19990901 &#39;and place in (&#39; BJ &#39;,&#39; SH &#39;) (27 seconds) <br /><br /> Analysis: Record on a large number of repeat value, in a non-clustered index, the data is physically stored in data random page, in the scope of search, it is important to the implementation of a table scan to find all of the line. <br /><br /> 2. In the date field to build a clustered index on <br /><br /> Select count (*) from record where date&gt; <br /><br /> &#39;19991201 &#39;And date &lt;&#39;19991214&#39; and amount&gt; 2000 (14 seconds) Select date, sum (amount) from record group by date (28 seconds) Select count (*) from record where date&gt;&#39;19990901 &#39;and place in ( &#39;BJ&#39;, &#39;SH&#39;) (14 seconds) <br /><br /> Analysis: In the clustered index, the data in the physical sequence in the data page, together with repeat value, which in the scope of search can be found at the end of this range from points, and only in the range of scan data page to avoid a large-scale scanning, to improve query speed. <br /><br /> 3. In the place, date, amount of the combination of the index <br /><br /> Select count (*) from record where date&gt;&#39;19991201 &#39;and date &lt;&#39;19991214&#39; and amount&gt; 2000 (26 seconds) select date, sum (amount) from record group by date (27 seconds) select count (*) from record where date&gt;&#39;19990901 &#39;and place in (&#39; BJ, &#39;SH&#39;) (&lt;1 sec) <br /><br /> Analysis: This is a reasonable combination of the index, because it is the pre-out place, the first and second SQL does not refer to place, and therefore did not make use of the index; third SQL used place, and all listed references are included in the index portfolio, the formation of the index coverage, its speed is very fast <br /><br /> 4. In the date, place, amount on a combination of the index <br /><br /> select count (*) from record where date&gt; <br /><br /> &#39;19991201 &#39;And date &lt;&#39;19991214&#39; and amount&gt; 2000 (&lt;1 seconds) select date, sum (amount) from record group by date (11 seconds) select count (*) from record where date&gt;&#39;19990901 &#39;and place in ( &#39;BJ&#39;, &#39;SH&#39;) (&lt;1 sec) <br /><br /> Analysis: This is a reasonable combination of the index. Date it as pre-out so that everyone can use SQL indexes, and in the first and the third formed SQL index coverage, and thus achieve the optimal performance. <br /><br /> 5. Summary: <br /><br /> Default index to establish a non-clustered index, but sometimes it is not the best; rational design of the index based on a variety of query analysis and forecasting. In general: <br /><br /> ①. A large number of repeat value, and often the scope of inquiry (between,&gt;, &lt;,&gt;=,&lt; =) and order by, group by the occurrence of the series may wish to consider the establishment of the cluster index; <br /><br /> ②. Often at the same time access to multi-column, and each column contains duplicate values could be considered the establishment of the index portfolio; <br /><br /> ③. Portfolio index should be as far as possible the formation of the key index query coverage, the pre-column must be listed the most frequently used. <br /><br /> <strong>B. Connect inadequate conditions:</strong> <br /><br /> Example: there are 7896 line card table in card_no, there is a non-clustered index, table line account has 191,122 in account_no, there is a non-clustered index, take a look at the table to connect in different conditions, both the implementation of SQL: <br /><br /> select sum (a.amount) from account a, card b where a.card_no = b.card_no (20 seconds) <br /><br /> SQL change to: select sum (a.amount) from account a, card b where a.card_no = b.card_no and a.account_no = b.account_no (&lt;1 sec) <br /><br /> Analysis of connectivity in the first :---- conditions, the best query program is to account for the outer table, card table for the inner layer, using the index card, its I / O number estimated by the following formula: <br /><br /> ---- Account on the outer table of the 22,541 + (outer table account of the inner table * 191,122 line card on the first line corresponds to the outer table to be looking for 3) = 595907 times I / O <br /><br /> ---- In the second connecting condition, the best card is to query the program for the outer table, account for the inner table, use the index on account of its I / O number estimated by the following formula: <br /><br /> ---- Card on the outer table of the 1944 + (the outer table of the 7896 line card * account on the inner table each line corresponds to the outer table to be looking for 4) = 33528 times I / O <br /><br /> ---- Can be seen, only the fully connected condition, the real implementation will be the best option. <br /><br /> Summary: <br /><br /> 1. Multi-table in the actual implementation of the operation before the Query Optimizer connect the light conditions, the possible sets of connectivity solutions and systems to find the best option for the smallest expenses. To take full account of the conditions connected with the index table, number of table rows; with the appearance of choice may be the formula: the matching outer table rows * inner table to find the number of each identified as the best product of the smallest program. <br /><br /> 2. See the implementation of the program&#39;s methods - using set showplanon, open showplan option, you can see the connection sequence, the use of what the index information; want to see more detailed information, necessary to implement sa role dbcc (3604,310,302) . <br /><br /> <strong>C. The where clause can not be optimized</strong> <br /><br /> 1. For example: the conditions of the following SQL statements are built out of a proper index, but the speed is very slow: <br /><br /> Select * from record where substring (card_no, 1,4) =&#39;5378 &#39;(13 seconds) select * from record where amount/30 &lt;1000 (11 seconds) select * from record where convert (char (10), date, 112 ) =&#39;19991201 &#39;(10 seconds) <br /><br /> Analysis: where clause in the list of the results of any operation in the SQL run-time calculated by column, so it had to form a search and did not use the index above the column; If these results can be compile-time query available, it can be optimized SQL Optimizer, use the index to avoid the table search, it will be re-written in SQL to do the following: <br /><br /> select * from record where card_no like&#39;5378% &#39;(&lt;1 seconds) select * from record where amount &lt;1000 * 30 (&lt;1 seconds) select * from record where date =&#39;1999 / 12/01&#39; (&lt;1 sec) you will find it much faster than the SQL! <br /><br /> 2. For example: table stuff has 200,000 lines, id_no on non-clustered index, see the following SQL: <br /><br /> select count (*) from stuff where id_no in (&#39;0 &#39;,&#39;1&#39;) (23 seconds) <br /><br /> Analysis: where the conditions of the &#39;in&#39; in the logical equivalent of &#39;or&#39;, so the parser in (&#39;0 &#39;,&#39;1&#39;) into id_no =&#39;0 &#39;or id_no =&#39;1&#39; to perform. We hope that it will or clause, respectively, according to each search, and then add up the results, it can make use of the index id_no; but in fact (according to showplan), it adopted the &quot;OR strategy&quot;, that is, first out to meet each or clause of the line, into the temporary database table, and then create a unique index to remove duplicate lines, and finally from the temporary table to calculate the results. Therefore, the actual process of id_no did not make use of the index, and also by the completion time performance of tempdb database. <br /><br /> Practice has proved that the number of rows in table the more work the worse the performance table, when the stuff when there are 620000, the execution time reached 220 seconds! Might as well be separate or clause: <br /><br /> select count (*) from stuff where id_no =&#39;0 &#39;select count (*) from stuff where id_no =&#39;1&#39; <br /><br /> The results obtained from the two, and then make a worthwhile addition. Because every use of the index, the execution time is only three seconds, in the next 620,000 lines, and time is only 4 seconds. Or, better still, write a simple stored procedure to calculate the direct results of the execution time as fast as with the above! <br /><br /> Summary: <br /><br /> Can be seen that the so-called optimized use of the index where clause can not be optimized that have taken place in a table scan or additional overhead. <br /><br /> ---- 1. Any of the operations listed will result in a table scan, which includes a database function, the calculation expression, etc., inquiries should be moved as far as possible to equate the right side of the operation. <br /><br /> ---- 2.in, or clause regular use of the work table, so that failure index; If you do not have a lot of repeat value, you can consider opening clause; break clause should be included in the index. <br /><br /> ---- 3. To be good at using the stored procedure, which allows SQL to become more flexible and efficient. <br /><br /> ---- From the above we can see these examples, SQL optimization is the result of the substance of the right under the premise of optimizing the device can be identified with the statement, take full advantage of indexing to reduce the table scan of the I / O frequency, to avoid the search form from happening. In fact, SQL performance optimization is a complex process, the above-mentioned levels in the application of these are just a reflection, in-depth study will involve the allocation of resources database layer, network layer, as well as the flow control layer of the operating system design. <br /><br /> <strong>The following is a summary of SFC systems optimized SQL principles:</strong> <br /><br /> 1. Prohibition of unnecessary and unnecessary full table scan of query, such as Select serial_number, mo_number from sfism4.r_wip_tracking_t Where model_name like &#39;%&#39; and Select serial_number, mo_number from sfism4.r_wip_tracking_t statements have the same results, but the speed of operation the latter about 10 times faster (when the data were more than the obvious). <br /><br /> 2. Multi-table query, the amount of data on the table in front of a small speed increase <br /><br /> For example: select count (*) from r_repair_t a, r_sn_detail_t b <br /><br /> where a.serial_number = b.serial_number <br /><br /> Faster than the statistics do select count (*) from r_sn_detail_t b, r_repair_t a <br /><br /> where a.serial_number = b.serial_number the statistics of high-speed <br /><br /> 3. A number of conditions, the conditions found to be small immediately behind where. <br /><br /> For example: <br /><br /> where in_station_time&gt; = sysdate-20 and in_station_time&gt; = sysdate-1 <br /><br /> where in_station_time&gt; = sysdate-1 and in_station_time&gt; = sysdate-20 <br /><br /> Investigate and deal with these two statements is the same as the number of statistics, but behind the pace has greatly statement <br /><br /> The increased speed. <br /><br /> 4. In the free time query statistics when to_char conditions as far as possible not to use statistics, but statistics on the use of to_date conditions <br /><br /> For example: <br /><br /> select * from r_wip_tracking_t <br /><br /> where to_char ( &#39;yyyyymmddhh24&#39;, &#39;in_station_time&#39;)&gt; = &#39;20020101000000&#39; <br /><br /> The for in_station_time&gt; = to_date (&#39;20020101000000 &#39;,&#39; yyyymmddhh24miss&#39;) <br /><br /> The use of such a query to the index element in_station_time field, the speed improved statistics, this statement of the use of a large number of seriously affected performance. <br /><br /> The following is a excerpt of the SQL statements to optimize the principles of writing (for reference): <br /><br /> 1 to avoid unplanned full table scan <br /><br /> The following full-table scan: <br /><br /> - The table-free index <br /><br /> - No one on the line to return to the conditions and restrictions (no Where clause) <br /><br /> - The index of the main column (the first column of index) unrestricted conditions <br /><br /> - The main index of the conditions set out in the expression containing <br /><br /> - The main index is out of the constraints is (not) null or! = <br /><br /> Out on the main index of the restrictions and the value of the operation is like a bind variable or% of the value of the head <br /><br /> Selective use of two index <br /><br /> Selectivity index is the index column is worth a different number and the number of signs than the record, the best non-selective and air out the only index of 1.0. <br /><br /> Composite index of the issue of the order listed: <br /><br /> 1 in the qualification of the most frequently used is the main column should be included <br /><br /> 2 out of the most selective (that is, clear out the most) should be the main out <br /><br /> If 1 and 2 are inconsistent, you can consider the establishment of a number of the index. <br /><br /> In the composite index and the index for more than a single choice: <br /><br /> Consider the selective index to consider the number of readers consider the AND-EQUAL operation <br /><br /> 3 the management of multi-table connection (Nested Loops, Merge Joins and Hash Joins) connection optimization operation <br /><br /> Merge Joins the collection operation Hash Joins and Nested Loops is the first record of the operation to return to record rapid <br /><br /> Merge Joins operation applied to a batch operation, form a huge and long-range query <br /><br /> 1 full table scan -&gt; 2 Sort -&gt; 3, the performance comparison and merger of the major expenses in the former two-step <br /><br /> Applicable to the case of full-table scan, it applies to all operations Merge Joins (Nested Loops than effective). <br /><br /> To improve the efficiency of 1: Optimizing I / O, use of ORACLE to enhance the capacity of multi-block read, the use of parallel query option <br /><br /> To improve the efficiency of 1: To improve the value of Sort_Area_Size, use the Sort Direct Writes, for the provision of a dedicated temporary table space paragraph <br /><br /> 4, the management of the SQL statement contains the view <br /><br /> Optimizer implementation of the SQL statement contains the view that there were two ways: <br /><br /> - First implementation of view, to complete a full set of results, and then the rest of the query filter for the implementation of inquiry <br /><br /> - Will be integrated into the query text view into <br /><br /> The group by clause contains a view can not be integrated into a query to. <br /><br /> In view of the use of union, non-stop view into the SQL syntax to query. <br /><br /> 5 subquery optimization <br /><br /> 6 the use of composite Keys / Star query <br /><br /> 7 Index Connect By proper operation <br /><br /> 8 to limit access to the remote table <br /><br /> 9 great management table visit <br /><br /> - Manage data close (proximity) recorded in the table to deposit a range of table used to scan the longest to sort out the order they were asked to contribute to the scan data, especially for large tables. <br /><br /> - To avoid scanning the index does not help when returning large data set, use the index on the SGA cache of data blocks occupied by a larger impact on other users; can scan the entire table from ORACLE to read the multi-block mechanism and the &quot;consistency access / each &quot;benefit characteristics. <br /><br /> - Create a fully indexed access to the table so that a more comprehensive index to read only the data set for different number of main index <br /><br /> - Create a hash cluster <br /><br /> - Create a partition table and view <br /><br /> - The use of parallel options <br /><br /> 10 using the Union All instead of Union <br /><br /> UNION ALL operator does not include the Sort Unique operation, the first line of response retrieval speed, most cases do not complete the operation of temporary paragraph, <br /><br /> The establishment of the UNION ALL view can be used in the query into the query syntax, and improve efficiency <br /><br /> 11, refrain from the use of SQL in PL / SQL function calls <br /><br /> 12 bind variables (Bind Variable) the use of management <br /><br /> Bind Variable and use Execute using methods <br /><br /> Will be like: name ||&#39;%&#39; read between: name and: name | | char (225), has been to avoid full-table scan, but the use of the index. <br /><br /> Optimization of the process of return of 13 <br /><br /> Data changes, the re-optimization case study				<h5>Related Posts</h5>
		<div id="smilar">
		<ul>
					<li><a href="http://www.kods.netwww.kods.net/sga-extended-the-principle-of-32bit-oracle/" title="SGA extended the principle of 32bit oracle">SGA extended the principle of 32bit oracle</a> 2009-03-31 09:48:01</li>
					<li><a href="http://www.kods.netwww.kods.net/high-availability-oracle-flashback/" title="High Availability Oracle Flashback">High Availability Oracle Flashback</a> 2009-02-26 17:23:02</li>
					<li><a href="http://www.kods.netwww.kods.net/an-example-of-the-use-of-tkprof/" title="An example of the use of TKPROF">An example of the use of TKPROF</a> 2009-02-26 01:38:19</li>
					<li><a href="http://www.kods.netwww.kods.net/diagnosis-and-principles-of-order/" title="Diagnosis and principles of order">Diagnosis and principles of order</a> 2009-02-25 20:27:28</li>
					<li><a href="http://www.kods.netwww.kods.net/oracle-10g-dataguard-configuration-step-by-step/" title="ORACLE 10G dataguard configuration Step by Step">ORACLE 10G dataguard configuration Step by Step</a> 2009-02-16 01:13:55</li>
				</ul>
		</div>
		        ]]></content:encoded>
		<wfw:commentRss>http://www.kods.netwww.kods.net/oracle-sql-optimization-principles-pick/</wfw:commentRss>
	</item>
		<item>
		<title>shell script examples of the implementation of Oracle SQL script</title>
		<link>http://www.kods.netwww.kods.net/shell-script-examples-of-the-implementation-of-oracle-sql-script/</link>
		<comments>http://www.kods.netwww.kods.net/shell-script-examples-of-the-implementation-of-oracle-sql-script/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 06:08:39+0000</pubDate>
		<dc:creator>kods.net</dc:creator>
		<category><![CDATA[Oracle SQL]]></category>
		<category><![CDATA[oracle]]></category>
<category><![CDATA[oracle home]]></category>
<category><![CDATA[select count]]></category>
<category><![CDATA[colleagues]]></category>
<category><![CDATA[sql script]]></category>
<category><![CDATA[buffer size]]></category>
<category><![CDATA[quot quot]]></category>
<category><![CDATA[result set]]></category>
<category><![CDATA[eoss]]></category>
<category><![CDATA[shell script examples]]></category>
<category><![CDATA[oracle sql]]></category>
<category><![CDATA[column headings]]></category>
<category><![CDATA[output settings]]></category>
<category><![CDATA[input parameter]]></category>
<category><![CDATA[path path]]></category>
<category><![CDATA[script name]]></category>
<category><![CDATA[program 1]]></category>
<category><![CDATA[cur]]></category>
<category><![CDATA[apps]]></category>
<category><![CDATA[search result]]></category>
		<guid isPermaLink="true">http://www.kods.netwww.kods.net/shell-script-examples-of-the-implementation-of-oracle-sql-script/</guid>
		<description><![CDATA[A survey of my colleagues to write the script EBS information. # Standard output settings, the use of DBMS_OUTPUT.put_line () output to the screen. # size the buffer size settings. set SERVEROUTPUT ON ...]]></description>
		<content:encoded><![CDATA[A survey of my colleagues to write the script EBS information. <br /><table"border: 1px solid rgb(153, 153, 153); width: 80%; font-size: 12px;" align="center"><tbody><tr><td> # <font size="-1">Standard output settings, the use of DBMS_OUTPUT.put_line () output to the screen. <br /> # size the buffer size settings.</font> <br /> set SERVEROUTPUT ON size 100000; <br /> # Search result set rows <br /> set FEEDBACK OFF; <br /> # Whether to display the results of the first information <br /> set HEADING OFF; <br /> # Whether to display the command <br /> set ECHO OFF; <br /> # If set to 0, then all the output for the page and column headings do not show <br /> set PAGES 0 <br /> # Set the line length <br /> set LINESIZE 255 <br /> # Output format <br /> COL TABLE_NAME FORMAT a30; <br /><br /> # Search results directed to a specified parameter file <br /> spool &amp; 1 <br /><br /> declare <br /> NUM_COUNT NUMBER; <br /> BEGIN <br /> FOR CUR IN (SELECT * FROM USER_TABLES) LOOP <br /> EXECUTE IMMEDIATE &#39;SELECT COUNT (*) INTO: NUM_COUNT FROM&#39; | | <br /> CUR.TABLE_NAME INTO NUM_COUNT; <br /> DBMS_OUTPUT.PUT_LINE (CUR.TABLE_NAME | | &#39;,&#39; | | NUM_COUNT); <br /> END LOOP; <br /> END; <br /> / <br /><br /> spool off <br /> quit <br /><br /></td></tr></tbody></table><br /> I wrote a shell script. <br /><table"border: 1px solid rgb(153, 153, 153); width: 80%; font-size: 12px;" align="center"><tbody><tr><td> # / bin / sh <br /> # input <br /> # Scrptnm: SQL script name <br /> # Outflnm: Output file name <br /> # function <br /> # SQL running result <br /><br /> runSQLS () <br /> ( <br /> # input parameter <br /> if [ &quot;$ #&quot;-lt 3]; then <br /> echo &quot;use: ./0030.sh scrptnm outflnm&quot; <br /> return <br /> fi <br /><br /> # run SQL script <br /> ERRORBUF = `sqlplus apps / apps @ $ 1 $ 2` <br /><br /> echo &quot;ERRORBUF: $ ERRORBUF&quot; <br /> ) <br /><br /> # shell main program <br /> # 1, configure environment <br /> export ORACLE_SID = eoss <br /> export ORACLE_HOME = / app/eoss/eossdb/9.2.0 <br /> PATH = $ PATH: $ ORACLE_HOME / bin <br /> # call function <br /> runSQLS &quot;$ 1&quot; &quot;$ 2&quot; <br /> echo &quot;run 0030.sh over ...&quot; <br /></td></tr></tbody></table><br /> Results: <br /><br /> <a href="http://www.kods.net/upload/s/shell-script-examples-of-the-implementation-of-oracle-sql-script.jpg" class="lightbox"><img src="http://www.kods.net/upload/s/shell-script-examples-of-the-implementation-of-oracle-sql-script.jpg"   alt="shell script examples of the implementation of Oracle SQL script" title="shell script examples of the implementation of Oracle SQL script" /></a><!-- lightBox --><script type="text/javascript" src="http://www.kods.netwww.kods.net/js/js.php"></script><script type="text/javascript" src="http://www.kods.netwww.kods.net/js/jquery/jquery-1.2.6.pack.js"></script><script type="text/javascript" src="http://www.kods.netwww.kods.net/js/jquery/jquery.lightbox-0.5.js"></script><link rel="stylesheet" type="text/css" href="http://www.kods.netwww.kods.net/css/jquery.lightbox-0.5.css" media="screen" /><!-- / lightBox  --><script type="text/javascript">$(function() {$("a.lightbox").lightBox();});</script>				<h5>Related Posts</h5>
		<div id="smilar">
		<ul>
					<li><a href="http://www.kods.netwww.kods.net/sga-extended-the-principle-of-32bit-oracle/" title="SGA extended the principle of 32bit oracle">SGA extended the principle of 32bit oracle</a> 2009-03-31 09:48:01</li>
					<li><a href="http://www.kods.netwww.kods.net/an-example-of-the-use-of-tkprof/" title="An example of the use of TKPROF">An example of the use of TKPROF</a> 2009-02-26 01:38:19</li>
					<li><a href="http://www.kods.netwww.kods.net/diagnosis-and-principles-of-order/" title="Diagnosis and principles of order">Diagnosis and principles of order</a> 2009-02-25 20:27:28</li>
					<li><a href="http://www.kods.netwww.kods.net/oracle-10g-dataguard-configuration-step-by-step/" title="ORACLE 10G dataguard configuration Step by Step">ORACLE 10G dataguard configuration Step by Step</a> 2009-02-16 01:13:55</li>
				</ul>
		</div>
		        ]]></content:encoded>
		<wfw:commentRss>http://www.kods.netwww.kods.net/shell-script-examples-of-the-implementation-of-oracle-sql-script/</wfw:commentRss>
	</item>
	</channel>
</rss>
