how to insert picture or image into oracle database? - oracle

<code>
sql>CREATE TABLE Employees
(
Id int,
Name varchar(50) not null,
Photo varbinary(max) not null
)
</code>
This code is showing error like this:
photo varbinary(max) not null
*
ERROR at line 5:
ORA-00907: missing right parenthesis
Please help

You should use BLOB (Binary Large Object) which is ideal for storing multimedia content like images.
Check this out for storing images using BLOB.

You can create the table like below and insert into the table, below are the sample scripts for that
create table graphics_table (
bfile_id number,
bfile_desc varchar2(30),
bfile_loc bfile,
bfile_type varchar2(4));
INSERT INTO graphics_table
VALUES(4,'April Book of Days Woodcut',bfilename('GIF_FILES','APRIL.JPG'),'JPEG');
INSERT INTO graphics_table
VALUES(30,'',bfilename('GIF_FILES','SHAPIROS.GIF'),'GIF');
If u need more Info on this please refer to
http://www.dba-oracle.com/t_storing_insert_photo_pictures_tables.htm

First the question that has been posted is for SQL
varbinary(max) is a new datatype in sql2012
Cast f(x) will be used in order to convert the image into Binary format.
The insert query for the insertion of image is
insert into Employees values(1, 'ABC', cast('path\abc.jpeg') as varbinary(max));

Related

Unable to create table through another table in oracle SQL developer

I have been trying to create a new table by using below query :
"Create table d1_details_test2
as
select * from d1_details"
this above query gives me an error :
actually "d1_details" table has one column which has "Long" datatype and i cannot change it.
so i want to know the any other way to create the table.
Thanks
The long data type is subject to many restrictions. Create table as select is one of these.
You can get around it by applying to_lob in the select, which converts it to a clob:
create table views as
select view_name, text from user_views;
ORA-00997: illegal use of LONG datatype
create table views as
select view_name, to_lob ( text ) lob
from user_views;
desc views
Name Null? Type
VIEW_NAME VARCHAR2(128)
LOB CLOB

How do you insert data into complex data type "Struct" in Hive

I'm completely new to Hive and Stack Overflow. I'm trying to create a table with complex data type "STRUCT" and then populate it using INSERT INTO TABLE in Hive.
I'm using the following code:
CREATE TABLE struct_test
(
address STRUCT<
houseno: STRING
,streetname: STRING
,town: STRING
,postcode: STRING
>
);
INSERT INTO TABLE struct_test
SELECT NAMED_STRUCT('123', 'GoldStreet', London', W1a9JF') AS address
FROM dummy_table
LIMIT 1;
I get the following error:
Error while compiling statement: FAILED: semanticException [Error
10044]: Cannot insert into target because column number type are
different 'struct_test': Cannot convert column 0 from struct to
array>.
I was able to use similar code with success to create and populate a data type Array but am having difficulty with Struct. I've tried lots of code examples I've found online but none of them seem to work for me... I would really appreciate some help on this as I've been stuck on it for quite a while now! Thanks.
your sql error. you should use sql:
INSERT INTO TABLE struct_test
SELECT NAMED_STRUCT('houseno','123','streetname','GoldStreet', 'town','London', 'postcode','W1a9JF') AS address
FROM dummy_table LIMIT 1;
You can not insert complex data type directly in Hive.For inserting structs you have function named_struct. You need to create a dummy table with data that you want to be inserted in Structs column of desired table.
Like in your case create a dummy table
CREATE TABLE DUMMY ( houseno: STRING
,streetname: STRING
,town: STRING
,postcode: STRING);
Then to insert in desired table do
INSERT INTO struct_test SELECT named_struct('houseno',houseno,'streetname'
,streetname,'town',town,'postcode',postcode) from dummy;
No need to create any dummy table : just use command :
insert into struct_test
select named_struct("houseno","house_number","streetname","xxxy","town","town_name","postcode","postcode_name");
is Possible:
you must give the columns names in sentence from dummy or other table.
INSERT INTO TABLE struct_test
SELECT NAMED_STRUCT('houseno','123','streetname','GoldStreet', 'town','London', 'postcode','W1a9JF') AS address
FROM dummy
Or
INSERT INTO TABLE struct_test
SELECT NAMED_STRUCT('houseno',tb.col1,'streetname',tb.col2, 'town',tb.col3, 'postcode',tb.col4) AS address
FROM table1 as tb
CREATE TABLE IF NOT EXISTS sunil_table(
id INT,
name STRING,
address STRUCT<state:STRING,city:STRING,pincode:INT>)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '.';
INSERT INTO sunil_table 1,"name" SELECT named_struct(
"state","haryana","city","fbd","pincode",4500);???
how to insert both (normal and complex)data into table

SQL*Plus output messed up

when insert values into table the values are displayed unclear
here is the create statement
CREATE TABLE DEPARTMENTMANAGER(
MANAGER_ID INTEGER,
LAST_NAME VARCHAR(50),
FIRST_NAME VARCHAR(50),
PHONE_NUMBER INTEGER,
SSN INTEGER,
PRIMARY KEY (MANAGER_ID)
);
INSERT INTO DEPARTMENTMANAGER
VALUES
(120.'TOM','JERRY',2233445,109-38-2483);
SELECT * FROM DEPARTMENTMANAGER;
The data which I have inserted is displaying in random way:
After you create a table run the below line to fix the issue.
set linesize 200;
There is no problem with your data. The problem is with a way that result is presented to you.
Your client program, you use to connect to DB, does not have enough width so header and data are wrapped.
You can change the width and/or change the font size in your terminal.

ORA-01465: invalid hex number in oracle while using BLOB

i am designing a database in oracle 11g. I have designed a table with fields,
CUST_ID, NUMBER(5) //this is a foreign key
Review, BLOB //to store big strings
Date, SYSDATE
now when i'm trying to insert data in the table like-
insert into "ReviewTable" values ( 3, 'hello, this is the first review',SYSDATE)
it gives [Err] ORA-01465: invalid hex number.
If someone can help me with the error?
you cast your string into BLOB, you can do this via package utl_raw.cast_to_raw or convert varchar to clob via to_clob('mystring') and then use procedure DBMS_LOB.convertToBlob in your code
but if you are going to use the fields for string why don`t save them as a CLOB?
Here are 2 examples below with BLOB and CLOB fields
BLOB
create table ReviewTable( CUST_ID NUMBER(5)
,Review BLOB
,Dt Date);
insert into ReviewTable values ( 3, utl_raw.cast_to_raw('hello, this is the first review'),SYSDATE);
CLOB
create table ReviewTable2( CUST_ID NUMBER(5)
,Review CLOB
,Dt Date);
insert into ReviewTable2 values ( 3, 'hello, this is the first review',SYSDATE);

select inside CLOB and get what it cotains

I am not sure if this is duplicated ,I havent find it in the search.
I have a table called mytable that has column STORY the type of this column is CLOB
mytable
The elder tree
Soldiers
Going for a hunt
The blue moon
If i write :
select story from mytable
I will have the result:
Mytable
1-clob
2-clob
3-clob
4-clob
What I want what inside CLOB , can I achieve that ?
dbms_lob.substr( clob, bytes, startbyte );
but in sql you can retrieve only 4000 bytes into varchar

Resources