OPENROWSET for Oracle - oracle

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.

Related

How to export data from multiple tables in a dynamic fashion in plsql

I have an plsql SP that creates multiple tables on a daily basis, however the number of tables are not always the same, however, the generated tables have a predefined pattern in its name.
I'm trying to create a plsql SP who exports those tables to a csv or excel file, based on a list input with the name of the generated tables.
Any ideas for achieving this rather than use PLSQL or is there any useful way of achieve this with it?
Thanks in advance
i think this question is very abstract and can have many solutions. Here is a solution that you can try if you want to create Excel from your data.
First you need a tool to create an excel file. Anton Scheffer has developed a package that you can use to create easily an Excel file from a cursor. Have a look: Create an Excel-file with PL/SQL.
Next, you can determine the created tables and create a query string that you can pass as parameter into query2sheet procedure of the Anton's package. All Tables you can find in user_tables View.
So your code could looks like:
for rec in (select * from user_tables where 1=1 /* or condition you need to filter the correct tables*/)
loop
-- as_xlsx - is a package created by Anton Scheffer
as_xlsx.query2sheet( 'select * from '||rec.table_name );
-- MY_DIR is a database Directory that you have to create
as_xlsx.save( 'MY_DIR', rec.table_name||'.xlsx' );
end loop;
Edit:
If you want to create a csv files, so you can use a package developed by William Robertson, Ref cursor to CSV converter.
The usage is quite similar to the Excel package.

How to execute select query on oracle database using pi spark?

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.

No records when using SELECT query on DBLINK in Oracle

I'm trying to move data in between two oracle databases say SOURCE_A and DEST_B. I have created a dblink (LINK_A) using TOAD on DEST_B to SOURCE_A to copy data from the tables. Dblink creation was fine, but when I used a select statement like below, I see no data except column names.
SELECT * FROM TABLE_A#LINK_A;
Could you please help me understand what am I doing wrong or missing here. I tried running a DESC on the TABLE_A using the link and it worked fine. Not sure why its not pulling any data from the SOURCE_A database.
Any help is greatly appreciated. Thanks.
Alright, with many trial and errors, I managed to get a solution that works for me in this SO question.
I used the technique provided by - Jeremy Scoggins and it worked like charm. I was able to move data using toad and its perfect. Thanks to all of you for your time and support.
Appreciate it.

Any tools to export the whole Oracle DB as SQL scripts

Here is my problem, I wants to create a baseline on our development Dateabase (Oracle 10g), and check into our svn for version control, and after this we will use liquibase to help us manage the incremental database changes.
My problem is how should I create baseline of Oracle 10g? the database now consists of 500+ tables, with large amount of configuration data, and I wants my db baseline to base on a set SQL scripts to check into subversion, rather then check in Oracle dump..
I have try use liquibase generateChangeLog, but it have some performance problem.. can anyone can recommends me any tools that will help me
1. Scan any Oracle Schema
2. Generate a set of SQL Scripts (With Table structures, and Data)..
Thanks in advance
James!
Something like
SELECT DBMS_METADATA.GET_DDL('TABLE',table_name) FROM USER_TABLES;
is a good start. You can tweak it with PL/SQL and UTL_FILE to get it to write each table to a different file. You will probably need to do sequences too (though versioning them is fairly pointless), and maybe triggers/procedures/functions/packages etc.
Don't forget grants.
Have you tried Oracle's free SQLDeveloper tool? It gives you the possibility of exporting DDL and data.
EXPDP with CONTENT=METADATA_ONLY option, then IMPDP with SQLFILE=your_script.sql ?
Nicolas.
More general solution would be to dump DDL sql for selected list of tables, but additionally also other types of objects. This could be done by using all_objects and all_users views.
Example that worked for me:
select dbms_metadata.GET_DDL(u.object_type,u.object_name, u.owner)
from all_objects u
where 1=1
-- filter only selected object types
and u.object_type in ('TABLE', 'INDEX', 'FUNCTION', 'PROCEDURE', 'VIEW',
'TYPE', 'TRIGGER', 'SEQUENCE')
-- don't want system objects, generated, temp, invalid etc.
and u.object_name not like 'SYS_%'
and temporary!='Y'
and generated!='Y'
and status!='INVALID'
and u.object_name not like 'TMP_%'
and u.object_name not like '%$%'
-- if you want to filter only changed from some date/timestamp:
-- and u.last_ddl_time > '2014-04-02'
-- filter by owner
and owner in (
select username from dba_USERS where DEFAULT_TABLESPACE not like 'SYS%'
and username not in ('ORACLE_OCM')
and username not like '%$%'
)
;
I wrote a python script that refreshes db schema in incremental mode based on similar sql:
runs sql with last_ddl_time>=max(last_ddl_time from last refresh)
at the end stores last_ddl_time somewhere in filesystem for next refresh
References:
oracle dbms_metadata.GET_DDL function
oracle all_objects view

Oracle: LONG RAW to?

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

Resources