Oracle不像Sqlserver,并没有提供l默认约束,但提供了默认值,效果一样。
--------------------------- 在建表时设置默认约束---------------------------

create table t1 (tname varchar2(20) default 'yang');

--------------------------- 在修改表时设置默认约束---------------------------

alter table t1 modify (tname varchar2(20) default 'yang');

--------------------------- 创建序列---------------------------
create sequence ZHPT_P_USER_SEQ
minvalue 1
maxvalue 999999999
start with 86283141
increment by -3026
nocache
cycle
order;
--------------------------- 创建存储过程---------------------------

CREATE OR REPLACE PROCEDURE create_table
IS
v_Cursor NUMBER;--定义游标
v_CreateString VARCHAR2(100);--这个变量存放创建表的SQL语句。
BEGIN
v_Cursor := DBMS_SQL.OPEN_CURSOR;--打开游标
v_CreateString := 'CREATE TABLE tp (id int,name varchar2(20))';--创建表的SQL语句。
DBMS_SQL.PARSE(v_Cursor, v_CreateString, DBMS_SQL.V7);执行建表的SQL语句
DBMS_SQL.CLOSE_CURSOR(v_Cursor);--关闭游标
END create_table;

--------------------------- 执行存储过程---------------------------

execute create_table;

---------------------------创建函数执行从A表到B表一条一条导入数据并验证---------------------------

create or replace function cux_user_imp(code out VARCHAR2) RETURN VARCHAR2 is
/*
作者:ocean
主要功能:数据导入测试
创建日期:2015年11月26日
*/
cux_a varchar2(10); --姓名变量
cux_i number;
cux_user p_user_temp%rowtype;
cursor cux_user_cr is
select * from p_user_temp p where p.xb = '1';
begin

delete from p_user;
commit;

cux_i := 1;

for cux_user in cux_user_cr loop

cux_a := cux_user.name;

if cux_a = 'lxx' then
dbms_output.put_line(cux_a);

elsif cux_a <> 'lxx' then

insert into p_user
(p_user.id,
p_user.name,
p_user.age,
p_user.tel,
p_user.csri,
p_user.xb)
values
(cux_user.id,
cux_user.name,
cux_user.age,
cux_user.tel,
cux_user.csri,
cux_user.xb
);
cux_i := cux_i + 1;
dbms_output.put_line(to_char(cux_i) || ' ' || cux_user.name);
commit;
end if;

end loop;

return 'ok';

end;

--------------------------- 简单主键定义如下并设置为自增(只取出主键定义)---------------------------

typeid int not null primary key identity(1,1),

--------------------------- 表和序列的关系,是通过业务逻辑的SQL语句来维护---------------------------

即:insert into table_name (column_name) values (seq_name.nextval);

--------------------------- 向表中加时间字段默认值为系统时间---------------------------

insert into table(j) values(to_date('2000-11-26 00:04:47','yyyy-mm-dd hh24:mi:ss'));
create table test
(id int,
starttime date default sysdate not null );
插入测试数据:
insert into test (id) values (1);
commit;

--------------------------- 创建表的时候调用序列 需要写一个触发器---------------------------

create or replace trigger 你的表名_tri
before insert on 你用到的表
for each row
DECLARE
BEGIN
SELECT 你的序列名.nextval into :new.id from dual;
end test_oo_tri;

--------------------------- A表数据导入B表,如果长度不够截取---------------------------

insert into test_PP(ID,NAME) select o.id,SUBSTR(o.name,0,3) from test_oo o;

insert into pUser p (p.名,p.性别,p.年龄,p.电话) select substr(u.姓名,1,20),u.性别,u.年龄,u.电话 from User u
说明:截取函数oracle中是substr,sqlserver中是substring
不管大于不大于20长度全截取。

--------------------------- A表数据导入B表---------------------------

insert into ZHPT_P_USER select * from PUSER
按字段插入
Insert into B (字段1,字段2,字段3) select 字段1,字段2,字段3 from A;

---------------------------给一个表循环插入1000条数据---------------------------

declare
idx number(22) := 8;
val varchar2(22) := 'test';
begin
loop
idx := idx + 1;
insert into abook2 values (idx, val || TO_CHAR( idx ) );
exit when idx > 1000;
end loop;
end;

--------------------------- 查询表中某个字段的值---------------------------

select * from puser where XM='王茜红统计'

--------------------------- 查询字段备注---------------------------

select * from user_tab_comments where comments like '%处室%'

--------------------------- 插入---------------------------

Insert into table_name 字段 1,字段 2、、字段 n values (字段值 1,字段值 2、、字段值 n );

INSERT INTO lxx VALUES(10,'ACCOUNTING','NEW YORK');

--------------------------- 循环插入---------------------------
begin
for i in 1..10 loop
insert into table_name values (...);
end loop;
end;

--------------------------- 序列---------------------------

AA3349_BFA001_SEQUENCE

sql:

1)-- Create sequence
create sequence AA3349_BFA001_SEQUENCE
minvalue 1
maxvalue 999999999999999999999999999
start with 81
increment by 1
cache 20;

--------------------------- 修改表 字段 结构---------------------------
alter table AA3350
add constraint BFA001 primary key (BFA001)
using index
tablespace FSSR
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);

-- Add comments to the table
comment on table AA3350
is '文件审核表';
-- Add comments to the columns
comment on column AA3350.bfa303
is '文号';
comment on column AA3350.faf006
is '审核日期';
comment on column AA3350.faf007
is '审核人';
comment on column AA3350.faf008
is '审核说明';
comment on column AA3350.bfa314
is '修订状态';
comment on column AA3350.bfa001
is '序号';

