我是oracle数据库的新手,我正在制作一个非常简单的双语词典(2个表 - 英语和法语)。
字典通常包含数千个单词。我的问题是,有没有更好的方法以某种方式自动化过程,比如制作导入表单,而不是编写数千个[INSERT INTO ... VALUES]命令?由于我的学校书中只提到INSERT命令。
答案 0 :(得分:0)
您可以结合使用电子表格和INSERT ALL命令快速生成SQL INSERT命令以插入数据。
如果您的数据采用电子表格格式,则可以使用公式为每一行构建INSERT语句。
但是,您可以使用INSERT ALL语法而不是INSERT(单行)语法。
要做到这一点:
/**********************************************************************************************************************
* Import definitions
*********************************************************************************************************************/
import java.awt.Desktop;
import java.io.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.util.*;
import org.apache.poi.xssf.streaming.*;
import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.ss.util.ImageUtils;
/**********************************************************************************************************************
* This class implements a Minimal, Complete and Verifiable example for the problem of the maximum dy value for the
* {@link XSSFClientAnchor}.
*********************************************************************************************************************/
public class TestPictureOffset
{
/********************************************************************************************************************
* This constants represents the name of the file with the picture to import within the sheet.
*******************************************************************************************************************/
private static final String FILENAME_PICTURE = "./excel.png";
/********************************************************************************************************************
* These constants represents the width and height of the big cell within the sheet.
*******************************************************************************************************************/
// Don't do that. Instead do the same as apache poi does and use
// sheet.getColumnWidthInPixels and
// ImageUtils.getRowHeightInPixels to calculate width and height
private static final short BIG_CELL_COLUMN_WIDTH_IN_PIXELS = 317;
private static final short BIG_CELL_ROW_HEIGHT_IN_PIXELS = 56;
/********************************************************************************************************************
* This constants represents the default height of a cell within the sheet.
*******************************************************************************************************************/
private static final short DEFAULT_ROW_HEIGHT_IN_PIXELS = 20;
/********************************************************************************************************************
* This method places the specified picture on the sheet.
*******************************************************************************************************************/
private static void setPicture(int picture_index,
Sheet sheet)
{
// -----------------
// Initialize anchor
// -----------------
ClientAnchor anchor;
anchor = sheet.getWorkbook().getCreationHelper().createClientAnchor();
anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE);
// -----------------------------
// Set position
// THIS IS WHERE THE FUN HAPPENS
// -----------------------------
anchor.setCol1(1);
anchor.setRow1(0);
//anchor.setDx1((int)(0.5 * BIG_CELL_COLUMN_WIDTH_IN_PIXELS * Units.EMU_PER_PIXEL));
//anchor.setDy1((int)(0.4 * BIG_CELL_ROW_HEIGHT_IN_PIXELS * Units.EMU_PER_PIXEL));
anchor.setDx1((int)(0.5 * sheet.getColumnWidthInPixels(1) * Units.EMU_PER_PIXEL));
anchor.setDy1((int)(0.4 * ImageUtils.getRowHeightInPixels(sheet, 0) * Units.EMU_PER_PIXEL));
anchor.setCol2(anchor.getCol1() + 1);
anchor.setRow2(anchor.getRow1() + 1); // Fails if dy1 > 190500
//anchor.setRow2(anchor.getRow1() + 2); // OK independently from dy1
anchor.setDx2(0);
anchor.setDy2(0);
// ----------------------
// Show some measurements
// ----------------------
System.out.println("Got dy1: " + anchor.getDy1());
System.out.println("Maximum dy in default cell: " + (DEFAULT_ROW_HEIGHT_IN_PIXELS * Units.EMU_PER_PIXEL));
// ----------------
// Draw the picture
// ----------------
sheet.createDrawingPatriarch().createPicture(anchor, picture_index);
} // setPicture
/********************************************************************************************************************
* This method runs the application.
*******************************************************************************************************************/
private static void run()
throws Exception
{
// ---------------
// Create workbook
// ---------------
SXSSFWorkbook workbook;
workbook = new SXSSFWorkbook();
workbook.setCompressTempFiles(true);
// ------------
// Create sheet
// ------------
SXSSFSheet sheet;
sheet = workbook.createSheet("TestSheet");
sheet.trackAllColumnsForAutoSizing();
// --------------------------
// Create style with big font
// --------------------------
Font font;
CellStyle style;
font = workbook.createFont();
font.setFontHeightInPoints((short)32);
style = workbook.createCellStyle();
style.setFont(font);
// -------------------
// Write something big
// -------------------
SXSSFRow row;
SXSSFCell cell;
row = sheet.createRow(0);
cell = row.createCell(1);
cell.setCellStyle(style);
cell.setCellValue("Hello everybody");
// -----------------------
// Set row heigth according to the fonts height
// -----------------------
row.setHeightInPoints(workbook.getFontAt(style.getFontIndex()).getFontHeightInPoints()*1.275f);
// -----------------------
// Auto resize this column
// -----------------------
sheet.autoSizeColumn(1);
// ------------
// Load picture
// ------------
InputStream input_stream;
byte[] bytes;
input_stream = new FileInputStream(FILENAME_PICTURE);
bytes = IOUtils.toByteArray(input_stream);
input_stream.close();
// ---------------
// Add to workbook
// ---------------
int picture_index;
picture_index = workbook.addPicture(bytes, SXSSFWorkbook.PICTURE_TYPE_PNG);
// -------------------------
// Position picture in sheet
// -------------------------
// Workaround for SXSSFSheet which has not the correct row height in
// private CTTransform2D createXfrm(XSSFClientAnchor anchor)
// because of the streaming manner.
// So set default row height that big:
sheet.setDefaultRowHeight(sheet.getRow(0).getHeight());
// set the picture then:
setPicture(picture_index, sheet);
// and reset the default row height after that:
sheet.setDefaultRowHeight((short)(15*20));
// -------------
// Save workbook
// -------------
File output_file;
FileOutputStream output_stream;
output_file = new File("testxls.xlsx");
output_stream = new FileOutputStream(output_file);
workbook.write(output_stream);
output_stream.close();
workbook.close();
workbook.dispose();
// -------
// Open it
// -------
Desktop.getDesktop().open(output_file);
} // run
/********************************************************************************************************************
* M A I N
*******************************************************************************************************************/
public static void main(String[] args)
{
try
{
run();
}
catch (Exception exception)
{
exception.printStackTrace();
}
} // main
} // class TestPictureOffset
。您需要使用串联将值添加到此公式中。所以你的公式看起来像这样(假设A,B和C的列):
=" INTO表(col1,col2,col3)VALUES('"& A2&"''"& B2&"','"& C2&"')"
"INTO table (col1, col2, col3) VALUES ('val1', 'val2', 'val3')"
字样INSERT ALL
字样您的命令将如下所示:
SELECT * FROM dual;
这将在单个语句中插入所有记录,并且可能比数百或数千个INSERT语句快得多。
或者,您可以使用数据泵导入和导出等工具,但我的经验有限,所以也许其他用户可以详细说明。
答案 1 :(得分:0)
如果您的数据存储在文件中,则可以使用UTL_FILE包来读取,解析和加载数据。 Oracle ULT_FILE package
您也可以使用Oracle的外部表功能。看这里 Oracle External tables
答案 2 :(得分:0)
Oracle的Sql Loader产品非常适合快速加载大量数据。