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
Similar Messages
-
How to generate sql script based on table structure
I want to generate a sql script based on a table structure.
For example:
if the table is:
cid id c_value
1 1 zz
2 1 yy
3 2 zz
4 2 xx
5 3 ss
6 3 tt
The expected output is:
WITH
CHILD_tab as (
SELECT 1 cid, 1 id,'zz' c_value from dual union all
SELECT 2 cid, 1 id,'yy' c_value from dual union all
SELECT 3 cid, 2 id,'zz' c_value from dual union all
SELECT 4 cid, 2 id,'xx' c_value from dual union all
SELECT 5 cid, 3 id,'ss' c_value from dual union all
SELECT 6 cid, 3 id,'tt' c_value from dual )
Release 11.1.0.7.0I'm doing a lot of XML these days (too much perhaps) so here's a solution involving XQuery.
We pass a query string and it outputs a CLOB containing the WITH clause :
SELECT DBMS_XMLGEN.Convert(
XMLQuery(
q'[concat(
"WITH t AS (
string-join(
for $i in /ROWSET/ROW
return concat( " SELECT ",
string-join($i/*/concat("'",ora:replace(text(),"'","''"),"' ",local-name()),", "),
" FROM dual" ),
" UNION ALL
passing dbms_xmlgen.getXMLType('SELECT * FROM scott.emp')
returning content
).getClobVal(), 1) AS WITH_CLAUSE
FROM dual;
WITH_CLAUSE
WITH t AS (
SELECT '7369' EMPNO, 'SMITH' ENAME, 'CLERK' JOB, '7902' MGR, '17/12/80' HIREDATE, '800' SAL, '20' DEPTNO FROM dual UNION ALL
SELECT '7499' EMPNO, 'ALLEN' ENAME, 'SALESMAN' JOB, '7698' MGR, '20/02/81' HIREDATE, '1600' SAL, '300' COMM, '30' DEPTNO FROM dual UNION ALL
SELECT '7521' EMPNO, 'WARD' ENAME, 'SALESMAN' JOB, '7698' MGR, '22/02/81' HIREDATE, '1250' SAL, '500' COMM, '30' DEPTNO FROM dual UNION ALL
SELECT '7566' EMPNO, 'JONES' ENAME, 'MANAGER' JOB, '7839' MGR, '02/04/81' HIREDATE, '2975' SAL, '20' DEPTNO FROM dual UNION ALL
SELECT '7654' EMPNO, 'MARTIN' ENAME, 'SALESMAN' JOB, '7698' MGR, '28/09/81' HIREDATE, '1250' SAL, '1400' COMM, '30' DEPTNO FROM dual UNION ALL
SELECT '7698' EMPNO, 'BLAKE' ENAME, 'MANAGER' JOB, '7839' MGR, '01/05/81' HIREDATE, '2850' SAL, '30' DEPTNO FROM dual UNION ALL
SELECT '7782' EMPNO, 'CLARK' ENAME, 'MANAGER' JOB, '7839' MGR, '09/06/81' HIREDATE, '2450' SAL, '10' DEPTNO FROM dual UNION ALL
SELECT '7788' EMPNO, 'SCOTT' ENAME, 'ANALYST' JOB, '7566' MGR, '19/04/87' HIREDATE, '3000' SAL, '20' DEPTNO FROM dual UNION ALL
SELECT '7839' EMPNO, 'KING' ENAME, 'PRESIDENT' JOB, '17/11/81' HIREDATE, '5000' SAL, '10' DEPTNO FROM dual UNION ALL
SELECT '7844' EMPNO, 'TURNER' ENAME, 'SALESMAN' JOB, '7698' MGR, '08/09/81' HIREDATE, '1500' SAL, '0' COMM, '30' DEPTNO FROM dual UNION ALL
SELECT '7876' EMPNO, 'ADAMS' ENAME, 'CLERK' JOB, '7788' MGR, '23/05/87' HIREDATE, '1100' SAL, '20' DEPTNO FROM dual UNION ALL
SELECT '7900' EMPNO, 'JAMES' ENAME, 'CLERK' JOB, '7698' MGR, '03/12/81' HIREDATE, '950' SAL, '30' DEPTNO FROM dual UNION ALL
SELECT '7902' EMPNO, 'FORD' ENAME, 'ANALYST' JOB, '7566' MGR, '03/12/81' HIREDATE, '3000' SAL, '20' DEPTNO FROM dual UNION ALL
SELECT '7934' EMPNO, 'MILLER' ENAME, 'CLERK' JOB, '7782' MGR, '23/01/82' HIREDATE, '1300' SAL, '10' DEPTNO FROM dual
)It may be useful for small data sets only because we quickly hit ORA-01706. -
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 -
How to generate .SQL format file from oracle database?
How to generate .SQL format file from oracle database?
I have a database of Oracle 8.1.6,now want to generate script file (including table structure,index,etc.) from it,What should I do?
Thanks.Your question pertains to the Database Export/Import. This forum exclusively focusses on the export/import utilities that come along with "Oracle Portal" which is a web-based tool. Could you please post your question under the RDBMS export/import or migration forum.
-
Hi,
How to Validate SQL scripts?
I am having set of sql files i wish to run one by one if there is any error at one file i need to notify to the user.I have created Bat file in-order to execute in a sequence.how to validate in bat file
say
01.sql ---Sucess
02.sql --- Fail -- intimate and not to execute rest of sql files
03.sql
04.sql
Thanks!933663 wrote:
I am going to create the database
cloneDBCreation.sql
CloneRmanRestore.sql
init.ora
initEDIDBTemp.ora
lockAccount.sql
postDBCreation.sql
postScripts.sql
rmanRestoreDatafiles.sql
dbname.bat
dbname.sqlSo i need to validate each and every .sql whether it succeed or not. if there is failure then needs to notify the user. Use the SQL*Plus macro/command, WHENEVER SQLERROR EXIT <n>, to terminate a sql script when it hits an error - and have it return a specific exit code to the caller (o/s command line in this case). Note that exit codes are typically defined as a single byte in shells - which means it can only returns 0 to 255.
In the command line shell, check the exit code of the previous command - which would be command than ran sqlplus and the sql script. If the exit code is for example 255, then you know the WHENEVER SQLERROR command was executed. And then you cease processing sql scripts.
Simplistically (I do not do Windows), it will look as follows:
--// sql script
whenever sqlerror exit 255
... rest of the script
@echo off
rem command shell script
prompt executing script 1
sqlplus -s /nolog @sqlscript1.sql
if ERRORLEVEL 255 goto :ScriptFailed
prompt executing script 2
sqlplus -s /nolog @sqlscript2.sql
if ERRORLEVEL 255 goto :ScriptFailed
goto :Success
:ScriptFailed
echo ...
goto :End
:Sucess
echo ..
goto :End
:End -
How to call SQL Script in DBMS_SCHEDULER
How to call SQL Scripts in DBMS_SCHEDULER?
Things I got working
1) Successfully created and tested a PL/SQL that was created under SQL Workshop->SQL Scripts (I named it 'TEST'). I was able to run this no problem.
2) Successfully created a DBMS_SCHEDULER that runs every minutes. (See below)
begin
dbms_scheduler.create_job(
job_name => 'myjob',
job_type => 'plsql_block',
job_action => 'null;',
start_date => '19-JUL-11 03.10.00 PM', /* Remember to use the DB time, not your local time if not specifying a timezone */
repeat_interval => 'freq=minutely',
enabled => true);
end;The problem i am having is to make the PL/SQL script (named 'TEST') runs every minute. Its probably very easy to do that but i dont seems like finding any examples online.
I tried replacing the job_action attribute to " job_action => 'begin TEST; END;', " However, that did not work.
I am stuck here for couple hours already, any clues would be great :)
Thanks in advance
John
Application Express 4.1.0.00.32
Edited by: John Lau on Aug 14, 2012 12:47 PM
Edited by: John Lau on Aug 14, 2012 12:48 PMThe PL/SQL is pretty long, I would like to call it from a different location rather then putting the whole coding as part of the argument. Sounds like I should be looking into procedure package in database?
I will do some more research on procedure package, how to create one and how to call from it.
Thanks
John -
can we create sql scripts in ssis ; just like we create new excel files on package execution .
well I simplified requirement:
I want to run an SP and run this query and return the below update statement as output.
:select BusinessEntityID, into #temp from [HumanResources].[Employee]
where jobtitle ='Engineering Manager'
update ph
set ph.payfrequency=10*2
from [HumanResources].[EmployeePayHistory] ph where BusinessEntityID in (select * from #temp)
Hi Chelseasadhu,
Do you want to generate such an T-SQL script as you posted above or you want to execute the above script in a SSIS package? If the former, there is not a stock task/component in SSIS can generate T-SQL script; if the later, you can execute
the script via Execute SQL Task. One option is to use Script Task or Script Component to generate SQL script via SQL Server Management Objects (SMO):
http://www.mssqltips.com/sqlservertip/1833/generate-scripts-for-database-objects-with-smo-for-sql-server/
http://msdn.microsoft.com/en-IN/library/ms162153.aspx
Regards,
Mike Yin
TechNet Community Support -
How to restore SQL Server 2008 database to SQL Server Express 2012
How to restore SQL Server 2008 database to SQL Server Express 2012.
I BACKED UP a SQL Server 2008 database from work, which runs the enterprise version of 2008, and I tried to RESTORE it to my new 64-Bit home PC which is running the new SQL Server Express 2012 64-Bit (Advanced Edition).
But if fails. I get the following message text.
Can anyone help me please. I thought restoring a 2008 database to the later version 2012 would be possible.
Here is the error message. Thanks.
TITLE: Microsoft SQL Server Management Studio
Restore of database failed. (Microsoft.SqlServer.Management.RelationalEngineTasks)
ADDITIONAL INFORMATION:
System.Data.SqlClient.SqlError: The database was backed up on a server running version 8.00.2039. That version is incompatible with this server, which is running version 11.00.3128. Either restore the database on a server that supports the backup, or use a
backup that is compatible with this server. (Microsoft.SqlServer.SmoExtended)ADDITIONAL INFORMATION:
System.Data.SqlClient.SqlError: The database was backed up on a server running version 8.00.2039. That version is incompatible with this server, which is running version 11.00.3128. Either restore the database on a server that supports the
backup, or use a backup that is compatible with this server. (Microsoft.SqlServer.SmoExtended)
Are you sure your database is SQL server 2008 from error message it seems your SQL server version is 2000.I guess you have multiple versions of SQL server.
AFAIK you cannot restore backup of SQL server 2000 to 2012 directly .Restore it first to SQL 2008/2008R2 or 2005 then take backup again of new database created and then you would be able to restore it on 2012.Its kind of intermediate way
Also make sure your DB size is less than 10 G as max DB size supported by Express edition is 10 G and if your DB size is more than 10 G restore will fail.
You are also trying to restore enterprise DB backup on express edition so you will loose enterprise features on express edition
Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers -
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,
hanyyou 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 -
How to Use Discoverer Desktop without Database User ?
Hi,
I am new to Discoverer Desktop,
How to Use Discoverer Desktop without Database User ?
SureshYou'll need to have access to some sort of database account to use the tool. If you just loaded the tool onto a machine, Disco is not going to be useful - you need to create an end user layer, and business areas.
I suggest you start here:
www.oracle.com/technology/documentation/bi.html -
How to get SQL script for generating table, constraint, indexes?
I'd like to get from somewhere Oracle tool for generating simple SQL script for generating table, indexes, constraint (like Toad) and it has to be Oracle tool but not Designer.
Can someone give me some edvice?
Thanks!
m.I'd like to get from somewhere Oracle tool for
generating simple SQL script for generating table,
indexes, constraint (like Toad) and it has to be
Oracle tool but not Designer.
SQL Developer is similar to Toad and is an Oracle tool.
http://www.oracle.com/technology/products/database/sql_developer/index.html -
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 -
Generating .sql script for all objects of a User/Schema
Hi All,
What are the ways in which I can generate scripts for a full USER (all objects) with dependencies. (by dependencies I mean for example that PK be created first before creating FK).
We can export the full schema using (exp rows=n) but this will generate a .dmp file. I want a .sql file which can be run on any other machine (from SQL> prompt) so that user and all objects are created (without the need to use "imp").
Thanks
-AKJBut the easiest way to do this would be to do an export with rows=N and then an import.
You coule do an export and then let run the import utility with indexfile=<you_name_it>.sql and this way you'll get a file with all statements included (but table definition commented out).
Or you do it yourself (DIY-method), where you have to select all your relevant objects and their dependencies. -
Generating SQL Script for Existing Tables and DBs
Hello,
is it possible to generate automatically a SQL-Script from an existing table or oracle database ?
I want to export an existing table from an Oracle DB (g11) if its possible with the data.
Perhaps somebody could me explain how to to do this.
I am using the "SQL Developer 2.1" and the "enterprise manager konsole".
I'm a rookie in using this tools.
Thank you for any informations.
N. WylutzkiIf you want to export data, you should use the export utility. This is documented:
http://tinyurl.com/23b7on -
What would be the best way to generate an SQL script from a development environment to a customer site?
Any suggestions greatly apprecaited.
JohnIf your question is about running a SQL script from box 1 to box 2, you could just configure your Net8 (tnsnames,sqlnet.ora) so that you can "talk" to the other database.
If your question is about having an application build sqlscripts, then I would use generic coding with bind variables or lexical variables.
If on the other hand, you want to just generate the SQL Scripts for users to execute at the other site, just send them your SQL in a text file.
Maybe you are looking for
-
Unable to download Oracle Data Integrator-Version 11.1.1.6(Important)
Unable to download Oracle Data Integrator with version 11.1.1.6.Hope this could be resolved ASAP.
-
With an iMac (one year old), we are using Time Machine to backup the iMac and one small external HD to a 2TB HD (USB). The iMac is on a small wired network along with an Airport Extreme hosting a 1TB HD for shared iPhoto Libraries, 2 printers and a r
-
Price getting changed in purchase order while clicking on delivery complete
Hi Frnds, We are using SAP AFS , i have made a purchase order for one item which has 6 grids ( and all the six grids are having different prices ) . I am mainitainng the standard price in Info record ( ME11 ) and Grid wise prices in MEk1. Now for
-
Row level security with session variables, not a best practice?
Hello, We are about to implement row level security in our BI project using OBIEE, and the solution we found most convenient for our requirement was to use session variables with initalization blocks. The problem is that this method is listed as a "n
-
On my iPad 2-3G, when I am in Safari, on a google blogg page, I want to leave a comment. If I make a mistake, use backspace and then the keyboard (virtual keyboard) breaks. Nothing else works. I Have to close safari and reopen and pray I don't make m