啟動(dòng)服務(wù)器
sqlplus /nolog;
連接服務(wù)器
connect sys as sysdba;
推出服務(wù)器
exit;
設(shè)置
#若命令行要輸出DBMS_PUT.PUT_LINE 的內(nèi)容娜膘。卻沒輸出設(shè)置
set serveroutput on;
引用輸出包極其過程進(jìn)行輸出
DBMS_OUTPUT.PUT_LINE(' The First Name of the
Employee is ' || f_name);
創(chuàng)建表
create table users (
id number(10) primary key,
username varchar2(20) not null,
passwords varchar2(20) not null
);
/
查詢表信息
desc users;
創(chuàng)建且替換過程
# 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;
/
#查詢總?cè)藬?shù)
create or replace procedure selAllUserCOUNT
is
cnt number;
begin
select count(id) into cnt from users;
DBMS_OUTPUT.PUT_LINE('總?cè)藬?shù) = ' || cnt);
end;
/
刪除過程
drop procedure users;