oracle 入门使用

启动服务器

sqlplus /nolog;

连接服务器

connect sys as sysdba;

推出服务器

exit;

设置

#若命令行要输出DBMS_PUT.PUT_LINE 的内容。却没输出设置
set serveroutput on;

引用输出包极其过程进行输出

DBMS_OUTPUT.PUT_LINE(' The First Name of the
Employee is ' || f_name);

创建表

create table users (
    id number(10) primary key,
    username varchar2(20) not null,
    passwords varchar2(20) not null
);
/

查询表信息

desc users;

创建且替换过程

# hello示例
create or replace procedure hello
as
begin
    DBMS_OUTPUT.PUT_LINE('hello');
end;
/

# 选择指定单行
create or replace procedure selIdUser(
    uid in number)
is
cur users%ROWTYPE;
begin 
select id, username, passwords into cur 
from users
where id = uid;
     DBMS_OUTPUT.PUT_LINE(
        'id = ' || cur.id || 
        ' username = ' || cur.username || 
        ' password = ' || cur.passwords);
end;
/

# 查询多行
create or replace procedure selAllUser
is
cursor users_cursor is select id, username, passwords from users;
begin 
    for cur in users_cursor
        loop
    DBMS_OUTPUT.PUT_LINE(
        'id = ' || cur.id || 
        ' username = ' || cur.username || 
        ' password = ' || cur.passwords);
        end loop;
end;
/

#查询总人数
create or replace procedure selAllUserCOUNT
is
cnt number;
begin 
    select count(id) into cnt from users;
    DBMS_OUTPUT.PUT_LINE('总人数 = ' || cnt);
end;
/

删除过程

drop procedure users;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,067评论 19 139
  • 国家电网公司企业标准(Q/GDW)- 面向对象的用电信息数据交换协议 - 报批稿:20170802 前言: 排版 ...
    庭说阅读 11,220评论 6 13
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,826评论 25 709
  • 第一次是大花这样说的,她的原话是“我的男友力好强”。那天是我去她家,她刚洗完澡穿着睡衣,松散着有一些潮湿的头发坐在...
    修坯刀阅读 334评论 0 0
  • 傍晚,在穿梭于北京众多车的大巴窗前看北京的夜晚,点点灰蒙的天空下的灯光闪烁,在我眼前转瞬即逝,只余下一片模糊的光影...
    Ruby阅读 289评论 1 2