易截截图软件、单文件、免安装、纯绿色、仅160KB

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


相关文档:

LINQ to SQL 查询数据库和使用存储过程


如下列出查询表达式,常用操作符,与SQL语句对应。

where  关键字的使用
public void MyWhere()
{
NorthwindDataContext dc = new NorthwindDataContext();
//查询产品名称以L开头的记录
var query = from p in dc.Products
where p.Prod ......

SQL操作全集


SQL操作全集
下列语句部分是Mssql语句,不可以在access中使用。
SQL分类:
DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE)
DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT)
DCL—数据控制语言(GRANT,REVOKE,COMMIT,ROLLBACK)
首先,简要介绍基础语句:
1、说明:创建数据库
CREA ......

SQL code动态sql语句基本语法

SQL code动态sql语句基本语法
 1 :普通SQL语句可以用Exec执行
eg: Select * from tableName
Exec('select * from tableName')
Exec sp_executesql N 'select * from tableName'
 -- 请注意字符串前一定要加N
2:字段名,表名,数据库名之类作为变量时,必须用动态SQL
eg: declare @fname varchar(20) ......

sql分页

declare @p int
declare @p1 int
declare @count int
set @p=0
set @p1=10
set @count=2
if(@count<>0 or @count<>1)
set @p=@p1*@count-10
SELECT [t1].[userid], [t1].[username], [t1].[userorder]
from (
    SELECT ROW_NUMBER() OVER (ORDER BY [t0].[userorder]) AS [ROW_NU ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号