PL/SQL 学习笔记3

来源:互联网 发布:c语言中char grade 编辑:程序博客网 时间:2024/06/05 06:01

 

 

%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)可以打印出这个值

   

 

 

注意 set verify off|on 的命令是对 替代变量造成输出显示的新旧值 的控制 on 是显示

 off 是关闭

 

define命令声明的用户变量会把你初始化的值转化为char类型 50000转化为 5,0,0,0,0 5个char类型的字符


 

 

 

 

nested block

 

An identifier is visible in the block in which it is declared and in all nested subblocks, procedures, and  
functions. If the block does not find the identifier declared locally,

it looks up to the declarative section of  the enclosing (or parent) blocks.

The block never looks down to enclosed (or child) blocks or sideways to sibling blocks.  

 

 

 

practise:

 

Create and execute a PL/SQL block that accepts two numbers through iSQL*Plus substitution
variables. Use the DEFINE command to provide the two values. Pass these two values to the PL/SQL
block through iSQL*Plus substitution variables. The first number should be divided by the second
number and have the second number added to the result. The result should be stored in a PL/SQL
variable and printed on the screen.
Note: SET VERIFY OFF in the PL/SQL block.
DEFINE p_num1 = 2
DEFINE p_num2 = 4

 

 

原创粉丝点击