August 3, 2010

Basic Commands 3

ALTER TABLE


The ALTER TABLE statement is used to add or drop columns in an existing table.


  • ALTER TABLE table_name ADD column_name datatype;
  • ALTER TABLE table_name DROP COLUMN column_name;
To add a column named "City" in the "Person" table:




  • ALTER TABLE Person ADD City varchar(30);
  • ALTER TABLE Person DROP COLUMN Address;
SQL Functions


Types of Functions




There are several basic types and categories of functions in SQL. The basic types of functions are:


• Aggregate Functions


• Scalar functions



Aggregate functions




Aggregate functions operate against a collection of values, but return a single value.


Function Description




AVG(column)


select avg(salary) from employees;


Returns the average value of a column


COUNT(column)


Returns the number of rows (without a NULL value) of a column


COUNT(*)


Returns the number of selected rows


FIRST(column) Returns the value of the first record in a specified field


LAST(column) Returns the value of the last record in a specified field


MAX(column)


Returns the highest value of a column


MIN(column)


Returns the lowest value of a column


STDEV(column)


STDEVP(column)


SUM(column)


Returns the total sum of a column


VAR(column)


VARP(column)




SQL GROUP BY and HAVING


SELECT column,SUM(column) FROM table GROUP BY column;


all the coumns selected should be called in group by.


SELECT column,SUM(column) FROM table GROUP BY column HAVING SUM(column) condition value


  • SELECT Company,SUM(Amount) FROM Sales GROUP BY Company HAVING SUM(Amount)>10000;

Basic Commands 2

Referring to Two Tables:always compare two tables which have one referencing column as common;

  • SELECT Employees.Name, Orders.Product FROM Employees, Orders WHERE employees.Employee_ID=Orders.Employee_ID;--both column should match(mostly primary keys will be ref)
  • SELECT Employees.Name FROM Employees, Orders WHERE Employees.Employee_ID=Orders.Employee_ID AND Orders.Product='Printer';-Comparing two tables and taking out condition from one table;
Using Joins:join used to compare & combine the results of two tables.

The INNER JOIN returns all rows from both tables where there is a match. If there are rows in Employees that do not have matches in Orders, those rows will not be listed.

  • SELECT Employees.Name, Orders.Product FROM Employees INNER JOIN Orders ON Employees.Employee_ID=Orders.Employee_ID;
The LEFT JOIN returns all the rows from the first table (Employees), even if there are no matches in the second table (Orders). If there are rows in Employees that do not have matches in Orders, those rows also will be listed.
  • SELECT Employees.Name, Orders.Product FROM Employees LEFT JOIN Orders ON Employees.Employee_ID=Orders.Employee_ID;
The RIGHT JOIN returns all the rows from the second table (Orders), even if there are no matches in the first table (Employees). If there had been any rows in Orders that did not have matches in Employees, those rows also would have been listed.
  • SELECT Employees.Name, Orders.Product FROM Employees RIGHT JOIN Orders ON Employees.Employee_ID=Orders.Employee_ID;
SQL UNION and UNION ALL

The UNION command is used to select related information from two tables, much like the JOIN command. However, when using the UNION command all selected columns need to be of the same data type excluding Duplicate values

  • SELECT E_Name FROM Employees_Norway UNION SELECT E_Name FROM Employees_USA;
The UNION ALL command is equal to the UNION command, except that UNION ALL selects all values including Duplicate Values.
  • SELECT E_Name FROM Employees_Norway UNION ALL SELECT E_Name FROM Employees_USA;
SQL Create Database, Table, and Index

  • CREATE DATABASE database_name
  • CREATE TABLE table_name(  column_name1 data_type,column_name2 data_type);
  • CREATE TABLE Person

    (

    LastName varchar,

    FirstName varchar,

    Address varchar,

    Age int

    );
Create Index


Indices are created in an existing table to locate rows more quickly and efficiently.
A Unique Index


