PL/SQL ѧϰ±Ê¼Ç3
SQL> var a number
SQL> begin
2 :a :=1000;
3 end;
4 /
PL/SQL procedure successfully completed.
SQL> edit
Wrote file afiedt.buf
1 begin
2 dbms_output.put_line(:a);
3* end;
SQL> /
ͨ¹ýÕâ¸ö´úÂë¿ÉÒÔ¿´³öͨ¹ýpl/sql³õʼ»¯¸³ÖµµÄBind variable¿ÉÒÔ±»ÆäËûPl/sql³ÌÐòµ÷ÓÃ
%type ÀàÐÍÓ¦ÓõĻ° Èç¹ûÇ°ÃæÓõÄÊÇdatabase columnµÄ»° ÄÇô²»¿ÉÒÔ¼Ónot null,Ç°ÃæÒýÓõÄÊÇÉùÃ÷µÄ±äÁ¿¿ÉÒÔÓ¦ÓÃnot null
A NOT NULLdatabase column constraint does not apply to variables that are declared using %TYPE.
Therefore, if you declare a variable using the %TYPEattribute that uses a database column defined as NOT
NULL, you can assign the NULLvalue to the variable.
eg:
°ó¶¨±äÁ¿
A bind variable is a variable that you declare in a host environment.
Bind variables can be used to pass run-time values, either number or character, into or out of one or more PL/SQL programs. The PL/SQL
programs use bind variables as they would use any other variable. You can reference variables declared in the
host or calling environment in PL/SQL statements, unless the statement is in a procedure, function, or
package. This includes host language variables declared in precompiler programs, screen fields in Oracle Developer Forms applications, and iSQL*Plus bind variables.
°ó¶¨±äÁ¿¿ÉÒÔÔÚÖ÷»ú»·¾³ÏÂÉùÃ÷ ¿ÉÒÔÔÚsqlplus ÕâÖÖÓ¦ÓóÌÐòÏÂÉùÃ÷ È»ºópl/sql³ÌÐòÀ´µ÷Óà µ÷ÓÃÐèÒªÔڸñäÁ¿Ç°¼Ócolon
¸³ÖµµÄʱºò¿ÉÒÔʹÓà exec :var_name := 10000; or begin :var_name := 1000 end; »òÕßÊÇÔÚPL/SQLÖи³Öµ
print(sqlplus command)¿ÉÒÔ´òÓ¡³öÕâ¸öÖµ
SQL> var result number
SQL> begin
2 select (sal*12) + nvl(comm,0)
3 into :result
4 from emp
5 where empno = 7369;
6 end;
7 /
PL/SQL procedure successfully completed.
SQL> print result
RESULT
------
9600
SQL> exec :result = 10000
BEGIN :result = 10000; END;
*
ERROR at line 1:
ORA-06550: line 1, column 15:
PLS
Ïà¹ØÎĵµ£º
ÔÚÊý¾Ý¿âÓ¦ÓóÌÐò·¢²¼Ê±£¬¿Í»§¶Ë°²×°ÔÚ¾ÖÓòÍøÖеÄÖ÷»úAÉÏ£¬sql server °²×°ÔڸþÖÓòÍøµÄÖ÷»úBÉÏ¡£¿Í»§¶ËÈí¼þÖаüº¬ÓÐËüÒªÁ¬½ÓµÄÊý¾Ý¿âµÄÐÅÏ¢¡£ÈçÊý¾ÝÔ´£¬·þÎñÆ÷Ãû³Æ£¬Êý¾Ý¿âµÈ£¬ÊµÀý£ºdata source=SQLOLEDB;SERVER=DongZi\sqlExpress;uid=sa;pwd=123;database=MachineRoom
¡£ÄÇôÎÒÃÇÔÚÖ÷» ......
SQL²Ù×÷È«¼¯
ÏÂÁÐÓï¾ä²¿·ÖÊÇMssqlÓï¾ä£¬²»¿ÉÒÔÔÚaccessÖÐʹÓá£
SQL·ÖÀࣺ
DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)
DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)
DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£º
1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CREATE ......
ϱí˵Ã÷ÔÚ Microsoft SQL Server Êý¾Ý¿âÖж¨ÒåµÄ£¬»òÔÚ Transact-SQL
Óï¾äÖÐÒýÓõĸ÷ÖÖ¶ÔÏóµÄ×î´óÖµ£¨ÊýÁ¿»ò´óС£©¡£ÏÂ±í²»°üº¬ Microsoft® SQL Server 2000™ Windows® CE °æ¡£
×î´óÖµ£¨ÊýÁ¿»ò´óС£©
¶ÔÏó
SQL Server 7.0
SQL Server 2000
Åú´¦Àí´óС
65,536 * ÍøÂçÊý¾Ý°ü´óС1
65,536 * Í ......
±äÁ¿ÉùÃ÷
Syntax:
identifier [CONSTANT] datatype [NOT NULL] [:= | DEFAULT expr];
SQL> declare
2 a date;
3 b number(20) not null :=100;
4 c varchar2(10);
5 d constant number(20) default 1000;
6 begin
7 null;
8 end;
9 /
PL/SQL procedure successful ......
SqlServer 2000 ÓαêÓ÷¨Ð¡Àý ·µ¯ÑºÎ²É£Cannon(¿¨Ù¯) »
--------------------------------------------------------------------------------
DECLARE CURSOR (T-SQL)´´½¨Óαê
September 14th, 2006 by OoperMan (1 votes, average: 5 out of 5) Loading ...
SQL Server 2005 Áª»ú´ÔÊé
DECLARE CURSOR ......