PL/SQL ѧϰ±Ê¼Ç2
±äÁ¿ÉùÃ÷
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 successfully completed.
SQL> var v_bind number
SQL> exec :v_bind := 2984;
PL/SQL procedure successfully completed.
SQL> r
1 declare
2 v_a number(20);
3 v_b constant number := 1000;
4 v_c constant number default 2000;
5 v_d varchar2(20) not null default 'asf';
6 begin
7 v_a := 2003;
8 dbms_output.put_line(v_a ||' '|| v_b ||' '|| v_c ||' ' || v_d || ' ' || '&a' || ' '||:v_bind) ;
9* end;
Enter value for a: 34567
old 8: dbms_output.put_line(v_a ||' '|| v_b ||' '|| v_c ||' ' || v_d || ' ' || '&a' || ' '||:v_bind) ;
new 8: dbms_output.put_line(v_a ||' '|| v_b ||' '|| v_c ||' ' || v_d || ' ' || '34567' || ' '||:v_bind) ;
2003 1000 2000 asf 34567 2984
PL/SQL procedure successfully completed.
Scalar ±êÁ¿ data type holds a single value and has no internal components.
number,
character,
date,
Boolean.
Character and number data types have subtypes that
associate a base type to a constraint. For example, INTEGERand POSITIVEare subtypes of the NUMBER
base type.
?CHAR [(maximum_length)]
? VARCHAR2(maximum_length)
? LONG
? LONG RAW
? NUMBER [(precision, scale)]
? BINARY_INTEGER
? PLS_INTEGER
? BOOLEAN
SQL> declare
2 v_job varchar2(20);
3 v_count binary_integer := 0;
4 v_total_sal number(9,2) := 0;
5 v_orderdate date := sysdate + 7;
6 c_tax_rate constant number(3,2) := 8.02;
7 v_valid boolean not null :=true;
8 begin
9 null;
10 end;
11 /
v_job: variable to store an employee job title
v_count: variable to count the iterations of a loop and initialized to 0
v_total_sal: variable to accumulate the total salary for a department and i
Ïà¹ØÎĵµ£º
ÔÚÊý¾Ý¿âÓ¦ÓóÌÐò·¢²¼Ê±£¬¿Í»§¶Ë°²×°ÔÚ¾ÖÓòÍøÖеÄÖ÷»úAÉÏ£¬sql server °²×°ÔڸþÖÓòÍøµÄÖ÷»úBÉÏ¡£¿Í»§¶ËÈí¼þÖаüº¬ÓÐËüÒªÁ¬½ÓµÄÊý¾Ý¿âµÄÐÅÏ¢¡£ÈçÊý¾ÝÔ´£¬·þÎñÆ÷Ãû³Æ£¬Êý¾Ý¿âµÈ£¬ÊµÀý£ºdata source=SQLOLEDB;SERVER=DongZi\sqlExpress;uid=sa;pwd=123;database=MachineRoom
¡£ÄÇôÎÒÃÇÔÚÖ÷» ......
Microsoft SQL Server£¨ÒÔϼò³ÆSQL Server£©×÷ΪһÖÖÖÐСÐÍÊý¾Ý¿â¹ÜÀíϵͳ£¬ÒѾµÃµ½Á˹㷺µÄÓ¦Ó㬸Ãϵͳ¸üÇ¿µ÷ÓÉϵͳÀ´¹ÜÀíËø¡£ÔÚÓû§ÓÐSQLÇëÇóʱ£¬ÏµÍ³·ÖÎöÇëÇó£¬×Ô¶¯ÔÚÂú×ãËø¶¨Ìõ¼þºÍϵͳÐÔÄÜÖ®¼äΪÊý¾Ý¿â¼ÓÉÏÊʵ±µÄËø£¬Í¬Ê±ÏµÍ³ÔÚÔËÐÐÆڼ䳣³£×Ô¶¯½øÐÐÓÅ»¯´¦Àí£¬ÊµÐж¯Ì¬¼ÓËø¡£
¡¡¡¡¶ÔÓÚÒ»°ãµÄÓû§¶øÑÔ£¬Í¨¹ýϵͳµÄ× ......
»úÆ÷Çé¿ö
p4: 2.4
ÄÚ´æ: 1 G
os: windows 2003
Êý¾Ý¿â: ms sql server 2000
Ä¿µÄ: ²éѯÐÔÄܲâÊÔ,±È½ÏÁ½ÖÖ²éѯµÄÐÔÄÜ
SQL²éѯЧÂÊ step by step
-- setp 1.
-- ½¨±í
create table t_userinfo
(
userid int identity(1,1) primary key nonclustered,
nick&nbs ......
PL/SQL ²»¾ß±¸ÊäÈëÊä³öµÄÄÜÁ¦
µ«ÊÇ¿ÉÒÔÒÀ¿¿»·¾³À´Ö´ÐÐÊýÖµµÄÊäÈëÊä³ö¸øPL/SQL ¿é
SQLPLUS »·¾³ÓÃsubstitution variables ºÍ host(bind) variable À´´«ÈëÊýÖµ¸øPL/SQL¿é
substitution variable: such as a preceding ampersand &a
host(bind) variable : such as a preceding colon :x
Ìæ ......