Está en la página 1de 2

Q- DO you know Trim Funtion ??

---- The Oracle TRIM function allows you to remove characters from the left, right, or both sides of a string. By
default, it trims from both sides of a string, but you can specify which side. The TRIM function looks like this:
TRIM (trim_string FROM source_string)
You can trim the characters from the left of the string (LEADING) or the right of the string (TRAILING) using extra
keywords:
TRIM (LEADING trim_string FROM source_string)
An example of the TRIM function is:
SELECT TRIM('a' FROM 'anaconda') FROM dual;

Q- Do you know about padding in sql lpad and rpad?


--The Oracle LPAD() function is used to padding the left side of a string with a specific set of characters. The
function is useful for formatting the output of a query.

Q- what is substr function>


--The Oracle INSTR function is used to search string for substring and find the location of the substring in
the string. If a substring that is equal to substring is found, then the function returns an integer indicating the
position of the first character of this substring

Q- what is difference between union and union all??


UNION
The UNION command is used to select related information from two tables, much like the JOINcommand.
However, when using the UNION command all selected columns need to be of the same data type.
With UNION, only distinct values are selected.
UNION ALL
The UNION ALL command is equal to the UNION command, except that UNION ALL selects all values.
The difference between Union and Union all is that Union all will not eliminate duplicate rows, instead it just
pulls all rows from all tables fitting your query specifics and combines them into a table.
A UNION statement effectively does a SELECT DISTINCT on the results set. If you know that all the records
returned are unique from your union, use UNION ALL instead, it gives faster results.

Q- what is difference between rownum and rowed??


-- The actual difference between rowid and rownum is, that rowid is a permanent unique identifier for that row.
However, the rownum is temporary. If you change your query, the rownum number will refer to another row,
the rowid won't. So theROWNUM is a consecutive number which applicable for a specific SQL statement only
Q- what is use of over() function??
The OVER clause specifies the partitioning, ordering & window "overwhich" the analytic function operates. It
operates over a moving window (3 rows wide) over the rows, ordered by date. It operates over a window that
includes the current row and all prior rows

Q what is % type and %rowtype what is advantages over using this data types?
--%TYPE can be used with the column name preceded with table name to decide the datatype and length of the
variable at runtime. In this case there is no dependency on changes made to the data structure.

%ROWTYPE can be used to declare the variable having the same no. of variables inside it (ROWTYPE) as no. of
columns there in the table. In this case columns selected with SELECT statement must match with variables
inside the rowtype variable. If not then induvidually refer these variables inside the ROWTYPE variables
No need to know about data type of variable, if database definition of column of table are changes then type of
variables changed accordingly .
Q- what is difference between rowtype and type??
%rowtype is used whenever query returns a entire row of table or view
Type rec record is to be used whenever query returns column of different table or views and variables.
Q- what Is pl/sql table??
Object of type table are called plsql tables. Which are modeled as database tables. Plsql tables use a primary
plsql tables can have one column and a primary key
PL/SQL tables help you move bulk data. They can store columns or rows of Oracledata, and they can be passed
as parameters. So, PL/SQL tables make it easy to move collections of data into and out of database tables or
between client-side applications and stored subprograms
Q- what is cursor??
Cursor is a named private area in SQL from which information can be accessed. They are required to process
each row individually for queries which return multiple rows.
Plsql require a special capability to reterive and process more than one row and that resource is known as
cursors. A cursor is pointer to cotext area whichis an area of memory containing sql statements and information
for processing the statement.
Pl sql cursor is mechanism under which multiple rows of the datat form the database are selected and then each
row is individually processed inside plsql program.
There are two types of cursor-
Explicit cursor- For query that return more than one row an explicit cursor is declared and named by a
programmer in order to use explicit cursor in plsql .
A cursor is implicit by default. The user cannot control or process the information in this cursor.
If a query returns multiple rows of data, the program defines an explicit cursor. This allows the application to
process each row sequentially as the cursor returns it.
Q- what are the plsql statements used in cursor processing??
Declare cursor <cursor name> , open <cursor name>, fetch <cursor name> into <variable list> or record types,
close cursor name.
Q- what are the cursor attribute used in pl sql??
Anw- %isopen- to check whether cursor is open or not
%rowcount- number of rows fetched/updated/ deleted
%found- to check whether cursor fetch any row, true rows are fetched
%notfound- to check whether cursor fetched any rows, trues if rows fetched any row.
These attributes are processed with sql for implicit cursors with cursor name for explicit cursor.

Q- what is cursor for loop??


Ans- cursor for loop implicitly declare %rowtype as loop index, open the cursor , fetch rows of values from
active set into fields and record and close when all the records have been processed.
For emp_rec into in c1 loop
Salary total :=salary_total+emp_rec sal;
End loop;

También podría gustarte