Used Columns in SQL script/query
Hi,
we really have many SQL scripts.
Since we expect changes within the schema, we need to know the scripts which have to be reworked.
Is there any tool available which identifies all columns refereced by a sql script (columns used in select-list, where-clause, order-by clause, ...) ?
Axel.
There is a function in TOAD (http://www.toadsoft.com/) Schema Browser you select the table that need to be changed then you select the tab "used by" and it will show the stored procedures that are using this TABLE (not columns). Also this option only display stored code in the database and not unnamed scripts.
This is a script you can use:
Select owner, object_type, object_name, object_id, status
from sys.DBA_OBJECTS where object_id in (
Select object_id
from public_dependency
connect by prior object_id = referenced_object_id
start with referenced_object_id = (
Select object_id from sys.DBA_OBJECTS
where owner = 'OWNER'
and object_name = 'TABLE_NAME'
and object_type = 'TABLE' ))
I hope this is useful to you.
Message was edited by:
Delfino N.
Similar Messages
-
How to use views in sql script report?
All all
Can any one tell how to use views in sql script report?Most of the views are based on tables (or other views which are based on tables).
The view typically shows one org at a time based on the context that is set.
If you need records for all orgs, you need to use the underlying tables. Oracle typically names the tables with a _all suffix.
e.g. PO_HEADERS will show records for one org at a time. PO_HEADERS_ALL will show records for all orgs.
Hope this answers your question,
Sandeep Gandhi -
Problem while executing script in Toad - How to use '&' in the sql script ?
I have to execute sql script in toad. Sql script has one insert query in which one insert-value is 'USA & CAN'. When I executed the script in toad by pressing F5, I got a prompt window asking for the value if 'CAN' as it is after the &.
I tried using[b] {escape '\' } .... but could not resolve the problem.
Is there any solution or workaround to overcome this problem. I have thousands of records with such values and I have to use sql script only.There is an option in TOAD to change this behaviour.
Look in VIEW/OPTIONS/SQL Editor/
Uncheck the box for "Scan statements for bound variables before execution".
In SQL*PLUS it would be SET SCAN OFF
(desupported version is SET DEFINE OFF)
Message was edited by:
Sven Weller -
Using variables in sql scripts
I am trying to pass a variable into a simple
sql script - but each time I run it, it still asks for the variable.
Here is my example:
test.sql contains:
select count(*) from &tbl
I try to run it by typing the following
at the sqlplus prompt:
@test the_tbl
Even though I provide a value for &tbl,
sqlplus still asks me for the value:
Enter value for tbl:
I am sure that the answer is very simple.
what am I doing wrong ?
Thanks !<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by KR:
I am trying to pass a variable into a simple
sql script - but each time I run it, it still asks for the variable.
Here is my example:
test.sql contains:
select count(*) from &tbl
I try to run it by typing the following
at the sqlplus prompt:
@test the_tbl
Even though I provide a value for &tbl,
sqlplus still asks me for the value:
Enter value for tbl:
I am sure that the answer is very simple.
what am I doing wrong ?
Thanks !<HR></BLOCKQUOTE>
In SQL Plus 8.0 this command goes correctly:
select count(*) from &tb ;
null -
Hello,
I was wondering if it is possible to retrieve a unique value from a column example if i have
Staffno Building
1 Grey
2 Grey
3 Blue
If i wanted to only call the unique value which would be staff number 3 how would I do this?
Many thanks :)903234 wrote:
Hello,
I was wondering if it is possible to retrieve a unique value from a column example if i have
Staffno Building
1 Grey
2 Grey
3 Blue
If i wanted to only call the unique value which would be staff number 3 how would I do this?
Many thanks :)HAVING COUNT(BUILDING) = 1 -
How to use parameters in oracle SQL script????
Right now I am writing a SQL script to create a schema and build the objects of this schema....
I use a .net winform program to run sqlplus to parse this sql script ...
The problem is that the schema name and the tablespace's location and the sys password must be input by the user, so my SQL script should use these runtime input parameters instead of const parameters....
So, how to use parameter in SQL script ...........
Are there some example scripts in oracle home directory for me to refer to????Hi,
UNISTD wrote:
thanks .....
what's the difference between variable , define, accept in sqlplus ???VARIABLE declares (but does not assign a value to) a bind variable. Unlike substitution variables, bind variables are passed to the back end to be compiled, and they can only be values in certain data types. You can not use a bind vaiable in place of an identifier, so to do something like
CREATE USER &1 ...a bind variable won't work.
"DEFINE x = y" sets the substitution variable &x to have the value y. There is no user interaction (unless x or y happen to contain undefined substtiution variables).
"DEFINE x" shiows the value of the substitution variable &x, or, if it is undefined, raises a SQL*Plus error. I use this feature below.
ACCEPT sets a substitution variable with user interaction.
And if the user miss some parameters in “sqlplus /nolog ssss.sql par1 par2 par5 par6”, how to use default value of the miss parameters??Don't you need a @ befiore the script name, e.g.
sqlplus /nolog @ssss.sql par1 par2 par5 par6Sorry, I don't know of any good way to use default values.
The foloowing works, but, as you can see, it's ugly.
"DEFINE 1" display a message like
DEFINE 1 = "par1" (CHAR)if &1 is defined; otherwise,it will display a SQL*Plus error message like
SP2-035: symbol 1 is UNDEFINEDNotice that the former contains an '=' sign, but the latter does not.
The best way I know to use default values is to run the DEFINE command, save the output to a filee, read the file, and see if it's an error message or not.
So you can use a script like this:
-- This is DEFINE_DEFAULT.SQL
SPOOL got_define_txt.sql
DEFINE &dd_old
SPOOL OFF
COLUMN dd_new_col NEW_VALUE &dd_new
WITH got_define_txt AS
SELECT q'[
@got_define_txt
]' AS define_txt
FROM dual
SELECT CASE
WHEN define_txt LIKE '%=%'
THEN REGEXP_REPLACE ( define_txt
, '.+"
([^"]*)
, '\1'
ELSE '&dd_default'
END AS dd_new_col
FROM got_define_txt
{code}
and start your real script, ssss.sql, something like this:
{code}
DEFINE dd_new = sv1
DEFINE dd_old = 1
DEFINE dd_default = FOO
@DEFINE_DEFAULT
DEFINE dd_new = sv2
DEFINE dd_old = 2
DEFINE dd_default = "Testing spaces in value"
@DEFINE_DEFAULT
{code}
when this finishes running, the substitution variable &sv1 will either have the value you passed in &1 or, if you didn't pass anything, the default value you specified, that is FOO.
Likewise, &sw2 will have the value you passed, or, if you didn't pass anything, the 23-character string 'Testing spaces in value'.
Here's how it works:
Define_default.sql puts the output of the "DEFINE x" command into a column, define_txt, in a query. That query displays either the existing value of the substitution variable indicated by &dd_old or, if it is undefined, the default value you want to use, which is stored in the substitution variable &dd_default. The substitution variable named in &dd_new is always set to something, but that something may be its existing value.
Notice that the paramerters to define_default.sql must be passed as global varibales.
Why didn't I just use arguments, so that we could simply say:
{code}
@DEFINE_DEFAULT sv1 1 FOO
{code}
? Because that would set the substitution variables &1, &2 and &3, which are miost likely the very ones in which you're interested.
I repeat: there must be a better way, but I'm sorry, I don't know what it is.
I usually don't do the method above. Instead, I always pass the required number of parameters, but I pass dummy or plce-holder values.
For example, if I wanted to call ssss.sql, but use defulat vlaues for &1 and &3, then I would say something like:
{code}
@ssss ? par2 ?
{code}
and, inside ssss.sql, test to see if the values are the place holder '?', and, if so, replace them with some real default value. The use has to remember what the special place holder-value is, but does not need to know anything more, and only ssss.sql itself needs to change if the default values change. -
How can I read/write data files (text file) from PL/SQL Script
I had an oracle forms pl/sql program to read/write a data file (text file). When this code is run on a command line as a PL/SQL script using the SQL*Plus I am getting an error:
-- sample.sql
DECLARE
vLocation VARCHAR2(50) := 'r:\';
vFilename VARCHAR2(100) := 'sample.dat';
vTio TEXT_IO.FILE_TYPE;
vLinebuf VARCHAR2(2000);
vRownum NUMBER := 0;
-- use array to store data FROM each line of the text file
TYPE array_type IS VARRAY(15) OF VARCHAR2(100);
vColumn array_type := array_type('');
PROCEDURE prc_open_file(p_filename IN VARCHAR, p_access IN VARCHAR2) is
BEGIN
vTio := TEXT_IO.FOPEN(vLocation||p_filename,p_access);
EXCEPTION
WHEN OTHERS then
-- raise_application_error(-20000,'Unable to open '||p_filename);
message(sqlerrm);pause;
END;
PROCEDURE prc_close_file is
BEGIN
IF TEXT_IO.IS_OPEN(vTio) then
TEXT_IO.FCLOSE(vTio);
END IF;
END;
BEGIN
--extend AND initialize the array to 4 columns
vColumn.EXTEND(4,1);
prc_open_file(vFilename,'r');
LOOP
LTEXT_IO.GET_LINE(vTio,vLinebuf);
vColumn(1) := SUBSTR(vLineBuf, 1, 3);
vColumn(2) := SUBSTR(vLineBuf, 5, 8);
vColumn(3) := SUBSTR(vLineBuf,10,14);
Insert Into MySampleTable
Values
(vColumn(1), vColumn(2), vColumn(3));
EXIT WHEN vLinebuf IS NULL;
END LOOP;
prc_close_file;
END;
SQL> @c:\myworkspace\sql\scripts\sample.sql;
PLS-00201: identifier 'TEXT_IO.FILE_TYPE' must be declaredIt works on the oracle forms but not on the SQL*Plus. Is there an alternative method using a PL/SQL script? A simple sample would help. Thanks.Did you ever noticed the search box at the right side of the forum?
A quick search (limited to this years entries) brought up this thread for example
Re: UTL_FILE Examples -
Trouble calling .sql script
I have looked on the forum for about a half an hour and can't find the exact answer I'm searching for, so here goes.
I'm trying to update about a 100 records or so through use of an .sql script.
I put the following in my sql script file
UPDATE TABLE1 SET COL_NAME1 = 'some val.', COL_NUM_VAL = 12345, BOOL_VAL_COL = -1
WHERE AUTOID = 9554 OR AUTOID = 1082
OR AUTOID = 1305 OR AUTOID = 133
OR AUTOID = 9124
OR AUTOID = 8712
OR AUTOID = 55 OR AUTOID = 6741 OR AUTOID = 9881
OR AUTOID = 1012 OR AUTOID = 9158 OR AUTOID = 9378
OR AUTOID = 9101 OR AUTOID = 8351 OR AUTOID = 7110 OR AUTOID = 922 OR AUTOID = 732
OR AUTOID = 7253 OR AUTOID = 7825 OR AUTOID = 6772 OR AUTOID = 9854;
commit;however, I get some kind of message back in the SQL Plus prompt showing.
8 OR AUTOID = 9101 OR AUTOID = 8351 OR AUTOID = 7110 OR AUTOID = 922 OR AUTOID = 732
9 OR AUTOID = 7253 OR AUTOID = 7825 OR AUTOID = 6772 OR AUTOID = 9854
10* commit;
11 /I can't really discern from this output stmt what happened or what is wrong,
and needless to say, the update query doesn't execute. Any ideas as to what I need to put in there? And can't I just open it up in SQL Plus after I've created the sql file?Or is there more to it than that?
I welcome any feedback.
Thanks!
Message was edited by:
user515689Hi,
If you have a file called foo.sql that contains just the 10 lines of code that you posted, then you can run it from SQL*Plus by saying "@foo" (depending on where foo.sql is stored. You may actually have give the full path name: e.g.
SQL> @c:\my_folder\sub_folder\fooWhat are you doing to run the script?
By the way, instead of all those ORs you can use the IN operator:
UPDATE TABLE1 SET COL_NAME1 = 'some val.', COL_NUM_VAL = 12345, BOOL_VAL_COL = -1
WHERE AUTOID IN (9554, 1082, 1305, ..., 9854); -
IF statement syntax in SQL script view
I need to include a "IF" condition in the "SELECT" section of my SQL script view.
I tried the following syntax's but I get the error 'Incorrect SQL syntax near 'IF'
1. IF(Revenue <> '0' AND Quantity <> '0', Revenue/Quantity, '0') AS Gross Price
2. IF(Revenue != '0' AND Quantity != '0', Revenue/Quantity, '0') AS Gross Price
3. IF(Revenue <> '0' AND Quantity <> '0' THEN Revenue/Quantity ELSE '0' END) AS Gross Price
4. IF(Revenue != '0' AND Quantity != '0' THEN Revenue/Quantity ELSE '0' END) AS Gross Price
My final SQL would read like follows:
SELECT field1, field2, IF(......) AS field3
FROM table1
Can anybody please help with the correct IF statement syntax to be used in the SQL script based view?Hi Lakshmi,
below is the syntax for IF statement.
IF <bool_expr1> THEN
<then_stmts1>
ELSEIF <bool_expr2>
THEN <then_stmts2>
[ELSE <else_stmts3>]
END IF
eg :
BEGIN
DECLARE found INT := 1;
SELECT count(*) INTO found FROM books WHERE isbn = :v_isbn;
IF :found = 0 THEN
INSERT INTO books VALUES (:v_isbn, 'In-Memory Data Management', 1, 1, '2011', 42.75, 'EUR');
ELSE
UPDATE books SET price = 42.75 WHERE isbn =:v_isbn;
END IF;
END;
Sreehari -
Error while trying to add a SQL Script via DB02
Good Morning and happy Sysadmin day to everyone,
I have the following Problem regarding DB2 9.5
I'm trying to run a SQL Script via DB02 in an ERP 6.0 System.
I'm using DB02 -> Jobs -> SQL Script Maintenenace -> Add
Then there is a Textfield "Script Name". When i'm using the F4-Help I'm getting the following error Message:
List box value range for field DYN_SED-SCRIPT_NAME could not be created
Message no. DB6PM004
Any suggestions what might be the Error?
Thanks in Advance
MarcoAre you trying to create a new Model or trying to import a Model ?
-
Can it be done? If so, how would they be used within a SQL script?
Wait, by $ do you mean UNIX environment variables? Yes those can be passed to a SQL script.
# cat > x.sql
select * from &1 ;
exit
# export VARX="dual"
# sqlplus system @x $VARX
SQL*Plus: Release 9.2.0.1.0 - Production on Fri Apr 25 11:23:21 2003
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Enter user-name: system
Enter password:
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
old 1: select * from &1
new 1: select * from dual
D
X
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.1.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
# -
We have turned off LDAP authentication using the ssolocal.sql script. However, only the portal30 user is able to log in now.
The other users who were created using OID and who have logged in earlier are not able to log in after we turned off LDAP authentication using the ssolocal.sql script. Has anyone faced a similar problem?
Thanks.This behavior is to be expected. When using LDAP authentication, the repository used for authentication is the LDAP directory -- binding to user entries defined in the directory.
When you switch authentication to local mode, it is going to attempt to authenticate the users against the local table. However, since the user accounts were created in the directory, the local table does not have the password information, even though "shadow entries" in the WWSSO_SSO_USER view may have been created.
In order to get these accounts authenticatable, passwords need to be assigned to the local entries. Since it won't be possible to "copy" over the passwords from the directory, you'll need to reset or reassign the passwords in the local table.
If you are on version 3.0.8 or 3.0.9 of the portal, you can use the following procedure to reset the passwords:
WWSSO_API_USER_ADMIN.RESET_PASSWORD
P_USERNAME IN VARCHAR2
,P_NEWPASSWORD IN VARCHAR2
,P_ERROR_CODE OUT NUMBER
);This procedure will raise and error code or exception depending on the problem, if any. The codes and exceptions are listed in the package specification in sso/ssoumgt.pks.
If your code is not running in the Login Server schema, then the permission to execute this package needs to be granted to the schema in which your code resides.
null -
Retrieve alert values for use as parameter in corrective action sql script
I am trying to write a corrective action sql script to kill a session that is blocking other sessions. I have the "blocking session count" metric set and the alert is firing correctly.
Is there any way to retrieve the sid and serial number from the alert generated and use it in a corrective action sql script?
Here is the alert generated:
Target Name=myproddb.world
Target Type=Database Instance
Host=myprodserver
Metric=Blocking Session Count
Blocking Session ID=SID: 522 Serial#: 5228
Timestamp=Mar 4, 2008 5:57:12 PM EST
Severity=Warning
Message=Session 522 is blocking 1 other sessions
Notification Rule Name=Testing Corrective actions
Notification Rule Owner=sysman
Clearly the sid, and serial # is contained within the alert Message field
what I want to write for the sql script is :
alter system kill session '%sid%,%serial_no%' immediate;
and have GC pass in the sid and serial_no to the script.
The "Target Properties" listed on the right of the Edit Corrective Action screen lists minimal details pertaining to the alert and certainly not the session sid, serial no.
Generically, is there any way to retrieve the values from an alert and use them in a corrective action script or job?
I've looked into getting the values from the mgmt$alert_history table, but I'm hoping that GC can pass the values to the sql script.
thanks in advance for your help.Hi
You can implementing a procedure like this.
1. When a block session count alarms occurs, there is a column in the v$lock that you can examine.
#!/bin/ksh
#kill_block_session.sh
#first export your variables
export ORACLE_HOME=/oracle/product/10.2.0.3
export ORACLE_SID=SIDNAME
$ORACLE_HOME/bin/sqlplus "/ as sysdba" << EOF
execute immediate killed_blocks;
EOF
# end
The killed_blocks is a procedure:
create procedure
declare
v_sid varchar2(15);
v_serial varchar2(15);
-- now a sql query that retrieve the sid and serial
-- you can obtain these values from v$session and v$lock
select vs.sid,vs.serial into v_sid,v_serial
from v$session vs,v$lock vl
where vs.sid=vl.sid
and vl.block >0
-- After this, you execute a dbms_put line with these
-- values
But you understant that this response action is very dangerous, because its possible that you kill sessions that the blocking are transitient.
You must examine your enviroment and your application and establish the metric like UDM and not for only session blocking count.
You must to see:
- The type of block
- The ctime time in the v$lock for to understatn the amount of time to determine that the block is need killed.
- In my opinion you need a special UDM and deactivate the blocking sesion count
If you want help to create this UDM send me a mail to [email protected]
Regards
Robert -
Hi All,
I am a newbie for T-Sql, I came across a SP where multiple tables are engaged using multiple joins but the where clause contain a column field without any table reference and assigned for an incoming variable,like
where 'UserId = @UserId'
instead - no table reference like 'a.UserId = @Userid' ............ Can any please do refer to me any material that clears my mind regarding such issue................... help is appreciated.
Thank You.As suggested above, use table alias with columns for unique referencing and to make the code easier to read.
BOL example for table aliasing:
USE AdventureWorks;
GO
SELECT S.CustomerID, S.Name AS Store, A.City, SP.Name AS State, CR.Name
AS CountryRegion
FROM Sales.Store AS S
JOIN Sales.CustomerAddress AS CA ON CA.CustomerID = S.CustomerID
JOIN Person.Address AS A ON A.AddressID = CA.AddressID
JOIN Person.StateProvince SP ON
SP.StateProvinceID = A.StateProvinceID
JOIN Person.CountryRegion CR ON
CR.CountryRegionCode = SP.CountryRegionCode
ORDER BY S.CustomerID ;
GO
GO
LINK:
http://technet.microsoft.com/en-us/library/ms124824(v=sql.100).aspx
Check the use of TABLE ALIASes and COLUMN ALIASes in the following blog:
http://www.sqlusa.com/bestpractices2005/organizationtree/
Without the use of aliases the code would become unreadable.
Kalman Toth Database & OLAP Architect
Free T-SQL Scripts
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012 -
Out of memory Error while querying SQL Script based Calculation View
Hi All,
I wanted to test the performance of Graphical and SQL Script based Calculation views.
Created Graphical (CA_GRPH) and SQL Script (CA_SQL) Calculation views.
Analytic View (AN_GRPH) for both Calculation views are the same which is Graphical based (90 Attributes and 5 Measures)
In Analytic View data foundation I have a Fact table which has 1.5 Billion records and 9 Dimension Tables –collectively 500 million records (7 Attribute Views). 9 Referential joins with cardinality N:1 and 1 Referential join with cardinality N:N.
I wanted to keep (CA_GRPH) and (CA_SQL) as a base Calculation views and leverage those to create various calculation views (Will be creating different Calc views for respective Business segments)
In order to test this I have created below calc views on top of base calc views.
Graphical Based: Created (CA_GRAPH_XYZ) by having CA_GRPH in projection with 30 Calculated Columns. – This retrieves data in 13 secs
SQL Script Based: Created (CA_GRPH_ABC) by having CA_SQL in projection view with 30 calculated columns – This errors out after 1.50 mins.
Could not execute 'SELECT "COLUMN_A","COLUMN _B"," COLUMN _C"," COLUMN _D", SUM("COLUMN _REVENUE") AS ...' in 1:50.480 minutes .
SAP DBTech JDBC: [2048]: column store error: [2048] column store error: search table error: [1000002] Error executing physical plan: exception 1000002:
ltt/impl/memory.cpp:63
Out of memory ; $size$=1507711; $name$=ihm; $type$=pool; $inuse_count$=170104; $allocated_size$=219215007925
exception 1000002:
Any suggestion / help in fixing this issue will be greatly appreciated.
Regards,
AvHi Raj,
Thanks for your time, please find edited snap hot of Analytic View (AN_GRPH) below,
Calculation view(CA_SQL)
/********* Begin Procedure Script ************/
BEGIN
var_out =
SELECT
"COLUMN_1"
"COLUMN_2",
"COLUMN_84",
"COLUMN_85;",
SUM("REVN") AS "REVN",
SUM("MGN") AS "MGN",
SUM("ORD_QTY") AS "ORD_QTY",
SUM("SYS_QTY1") AS "SYS_QTY1",
SUM("SYS_QTY") AS "SYS_QTY"
FROM
"_SYS_BIC"."XYZ/AN_GRPH"
GROUP BY
"COLUMN_1"
"COLUMN_2",
"COLUMN_84",
"COLUMN_85";
END
/********* End Procedure Script ************/
Later i have built one more Calculation view(CA_GRPH_ABC) using (CA_SQL)in projection. i have 30 calculated measures in this final calc view. this final calc view is throwing above mentioned error.
Not sure if i can use SQL script based calc view in graphical based calc views?
Regards,
AV
Maybe you are looking for
-
Purchase Order approval workflows not forwarding through TC SWIA
Hi When I am forwarding work item to other user I am getting following error. Work item 000015375242: Forwarding not allowed in status READY Message no. WL842 Diagnosis The work item cannot be forwarded in its current status. System Response The acti
-
Lenovo IdeaPad Y500, expand with ssd
Hello Im from the Netherlands. i have a question. I want to buy the Lenovo IdeaPad Y Series Y500-00619. but it doenst have a ssd it only has a hdd 1tb. Now is my question does this notebook have a extra place for a ssd? Or do i need to replace the hd
-
Oracle Application Server 10g thread stuck issue.
We are having, Oracle Application Server 10g [10.1.3.1 + 10.1.3.4patch] along with Oracle Http Server 2.0 Now there is a issue of thread stuck [some application threads taking longer times] due to which the application server is unable to respond and
-
Inventory Load - Running Init of Setup tables
I'm planning the initial load of Inventory data and want to make sure that I understand what needs to be done. Question 2 - To save time can I run the initialization of the setup tables for 2LIS_03_BX,BF,UM in parallel. Or do I have to wait for one
-
help: I download "Yellow Submarin" which is 294mb, my iBooks 2 keep forbidden me open it to read saying exceed file limite. Please tell me how shall i do ?