Creates a unique index on a table. A unique index means that two rows cannot have the same index value.

  • CREATE UNIQUE INDEX index_name ON table_name (column_name);
  • CREATE INDEX PersonIndex ON Person (LastName);
SQL Drop Index, Table and Database:

  • DROP INDEX index_name ON table_name;
  • DROP TABLE table_name;
Difference between TRUNCATE, DELETE and DROP commands

DELETE


The DELETE command is used to remove rows from a table. A WHERE clause can be used to only remove some rows. If no WHERE condition is specified, all rows will be removed. After performing a DELETE operation you need to COMMIT or ROLLBACK the transaction to make the change permanent or to undo it. Note that this operation will cause all DELETE triggers on the table to fire.

TRUNCATE


TRUNCATE removes all rows from a table. The operation cannot be rolled back and no triggers will be fired. As such, TRUCATE is faster and doesn't use as much undo space as a DELETE.

DROP


The DROP command removes a table from the database. All the tables' rows, indexes and privileges will also be removed. No DML triggers will be fired. The operation cannot be rolled back.





 
  

 

Basic commands 1

SQL SELECT Statement




  • SELECT * FROM table_name; --(selects all columns in the table)
  • SELECT column_name(s) FROM table_name;
  • SELECT LastName,FirstName FROM Persons;


The SELECT DISTINCT Statement


To SELECT unique values from a table eliminating the duplicates.
  • SELECT DISTINCT column_name(s) FROM table_name; 
  • SELECT DISTINCT Company FROM Orders;

SQL WHERE Clause

 The where clause is used for conditional selection of statements.
 
  •  SELECT column FROM table WHERE column operator value;
  •  SELECT * FROM Persons WHERE City='Sandnes';
 You have give the selection Keyword inside the quotes.
 you can use different types of condition in where clause
Operator Description

= Equal
<> Not equal


 > Greater than


< Less than


 >= Greater than or equal


 <= Less than or equal


 BETWEEN Between an inclusive range


 LIKE Search for a pattern


 IN If you know the exact value you want to return for at least one of the columns




 The LIKE Condition

• SELECT column FROM table WHERE column LIKE pattern;


Can use percentage symbol to initate the query to retrive sort based on first letter or last letter;


• SELECT * FROM Persons WHERE FirstName LIKE 'O%';


• SELECT * FROM Persons WHERE FirstName LIKE '%a';


• SELECT * FROM Persons WHERE FirstName LIKE '%la%'


Can add and condition in where clause to add more then one condition


  
SELECT CompanyName, ContactName FROM customers WHERE CompanyName > 'g' AND ContactName > 'g'


 SQL INSERT INTO Statement


Inserts values into the table


• INSERT INTO table_name VALUES (value1, value2,....);


• INSERT INTO table_name (column1, column2,...)VALUES (value1, value2,....);


 SQL UPDATE Statement


 Update the existing column value in a table

• UPDATE table_name SET column_name = new_value WHERE column_name = some_value;


• UPDATE Person SET FirstName = 'abc' WHERE LastName = 'efg'


• UPDATE Person SET Address = 'Dubai', City = 'Karama' WHERE LastName = 'EFG'


SQL DELETE Statement


• DELETE FROM table_name WHERE column_name = some_value;


• DELETE FROM Person WHERE LastName = 'EFG';


• DELETE FROM table_name


or


DELETE * FROM table_name

 Sorting in sql


SQL ORDER BY


• SELECT Company, OrderNumber FROM Orders ORDER BY Company;


• SELECT Company, OrderNumber FROM Orders ORDER BY Company, OrderNumber;


• SELECT Company, OrderNumber FROM Orders ORDER BY Company DESC;


• SELECT Company, OrderNumber FROM Orders ORDER BY Company DESC, OrderNumber ASC;


SQL AND & OR
AND and OR join two or more conditions in a WHERE clause.


The AND operator displays a row if ALL conditions listed are true. The OR operator displays a row if ANY of the conditions listed are true.

