oracle随机读取一条数据以及excle导入数据库

来源:互联网 发布:python 实现图像识别 编辑:程序博客网 时间:2024/05/17 22:23

随机读取一条数据

---------------------------随机取一条数据------------------------------------------
select * from (select rownum rr,return_info.* from return_info)
where rr= (select trunc(dbms_random.value(1,(select count(*) from return_info)+1)) from dual)
------------------随机排序然后取一条数据-------------------------------------------------------
select a.*,rownum from(select m.* from return_info m order by dbms_random.random)a where rownum=1

将excle导入数据库

方法一:

1.打开需导入的excel表格,单击office按钮,选择另存为--其他格式
选择保存路径(置于D:\),保存类型CSV(逗号分隔)(*.csv),设置文件名为student.csv,单击保存 
2.新建input.ctl文件(置于D:\),内容为:
load data
infile 'd:\student.csv' 
append into table student fields terminated by ','
trailing nullcols(id,name,sex,age)
说明:infile后面参数为欲导入的excel表(已转换成csv格式)路径及名称;append在表后追加;table后面跟oracle数据库中的表名称; terminated by ','表示字段分隔符;(id,name,sex,age)表示字段名称列表
3.打开运行,输入cmd,打开命令提示符,输入命令:
sqlldr userid=system/test@netservicename control=d:\input.ctl
说明:system/test,为oracle数据库表student的所有者及其密码;
@netservicename为网络服务名;
control是input.ctl文件名称及路径

方法二(使用PLSQL Developer):

1.在Excel中准备好要导入的数据。具体操作:在Excel中,把第一列设置为空列,第二列以后
的列应与要导入的数据表的字段相对应。
2.登录PLSQL Developer,找到需要导入数据的数据库表后,点击右键--edit data(或编辑数据),进入了编辑
此表的数据对话框,并点击最左侧选中一行(此时这行为空行)。
3.copy Excel表中的数据记录,将数据粘贴到上步中PLSQL Developer显示的表列中。
4.点击PLSQL Developer中的对号按钮进行Post。
注意:PLSQL Developer不认识“-”

0 0