Giter Site home page Giter Site logo

sql's People

Contributors

albatronhenry avatar

Watchers

 avatar

sql's Issues

mysql脚本数据导出成oracle执行脚本

将mysql格式的数据库ddl/dml脚本转换成oracle可执行脚本,步骤如下:

1.mysql创建数据库,导入原有mysql脚本。
2.navicat连接,选择刚才的数据库,右键--数据传输--文件--数据格式选择对应的数据库(此处选oracle x版本)--然后导出即可

Oracle Dblink使用

Oracle Dblink使用
私有(private和公有(public的dblink权限:

创建数据库链接的帐号必须有CREATE DATABASE LINKCREATE PUBLIC DATABASE LINK的系统权限,

用来登录到远程数据库的帐号必须有CREATE SESSION权限。这两种权限都包含在CONNECT角色中(CREATE PUBLIC DATABASE LINK权限在DBA中)。

一个公用数据库链接对于数据库中的所有用户都是可用的,而一个私有链接仅对创建它的用户可用。

1.创建DBLINK:
image
创建好后可以看到以下sql:
image
2.执行相应的远程SQL操作:
image
其他操作也是如此,只需加上@dblink别名

sql中查询/删除重复数据

参考链接
针对没有主键的重复数据

表test20181109
----------------
id    -    name
2     |      c
1     |      a
2     |      b
1     |      a
2     |      b
----------------

查询重复数据:

select id from test20181109 group by id having `count(1)`>1

id
1
2

删除重复数据,并保留其中一条

delete from test20181109 where id in (
select id from test20181109 group by id having count(1)>1
) and rowid not in (
 select min(rowid) test20181109 group by id having count(1)>1
)

处理后的数据:

----------------
id    -    name
2     |      c
1     |      a
----------------

oracle之自治事务(PRAGMA AUTONOMOUS_TRANSACTION

自治事务 PRAGMA AUTONOMOUS_TRANSACTION;参考连接

项目中,记录回滚数据操作记录,以便排查问题,用到该知识,故以此记录。

CREATE OR REPLACE TRIGGER "GL_BALANCE_CACHE_ZHH"
  after insert or update  on gl_balance_cache
  for each row

declare
    PRAGMA AUTONOMOUS_TRANSACTION;
     begin
      execute   immediate 'insert into gl_balance_cache1 (sum_id,fromctrlid, set_year, rg_code, account_id, ccid, set_month, avi_money,use_money, minus_money, aving_money, remark, bal_version, create_date, latest_op_date, last_ver, balance_id,is_enforce, index_) values ('''||
      :new.sum_id||''','''||:new.fromctrlid||''','''|| :new.set_year||''','''|| :new.rg_code||''','''|| :new.account_id||''','''||
 :new.ccid||''','''|| :new.set_month||''','|| :new.avi_money||','|| :new.use_money||','||
 :new.minus_money||','|| :new.aving_money||','''|| :new.remark||''','''|| :new.bal_version||''','''||
 :new.create_date||''','''|| :new.latest_op_date||''','''|| :new.last_ver||''','''|| :new.balance_id||''','''||
  :new.is_enforce||''','''||:new.index_||''')';
  commit;
end gl_balance_cache_zhh;

windows下安装PLSQL

参考网址
需求:

  本地开发环境需通过PLSQL连接Oracle数据库,但不想单独去安装几百兆的oracel客户端。

环境:

  WIN10企业版64位、PLSQL11 64位安装程序和oracle instantclient-basic-windows.x64-11.2.0.4.0,

  注意:PLSQL与oracle instantclient必须同为32位或64位,否则PLSQL会初始化oci.dll报错。

  下载链接:

   oracle instantclient-basic-windows.x64-11.2.0.4.0:链接: https://pan.baidu.com/s/1jId534y 密码: 7qif

   PLSQL11 x64:链接: https://pan.baidu.com/s/1slkILKp 密码: 5z5u

解决办法:

  1. 下载oracle官网提供的文件instantclient-basic-win64-11.2.0.1.0,以上百度网盘已提供,可免去登陆oracle烦恼。

  2. 解压配置instantclient
    下载后,解压文件到D:\instantclient_11_2,在目录中新建文件tnsnames.ora,文件内容如下:

192.168.8.29 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.8.29)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = YHT)
)
)

请根据本地oracle的安装配置自行更改黄色区域的内容,oracle主机名/服务名。

  1. 设置操作系统环境变量

TNS_ADMIN=D:\instantclient_11_2

NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK

配置完系统环境变量后 必要时建议重启一下电脑。

  1. 配置PLSQL

启动PLSQL,点击[取消] 进入PL/SQL主界面,点击“Tools -- Preferences”后,修改Oracle主目录名以及OCI库目录,如下图:
image

点击【确定】保存配置,重启PLSQL,如下图:
image

数据库下拉项已列出我们配置的数据库连接了,输入用户名、密码登录即可~

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.