• SELECT * FROM Persons WHERE FirstName='Tove' AND LastName='Svendson';


• SELECT * FROM Persons WHERE firstname='Tove' OR lastname='Svendson';


• SELECT * FROM Persons WHERE (FirstName='Tove' OR FirstName='Stephen') AND LastName='Svendson';

SQL IN


 The IN operator may be used if you know the exact value you want to return for at least one of the columns.


 • SELECT column_name FROM table_name WHERE column_name IN (value1,value2,..)


• SELECT * FROM Persons WHERE LastName IN ('Hansen','Pettersen')


SQL BETWEEN

• The BETWEEN ... AND operator selects a range of data between two values. These values can be numbers, text, or dates.


• SELECT column_name FROM table_name WHERE column_name BETWEEN value1 AND value2;


• SELECT * FROM Persons WHERE Salary BETWEEN '10000' AND '150000';


• SELECT * FROM Persons WHERE Salary NOT BETWEEN '10000' AND '150000';


SQL Alias

can assign different names to the columns and tables


• SELECT column AS column_alias FROM table;


• SELECT last_name as NAME from emp;


• SELECT LastName, FirstName FROM Persons AS Employees;










SQL INTRO

SQL is  Structured Query Language to acces database For Manipulations and Analysis.
SQL works with database programs like MS Access, DB2, Informix, MS SQL Server, Oracle, Sybase, etc.


Queries are Categorised as


  • SQL Data Manipulation Language (DML)
  • SQL Data Definition Language (DDL)
  • SQL Tansaction Control Language(TCL)
  • Data Control Language (DCL)
1.SQL Data Manipulation Language (DML)



SQL (Structured Query Language) is a syntax for executing queries. But the SQL language also includes a syntax to update, insert, and delete records.


These query and update commands together form the Data Manipulation Language (DML) part of SQL:


• SELECT - extracts data from a database table


• UPDATE - updates data in a database table


• DELETE - deletes data from a database table


• INSERT INTO - inserts new data into a database table




2.SQL Data Definition Language (DDL)




The Data Definition Language (DDL) part of SQL permits database tables to be created or deleted. We can also define indexes (keys), specify links between tables, and impose constraints between database tables.


The most important DDL statements in SQL are:


• CREATE TABLE - creates a new database table


• ALTER TABLE - alters (changes) a database table


• DROP TABLE - deletes a database table


• CREATE INDEX - creates an index (search key)


• DROP INDEX - deletes an index


3.Transaction Control Language (TCL) - These SQL commands are used for managing changes affecting the data. These commands are COMMIT, ROLLBACK, and SAVEPOINT.




4.Data Control Language (DCL) - These SQL commands are used for providing security to database objects. These commands are GRANT and REVOKE.

August 2, 2010

Setting who columns on validation

Set Who columns in pre-insert:
BEGIN
DATA BLOCK NAME;
FND_STANDARD.SET_WHO;
PACKAGE.VALIDATE_APPROVAL;(Define this procedure in program units)
END;
Set Who columns in pre-update:

begin

XX_VALIDATE1;--procedure 1
XX_VALIDATE2;--procedure 2
fnd_standard.set_who;
PACKAGE.VALIDATE_APPROVAL;(Define this procedure in program units)
end;
Set triggers at when-new-record-instance-level
DECLARE
v_count number;

v_count2 number;

BEGIN

SELECT count(*) into v_count

FROM fnd_lookup_values
WHERE lookup_type = ‘Receipt Number’(count records ad new in db)

and sysdate between start_date_active and nvl(end_date_active,sysdate)

and lookup_code=fnd_global.user_id;
IF v_count = 0 then
--set datablock and procedure to validate SET_ITEM_PROPERTY('XXGOD_JOB_CARD.APPROVE',ENABLED,PROPERTY_FALSE);
END IF;
IF v_count = 1 THEN

