- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试将数据帧传输到 oracle 数据库,但传输时间太长,因为变量的数据类型在 oracle 中显示为 clob。但是我相信,如果我将数据类型从 clob 转换为 9 位数字 并用填充 0,它不会花费那么多时间。数据是
product
000012320
000234234
有没有办法将此变量的数据类型更改为 9 位数字的字符串。这样 oracle 就不会将其视为 CLOB 对象。我尝试了以下方法。
df['product']=df['product'].astype(str)
或者是否有其他因素可能会减慢从 python 到 oracle 的传输速度?
最佳答案
这是一个演示:
import cx_Oracle
from sqlalchemy import types, create_engine
engine = create_engine('oracle://user:password@host_or_scan_address:1521:ORACLE_SID')
#engine = create_engine('oracle://user:password@host_or_scan_address:1521/ORACLE_SERVICE_NAME')
In [32]: df
Out[32]:
c_str c_int c_float
0 aaaaaaa 4 0.046531
1 bbb 6 0.987804
2 ccccccccccccc 7 0.931600
In [33]: df.to_sql('test', engine, index_label='id', if_exists='replace')
在 Oracle 数据库中:
SQL> desc test
Name Null? Type
------------------- -------- -------------
ID NUMBER(19)
C_STR CLOB
C_INT NUMBER(38)
C_FLOAT FLOAT(126)
现在让我们指定一个 SQLAlchemy 数据类型:'VARCHAR(max_length_of_C_STR_column)':
In [41]: df.c_str.str.len().max()
Out[41]: 13
In [42]: df.to_sql('test', engine, index_label='id', if_exists='replace',
....: dtype={'c_str': types.VARCHAR(df.c_str.str.len().max())})
在 Oracle 数据库中:
SQL> desc test
Name Null? Type
--------------- -------- -------------------
ID NUMBER(19)
C_STR VARCHAR2(13 CHAR)
C_INT NUMBER(38)
C_FLOAT FLOAT(126)
关于用 0 填充字符串的 PS,请检查 @piRSquared's answer
关于python - 在 Oracle DB 中将 pandas(字符串/对象)列保存为 VARCHAR 而不是 CLOB(默认行为),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39504351/
我在 presto 中有表,名为(“mappings”)的列将键值对作为字符串 从 hello 中选择映射; 例如:{“foo”:“baar”,“foo1”:“bar1”} 我想将“映射”列转换为 M
我总是会在表格的特定列中输入 20 个字符的内容。 我需要此列是唯一的。 如果我将此列设置为 varchar(255) 而不是 varchar(20),SELECT 查询的速度会有任何差异吗? (输入
我在 the Dapper .NET project home page 上发现了以下评论. Dapper supports varchar params, if you are executing
我有以下代码。 Case 语句将列出的数字转换为文本并将其余代码转换为 NULL,但我不断收到以下错误:将 VARCHAR 值“RDG5”转换为数据类型 INT 时转换失败。 RDG5 是被转换为 N
运行此脚本时出现以下错误。我尝试过使用以下内容:整理 Latin1_General_CI_AS。请问可以排序吗?谢谢 Msg 457, Level 16, State 1, Line 8 Implic
是否可以将 SQL Server 2008 数据库中的列类型从 varchar(255) 更改为 varchar(MAX),而无需删除表并重新创建? 每次我尝试使用它来执行此操作时,SQL Serve
每次我对选择 varchar(max) 或 varchar(fix) 数据类型感到困惑。假设我有一个大约 5000 个 varchar 的数据列。列不是 null 类型。 我应该将其设置为 varch
您好,我遇到问题,我的 friend 拒绝更改字段的数据类型,所以我在使用 order by 时遇到问题,这里是示例数据 04-07-2016(mm-dd-yyyy) 和字段名称名为 regis_da
对于文字游戏,我正在尝试向 VARCHAR 数组添加 CHECK 约束: CREATE TABLE words_games ( gid SERIAL PRIMARY KEY,
我有一个 varchar 字段,其内容如下: a,b,c,d e,d,a,c b,q,d,e 我需要执行一个查询,仅选择具有与输入字符串相等的元素的字段的行。 前输入:c,a 选择的行: a,b,c,
大家好,我计划创建包含 10 列的表,该表应该至少有 10,000,000 行,并且在其中,我将有列 description - VARCHAR(600) 和索引。 所以问题是,在该列上查询 LIKE
我读过这个question关于MySQL中VARCHAR(254)和VARCHAR(255)的区别。 HiveQL 中是否有必须考虑的类似内容?也许 HiveQL 实现了一些类似于 MySQL 的存储
在 MySQL 中,VARCHAR(1024) 和 VARCHAR(512) 有什么区别?如果我的项目永远不会超过 512 个字符,那么使用 VARCHAR(1024) 我会失去什么? 最佳答案 不知
由于 Varchar 字段的存储要求基于输入的字符串的实际长度,将每个 Varchar 字段指定为最大可能的缺点是什么:Varchar (65535)?那么,除了最大字段 > 255 个字符的 1 个
我正在尝试搜索具有数据类型 map(varchar,varchar) 的列。现在访问列的一种方法是使用这个结构,name_of_column[' key '],它将给出该键的值。但我想知道什么是可能的
快速提问。如果我将使用十进制字段限制或十六进制(比如 16、32、64 而不是 10、20、50),从存储数据的角度来看是否重要? 我问是因为我想知道这是否与 HDD 上的集群有关? 谢谢! 最佳答案
我发现我可以写 SELECT CAST(Min(mynumber) AS VARCHAR(Max))+'mystring' AS X 作为 SELECT CAST(Min(mynumber) AS V
我必须将字符串“johnmelling”值插入到列为 的表中[用户密码] varbinary NOT NULL。 请有人建议我,插入“johnmelling”的最佳转换是什么? 我尝试插入如下, In
我已经在 MSDN 论坛和此处阅读了此内容,但仍然不清楚。我认为这是正确的: Varchar(max) 将存储为文本数据类型,因此有缺点。假设您的字段可靠地少于 8000 个字符。就像我的数据库表中的
我有一个这样描述的表: mysql> describe easy_table; +---------------------+--------------+------+-----+---------
我是一名优秀的程序员,十分优秀!