-------------------------- 导入、导出--------------------------

导入:imp 数据库名/数据库密码@服务 file=D:\名称.dmp full=y
导出:exp 数据库名/数据库密码@服务 file=D:\名称.dmp

---------------------------建立表空间--------------------------

CREATE TABLESPACE "FSSR"

LOGGING

DATAFILE 'D:\oracle\product\10.2.0\oradata\orcl\FSSR.ora' SIZE 500M

AUTOEXTEND ON NEXT 100M

MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL

SEGMENT SPACE MANAGEMENT AUTO

------------------------ 更新字段-------------------------

update 表名 set 字段名='更新数据'

Oracle常用sql的更多相关文章

  1. oracle常用SQL语句(汇总版)

    Oracle数据库常用sql语句 ORACLE 常用的SQL语法和数据对象一.数据控制语句 (DML) 部分 1.INSERT (往数据表里插入记录的语句) INSERT INTO 表名(字段名1, ...

  2. oracle 常用sql语句

    oracle 常用sql语句 1.查看表空间的名称及大小 select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_sizefrom d ...

  3. Oracle常用SQL查询(2)

    三.查看数据库的SQL 1 .查看表空间的名称及大小 select  t.tablespace_name,  round ( sum (bytes / ( 1024 * 1024 )), 0 ) ts ...

  4. Oracle常用SQL查询

    一.ORACLE的启动和关闭 1.在单机环境下要想启动或关闭oracle系统必须首先切换到oracle用户,如下: su - oracle a.启动Oracle系统 oracle>svrmgrl ...

  5. ORACLE 常用SQL查询

    一.ORACLE的启动和关闭 1 .在单机环境下 要想启动或关闭ORACLE系统必须首先切换到ORACLE用户,如下 su  -  oracle a.启动ORACLE系统 oracle > sv ...

  6. Oracle常用SQL语句大全

    常用Oracle数据库SQL语句汇总. 1.常用操作 --清空回收站purge recyclebin;--查询回收站select * from recyclebin--查询Oracle版本信息sele ...

  7. Oracle常用sql命令

    1.查看数据库归档是开启还是关闭SQL> archive log list 更改数据库归档模式: SQL> shutdown immediateSQL> startup mountS ...

  8. oracle 常用sql字符函数介绍

    常用字符函数介绍 1.ascii 返回与指定的字符对应的十进制数: SQL>select ascii('A') A,ascii('a') a,ascii('0') zero,ascii(' ') ...

  9. Oracle 常用Sql 语句

    Oracle数据库常常被用作项目开发的数据库之一:有时隔段时间没使用就会忘记一些常用的sql语法,所以我们有必要记录下常用的sql 语句,当我们需要时可以快速找到并运用. 1 创建表空间.创建用户及授 ...

  10. Oracle常用sql语句(一)

    # Sql的分类 # DDL (Data Definition Language):数据定义语言,用来定义数据库对象:库.表.列等: CREATE. ALTER.DROP DML(Data Manip ...

随机推荐

  1. 2014 UESTC 暑前集训队内赛(3) 部分解题报告

    B.Battle for Silver 定理:完全图Kn是平面图当且仅当顶点数n<=4. 枚举所有完全图K1,K2,K3,K4,找出最大总权重. 代码: #include <iostrea ...

  2. 关于jQuery的一些实用代码

    (1)修改默认编码:(将默认的utf-8,修改为GB2312) $.ajaxSetup({ ajaxSettings:{contentType:"application/x-www-from ...

  3. java11-5 String类的转换功能

    String的转换功能: byte[] getBytes():把字符串转换为字节数组. char[] toCharArray():把字符串转换为字符数组. static String valueOf( ...

  4. 【WPF】FillRule

    获取或设置如何组合此 GeometryGroup 中所包含对象的相交区域. Dependency property identifier field: FillRuleProperty FillRul ...

  5. 元祖签约K2 BPM,引领绿色健康食品!

    漫步街头,我们经常会被一些鲜艳的红色招牌所吸引,走进去会发现这里有一些普通西饼店不会卖的东西,比如红蛋.年糕.粽子.喜饼.等上海传统食品等......这就是元祖食品. 随着人们生活品质的不断提升,元祖 ...

  6. OSGEARTH三维地形开源项目

    第一章   OSGEarth介绍 第二章   OSGEarth编译环境配置 OSGEarth的编译环境配置随着版本的不同.运行平台的不同,也有很大的差异.本章主要以Windows XP SP3(x86 ...

  7. 用python简单处理图片(3):添加水印

    python版本:3.4 Pillow版本:3.0 一.添加文字水印 from PIL import Image, ImageDraw,ImageFont im = Image.open(" ...

  8. [vim配置]windows下在vim中使用gcc/g++编译调试c/cpp文件

    在Linux里面混了一个多月,vim编程用得甚爽.无奈前天将Linux里面的编程文件夹误删,而技术不精无法找回,悲痛欲绝.再者,无限怀念windows里面的游戏,并觉得现在在Linux里面也学不到什么 ...

  9. Spring MVC实现文件下载

     下载文件① 下载文件需要将byte数组还原成文件. 首先使用mybatis将数据库中的byte数组查出来,指定文件名(包括格式).然后使用OutputStream将文件输入 @RequestMapp ...

  10. 20135220谈愈敏Linux Book_18

    第18章 调试 调试内核艰难且风险高,关键在于对内核的深刻理解. 18.1 准备开始 需要的是: 一个bug 一个藏匿bug的内核版本 相关内核代码的知识和运气 内核中的bug不是很清晰,调试成功的关 ...