--SET_ITEM_PROPERTY('XXGOD_QUOTATION_HDR1.SALES_ORDER',ENABLED,PROPERTY_FALSE);

IF :XXGOD_JOB_CARD.APPROVALS ='Submitted' THEN

SET_ITEM_PROPERTY('XXGOD_JOB_CARD.APPROVE',ENABLED,PROPERTY_TRUE);

ELSE

SET_ITEM_PROPERTY('XXGOD_JOB_CARD.APPROVE',ENABLED,PROPERTY_FALSE);
END IF;
END IF;
END;
Validating Procedure and Package:


PACKAGE XX_VALIDATE IS
PROCEDURE VALIDATE_APPROVAL;
PROCEDURE VALIDATE_APPROVAL1;
PROCEDURE XVALID_DESC_PRO(EVENT IN VARCHAR2);
END;




PACKAGE BODY XX_VALIDATE IS
PROCEDURE VALIDATE_APPROVAL IS

BEGIN

IF :DATA_BLOCK_NAME.APPROVALS IS NULL THEN

FND_MESSAGE.SET_STRING('Status needs to be selected');

FND_MESSAGE.SHOW;

RAISE FORM_TRIGGER_FAILURE;

END IF;

IF :DATA_BLOCK_NAME.APPROVALS!='New'THEN

FND_MESSAGE.SET_STRING('This is a new Job card,select the status as New');
FND_MESSAGE.SHOW;

RAISE FORM_TRIGGER_FAILURE;

ELSE

XX_VALIDATE_1(CALLING ANOTHER PROCEDURE);
END IF;

EXCEPTION

WHEN OTHERS THEN
FND_MESSAGE.ERROR;

RAISE FORM_TRIGGER_FAILURE;
END;
---------------------------------------------------------------------------------------------

PROCEDURE VALIDATE_APPROVAL1 IS
CURSOR C1 IS SELECT APPROVALS FROM table_name WHERE JOB_ID=:data_bolck.item;
v1 VARCHAR2(20);

BEGIN

OPEN C1;

FETCH C1 INTO v1;

IF V1!=:DATA_BLOCK_NAME.APPROVALS THEN

IF V1='New' AND :DATA_BLOCK_NAME.APPROVALS!='Submitted' THEN
FND_MESSAGE.SET_STRING('This is a new Job card,needs to be Submitted');

FND_MESSAGE.SHOW;

RAISE FORM_TRIGGER_FAILURE;

END IF;
IF V1='Submitted' and :DATA_BLOCK_NAME.APPROVALS not in('Approved','Rejected') THEN
FND_MESSAGE.SET_STRING('Submitted Job card,needs to be Approved or Rejected');
FND_MESSAGE.SHOW;
raise form_trigger_failure;

END IF;


IF V1='Rejected' and :DATA_BLOCK_NAME.APPROVALS not in( 'Rejected','Submitted','Closed') THEN
FND_MESSAGE.SET_STRING('Rejected Quotation can only be Submitted or Closed');
FND_MESSAGE.SHOW;
raise form_trigger_failure;
END IF;
if v1='Approved' and :DATA_BLOCK_NAME.approvals not in('Inactive','Active') then
fnd_message.set_string('Approved Job can be Active or Inactive');
fnd_message.show;
raise form_trigger_failure;

end if;


IF v1='Inactive' and :DATA_BLOCK_NAME.approvals!='Active' then
FND_MESSAGE.SET_STRING('Select the status as Active');
FND_MESSAGE.SHOW;
raise form_trigger_failure;

END IF;


IF v1='Active' and : DATA_BLOCK_NAME .approvals!='Closed' then
FND_MESSAGE.SET_STRING('Active Job card has to be Closed');
FND_MESSAGE.SHOW;
raise form_trigger_failure;
END IF;
if v1='Closed' and : DATA_BLOCK_NAME.approvals!='Closed' then
FND_MESSAGE.SET_STRING('Closed Job card can not be modified');
FND_MESSAGE.SHOW;
raise form_trigger_failure;
end if;
END IF;
CLOSE C1;
EXCEPTION
WHEN OTHERS THEN
FND_MESSAGE.ERROR;
RAISE FORM_TRIGGER_FAILURE;
END;


