DDL commands --> create user / table / view / sequence

alter

DML --> data manipulation language (insert, select, update, delete)

eg :

SELECT ename FROM emp WHERE sal = (SELECT MAX(sal) FROM EMP);

%type(single col), %rowtype(single row/record)

cursor --> manu columns/rows

eg :

DECLARE

l_emp_ename emp.ename%type;

BEGIN

SELECT ename INTO l_emp_ename FROM emp WHERE sal = (SELECT MAX(sal) FROM EMP);

DBMS_OUTPUT.put_line('Message');

END;

DBMS_OUTPUT.put('message');

DBMS_OUTPUT.put_line('message);

the implicit cursor(give us 1 row/record)(create / open / get data / close by oracle automatically)

eg : select ename from emp where empno=1111;

the explicit cursor(give us many rows/records)(create / open / get data / close by ourselves)

eg : select * from emp;

an emplicit sursor works as follows :

open the cursor

fetch data from the cursor

fetch again to check if any more rows are found

eg :

DECLARE

l_find_job varchar2(10) := 'PROGRAMMER';

BEGIN

UPDATE emp

SET job = 'DEVELOPER'

WHERE job = 'PROGRAMMER';

END;

commir : save all DML commands

rollback : undo before commit

savepoint : roll back to the savepoint; clear all data till the last commit(when there is no savepoint)

aotocommit : when you  close SQL*PLUS if autocommit is on, the data is you delete, update or insert without commit is saved.

set autocommit on/off

show autocommit

transaction control

eg :

BEGIN

update

commit

END;

commit

eg :

BEGIN

DELETE debug;

SAVEPOINT deleted_debug;

DELETE transactions;

ROLLBACK TO deleted_debug;

COMMIT;

END;

TRANSACTION starts from the last commit end with the commit.

eg :

create table test1(ename varchar2(10));

whenever you issue a SQL statement in a PL/SQL block, PL/SQL creates an implicit cursor, the implicit cursor is using number of attribute that can be selected to find the result of the SQL command.

SQL%ROWCOUNT : the number of rows processed by the SQL statement

SQL%FOUND : true if at least one row was processed by the SQL statement, otherwise false

SQL%NOTFOUND : true if no rows were processed by the SQL statement, otherwise false.

eg : select ename from emp where empno = 1111;

DBMS_OUTPUT.put_line(SQL%ROWCOUNT); (1)

eg : select * from emp;

SQL%ROWCOUNT ()

eg : select ename from emp where 1 = 2;

SQL%ROWCOUNT(0)

copy emp table to emp1 with all rec & data : create table emp1 as select * from emp;

find the largest number from three numbers

eg:

DECLARE

num1 number(10) := '&num1';

num2 number(10) := '&num2';

num3 number(10) := '&num3';

BEGIN

if num1 >= num2 then

if num2 >= num3 then

DBMS_OUTPUT.put_line(num1);

elif num1 >= num3 then

DBMS_OUTPUT.put_line(num1);

else

DBMS_OUTPUT.put_line(num3);

elif num2 >= num3 then

DBMS_OUTPUT.put_line(num2);

else

DBMS_OUTPUT.put_line(num3);

END;

eg :

DBMS_OUTPUT.new_line;

DBMS_OUTPUT.put_line();

DBMS_OUTPUT.put();

write a program to reverse the number user input : 5678 output : 8765

eg :

write a program to find the factorial (input 4 --> 4*3*2*1 ==) total as a result

eg :

declare

num number(4) := #

total number(10) := 1;

begin

for i in num

loop

total := total *i;

end loop;

end;

/

write a program to print fibonacci series(the next number is the sum of last two numbers)(0112358...)

eg :

declare

num1 number(5) := 0;

num2 number(5) := 1;

num3 number(5) := 1;

num number(5) := #

begin

for i in 1.. num

loop

num1 := num3 + num2;

num2 := num3 + num1;

num3 := num1 + num2;

DBMS_OUTPUT.put_line(num1);

DBMS_OUTPUT.put_line(num2);

DBMS_OUTPUT.put_line(num3);

end loop;

end;

/

eg :

declare

num number(6) := #

num1 number(6) := 0;

num2 number(6) := 1;

num3 number(6) := 1;

begin

DBMS_OUTPUT.put(' ' || num1);

DBMS_OUTPUT.put(' ' || num2);

for i in 3..num

loop

num3 := num1 + num2;

DBMS_OUTPUT.put(' ' || num3);

num2 := num2;

num2 := num3;

end loop;

DBMS_OUTPUT.new_line;

end;

wtite a program to display the given number is a prome number or not.(质数)(using mod() remaining=0 )

eg :

declare

num number(6) := #

begin

for i in 2..num

loop

if mod(num, i) != 0 then

end loop;

end;

eg :

declare

num number(5) := #

a number(5);

begin

for i in 2..num-1

loop

a := MOD(num, i);

if  a = 0 then

goto ABC

end if;

end loop;

<<ABC>>

if a = 1 then

DBMS_OUTPUT.put_line(num || ' is a prime number');

else

DBMS_OUTPUT.put_line(num || ' is not a prime number');

end if;

end;

.

/

%type (single column)

%rowtype (all column)

some columns from the table

composite type

eg :

declare

TYPE emp_rec_type is record ( name varchar2(10), sal number(10), hiredate date);

emp_rec emp_rec_type;

begin

select ename, sal, hiredate into emp_rec from emp where empno = &empno;

DBMS_OUTPUT.put_line(emp_rec.name || emp_rec.sal || emp_rec.hiredate);

end;

.

/

最新文章

  1. 【原创】HDFS介绍
  2. Java 线程池
  3. asp.net 页面过程
  4. phpstorm配置svn
  5. React.js 样式组件:React Style
  6. HTTP协议理解与应用总结
  7. Unity NGUI实现Tabview
  8. [置顶] Jquery发展
  9. C++_auto
  10. 怎么样Ubuntu正在使用root账号登录
  11. artTemplate-3.0(与项目实际结合)
  12. 视觉slam十四讲习题ch3-6
  13. 【洛谷P1313 计算系数】
  14. Jaxb对xml报文头的小修小改
  15. [Go] Http包 使用简介
  16. 模拟日历计算 poj1008
  17. Java千百问_05面向对象(005)_接口和抽象类有什么差别
  18. actor binary tree lab4
  19. HDU4059_The Boss on Mars
  20. Appium robotframework-appium (ios 客户端测试)环境搭建

热门文章

  1. Oracle查看表结构的几种方法
  2. 车辆管理系统之搭建框架 添加必要的数据 安装svn(二)
  3. rsa加密--选择padding模式需要注意的问题。。。
  4. IoC 之 2.2 IoC 容器基本原理(贰)
  5. CentOS 7 /RHEL 7: How To Change The System Locale
  6. hdu----(3118)Arbiter(构造二分图)
  7. jdk 安装
  8. MVC 特殊字符的显示
  9. class、interface、struct的区别
  10. AngularJS directive入门例子