Wednesday, October 7, 2015

Attending first Startup Weekend Brisbane Women Oct 2015 #SWBNEwomen

Startup Weekend Brisbane Women

October 9-11, 2015

Usually I'm extremely private about events that I attend, however this is the first time I may pitch one of the many 'big ideas' that are floating in my head. 

The call out for the event is:  
  • Women. 
  • Girl Geeks. 
  • Developers. 
  • Designers. 
  • Marketers. 
  • Business Folk. 

And I feel that I tick at least 3 of those bullet points: Women, Girl Geek, Business Folk..

Hopefully I can get an idea off the ground surrounded by like minded women or help another woman or team with their problem to solve! 



Monday, July 6, 2015

PL SQL Add Decimal to make a dollar value

You may need to design a report with financial information, where the dollar value is in a text field without decimal points. 

So how is this possible and not a number field?? Well, in the original business process, legacy systems, the value had always been a real number, then last year, after 20 years, the business began to use cents in payment as well. There is no decision to change the column type, to the change was required in the reports, which contained that column.

The situation is that some number had decimals and others didn't... 

In the report the data looked like this:
TOTAL_AMOUNT
-------------------------
33
24.95
12
56.90

I then used NUMERIC_FORMATTING to present the column data in a currency format: 

select TO_CHAR(TOTAL_AMOUNT, '9999D99') from TABLE_NAME; 

The end result is: 

TOTAL_AMOUNT
-------------------------
33.00
24.95
12.00
56.90

When the value is null, a null will be returned.


You could also use: 
select TO_CHAR(TOTAL_AMOUNT, '9999.99') from TABLE_NAME; 



Saturday, May 5, 2012

Successfully completed a Diploma in Management

Since 2010 I have been studying part-time towards a Diploma in Management from MSIT and have just received an email to say that I have successfully completed my last unit!
The course details can be found here: http://www.msit.tafe.qld.gov.au/courses/info/545.php


What alot of hard work it was, totally out of my comfort zone, well worth it and one of the reasons I had been neglecting this blog.


At my normal day job, where I've been for just over 3.5 years, I am still an Analyst Programmer using PL\SQL, developing and maintaining Oracle Forms and Oracle Reports.


Now that my studies are complete, for now, I will again be writing posts about my SQL adventures...

Tuesday, November 2, 2010

My Hobby

For those who don't know, I have somewhat sort an arty side within me .. I can sew clothing, soft furnishings and even make jewlery, which I sell through ETSY.COM. Take a look and let mw know what you think...


The URL is http://www.etsy.com/shop/RBJohnson.




Friday, October 22, 2010

Delete all objects from Oracle database

Someitmes you wish to have a 'clean' database, or you may not wish to create your database from scratch, then in this case you can delete all the objects from your database as follows using SQLPlus:

You can use toad, using the results from the select statements between the spool lines below.

NOTE: USE WITH GREAT CAUTION!

1. Put the following in the file “DB_drop.sql”


set feedback off
set pagesize 0
spool AllObjectsDrop.sql
select 'drop view '||view_name||';' from user_views;
select distinct 'drop sequence '||sequence_name|| ';'from user_sequences;
select distinct 'drop table '||table_name|| ';'from user_tables;
select distinct 'drop procedure '||name|| ';'from user_source where type = 'procedure';
select distinct 'drop function '||name|| ';'from user_source where type = 'function';
select distinct 'drop package '||name|| ';'from user_source where type = 'package';
select 'drop synonym '||synonym_name||';' from user_synonyms where synonym_name not like 'sta%' and synonym_name like 's_%'
spool off



2. Log into the database as the user for the database you want to drop
3. Run the script (@DB_drop.sql). This creates the file “AllObjectsDrop.sql” which contains commands to drop all objects.
4. Run the created script (@AllObjectsDrop.sql)

Thursday, September 16, 2010

Login to Oracle as sysdba in one command

Log into your database via sqlplus with sysdba priv’s with a single command. You may set up an alias if you wish.

1. Log into the server as the oracle user end ensure you have the effective group of the appropriate DBA group. typical unix installations have the OS user as ‘oracle’ and the dba group as ‘dba’ (not to be confused with the ‘oinstall’ group).

2. Check your account with the unix ‘id’ command. Make sure your environment variables are set to the appropriate database
$ id
uid=510(oracle) gid=500(dba)
$ env | grep ORA
ORACLE_SID=TESTDB
ORACLE_HOME=/opt/app/oracle/product/9.2.0


