Home Article Practice Oracle JDBC PLSQL

Oracle JDBC PLSQL

2022-02-17 17:11  views:481  source:742049    

create tablespace ts01 datafile 'ts01.dbf' size 10m;
create user abc identified by "123456" default tablespace ts01;
grant dba to abc with admin option;
select * from cat;
drop tablespace ts01 including contents and datafiles;
drop user abc;
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(
"jdbc:mysql://127.0.0.1:3306/db1125", "root", "123456");
conn.setAutoCommit(false);
String sql = "insert into person(name, age) values('小王',23)";
PreparedStatement ps = conn.prepareStatement(sql);
int i = ps.executeUpdate();
System.out.println(i);
conn.commit();
conn.close();
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(
"jdbc:mysql://127.0.0.1:3306/db1125", "root", "123456");
String sql = "select name, age from person order by id desc";
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
System.out.println(rs.getString("name"));
System.out.println(rs.getInt("age"));
}
conn.close();
declare
a number(2) := 5;
begin
dbms_output.put_line(a);
end;
declare
a number(2) := 5;
b number(2) := 3;
begin
if (a > b) then
dbms_output.put_line(a);
else
dbms_output.put_line(b);
end if;
end;
declare
a number(2) := 9;
b number(2) := 5;
begin
case when a>b then
dbms_output.put_line(a);
else
dbms_output.put_line(b);
end case;
end;
declare
i number(10) := 1;
begin
while i <= 10 loop
dbms_output.put_line(i);
i := i + 1;
end loop;
end;
declare
i number(10);
begin
for i in 1..10 loop
dbms_output.put_line(i);
end loop;
end;
create table t(
id integer,
name varchar2(10),
age number(2)
);
insert into t values(1,'张三',30);
insert into t values(2,'李四',40);
select * from t;
declare
a varchar2(10);
begin
select name into a from t where id = 1;
dbms_output.put_line(a);
end;
declare
type myrecord is record(
a t.name%type,
b t.age%type
);
x myrecord;
begin
select name, age into x from t where id = 1;
dbms_output.put_line(x.a);
dbms_output.put_line(x.b);
end;
declare
a t%rowtype;
begin
select * into a from t where id = 1;
dbms_output.put_line(a.id || a.name || a.age);
end;
declare
a t%rowtype;
cursor mycur is select * from t;
begin
open mycur;
fetch mycur into a;
while mycur%found loop
dbms_output.put_line(a.name);
fetch mycur into a;
end loop;
close mycur;
end;
create or replace procedure pro1(a in number, b in varchar2, c in number) as
begin
insert into t values(a,b,c);
end pro1;
begin
pro1(3,'王五',50);
end;
select * from t;
create or replace procedure pro2(a in number, b out varchar2) as
begin
select name into b from t where id = a;
end pro2;
declare
c t.name%type;
begin
pro2(2, c);
dbms_output.put_line(c);
end;
create table t_log(u varchar2(255), t varchar2(255), d varchar2(255));
drop table t_log;
select * from t_log;
create or replace trigger t_trigger
after delete or insert or update on t
declare
s varchar2(255);
begin
if inserting then
s:='添加操作';
elsif updating then
s := '修改操作';
elsif deleting then
s := '删除操作';
end if;
insert into t_log values(user, s, to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'));
end;



Disclaimer: The above articles are added by users themselves and are only for typing and communication purposes. They do not represent the views of this website, and this website does not assume any legal responsibility. This statement is hereby made! If there is any infringement of your rights, please contact us promptly to delete it.

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)