This article is a mirror article of machine translation, please click here to jump to the original article.

View: 13656|Reply: 0

[Source] Oracle Chapter 5 Lesson Code

[Copy link]
Posted on 3/15/2015 10:36:35 AM | | |
  1. create table tab1
  2. (
  3.        tid number primary key,
  4.        tname varchar(10)
  5. );
  6. insert into tab1 values (1,'aaa');
  7. insert into tab1 values (2,'ddd');
  8. insert into tab1 values (3,'cccc');

  9. select * from tab1;

  10. --pl/sql
  11. begin
  12. dbms_output.put_line('my first pl/sql');
  13. end;
  14. --变量
  15. declare
  16.     --声明并初始化
  17.     a number := 1;
  18.     b number default 2;
  19.     c number;
  20.     d varchar(10);
  21. begin
  22.     dbms_output.put_line('a='||a);
  23.     dbms_output.put_line('b='||b);
  24.     --赋值1
  25.     c := 3;
  26.     dbms_output.put_line('c='||c);
  27.     --赋值2
  28.     select tname into d from tab1 where tid = 1;
  29.     dbms_output.put_line('d='||d);
  30. end;

  31. declare
  32.     --设置a的类型与tab1表中tid字段的类型一样
  33.     a tab1.tid%type;
  34.     b tab1.tname%type;
  35. begin
  36.     a := 123;
  37.     b := 'name';
  38.     dbms_output.put_line('a='||a);
  39.     dbms_output.put_line('b='||b);
  40. end;

  41. --循环4要素
  42. --1.loop
  43. declare
  44.     i int := 1;--1
  45. begin
  46.     loop
  47.         exit when i > 10;--2
  48.         dbms_output.put_line(i);--4
  49.         i := i + 1;--3
  50.     end loop;
  51. end;
  52. --2. while
  53. declare
  54.     i int := 1;--1
  55. begin
  56.     while i <= 10--2
  57.     loop
  58.         dbms_output.put_line(i);--4
  59.         i := i + 1;--3
  60.     end loop;
  61. end;
  62. --3. for
  63. begin
  64.     for i in 1..20--1,2,3
  65.     loop
  66.         dbms_output.put_line(i);--4
  67.     end loop;
  68. end;
Copy code






Previous:There is a trick to automatically log in to the Win2003 system without a password
Next:How to query the date and time of Baidu snapshot
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com