Skip to main content

Posts

Showing posts with the label Sql query

SQL Injection(SQLI) Tips

SQL injection (SQLi) is a type of attack in which a hacker can take advantage of the insecure SQL query a web application makes to a database server (such as MySQL, Microsoft SQL Server and Oracle). It exploits weaknesses in a web application that are usually the result of poor development practices or mistakes. SQL injections are among the oldest, most prevalent and dangerous web application vulnerabilities. Since SQL injections affect web applications that make use of an SQL database, virtually every type of web application needs to pay attention to it. By abusing an SQL injection vulnerability, an attacker may be able to bypass a web application’s authentication and authorization mechanisms, retrieve the contents of an entire database, and even add, modify and delete records  in that database, impacting its data integrity.

Query to show all tables names, see all the objects,create the table into the trigger in sql

Query to show all table names select table_name from dba_tables SELECT *FROM TAB; Query to see all the objects in sql This is a very simple query to get all the objects in sql. User_Objects is sql system table which include all object information as a records. select * from USER_OBJECTS; This is small query but it could be very helpful for you. Create the table into the trigger using pl sql To create table into the trigger using pl/sql you can try following code in SQL query editor or in stored procedure. Create or replace trigger b_br after delete on EMP declare n integer; PRAGMA AUTONOMOUS_TRANSACTION; begin dbms_output.put_line('Table Creation in process..'); execute immediate 'create table b_t(b varchar2(10))'; dbms_output.put_line('Table Created..'); end; Delete from EMP; Same way you can add more columns in tables with different data types.

How to use where and group by clause in same query in Axapta

Following is example of using group by clause in select query using axapta. Group by clause will display data as per mentioned fields after group by clause. SELECT D.DNO ,D.DNAME ,D.DLOCATION , Max(E.salary) FROM Emp E, Dept D                                                       where E.Dno = D.Dno                                                      Group by E.Dno, D.Dno, D.DNAME ,D.DLOCATION ; when you use group by clause then you will get distinct records ...

Sql query to get second maximum salary of employee

Sql query to get second maximum salary of employee 1st Solution:- select min(sal) from emp e where 1 = (select count(*) from emp where e.sal<sal)  In this query duplicate values are not considered hence we may not get 3rd maximum salary because there are two employees with the same salary. to avoid the duplication strictly the query needs some changes 2nd  Solution  :- select min(sal) from emp e where 1 = (select count(distinct sal) from emp where e.sal<sal)  The following query displays the total repeating salaries . to get the complete details of the records just replace "sal" with "*" in the following query 3rd  Solution :- select sal from emp e where 1 = (select count(distinct sal) from emp where  e.sal<sal) This is example of select query to get top 3 maximum from table. select * from (select salaries from SalaryTrans order by salaries desc) where rownum <= 3; or select salary from (select distinct salary fr...

finding null values columns in the table using sql

finding null values columns in the table using sql  declare L_STMT VARCHAR2(32767) := 'SELECT COUNT(1) FROM #1 WHERE #2 IS NULL'; NULL_CNT NUMBER; TBL_NAME VARCHAR2(30) := 'XYZ'; begin FOR I IN (SELECT COLUMN_NAME FROM USER_TABLES WHERE TABLE_NAME = TBL_NAME ORDER BY COLUMN_ID) LOOP L_STMT := REPLACE(L_STMT, '#1',TBL_NAME); L_STMT := REPLACE(L_STMT,'#2',I.COLUMN_NAME); EXECUTE IMMEDIATE L_STMT INTO NULL_CNT; DBMS_OUTPUT.PUT_LINE ('COLUMN OF ' || TBL_NAME ||' : ' ||' NULL COUNT FOR COLUMN '|| I.COLUMN_NAME ||' IS : ' || NULL_CNT; END LOOP; end;

Date format in SQL

Mon DD YYYY 1 HH:MIAM (or PM) Default SELECT CONVERT(VARCHAR(20), GETDATE(), 100) Jan 1 2005 1:29PM 1 MM/DD/YY USA SELECT CONVERT(VARCHAR(8), GETDATE(), 1) AS [MM/DD/YY] 11/23/98 MM/DD/YYYY USA SELECT CONVERT(VARCHAR(10), GETDATE(), 101) AS [MM/DD/YYYY] 11/23/1998 YY.MM.DD ANSI SELECT CONVERT(VARCHAR(8), GETDATE(), 2) AS [YY.MM.DD] 72.01.01 YYYY.MM.DD ANSI SELECT CONVERT(VARCHAR(10), GETDATE(), 102) AS [YYYY.MM.DD] 1972.01.01 DD/MM/YY British/French SELECT CONVERT(VARCHAR(8), GETDATE(), 3) AS [DD/MM/YY] 19/02/72 DD/MM/YYYY British/French SELECT CONVERT(VARCHAR(10), GETDATE(), 103) AS [DD/MM/YYYY] 19/02/1972 DD.MM.YY German SELECT CONVERT(VARCHAR(8), GETDATE(), 4) AS [DD.MM.YY] 25.12.05 DD.MM.YYYY German SELECT CONVERT(VARCHAR(10), GETDATE(), 104) AS [DD.MM.YYYY] 25.12.2005 DD-MM-YY Italian SELECT CONVERT(VARCHAR(8), GETDATE(), 5) AS [DD-MM-YY] 24-01-98 DD-MM-YYY...

Example of Create table in sql

This is a simple example to learn how to create table in sql with different data types and columns. You can see also how to add foreign key in table in create syntax. create table Authors ( AuthorNumber number primary key, RefNumber varchar2(10), LastName varchar2(40), FirstName varchar2(40) null, Organization varchar2(50) null, city varchar2(50) null, State varchar2(30) null, Country varchar2(40) null, Address varchar2(200) null, email varchar2(50) null, Phone varchar2(50) null, Fax varchar2(50) null, foreign key(RefNumber) references papermst(RefNumber) );