Ⅰ 求postgreSQL 的資料庫的表數據,導入導出的sql語句,謝謝!
Postgresql數據的導入和導出,以及命令介紹
如何導出PostgreSQL資料庫中的數據:
pg_mp -U postgres -f mp.sql mydatabase
具體某個表
pg_mp -U postgres -t mytable -f mp.sql mydatabase
導入數據時首先創建資料庫再用psql導入:
createdb newdatabase
psql -d newdatabase -U postgres -f mp.sql
把數據按照自己所想的方式導出,強大的命令:
echo " students to? stdout DELIMITER '|'"|psql school|head
(students為表名,school為庫名,各個欄位以|分隔)
echo ' (select * from students order by age limit 10) to stdout;' | psql school
Ⅱ 怎樣將postgresql數據遷移到oracle中
遷移PostgreSQL到Oracle涉及到兩方面工作:表結構的遷移和表數據的遷移。
表結構的遷移
表結構的遷移相對簡單可以藉助ESF DatabaseMigration Toolkit進行.。ESF Database MigrationTookit工具是試用版,所以不能通過其遷移數據(它會將所有varchar欄位的開頭替換為T)。通過ESF DatabaseMigration Toolkit遷移完成後,通過PL/SQL developer的export userobjects得到創建表結構的語句。
表數據的遷移
數據遷移有2種方式:postgreSQL導出insert語句然後執行語句導入或者postgreSQL導出文件然後用oracle的sqlldr方式導入。前者存在clob難以插入以及sql長度限制等問題,推薦後者方式進行數據遷移。
1.Copy命令導出數據文件
table1 to'd:/table1.data' delimiter as '|' nullas '';
注意:postgreSQL存在boolean類型導出為t或者f(oracle用int類型1或者2來代替),使用cast函數
Copy (select cast(column asint) from table1 )to 'd:/table1.data' delimiter as '|' null as '';
批量執行使用sql函數進行
create functionexportLiferay(path text) returns void
as
$$
begin
execute ' table1 to ''' || path || 'table1_.data''delimiter as ''|'' null as '''' ';
return;
end;
$$
languageplpgsql;
2. 製作sqlldr控制文件
注意:字元集、clob以及時間,日期類型
load data
CHARACTERSET UTF8
into table table1
fields terminated by "|"
optionally enclosed by '"'
trailing nullcols
(
folderid,
groupid,
companyid,
userid,
createdatetimestamp"yyyy-mm-dd hh24:mi:ss.ff",
modifieddatetimestamp"yyyy-mm-dd hh24:mi:ss.ff",
parentfolderid,
name,
descriptionchar(10000)
)
3.執行導入
sqlldr import/import data=table1.data control=table1.ctllog=table1.log readsize=100000000