- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Create a script to insert entry
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-12-2004 07:56 AM
тАО01-12-2004 07:56 AM
This is the select statement to show all the table...
select *
from CODE_LOGIN
order by CODE;
CODE TYPE LOGIN_ID PASSWORD ENABLED
ASHRM, SWITCH, log, 5555, 1
BCHTM, SWITCH, log, 5555, 1
BDVNM, SWITCH, log, 5555, 1
BNRVM, SWITCH, log, 5555, 1
BRNDM, SWITCH, dev, april, 1
DAPHM, SWITCH, dev, april, 1
FSBRM, SWITCH, log, 5555, 1
GDRPM, SWITCH, log, 5555, 1
GDRVM, SWITCH, log, 5555, 1
(there is alot more, 70)
I then made a script and that would only show the CODE if it matches 'dev'
select CODE
from CODE_LOGIN
where LOGIN_ID = 'DEV'
order by CODE;
BRNDM
DAPHM
...
(about 50 entries)
I have this saved to a file. All the CODES that have a login_id of 'dev'
Now the big part...
How do I insert a new record, basically I am adding another login_id to the CODE. But, only if the CODE had the dev login id.
Can I do a for loop to look at the file that I saved, and insert values into table.
SQL> insert into CODE_LOGIN (CODE, TYPE, LOGIN_ID, PASSWORD, ENABLED)
2 values (CODE(??),'SWITCH', 'DEV', 'APRIL', 1);
The ? is where the problem is... How do I get the CODE? There are about 50 entries, but they will have the same user_id and passwd inserted in all 50.
Any help would be appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-12-2004 08:14 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-12-2004 08:23 AM
тАО01-12-2004 08:23 AM
Re: Create a script to insert entry
forgot:
update blabla set LOGIN='NEWDEV';
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-12-2004 09:31 AM
тАО01-12-2004 09:31 AM
Re: Create a script to insert entry
There are many neat SQL solutions.
Bu in line with you tem file, here are some ideas:
For example, assume the file is called a.dat
Now create a.awk containing:
{print "insert into CODE_LOGIN (CODE, TYPE, LOGIN_ID, PASSWORD, ENABLED) values ('" $1 "','SWITCH','DEV','APRIL',1);"}
Now execute:
awk -f a.awk < a.dat > a.sql
and
sqlplus @a.sql
In perl you can of course readily piped the morphed input data straight into sqlplus, which coudl be interesting for frequently repeated transformation.
Or you could use sql to generate sql...
select 'insert into CODE_LOGIN (CODE, TYPE, LOGIN_ID, PASSWORD, ENABLED)' ||
' values (''' || code ||
''',''SWITCH'',''DEV'',''APRIL'',1);'
from test where login_id = 'DEV'
/
You have set sqlplus NOT to print header/footers or post-edit the spool file.
The ugly part is all those single quotes as we need a double-single quote in a quoted string. The above SQL takes an string with 'insert...' adds the current field value of code and concatenates the other values. You then execute the generated output. Good fun!
Enjoy,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-12-2004 04:28 PM
тАО01-12-2004 04:28 PM
Re: Create a script to insert entry
Mostly you should be able to do all this directyl witha single statement. I'm not sure I fully understand your requirement but it could be something like:
insert into code_login
select code, 'switch', 'dev', 'APRIL', 1
from code_login
where login_id = 'dev';
I used "'switch'" as per your partial example.
But if you wanted the same value as the original record, then just use "type".
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-12-2004 04:57 PM
тАО01-12-2004 04:57 PM
Re: Create a script to insert entry
create table temp1 (code char(5), login_id char(3));
insert into temp1 values ('AAAA', 'DEV');
insert into temp1 values ('BBBB', 'DEV');
insert into temp1 values ('CCCC', 'PRD');
create table temp2 as select * from temp1 where login_id='DEV';
alter table temp1 add constraint constraint_name1 primary key (code);
alter table temp2 add constraint constraint_name2 primary key (code);
alter table temp1 add constraint constraint_name3 foreign key (code) references temp2 (code);
delete from temp1;
insert into temp1 values ('AAAA', 'DEV');
sks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-12-2004 05:25 PM
тАО01-12-2004 05:25 PM
Re: Create a script to insert entry
try:
insert into code_login (code, type, login_id, password, enabled)
select code||'2', type, login_id, password, enabled
from code_login
where login_id = 'DEV';
where you can change the << code||'2' >> as desired.
hope this helps
regards
Yogeeraj