3. connect to the database$ sqlplus “/ as sysdba”
SQL>


4. that’s it! be *very* careful!

To make sure sure you in the correct instance enter:

SQL> select name from v$database;

Monday, January 11, 2010

Get extra records between two tables - Oracle

Here are examples of each when you wish to see matching data and data differences between two tables.

Example:
You have primary Person Table that has 100 records, unique identifier person_id,
then you have a another Table Person_Depts with only 63 records that has Person_id.

Table : Persons
person_id number,
person_name, etc...


Table : Person_Dept
person_id number,
dept_id number,
status char(1), etc...


When you wish to find the 63 matching records it's easy:

select distinct
from persons p,
person_dept pd
where p.person_id = pd.person_id


When you wish to return the 37 rows of the persons in person_dept and do not have a match in persons, you extract them using one of the followig two queries:

select distinct pd.person_id from person_dept pd
minus
select p.person_id from persons p


Or you could use the following lines on small sets of data, using this on long non-indexed tables

select tp.person_ID
from
person_dept tp
where (tp.person_ID ) NOT IN ( select p.person_id from persons p)

Tuesday, November 24, 2009

update one table with data from another table

This blog post illustrates how to update more than one column in a table with values from columns in another table and explains how to do it in two RDBMS that I use.

Table Structures and values:
TableA has four columns: a, b, c, d (a is the primary key column)
TableB has five columns: a1, b1, c1, d1, e1 (a1 and b1 together constitute the primary key for this table)
The foreign key relationship between the two tables is based on A.a = B.a1
The data in these 2 tables is as follows:
I. TableA
a b c d
1 x y z
2 a b c
3 t x z

II. TableB
a1 b1 c1 d1 e1
1 x1 y1 z1 40
2 a1 b1 c1 50

The requirement is to write a SQL to update columns b, c and d in TableA from the columns b1, c1 and d1 from TableB where-ever the join condition satisfies and e1 > 40 in TABLEB.

Oracle:
UPDATE TABLEASET (b, c, d) = (SELECT b1, c1, d1 from TABLEB WHERE TABLEB.a1 = TABLEA.a and TABLEB.e1 > 40)WHERE EXISTS (SELECT 1 from TABLEB WHERE TABLEB.a1 = TABLEA.a and TABLEB.e1 > 40)
/

Results after the update:
a b c d
————————————
1 x y z
2 a1 b1 c1
3 t x z


SQL Server:
UPDATE TABLEA
SET b = TABLEB.b1,
c = TABLEB.c1,
d = TABLEB.d1
FROM TABLEA, TABLEB
WHERE TABLEA.a = TABLEB.a1
AND TABLEB.e1 > 40
GO

Note: This is an extension in SQL Server i.e. the FROM clause – it does make it simple to understand and is a nice feature.
Results after the update:
a b c d
————————————
1 x y z
2 a1 b1 c1
3 t x z



Happy writing SQL

Monday, October 12, 2009

Alter table column

This is something so simple, yet can cause you to pull your hair out. All you want to do is alter the length of a column in an Oracle table:

An example table:
Members
MbrID number(5)
FirstName varchar2(30)
Surname varchar2(30)

Now you wish to increase the length of the surname to 50 characters, as someone has a longer than usual surname.
Here is the syntax to do this:

alter table members
modify surname varchar2(50)

This has now been updated to :
Members
MbrID char(5)
FirstName varchar2(30)
Surname varchar2(50)


When you wish to add a column:
alter table members
add DateOfBirth date

When you wish to remove a column:
alter table members
drop column DateOfBirth

When you wish to rename a column
alter table customers
rename column surname to lastname

Thursday, September 24, 2009

Find and replace text in MySQL and Oracle

Today someone told me that they have a blog with over 300 posts and just changed their URL, the problem is that the new blog still had reference to their previous blog's url. And all the images, and reference were to the previous URL which had a 401 re-direct to the new blog. The images, etc were already deleted from the previous blog and imported into the new URL.

He was actually going to update every single entry. I recommended that it the blog has all posts in it's SQL database and had to find all the fields which contained the text (old url address), with the new text (new url ).

Now I will show you and easy way to update this.

Go to your database SQL screen and type in as follows

UPDATE [your_table_name] SET [your_table_field] = REPLACE([your_table_field], '[string_to_find]' , '[string_to_be_replaced]');

example
UPDATE my_posts SET post_content = REPLACE(post_content, 'www.oldurl.com' , 'www.newurl.com');

So armed with only one query per column table combination, you can easily update your blog or database with the new text.