Home » SQL & PL/SQL » SQL & PL/SQL » Substitute variable in script (oracle 11g r2)
icon5.gif  Substitute variable in script [message #638826] Mon, 22 June 2015 12:17 Go to next message
ajaapba
Messages: 2
Registered: June 2015
Location: ATLANTA
Junior Member
Hi,

This is one of the script that runs on production system during deployment.

It sets the default password for some of the schemas.

However, I don't under stand what below code does exactly ? Can I get any help on this.
DECLARE
ls_sql VARCHAR2(2000);
v1 number;
CURSOR c1 IS
SELECT 1
FROM dba_tables
WHERE owner = 'AXIOM'
AND table_name = 'PWDSAVE';
BEGIN
ls_sql := 'CREATE TABLE axiom.pwdsave AS ';
ls_sql := ls_sql||'SELECT name as username, password FROM sys.user$ ';
ls_sql := ls_sql||'WHERE name IN (''AXIOM'',''AXIOM_ARCHIVE'',''AXIOSS_INTERNET'',''CUSTOM'',''UTAXIOSS'',''DASHBOARD'',
''EMS'',''EMS_API'',''HOMS'',''HOMS_API'',''HOMS_SYSTEM_AUTOMATIC'',
''FASTSTREAM'',''IMS_API'',''O2S_API'',''PAF'',''SAFE'',''XML_LIB'',''SAFE_API'',''COMMON_API'')';
OPEN c1;
FETCH c1 into v1;
IF c1%NOTFOUND THEN
EXECUTE IMMEDIATE ls_sql;
ELSE
dbms_output.put_line('Using existing saved password table...');
END IF;
CLOSE c1;
END;
/
Re: Substitute variable in script [message #638827 is a reply to message #638826] Mon, 22 June 2015 12:31 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>EXECUTE IMMEDIATE ls_sql;

change the line above to the line below & post the results back here (Be sure to enable SERVEROUTPUT ON)

DBMS_OUTPUT.PUT_LINE(ls_sql);
Re: Substitute variable in script [message #638828 is a reply to message #638826] Mon, 22 June 2015 12:45 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
OPEN c1;
FETCH c1 into v1;
IF c1%NOTFOUND THEN


This is useless and not correct, just try to create the table and trap the error if the table already exists.

Please read How to use [code] tags and make your code easier to read and apply it.

Re: Substitute variable in script [message #638829 is a reply to message #638826] Mon, 22 June 2015 12:48 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
It sets the default password for some of the schemas.


No, it does not, it just create a table if this one does not exist.
Re: Substitute variable in script [message #638847 is a reply to message #638827] Tue, 23 June 2015 09:04 Go to previous messageGo to next message
ajaapba
Messages: 2
Registered: June 2015
Location: ATLANTA
Junior Member
This is the output from DBMs Output
CREATE TABLE axiom.pwdsave AS SELECT name as username, password FROM sys.user$
WHERE name IN
('AXIOM','AXIOM_ARCHIVE','AXIOSS_INTERNET','CUSTOM','UTAXIOSS','DASHBOARD',


'EMS','EMS_API','HOMS','HOMS_API','HOMS_SYSTEM_AUTOMATIC
',


'FASTSTREAM','IMS_API','O2S_API','PAF','SAFE','XML_LIB',
'SAFE_API',
'COMMON_API')
Re: Substitute variable in script [message #638850 is a reply to message #638847] Tue, 23 June 2015 09:08 Go to previous messageGo to next message
gazzag
Messages: 1118
Registered: November 2010
Location: Bedwas, UK
Senior Member
It dynamically generates that code which creates a table PWDSAVE in the AXIOM schema that contains the username and the encrypted database password for the users mentioned in the IN clause.
Re: Substitute variable in script [message #638852 is a reply to message #638850] Tue, 23 June 2015 09:16 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
There is NOTHING dynamic about the generated CREATE TABLE statement so why not just make static call & avoid PL/SQL altogether?

Never do in PL/SQL that which can be done in plain SQL.
Re: Substitute variable in script [message #638853 is a reply to message #638852] Tue, 23 June 2015 09:20 Go to previous message
gazzag
Messages: 1118
Registered: November 2010
Location: Bedwas, UK
Senior Member
Quite right. It's a static SQL statement masquerading as a dynamic one Confused As Michel said, the code is pointless and incorrect.
Previous Topic: Date Parameter Issue
Next Topic: Update a column in table only if a condition is met for number of values for a field in other table
Goto Forum:
  


Current Time: Fri Apr 19 07:56:56 CDT 2024