I am writing a program in java where I need to create a copy of a table (without data). for that I am using the following query
CREATE TABLE NEW_TABLE AS
SELECT * FROM OLD_TABLE
I have come across a table where one of the columns has the data type LONG RAW which is depricated.
I tried using the query below but it did not work. (ORA-01003: no statement parsed
)
CREATE TABLE NEW_TABLE AS
SELECT ID, COL1, COL2, TO_LOB(COL3) FROM OLD_TABLE
Can someone tell me a simple query for this. It should be able to store the values from the previous table. I am using oracle 10g
Thanks in advance.
EDIT:
Sorry it was my mistake, the above query worked fine but I was calling executeQuery instead of executeUpdate
Perhaps this discussion would help.
Sorry it was my mistake, the above query worked fine but I was calling executeQuery instead of executeUpdate which was throwing an SQLException
Related
Could anybody help me translate this query from T-SQL to PLSQL, please?
I am using SQL Developer.
UPDATE schema.Table SET PICTURES =(SELECT * FROM OPENROWSET (BULK '\\shared folder\Picture.jpg', SINGLE_BLOB) a) WHERE (personID = 1111)
Thank you!
It looks to me like you are trying to apply a single image to a single person table row by selecting from an image file external to the database.
If my understanding is correct then I suggest you investigate Oracle EXTERNAL TABLE, DIRECTORY object and DBMS_LOB package.
Using some variant of these will certainly provide the solution you need.
I have written a program using pyspark to connect to oracle database and fetch data. Below command works fine and returns the contents of the table:
sqlContext.read.format("jdbc")
.option("url","jdbc:oracle:thin:user/password#dbserver:port/dbname")
.option("dbtable","SCHEMA.TABLE")
.option("driver","oracle.jdbc.driver.OracleDriver")
.load().show()
Now I do not want to load the entire table data. I want to load selected records. Can I specify select query as part of this command? If yes how?
Note: I can use dataframe and execute select query on the top of it but I do not want to do it. Please help!!
You can use subquery in dbtable option
.option("dbtable", "(SELECT * FROM tableName) AS tmp where x = 1")
Here is similar question, but about MySQL
In general, the optimizer SHOULD be able to push down any relevant select and where elements so if you now do df.select("a","b","c").where("d<10") then in general this should be pushed down to oracle. You can check it by doing df.explain(true) on the final dataframe.
I need to insert the huge records that are comes as Interface file(text files).
Now am using this format to insert records.
INSERT ALL
INTO POSTAL_CODE( postal_code,desc)
VALUES('100','Coimbatore')
INTO POSTAL_CODE (postal_code,desc)
VALUES('101','Mumbai') SELECT * FROM DUAL;
But this gives bad performance. I am new to database. So please help me to make faster inserting records. But in db2 this format is supports.
INSERT INTO POSTAL_CODE( postal_code,desc)
VALUES('100','Coimbatore'), (postal_code,desc),('101','Mumbai');
But why oracle is not support this type of insert. Please help me. Am stuck with this. I need to use another solution for this and that should be faster....
You can change the below statement
INSERT INTO POSTAL_CODE( postal_code,desc) VALUES('100','Coimbatore'),
(postal_code,desc),('101','Mumbai');
To be like below using UNION which should work in Oracle as well
INSERT INTO POSTAL_CODE( postal_code,"desc")
select '100','Coimbatore' from dual
union all
select '99','Goa' from dual
union all
select '101','Mumbai' from dual;
You should rather check the utilities provided by Oracle for this purpose like SQL*Loader
As well check this other SO post Loading data from a text file to a table in oracle
I am new to Sequel, but have a lot of background in SQL.
Getting frustrated with what I would call basic query functions not working. I am hoping it's a matter of just getting syntax correct.
I would like to create a temporary table, insert values into that table, then run a query against it.
In SQL I'd run this-
CREATE TABLE #TMP (CHRGCD VARCHAR)
INSERT INTO #TMP SELECT DISTINCT(CHRGCD) FROM PACPTCD WHERE CCTRMDT = '9999-01-01'
SELECT CHRGCD FROM PACPTCD
WHERE CHRGCD NOT IN (SELECT CHRGCD FROM #TMP)
Can I do this all from Sequel or am I going to have to create a real table, run a separate script to populate it, the run the last part of the query?
The data in the table PACPTCD can have multiple entries for CHRGCD but the CCTRMDT can vary. I'm trying to find all instances where CHRGCD doesn't have a value of 9999-01-01. Seems to be the easiest way to do it. Open to suggestions on other ways to get the data.
Thanks user007.
I ended up changing the query.
SELECT CHRGCD FROM PACPTCD
WHERE CHRGCD NOT IN (SELECT DISTINCT(CHRGC) FROM PACPTCD WHERE CCTRMDT='9999-01-01')
Dozen ways to do it. This one is the easiest. Even easier than my original.
I need to execute something like:
select
[very big SQL]
where phone_number in(:SQL2)
Is it possible to use bind variable for SQL2?
I want to save the execution plan of the major SQL.
Thanks.
Create a temporary table and save SQL2's results there prior to executing SQL1:
CREATE GLOBAL TEMPORARY TABLE mytemptable (id INT NOT NULL)
CREATE OUTLINE ol_sql1
ON
SELECT *
FROM sql1
WHERE id IN
(
SELECT id
FROM mytemptable
)
INSERT
INTO mytemptable
SELECT *
FROM sql2
SELECT *
FROM sql1
WHERE id IN
(
SELECT id
FROM mytemptable
)
If this query gets executed a lot of times, I wouldn't use a temporary table for it.
There is a 'trick' to bind an inlist, which Tom Kyte describes on his blog:
http://tkyte.blogspot.com/2006/06/varying-in-lists.html
I would bet on that being much more efficient. It should be easy to prove with a SQL Trace.
Further to Quassanoi's point. It sounds like you may not be familiar with temporary tables. This is a good introduction.
You only create the table once. Then within a given session you first:
populate the temporary table
execute your query pulling from the temporary table
rollback.
There's no risk of conflicting/overlapping with another session's data.