oracle中PLSQL语句

来源:互联网 发布:苹果mac充电器灯不亮 编辑:程序博客网 时间:2024/05/07 18:35

1.set  autot off 禁止使用autotrace命令

set autot on 这个命令包括exp 和 stat(执行语句、生成explain plan、生成统计信息)

set autot trace 不执行sql语句,但(生成explain plan、生成统计信息)

set autot trace exp stat 与上句同

set autot trace stat 不执行sql语句,但(生成explain plan)

2.序列Sequence_name.nextval 求出接下来的最高值
Sequence_name.currval 最近一次调用nextval时返回的值

3. 创建以10开始的序列create sequence my_sequence start with 10;
查询序列中接下来的最高值 select my_sequence.nextval from dual;

4. create sequence student_seq;
create table student(n varchar(10));
insert into student values('a'||lpad(student_seq.nextval,9,'0'));
select * from student;

N
----------
a000000002

5.  --execute immediate 'set constraints all deferred';
create or replace procedure p is
begin

 insert into student values ('a000000004');
 insert into student values('a000000005');
 insert into student values ('a000000006');
 commit;
 end p;

6.select * from tab;查看表空间中所有表

7.select * from v$tablespace;查看数据库中的所有表空间

8.
set serveroutput on
即打开oracle自带的输出方法dbms_output。在执行set serveroutput on以后,
使用dbms_output方法可以输出信息,
例如:dbms_output.put_line('This is mine');

1)创建存储过程
SQL> set serveroutput on
SQL> create or replace procedure hello IS
  2  begin
  3  dbms_output.put_line('hello world');
  4  end;
  5  /

过程已创建。

2)执行存储过程
SQL> execute hello (或者exec hello)
hello world

PL/SQL 过程已成功完成。

3)删除存储过程
SQL> drop procedure hello
  2  ;

过程已删除。
9.SQL*Plus 缓冲区默认大小是20,000字符,最大可以增加到1,000,000字符
SQL> execute dbms_output.enable(1000000);

PL/SQL 过程已成功完成。

将缓冲区的内容保存到文件中
SQL> create or replace procedure hello is
  2  begin
  3      dbms_output.put_line('hello world,zhang da wang,heihei');
  4  end;

过程已创建。

SQL> save hello
已创建 file hello.sql --文件的路径为:F:\oracle\product\10.2.0\db_1\BIN
SQL> @hello.sql

过程已创建。

SQL> exec hello
hello world,zhang da wang,heihei

PL/SQL 过程已成功完成。
10.赋值操作符“:=”
if条件判断表达式IF(a=b)
字符串连接操作符“||”
变量声明区位于IS和BEGIN之间