Querying v$session table


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Querying v$session table
# 1  
Old 05-14-2014
Querying v$session table

Hi All,

I'm using below code
Code:
entry_data_control=`sqlplus  ${sysuser}/${syspwd} << data_control
                      whenever sqlerror exit sql.sqlcode;
       whenever oserror exit failure;
       INSERT INTO LSHADMIN.STUDY_LEVEL_TABLE(SESSION_SID,SESSION_SERIAL_NO,FILE_NAME)
       select sid, serial# , '$i' FROM v\$session   WHERE audsid = userenv('sessionid');
       COMMIT;
       EXIT;
       data_control`

I'm getting the error:
ORA-00942: table or view does not exist

How can I query v$session table from shell
# 2  
Old 05-14-2014
try
Code:
table="v\$session"
var=`sqlplus -s ${DB_LOGON}<< EOSQL
WHENEVER SQLERROR EXIT FAILURE;
WHENEVER OSERROR EXIT FAILURE;
set longchunksize 200000 long 200000 pages 0
set heading off
select sid from $table where rownum < 2;
exit
EOSQL`
echo $var

output
Code:
Makarand >./mak2.sh
525


Last edited by Makarand Dodmis; 05-14-2014 at 06:38 AM..
This User Gave Thanks to Makarand Dodmis For This Post:
# 3  
Old 05-14-2014
Smilie thanks it worked

---------- Post updated at 04:43 AM ---------- Previous update was at 04:38 AM ----------

I am inserting :
timestamp=`date +"%Y%m%d%H%M%S"`
value of timestamp into a date type column .
it throws error:

ORA-00932: inconsistent datatypes: expected DATE got NUMBER.
# 4  
Old 05-14-2014
try
Code:
timestamp=`date +"%Y%m%d%H%M%S"`
var=`sqlplus -s ${DB_LOGON}<< EOSQL
WHENEVER SQLERROR EXIT FAILURE;
WHENEVER OSERROR EXIT FAILURE;
set longchunksize 200000 long 200000 pages 0
set heading off
insert into c values(to_date($timestamp,'YYYYMMDDHHMISS'));
exit
EOSQL`
echo $var

output
Code:
 Makarand >./mak4.sh
1 row created.

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Generic script for Querying a DB

I have a few databases that i need to get some basic output from... so I'll be returning 1 or 2 records from a variety of different databases and the input queries will always differ. What im looking for is a generic script that I can use across of the databases. Theory being i have: ... (2 Replies)
Discussion started by: atelford
2 Replies

2. Solaris

Difference between the desktop session and console session

what is the difference between desktop session and console session in solaris as i am wondering we use option -text for the former and -nowin for the later (1 Reply)
Discussion started by: kishanreddy
1 Replies

3. Red Hat

Error in querying file information

Hi, We have one application running where there is Linux Machine. For some some process I found the following message came, error 5.8/116455-02/116455-02.zip Error in querying file information: Permission denied :confused: If anybody has any idea for this please let me... (2 Replies)
Discussion started by: sptr
2 Replies

4. Solaris

I am not able to login in gnome session and java session in Sun solaris 9& 10

I am not able to login in gnome session and java session in Sun solaris 9& 10 respectively through xmanager as a nis user, I am able to login in common desktop , but gnome session its not allowing , when I have given login credentials, its coming back to login screen, what shoul I do to allow nis... (0 Replies)
Discussion started by: durgaprasadr13
0 Replies

5. Shell Programming and Scripting

Hiding Directories on a Session by Session basis

Hi, Apologies if anyone has read my recent post on the same subject in the Linux forum, just thought actually the solution might more likely come from scripting. Essentially, I am trying to restrict access to directories based on the user's name AND their location on a session-by-session... (3 Replies)
Discussion started by: en7smb
3 Replies

6. HP-UX

Querying HP VA array

Hello, all... I've got an older HP-UX 11i machine hooked up to an HP VA array. I've never worked with VA arrays, so I was wondering if anyone could point me in the direction of some documentation on querying and manipulating VAs (HP VAs for Dummies or something). I'm used to EMC arrays, so... (2 Replies)
Discussion started by: kknigga
2 Replies

7. Shell Programming and Scripting

Querying database from unix

Hi, I have a shell script to query the database to get the statistics of tables like sum,max,min,etc of all numeric columns,max and min of date columns and length of varchar columns for each and every table. There are nearly 1600 tables. My script queries few tables like about 100 tables and... (3 Replies)
Discussion started by: ragavhere
3 Replies

8. Shell Programming and Scripting

sqlplus session being able to see unix variables session within a script

Hi there. How do I make the DB connection see the parameter variables passed to the unix script ? The code snippet below isn't working properly. sqlplus << EOF user1@db1/pass1 BEGIN PACKAGE1.perform_updates($1,$2,$3); END; EOF Thanks in advance, Abrahao. (2 Replies)
Discussion started by: 435 Gavea
2 Replies
Login or Register to Ask a Question