Store sql script in database
Hi all,
pls is there any way to store a sql script in database and be able to run it from a report or a form.
many thanks,
hany
you can store functions, procedures and packages in a database and there a many ways to execute them.
select my_function(my_parameter) from dual;
or
begin
my_procedure(my_paramter);
end;
or
begin
my_package.my_procedure(my_paramter);
end;
please specify your sql script, for a more exact response
andreas
Similar Messages
-
How to generate sql script of database user
hello, I would like to generate the SQL script definition of a database user using JDveloper IDE (from ide connection).
Best Regards.You want to use jdeveloper to extract the info, don't you. The tool mostly used here is sql*plus.
You won't get any responses.
Sybrand Bakker
Senior Oracle DBA -
Is this possible in some form?
<cfquery name="name" datasource="dsn">
#query.sqlstatement#</cfquery>Yes, if you mean creating a query as a string, then using
that in a cfquery. Usually you would need to enclose the query text
within a PreserveSingleQuotes() function if you have parameters
that are enclosed within single quotes, something like this
<cfquery name="name" datasource="dsn">
#PreserveSingleQuotes(sqlstatement)#
</cfquery>
Phil -
Backingup Database using SQL script
Hello,
Let me start by saying I am new to Oracle, and I am trying to learn how to do a project where I must write an SQL script that can be used to back-up all the database files (i.e. control, redo log, and data files). Assuming that all of the files are stored in one folder, the source and destination locations of these files must be provided as "substitution variables". The script must implement the following tasks (directions)
Connect as user SYS with SYSDBA role
Shutdown the database
Copy the database files from the source location and store in the destination location
Restart the database
Connect as user SCOTT
In addition the script must use the "HOST" command to issue the operating system command to perform the copy task.
*Since this is just a learning project, and not a real scenario, I cannot run my script in SQLplus to verify if it is correct. This is why I am asking for some professional advice. I am currently working with Oracle 11g Enterprise running on a client Windows XP OS.
Below is what I have determined is a cold backup, please let me know if what I am doing is correct so far, and if not can you please steer me in the right direction.
connect SYS/<password> as SYSDBA
shutdown;
HOST copy from &source_file to &destination_file; --this is the line that is confusing me.
connect SYS/<password> as SYSDBA
startup;
connect scott/tiger
thank you in advance for your time and input.Thank you Brian and Frank. I agree with you that RMAN is the best way to perform a backup (from what I have read over the last week or so) in a production scenario., especially if the DB needs 24/7 access. Also , thank you Brian for the helpful links.
I currently have the free Oracle Enterprise 11g edition downloaded to my computer, running on VB with client Windows XP OS. But being new at this I find myself scared of running bad script that may break down my DB. I know I can just reload it and start over, but I am trying to approach this as carefully as possible. Although, the error codes help me understand what I am doing wrong a lot of the time.
Also, thank you Frank for the shutdown immediate advice. I also like the idea of writing/saving data to the spool for future reference that will definitely come in hand down the road. I didn't think about writing a .bat file to run via SQL*Plus, that would also be a great alternative.
Continuing with the hypothetical scenario that I need to perform a very basic cold backup that requires a shutdown (with archive logging off) and a restart, do you think this script would run error free. Also, assuming the substitute variables are actual paths to where the whole of the database files are stored and their new destination file actually exists.
--Windows XP OS
connect SYS/<password> as SYSDBA
shutdown IMMEDIATE;
HOST copy &source_file &destination_file
connect SYS/<password> as SYSDBA
startup;
connect scott/tiger
Thank you again for your time and patience.
I find myself learning more from asking questions to professionals on this site than from my own professors. -
Running sql script files to re create database
We have having around 10 sql script file that has sql statments inside it (example insert .... delete...update.... etc).Right now what we do is that in jdbc we open each script file, and read each line ,and then make jdbc call run jdbc for each sql statement inside the file.
Wondering if there is a better way to do this.
Right now the challenges are
1)The process goes wrong if there is an extra semi colon ...or extra space after a statments...etc...Basically I find this way of creating data odd...
2)it is slow because of the network traffic between application server and database server for every sql statements that gets executed.The solution for this issue is to do a batch update....But still I dont like this solution.
Can someone give me any better idea.
I am thinking to have all this sql script moved to a store procedure (rather than inside the sql script file) .JDBC then can pick this store procedure sql file ,and create this store procedure via jdbc, and then execute this store procedure.
This will be faster because all the sql will be running in the databsase.Only one trip to database to call this store procedure.
Is this a good idea ?
thx
mManjit wrote:
We have having around 10 sql script file that has sql statments inside it (example insert .... delete...update.... etc).Right now what we do is that in jdbc we open each script file, and read each line ,and then make jdbc call run jdbc for each sql statement inside the file.
Wondering if there is a better way to do this.
Right now the challenges are
1)The process goes wrong if there is an extra semi colon ...or extra space after a statments...etc...Basically I find this way of creating data odd...
2)it is slow because of the network traffic between application server and database server for every sql statements that gets executed.The solution for this issue is to do a batch update....But still I dont like this solution.
Can someone give me any better idea.
I am thinking to have all this sql script moved to a store procedure (rather than inside the sql script file) .JDBC then can pick this store procedure sql file ,and create this store procedure via jdbc, and then execute this store procedure.
This will be faster because all the sql will be running in the databsase.Only one trip to database to call this store procedure.
Is this a good idea ?
thx
mI'm not 100% sure i follow (it's Friday and i have a mild case of ADD).
Are you suggesting having the Java application create procedures in the database on the fly? If so i would say that's not a good idea.
Create the stored procedures in the database, have Java call them as needed to process data.
If you need to load copious amounts of data, look in to external tables, it's possible they could come in handy for what you are doing .... or not ... again, it's hard to say given i find your description of what's currently happening somewhat confusing. -
SQL script based on hostname and database name?
I am trying to write a script that I can run on several unix servers and databases that will do different sql statements based on which server and database it is being run in.
Something like:
if hostname = 'A' and database name = 'D' then do this
else if hostname = 'B' and database name = 'F' then do that
I have tried many diifferent combinations of shell scripts and sql scripts but can't seem to get anything that works.
Can someone help me out? Thanks.Since you are already able to get he db and host info, you are well on your way to branching based on that information. All you need is the basic framework:
declare
db VARCHAR2(30);
host VARCHAR2(30);
sqlcmd VARCHAR2(4000);
begin
select sys_context('userenv','host') host
, sys_context('userenv','db_name') db_name
into host
, db
from dual;
case
when db = 'XE' and host = 'mypc' then
sqlcmd := q'[local_package.do_something('parm1', :db, :host)]';
execute IMMEDIATE sqlcmd USING db, host;
when db = 'DEV' and host in ('serv1','serv2') then
sqlcmd := q'[different_packge.do_something('parm1', :db, :host)]';
execute IMMEDIATE sqlcmd USING db, host;
else
dbms_output.put_line('unrecognized db/host combination: '||db||', '||host);
end case;
end;
/In this example I've used dynamic SQL since not all instances are guaranteed to have any or all of the package procedures referenced in the dynamic sql. With out the dynamic sql, you would get errors and be unable to run the script on any instance lacking one or more of the reference package procedures.. -
Send mails with csv file as an attachment through oracle(SQL SCripts / Stor
Hello Everybody,
I have recently come across a requirement in which I am supposed to send mails with csv file as an attachment through oracle(SQL SCripts / Stored Procedure) .
The contents of the csv file are to be retreived from the Database as well as the content of the mail and to whom it needs to be sent has also to be picked up from the database.
Can somebody suggest me with a suitable code for the same?
Would be of great help..!!
Thanks & Regards,
- VR
Edited by: user646716 on Dec 18, 2009 10:44 AMread below links
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:255615160805
http://www.orafaq.com/wiki/Send_mail_from_PL/SQL#Send_mail_with_UTL_TCP_-withattachments
How to send csv file as an attachment -
Using an SQL Script file to create database in Java? (monkeyDB.sql)
Hello!
I am a writing an SQL Script so that I can re-create my database on another server (im using my laptop to test it on first though).
I'm connecting to mySQL server using JDBC which works fine, but I was wondering
how can I run an entire script file, say myScript.sql from within a Java class??
(an SQL Script is simply a file containing the regular SQL commands and expressions that you might enter at an sql command line prompt)
example of an SQL Scritp: monkeyDB.sql>>
//#create new db
CREATE DATABASE sample_db;
//#set active db
USE sample_db;
//#set table paramaters
CREATE TABLE monkeys
(name CHAR(20),
age INT UNSIGNED,
sex ENUM('M','F')
//#create standard monkeys
INSERT INTO monkeys(name,age,sex) VALUES("Sammy",10,"M");
INSERT INTO monkeys(name,age,sex) VALUES("Muncht",12,"M");
INSERT INTO monkeys(name,age,sex) VALUES("Jill",8,"F");
//#get recordset
SELECT * FROM monkeys WHERE age < 50;Thanks for your help!thanks. :-)
I thought about that too but I didnt want to hard wire it into the code.
I guess it isnt possible to output the script file using some command from the sql library..? -
Running the same sql script in multiple databases
Hello,
What is the method to run the same sql script in multiple databases? I want to write a unix script that would select from different databases and run a sql/plsql script in those different databases. What are the ways to write such a unix script? Thank you in advance.Just have a parameter which takes in the oracle connection parameters and use it in your sqlplus script with your shell script.
Your sqlplus script can have a procedure/function call or an anonymous block;
Then have a wrapper script to call the original script with different connection parameters. Hope this helps. -
Hi everyone,
I want to accomplish a task in TFS that I need to auto generate the database changes as SQL script file in drop folder for every build.
For ex.: If I add a table in a database and then check in the changes, I need to get that create table script in the drop folder as .sql file extension
I want to automate the build too for every check in. Help me out and guide me a step by step procedure because since I am new to TFS build in visual studio.
ThanksCheck out SSDT:
https://msdn.microsoft.com/en-us/data/tools.aspx
It can generate a DACPAC which can be used to update a SQL Database through the commandline. To ensure that the .sql file executed is compatible with the target database schema it contains a compiled version of teh schema and will generate the change script
on-the-fly.
If you want, you call SqlPackage,exe to generate a SQL script if you want to inspect it before executing.
https://msdn.microsoft.com/en-us/library/hh550080%28v=vs.103%29.aspx
My blog: blog.jessehouwing.nl -
How to get the database owner name in T-SQL script
Hello, All!
I want to get the database ower name (in format DOMAIN\user) by through T-SQL script. But SELECT * FROM sys.databases returns only owner_sid.
Please show me a way - how to get the owner name, if you have only owner_sid. Or, may be, somebody know another way ?
Andy MishechkinSELECT suser_sname( owner_sid ), * FROM sys.databases
http://www.t-sql.ru -
Cannot run SQL script on Oracle Database 10g Express Edition
I'm trying to upload a script, and the file is being uploaded fine, but in the Script Editor window where I'm going to actually run the script, the entire file content is shown on one line and the whole edit area is in red. I'm not being able to run that script. Also if I create a new script from the editor, the edit area is again in red and I'm not able to save it. Please help me understand what's to be done so that I can run my SQL scripts.
I'd bet the database is down.
Try a login through sqlplus ("Run SQL Command Line" in the Oracle Express Edition 'Start' menu).
Do a CONN / AS SYSDBA
If you get a message about database or memory area not available, try STARTUP.
If that doesn't work, you are best off in the General Database forum or the Express Edition forum.
You'll probably get the most expert response in General Database, but the Express Edition forum can be gentler on newbies (as it is more accepted that questioners are not and do not have access to full-time DBAs). -
Can anyone confirm if I need to modify the InsertVersionInfo.sql and Permisioins.sql scripts for both the APP-V Management and Reporting databases? KB3031340 only references the Management Database, but I suspect it is required for both.
Thank You!It should only apply to Management Database. There weren't any changes to the Reporting DB AFAIK.
Steve Thomas, Senior Consultant, Microsoft
App-V/MED-V/SCVMM/Server App-V/MDOP/AppCompat
http://blogs.technet.com/gladiatormsft/
The App-V Team blog: http://blogs.technet.com/appv/
The MED-V Team Blog: http://blogs.technet.com/medv
The SCVMM Team blog: http://blogs.technet.com/scvmm/
“This posting is provided "AS IS" with no warranties, and confers no rights. User assumes all risks.” -
How to execute sql scripts from Powershell across multiple databases
Re: How to execute sql scripts from Powershell across multiple databases
I have an tsql script that I want to run across a list of databases. How is the best way to do this in Powershell? Thanks.My example below, using just the SMO and not breaking up the batches, the ExecuteWithResults give the following error when the .sql file contains a GO. My script files are as simple as a DECLARE and then a GO.
WARNING: SQL Script Failed
The object of type "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not valid or not in the correct sequence. This is likely caused by a user-specified "format-list" comm
and which is conflicting with the default formatting.
+ CategoryInfo : InvalidData: (:) [out-lineoutput], InvalidOperationException
+ FullyQualifiedErrorId : ConsoleLineOutputOutOfSequencePacket,Microsoft.PowerShell.Commands.OutLineOutputCommand
Also, when executing from the ISE, is there a way to force the ISE to release the files. I am having to close the ISE and reopen my script every time I want to make a testing change to the .sql file.
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")
$scriptspath = "C:\temp\psExecuteSQLScripts\scripts"
$SQLServer = "fidevc10"
$SQLDB = "Bank03"
# Create SMO Server Object
$Server = New-Object ('Microsoft.SQLServer.Management.Smo.Server') $SQLServer
# Get SMO DB Object
$db = $Server.Databases[$SQLDB]
# Load All SQL Scripts in Directory
$scripts = Get-ChildItem -Path (Join-Path $scriptspath "*") -Include "*.sql" -Recurse
# Loop through each script and execute
foreach ($SQLScript in $scripts)
$fullpath = $SQLScript.FullName
# Read the Script File into Powershell Memory
$reader = New-Object System.IO.StreamReader($fullpath)
$script = $reader.ReadToEnd()
# Execute SQL
Write-Host "Executing $SQLScript on $SQLDB...."
try
$ds = $db.ExecuteWithResults($script)
Foreach ($t in $ds.Tables)
Foreach ($r in $t.Rows)
Foreach ($c in $t.Columns)
Write-Host $c.ColumnName "=" $r.Item($c)
Write-Host "Complete"
catch [Exception]
Write-Warning "SQL Script Failed"
echo $_.Exception|format-list -force
Write-Host " " -BackgroundColor DarkCyan -
Store SQL Query in Oracle database
Hello,
I am storing SQL query in database. here is an example of query.
INSERT INTO TABLE_1 Values (' " + getValue1() + " ', ' " + getValue2() + " ' )
getValue1() and getValue2() are functions to retrieve values.
When I read query from the database and execute it, it doesn't read values from function.
After I read query from database I would expect it to be
INSERT INTO TABLE_1 Values ('value1', ' value2' ) but it is not reading values and trying to execute whatever I got from database.
Any help?
ThanksThanks for your reply. Let me give you more info.
All I am trying to do is storing queries in oracle
database to use it in future for reporting. As I am
doing reporting where clause will be different every
time. Reporting involves queries not updates. But in any case that means that you would use a java SQL string that is useable via a prepared statement. As such your statement would look like....
INSERT INTO TABLE_1 Values (?,?)
Is it not possible to substitute variable string I
got from database?What do you mean?
SQL is SQL. You construct SQL so it is valid and runs. Can you construct SQL so it runs a function/select and uses that value in some more SQL - depends on the database, but usually.
But that has nothing to do with java - it is SQL.
Query contains variables that I have in Java code .Then it is SQL. It is java. You use bind variables (see PreparedStatement) and assign values to it.
The SQL for such a query would look like the following...
select field1, field2 from table1 where id=?
In your java you would then use something like PreparedStatement.setInt(1, 100), to fill in the value for the '?' in the above.
You might also note that your solution will not work for any arbritrary SQL statement unless you are also storing meta data about the SQL itself. For instance the following SQL statements would return the same result set but your java code would have to populate the bind variables different for both...
select field1, field2 from table1 where id=? and name=?
select field1, field2 from table1 where name=? and id=?
Maybe you are looking for
-
Firefox will not start until reboot
I am using FF newest version, win 7, etc. I have a very strange problem. Sometimes, once every 2-4 days, my FF will not start when the computer first start. That's when the computer cold boot, I click on FF and nothing happens. I looked in task manag
-
Yahoo mail keeps going offline
I updated my yahoo password the other day. Ever since then my yahoo mail (through imac mail app) has been going offline. I can not send messages using my imac. I should note that I do not have any issues signing into yahoo.com and sending/ receivin
-
Broken links to ABAP keyword documentation
Hi, The links to ABAP Keyword documentation on SAP Help portal mentioned by Horst Keller here: http://help.sap.com/abapdocu_740/en/index.htm http://help.sap.com/abapdocu_740/de/index.htm appear to be down again for me... Ditto for http://help.sap.com
-
Wrong photo count on my.mac page
WHY DOES THE .MAC (page with email,account,groups, www. etc.)PAGE SAY 59 PHOTOS WHEN IN FACT THE MAIN PAGE HAS FOUR PHOTOS & THE PHOTOS PAGE HAS 27, TOTAL 31?
-
ANN: WS Structure Tools 2.0 is released
Hi, West Street Consulting is pleased to announce the release of its Structure Tools plugin, version 2.0. This version includes a new modeless attribute editor that significantly speeds up the process of editing attribute values, with a variety of am