前言
起步
| # 在指定路径下创建表空间,并自动递增 |
| create tablespace waterboss |
| datafile 'c:\waterboss.dbf' |
| size 100m |
| autoextend on |
| next 10m |

| create user wateruser |
| identified by 123456 |
| default tablespace waterboss |
| |
| grant dba to wateruser |
-
查看是否创建成功


-
数据类型
| |
| CHAR : 固定长度的字符类型,最多存储 2000 个字节 |
| VARCHAR2 :可变长度的字符类型,最多存储 4000 个字节 |
| LONG : 大文本类型。最大可以存储 2 个 G |
| |
| |
| NUMBER : 数值类型 |
| NUMBER(5) 最大可以存的数为 99999 |
| NUMBER(5,2) 最大可以存的数为 999.99 |
| |
| |
| DATE:日期时间型,精确到秒 |
| TIMESTAMP:精确到秒的小数点后 9 位 |
| |
| |
| CLOB : 存储字符,最大可以存 4 个 G |
| BLOB:存储图像、声音、视频等二进制数据,最多可以存 4 个 G |
| CREATE TABLE 表名称( |
| 字段名 类型(长度) primary key, |
| 字段名 类型(长度), |
| ....... |
| ); |
| |
| create table t_owners |
| ( |
| id number primary key, |
| name varchar2(30), |
| addressid number, |
| housenumber varchar2(30), |
| watermeter varchar2(30), |
| adddate date, |
| ownertypeid number |
| ); |

| # 添加字段 |
| ALTER TABLE 表名称 ADD(列名 1 类型 [DEFAULT 默认值],列名 1 类型 |
| [DEFAULT 默认值]...) |
| |
| ALTER TABLE T_OWNERS ADD |
| ( |
| REMARK VARCHAR2(20), |
| OUTDATE DATE |
| ) |
| |
| |
| |
| # 修改字段类型 |
| ALTER TABLE 表名称 MODIFY(列名 1 类型 [DEFAULT 默认值],列名 1 类型 |
| [DEFAULT 默认值]...) |
| |
| ALTER TABLE T_OWNERS MODIFY |
| ( |
| REMARK CHAR(20), |
| OUTDATE TIMESTAMP |
| ) |
| |
| |
| |
| # 修改字段名称 |
| ALTER TABLE 表名称 RENAME COLUMN 原列名 TO 新列名 |
| |
| ALTER TABLE T_OWNERS RENAME COLUMN OUTDATE TO EXITDATE |
| |
| |
| |
| # 删除一个字段 |
| ALTER TABLE 表名称 DROP COLUMN 列名 |
| |
| ALTER TABLE T_OWNERS DROP COLUMN REMARK |
| |
| # 删除多个字段 |
| ALTER TABLE 表名称 DROP (列名 1,列名 2...) |
| |
| |
| |
| # 删除表 |
| DROP TABLE 表名称 |
| insert into T_OWNERS VALUES (1,' 张三丰',1,'2-2','5678',sysdate,1); |

| UPDATE 表名 SET 列名 1=值 1,列名 2=值 2,....WHERE 修改条件; |
| |
| update T_OWNERS set adddate=adddate-3 where id=1; |
| DELETE FROM 表名 WHERE 删除条件; |
| |
| delete from T_OWNERS where id=2; |
| TRUNCATE TABLE 表名称 |
| |
| delete 删除的数据可以 rollback |
| delete 删除可能产生碎片,并且不释放空间 |
| truncate 是先摧毁表结构,再重构表结构 |
| 右键Tables -> new |
| 选择在指定用户下建表,指定表名 |
| 创建字段,指定类型 |
| 设置主键:取1个主键约束名称,并指定字段为主键 |
| 点击Apply创建表 |



| 右键表 -> Edit |
| Nullable勾选上表示可以为空 |
| 删除字段时,选中1行,点击减号 |
| 刷新表:右键表 -> refresh |

