SQL 更改表 - 为 COLUMN 类型 BLOB 添加默认值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6688233/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Alter Table - add Default value for a COLUMN type BLOB
提问by Tom
Executing the below SQL is giving this error .
执行以下 SQL 会出现此错误。
alter table TABLE_NAME ADD FILE_DATA BLOB NULL default 'EMPTY_BLOB()'
Error starting at line 37 in command: alter table TABLE_NAME ADD FILE_DATA BLOB NULL default 'EMPTY_BLOB()' Error report: SQL Error: ORA-30649: missing DIRECTORY keyword 30649.0000 - "missing DIRECTORY keyword"
*Cause: DEFAULT DIRECTORY clause missing or incorrect.
*Action: Provide the DEFAULT DIRECTORY.
从命令第 37 行开始出错:alter table TABLE_NAME ADD FILE_DATA BLOB NULL default 'EMPTY_BLOB()' 错误报告:SQL 错误:ORA-30649:缺少 DIRECTORY 关键字 30649.0000 - “缺少 DIRECTORY 关键字”
*原因:缺少 DEFAULT 或 DIRECTORY 子句.
*操作:提供默认目录。
Could someone help me out ?
有人可以帮我吗?
I can either create a new column of TYPE BLOB , or I can convert the same column created as a VARCHAR with DEFAULT value - and then change the type to BLOB . But I am not able to either of them .
我可以创建一个新的 TYPE BLOB 列,或者我可以转换作为具有 DEFAULT 值的 VARCHAR 创建的同一列 - 然后将类型更改为 BLOB 。但我不能他们中的任何一个。
回答by Justin Cave
Assuming you want the default value to be an empty BLOB rather than the string 'EMPTY_BLOB()', you'd just need to remove the quotes
假设您希望默认值是一个空的 BLOB 而不是字符串 'EMPTY_BLOB()',您只需要删除引号
SQL> create table new_table (
2 col1 number
3 );
Table created.
SQL> alter table new_table
2 add( file_data blob default empty_blob() );
Table altered.