PROCEDURE XGOD_DESC_PRO(EVENT IN VARCHAR2)
IS
BEGIN
IF EVENT='PRE-FORM' THEN

FND_DESCR_FLEX.DEFINE(BLOCK => 'XXGOD_JOB_CARD',FIELD => 'DFF1',
APPL_SHORT_NAME => 'PO',DESC_FLEX_NAME => 'JobCardDFV');
END IF;
IF EVENT='WHEN-NEW-FORM-INSTANCE' THEN

FND_DESCR_FLEX.DEFINE(BLOCK => 'XXGOD_JOB_CARD',FIELD => 'DFF1',APPL_SHORT_NAME => 'PO',DESC_FLEX_NAME => 'JobCardDFV');

FND_DESCR_FLEX.DEFINE(BLOCK => 'XXGOD_JOB_CARD',FIELD => 'DFF',
APPL_SHORT_NAME => 'PO',DESC_FLEX_NAME => 'JobCardDFF1');

END IF;

EXCEPTION

WHEN OTHERS THEN

RAISE FORM_TRIGGER_FAILURE;
END;
END;


July 31, 2010

AR TABLES

  • RA_CUSTOMER_TRX_ALL :stores invoice header information.
  • RA_CUSTOMER_TRX_LINES_ALL stores information about invoice, debit memo, credit memo, bills receivable, and commitment lines.
  • The AR_PAYMENT_SCHEDULES_ALL table stores all transactions except adjustments and miscellaneous cash receipts.
  • RA_CUST_TRX_LINE_GL_DIST_ALL stores accounting distribution records for all transaction lines except bills receivable.
  • RA_CUSTOMERS – Customer information
  • RA_CUST_TRX_TYPES_ALL – Customer Transaction Type
  • AR_PAYMENT_SCHEDULES_ALL
  • AR_CASH_RECEIPTS_ALL stores one record for each receipt entry
  • AR_CASH_RECEIPT_HISTORY_ALL stores all of the activity that is contained for the life cycle of a receipt.
  • AR_RECEIVABLE_APPLICATIONS_ALL stores all accounting entries for cash and credit memo applications.
  • AR_DISTRIBUTIONS_ALL stores the accounting distributions for cash receipts, miscellaneous receipts, adjustments,credit memo applications, cash receipt applications, and bills receivable transactions.

July 27, 2010

Order To Cash

Order to cash normally refer to the process in which taking customer sale order via different sales channel like email, internet, sales person and then generating an invoice and collecting payment for that invoice and then receipt


Complete Order to cash cycle steps including



1. Entering the Sales Order



2. Booking the Sales Order



3. Launch Pick Release



4. Ship Confirm



5. Create Invoice



6. Create the Receipts either manually or using Auto Lockbox ( In this article we will concentrate on Manual creation)



7. Transfer to General Ledger



8. Journal Import



9. Posting
 
 
Tables:
 
1. OE_ORDER_HEADERS_ALL
2. OE_ORDER_LINES_ALL
3. WSH_DELIVERY_DETAILS
4. WSH_DELIVERY_ASSIGNMENTS
5. WSH_NEW-DELIVERIES
6. WSH_DELIVERY_LEGS
7. WSH_TRIP_STOPS
8. WSH_TRIPS
9. M TL_TRX_REQUEST_LINES
10. MTL_MATERIAL_TRANSACTION_TEMP
11. OE_SETS
12. OE_LINE_SETS
13. OE_LINES_ALL
14. MTL_RESERVATIONS



 

COALESCE-SQL

Coalesce- return the null values from the expression. It works similar to a case statement where if expression 1 is false then goes to expr...