| |
| exp system/123456 full=y |
| |
| exp system/123456 file=文件名 full=y |
| |
| |
| imp system/123456 full=y |
| |
| imp system/123456 full=y file=dbtest.dmp |
| exp system/123456 owner=用户名 file=dbtest.dmp |
| |
| imp system/123456 file=dbtest.dmp fromuser=用户名 |
| exp 用户名/密码 file=dbtest.dmp tables=t_account,a_area |
| |
| imp 用户名/密码 file=dbtest.dmp tables=t_account,a_area |
其他
整合mybatis plus参考
点击查看详情
| <dependencies> |
| <dependency> |
| <groupId>org.springframework.boot</groupId> |
| <artifactId>spring-boot-starter-web</artifactId> |
| </dependency> |
| <dependency> |
| <groupId>org.springframework.boot</groupId> |
| <artifactId>spring-boot-starter</artifactId> |
| </dependency> |
| |
| <dependency> |
| <groupId>org.projectlombok</groupId> |
| <artifactId>lombok</artifactId> |
| <version>1.18.18</version> |
| <scope>provided</scope> |
| </dependency> |
| <dependency> |
| <groupId>com.oracle.database.jdbc</groupId> |
| <artifactId>ojdbc8</artifactId> |
| <scope>runtime</scope> |
| </dependency> |
| <dependency> |
| <groupId>org.springframework.boot</groupId> |
| <artifactId>spring-boot-starter-test</artifactId> |
| <scope>test</scope> |
| <exclusions> |
| <exclusion> |
| <groupId>org.junit.vintage</groupId> |
| <artifactId>junit-vintage-engine</artifactId> |
| </exclusion> |
| </exclusions> |
| </dependency> |
| |
| <dependency> |
| <groupId>cn.easyproject</groupId> |
| <artifactId>orai18n</artifactId> |
| <version>12.1.0.2.0</version> |
| </dependency> |
| |
| <dependency> |
| <groupId>com.baomidou</groupId> |
| <artifactId>mybatis-plus-boot-starter</artifactId> |
| <version>3.2.0</version> |
| </dependency> |
| <dependency> |
| <groupId>org.springframework.boot</groupId> |
| <artifactId>spring-boot-starter-freemarker</artifactId> |
| </dependency> |
| <dependency> |
| <groupId>mysql</groupId> |
| <artifactId>mysql-connector-java</artifactId> |
| <scope>runtime</scope> |
| </dependency> |
| |
| <dependency> |
| <groupId>com.baomidou</groupId> |
| <artifactId>mybatis-plus-generator</artifactId> |
| <version>3.2.0</version> |
| </dependency> |
| </dependencies> |
| spring: |
| datasource: |
| driver-class-name: oracle.jdbc.driver.OracleDriver |
| url: jdbc:oracle:thin:@127.0.0.1:1521/orcl |
| username: wateruser |
| password: 123456 |
| mybatis-plus: |
| mapper-locations: classpath*:/mapper/**Mapper.xml |
| server: |
| port: 9000 |
| import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; |
| import org.mybatis.spring.annotation.MapperScan; |
| import org.springframework.context.annotation.Bean; |
| import org.springframework.context.annotation.Configuration; |
| import org.springframework.transaction.annotation.EnableTransactionManagement; |
| |
| @Configuration |
| @EnableTransactionManagement |
| @MapperScan("com.ychen.oracle.demo01.mapper") |
| public class MybatisPlusConfig { |
| |
| @Bean |
| public PaginationInterceptor paginationInterceptor() { |
| PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); |
| return paginationInterceptor; |
| } |
| |
| } |
- 启动类同级编写代码生成器类,启动后输入表名生成代码
| import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException; |
| import com.baomidou.mybatisplus.core.toolkit.StringPool; |
| import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| import com.baomidou.mybatisplus.generator.AutoGenerator; |
| import com.baomidou.mybatisplus.generator.InjectionConfig; |
| import com.baomidou.mybatisplus.generator.config.*; |
| import com.baomidou.mybatisplus.generator.config.po.TableInfo; |
| import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; |
| import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine; |
| import java.util.ArrayList; |
| import java.util.List; |
| import java.util.Scanner; |
| |
| |
| public class CodeGenerator { |
| |
| |
| |
| |
| |
| |
| public static String scanner(String tip) { |
| Scanner scanner = new Scanner(System.in); |
| StringBuilder help = new StringBuilder(); |
| help.append("请输入" + tip + ":"); |
| System.out.println(help.toString()); |
| if (scanner.hasNext()) { |
| String ipt = scanner.next(); |
| if (StringUtils.isNotEmpty(ipt)) { |
| return ipt; |
| } |
| } |
| throw new MybatisPlusException("请输入正确的" + tip + "!"); |
| } |
| |
| public static void main(String[] args) { |
| |
| AutoGenerator mpg = new AutoGenerator(); |
| |
| |
| GlobalConfig gc = new GlobalConfig(); |
| String projectPath = System.getProperty("user.dir"); |
| gc.setOutputDir(projectPath + "/src/main/java"); |
| |
| gc.setAuthor("关注公众号:MarkerHub"); |
| gc.setOpen(false); |
| |
| gc.setServiceName("%sService"); |
| mpg.setGlobalConfig(gc); |
| |
| |
| DataSourceConfig dsc = new DataSourceConfig(); |
| dsc.setUrl("jdbc:oracle:thin:@127.0.0.1:1521/orcl?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=UTC"); |
| |
| dsc.setDriverName("oracle.jdbc.driver.OracleDriver"); |
| dsc.setUsername("wateruser"); |
| dsc.setPassword("123456"); |
| mpg.setDataSource(dsc); |
| |
| |
| PackageConfig pc = new PackageConfig(); |
| pc.setModuleName(null); |
| pc.setParent("com.ychen.oracle.demo01"); |
| mpg.setPackageInfo(pc); |
| |
| |
| InjectionConfig cfg = new InjectionConfig() { |
| @Override |
| public void initMap() { |
| |
| } |
| }; |
| |
| |
| String templatePath = "/templates/mapper.xml.ftl"; |
| |
| |
| |
| |
| List<FileOutConfig> focList = new ArrayList<>(); |
| |
| focList.add(new FileOutConfig(templatePath) { |
| @Override |
| public String outputFile(TableInfo tableInfo) { |
| |
| return projectPath + "/src/main/resources/mapper/" |
| + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML; |
| } |
| }); |
| |
| cfg.setFileOutConfigList(focList); |
| mpg.setCfg(cfg); |
| |
| |
| TemplateConfig templateConfig = new TemplateConfig(); |
| |
| templateConfig.setXml(null); |
| mpg.setTemplate(templateConfig); |
| |
| |
| StrategyConfig strategy = new StrategyConfig(); |
| strategy.setNaming(NamingStrategy.underline_to_camel); |
| strategy.setColumnNaming(NamingStrategy.underline_to_camel); |
| strategy.setEntityLombokModel(true); |
| strategy.setRestControllerStyle(true); |
| strategy.setInclude(scanner("表名,多个英文逗号分割").split(",")); |
| strategy.setControllerMappingHyphenStyle(true); |
| strategy.setTablePrefix("m_"); |
| mpg.setStrategy(strategy); |
| mpg.setTemplateEngine(new FreemarkerTemplateEngine()); |
| mpg.execute(); |
| } |
| |
| } |
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术