1. If a line starts with / remove / sign.
$sed 's/^\/ *//g'
2. If a line starts with TABLESPACE remove it.
$sed 's/^TABLESPACE.*//g'
3. If line starts with ) proceeds with none or more spaces replace it with ) and next line.
$sed 's/^) */)\n\//g'
4. Replace ; with ; and next line.
$sed -i 's/;/;\n/g'
5. This command replaces ; \t\n\r or spaces and the / in a file to just \n /.
$sed ':a;N;$!ba;s/[^end];[\n\t\r ]*\//\n\//g'
First of all the filw is all read in come variable N and then we perform operation on it. Its a Multiline function.
6. Line starting with END or end or any of Upper or Lower combination of end, will be ended with a ;
$sed 's/^[eE][nN][dD].*/&;/g'
Monday, 31 January 2011
Monday, 24 January 2011
Extrating Table Column Names in CSV format using PL/SQL
This could be useful for writing dynamic code to generate DDL or DML.
1. Create a table Hello_world
create table hello_world(
hello_id integer,
hello_desc varchar2(30)
);
2. Insert some values [this is not important though]
insert into hello_world (hello_id, hello_desc) values (1, 'Fawad');
insert into hello_world (hello_id, hello_desc) values (2, 'NAZIR');
3. Execute the following function:
Input: table name
Output: CSV format of column names
CREATE OR REPLACE FUNCTION INSERT_STATEMENTS(TABLE_NAME_INPUT IN CLOB) RETURN VARCHAR IS
RETURN_VAL CLOB;
BEGIN
SELECT
LISTAGG (COLUMN_NAME, ',') WITHIN GROUP (ORDER BY COLUMN_NAME) INTO RETURN_VAL
FROM
ALL_TAB_COLUMNS
WHERE
TABLE_NAME LIKE TABLE_NAME_INPUT
GROUP BY
TABLE_NAME;
RETURN RETURN_VAL;
END INSERT_STATEMENTS;
4. Call the method:
SET SERVEROUTPUT ON
declare dd CLOB;
begin
SELECT INSERT_STATEMENTS(UPPER('hello_world')) into dd FROM DUAL;
DBMS_OUTPUT.put_line(dd);
end;
1. Create a table Hello_world
create table hello_world(
hello_id integer,
hello_desc varchar2(30)
);
2. Insert some values [this is not important though]
insert into hello_world (hello_id, hello_desc) values (1, 'Fawad');
insert into hello_world (hello_id, hello_desc) values (2, 'NAZIR');
3. Execute the following function:
Input: table name
Output: CSV format of column names
CREATE OR REPLACE FUNCTION INSERT_STATEMENTS(TABLE_NAME_INPUT IN CLOB) RETURN VARCHAR IS
RETURN_VAL CLOB;
BEGIN
SELECT
LISTAGG (COLUMN_NAME, ',') WITHIN GROUP (ORDER BY COLUMN_NAME) INTO RETURN_VAL
FROM
ALL_TAB_COLUMNS
WHERE
TABLE_NAME LIKE TABLE_NAME_INPUT
GROUP BY
TABLE_NAME;
RETURN RETURN_VAL;
END INSERT_STATEMENTS;
4. Call the method:
SET SERVEROUTPUT ON
declare dd CLOB;
begin
SELECT INSERT_STATEMENTS(UPPER('hello_world')) into dd FROM DUAL;
DBMS_OUTPUT.put_line(dd);
end;
Latex on Ubuntu Linux...
I am using the follwing Ubuntu:
$ cat /proc/version
Linux version 2.6.32-24-generic-pae (buildd@palmer) (gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) ) #42-Ubuntu SMP Fri Aug 20 15:37:22 UTC 2010
Its quite simple to install Latex on Ubuntu:
Just run the following command and let it finish, it might take quite some time.
$sudo apt-get install texlive-full
You are done. Now we need to test it:
Download a simple Latex example from the following link;
http://www.cs.technion.ac.il/~yogi/Courses/CS-Scientific-Writing/examples/simple/simple.htm
Run the following commands:
1. This command will compile the tex document and create a DVI file.
$latex simple.txt
2. To create a PDF out of it:
$pdflatex simple.tex
3. Time to view your pdf file:
$xpdf simple.pdf
Thanks!.
$ cat /proc/version
Linux version 2.6.32-24-generic-pae (buildd@palmer) (gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) ) #42-Ubuntu SMP Fri Aug 20 15:37:22 UTC 2010
Its quite simple to install Latex on Ubuntu:
Just run the following command and let it finish, it might take quite some time.
$sudo apt-get install texlive-full
You are done. Now we need to test it:
Download a simple Latex example from the following link;
http://www.cs.technion.ac.il/~yogi/Courses/CS-Scientific-Writing/examples/simple/simple.htm
Run the following commands:
1. This command will compile the tex document and create a DVI file.
$latex simple.txt
2. To create a PDF out of it:
$pdflatex simple.tex
3. Time to view your pdf file:
$xpdf simple.pdf
Thanks!.
Thursday, 20 January 2011
Undefine a variable in Oracle / Undo a variable defination in Oracle
To undefine a user variable named FIRST, enter
UNDEFINE FIRST
To undefine two user variables named FIRST and SECOND, enter
UNDEFINE FIRST SECOND
UNDEFINE FIRST
To undefine two user variables named FIRST and SECOND, enter
UNDEFINE FIRST SECOND
Monday, 17 January 2011
Using Curl to connect to https site to download and Extract a tar file...
Here is the command:
curl -k -u_username_ -O _URL_ | tar -xvf
Example:
curl -k -uhellouser -O https://192.168.2.3:8443/svn/project/V5.0.1.tar.gz | tar -xvf
curl -k -u_username_ -O _URL_ | tar -xvf
Example:
curl -k -uhellouser -O https://192.168.2.3:8443/svn/project/V5.0.1.tar.gz | tar -xvf
Using Curl to download and Extract a tar file...
Here is the command:
$curl -k -O _Tar File Path_ | tar -xvf
Example:
$curl -k -O http://192.168.4.189:8443/svn/testproject/releases/V1.0.1.x.tar.gz | tar -xvf
$curl -k -O _Tar File Path_ | tar -xvf
Example:
$curl -k -O http://192.168.4.189:8443/svn/testproject/releases/V1.0.1.x.tar.gz | tar -xvf
Friday, 14 January 2011
Oracle Schema Disk Usage
Login to oracle using sqlplus and user: system
For example:
$sqlplus system/_Password_
Then run this query:
SQL> select sum(s.bytes)/1024/1024/1024 as size_in_gb, s.owner from dba_segments s group by s.owner order by size_in_gb desc;
For example:
$sqlplus system/_Password_
Then run this query:
SQL> select sum(s.bytes)/1024/1024/1024 as size_in_gb, s.owner from dba_segments s group by s.owner order by size_in_gb desc;
Thursday, 13 January 2011
Schema or User Disk Usage in Oracle
#!/bin/bash
########### USER INPUTS ###########
sys_username="system"
sys_password=""
schema_name_string="" #Input standard name used in all tables.
########### USER INPUTS ###########
filename="username.txt"
SUCCESS=0
FAILURE=1
IMPORT_EXECUTABLE=sqlplus
function init
{
echo "Initialising..."
IMPORT_EXECUTABLE_LOCATION=$( which ${IMPORT_EXECUTABLE} | grep "no ${IMPORT_EXECUTABLE}" )
if [[ -n "${IMPORT_EXECUTABLE_LOCATION}" ]] ; then
echo "Unable to execute import script as the import executable [${IMPORT_EXECUTABLE}] is not on the path"
exit ${FAILURE}
fi
}
function getUserName {
sqlplus -s /nolog << EOF
CONNECT $sys_username/$sys_password
SPOOL $filename
SET LINESIZE 100
SET PAGESIZE 50
select username from all_users where username like '%$schema_name_string%';
SPOOL OFF
exit;
EOF
}
function readUserNamesandCheckDiskUsage {
awk '{ print $0}' $filename | grep -v -E '(^USERNAME|^SQL|^[0-9]|^$|^-)' | (
IFS='
' read -d '' -a arr
for linename in ${arr[@]}
do
echo USERNAME $linename
echo USER "$linename's" DISK USAGE
sqlplus -s $linename/cmms << EOF
Select sum(bytes)/1024/1024 Mb, tablespace_name from user_segments group by tablespace_name;
exit;
EOF
done
)
}
function removeTempFile {
rm $filename
}
init
getUserName
readUserNamesandCheckDiskUsage
removeTempFile
exit ${SUCCESS}
########### USER INPUTS ###########
sys_username="system"
sys_password="
schema_name_string="
########### USER INPUTS ###########
filename="username.txt"
SUCCESS=0
FAILURE=1
IMPORT_EXECUTABLE=sqlplus
function init
{
echo "Initialising..."
IMPORT_EXECUTABLE_LOCATION=$( which ${IMPORT_EXECUTABLE} | grep "no ${IMPORT_EXECUTABLE}" )
if [[ -n "${IMPORT_EXECUTABLE_LOCATION}" ]] ; then
echo "Unable to execute import script as the import executable [${IMPORT_EXECUTABLE}] is not on the path"
exit ${FAILURE}
fi
}
function getUserName {
sqlplus -s /nolog << EOF
CONNECT $sys_username/$sys_password
SPOOL $filename
SET LINESIZE 100
SET PAGESIZE 50
select username from all_users where username like '%$schema_name_string%';
SPOOL OFF
exit;
EOF
}
function readUserNamesandCheckDiskUsage {
awk '{ print $0}' $filename | grep -v -E '(^USERNAME|^SQL|^[0-9]|^$|^-)' | (
IFS='
' read -d '' -a arr
for linename in ${arr[@]}
do
echo USERNAME $linename
echo USER "$linename's" DISK USAGE
sqlplus -s $linename/cmms << EOF
Select sum(bytes)/1024/1024 Mb, tablespace_name from user_segments group by tablespace_name;
exit;
EOF
done
)
}
function removeTempFile {
rm $filename
}
init
getUserName
readUserNamesandCheckDiskUsage
removeTempFile
exit ${SUCCESS}
Command to remote login into Oracle DB using sqlplus...
$ sqlplus _username_/_password_@//_servername or ipaddredd_:_port_/_SID_
example:
$ sqlplus system/hello@//10.10.4.15:1521/INSTANCE
Enjoy.
example:
$ sqlplus system/hello@//10.10.4.15:1521/INSTANCE
Enjoy.
Thursday, 6 January 2011
Finding Searching Table name or Column name in Oracle
Try:
select table_name from user_tables where table_name like '%myString%';
select * from all_tab_columns where COLUMN_NAME like '%myString%'
Thanks...
select table_name from user_tables where table_name like '%myString%';
select * from all_tab_columns where COLUMN_NAME like '%myString%'
Thanks...
Tuesday, 4 January 2011
Opensource Forex Trading...
Open source Linux components (Marketcetra, openFAST, QuickFIX, MySQL etc) used in Forex.
Thanks!
Thanks!
Subscribe to:
Posts (Atom)
Azure OpenAI Architecture Patterns & Deployment Patterns
Sharing some useful links that will help customers architect Azure OpenAI solution using the best practices: (1) Azure OpenAI Landing Zone r...
-
Setting up a MPI cluster on Ubuntu involves the following steps: 1. Install OpenMPI on all machines. $sudo apt-get install libopenmpi-de...
-
Very Useful Link: http://people.cc.ku.edu/~grobe/intro-to-LSL/index.html#particle Using the Linden Script Language This page is a short...
-
float p_size = 0.1; default { state_entry() { llSay(0, "Hello, Avatar!"); llSetPrimitiveParams( [ PRIM_...