Good day,
I am trying to capture date from a apex_item.text but its not working
my classic report table is
SELECT apex_item.checkbox2(1,productID,'class=indCheck')
|| apex_item.hidden(2,productname)
|| apex_item.hidden(3, productcode)
|| apex_item.hidden(5,amount)
as "SELECT",
PRODUCTID,
PRODUCTCODE,
PRODUCTNAME,
PRODUCTDESC,
CATEGORYCODE,
SERIALNUMBER,
UNITPRICE,
REORDERLEVEL,
DISCONTINUED,
UNITSINHAND,
STATUS,
LOCATION,
LOCATIONDESCRIPTION,
apex_item.text (20,amount) as amount
from PRODUCTS
my pl/sql consist of
begin
for idx in 1 .. apex_application.g_f01.count loop
if apex_application.g_f01(idx) is not null then
insert into pending
(products,employeename,department,dates ,amount
)
values
(apex_application.g_f02(idx),:app_user,:app_user,
sysdate,apex_application.g_f05(idx));
end if ;
end loop;
end;
everything is being captured except the apex_item.text (20,amount) as amount which is being reference with apex_application.g_f05(idx)
I did use the same code as you are using and it worked fine.
See my understanding.
Table 1:
DROP TABLE ASHISH_SAMPLE_EMP CASCADE CONSTRAINTS;
CREATE TABLE ASHISH_SAMPLE_EMP
(
EMPNO NUMBER,
ENAME VARCHAR2(20 BYTE),
SAL NUMBER,
LOC VARCHAR2(22 BYTE),
DEPT VARCHAR2(22 BYTE),
ACTIVE VARCHAR2(4 BYTE) DEFAULT 'N'
);
Sample data
SET DEFINE OFF;
Insert into ASHISH_SAMPLE_EMP
(EMPNO, ENAME, SAL, LOC, DEPT,
ACTIVE)
Values
(1, 'Sahay', 1000, 'Delhi', 'SOFTWARE',
'N');
Insert into ASHISH_SAMPLE_EMP
(EMPNO, ENAME, SAL, LOC, DEPT,
ACTIVE)
Values
(4, 'TEst', 555, 'Noida', 'DBA',
'N');
Insert into ASHISH_SAMPLE_EMP
(EMPNO, ENAME, SAL, LOC, DEPT,
ACTIVE)
Values
(7, 'TEst', 555, 'Noida', 'DBA',
'N');
Insert into ASHISH_SAMPLE_EMP
(EMPNO, ENAME, SAL, LOC, DEPT,
ACTIVE)
Values
(2, 'Ashish', 1000, 'Gurugram', 'IT2',
'N');
COMMIT;
Table 2:
CREATE TABLE ashish_apex_item_issue
(
empno NUMBER,
amount NUMBER
);
Report Query
select apex_item.checkbox2(1,empno,'class=indCheck') || apex_item.hidden(5,sal) as "SELECT",
EMPNO,
ENAME,
apex_item.text (20,SAL) as amount,
LOC,
DEPT,
ACTIVE
from ASHISH_SAMPLE_EMP
Save data Process
begin
for idx in 1 .. apex_application.g_f01.count loop
if apex_application.g_f01(idx) is not null then
insert into ashish_apex_item_issue
(empno,amount
)
values
(apex_application.g_f01(idx),apex_application.g_f05(idx));
end if ;
end loop;
end;
Please follow the below article
https://roelhartman.blogspot.com/2018/02/apexapplicationgf0x-array-processing-in.html
I run queries in SQLPlus. Now I want to get all queries into .sql file. how can I do it? please help me.
I don't think that you save all of them, but - you can one by one. Use save command.
SQL> select empno, ename, job sal
2 from emp
3 where deptno = 10;
EMPNO ENAME SAL
---------- ---------- ---------
7782 CLARK MANAGER
7839 KING PRESIDENT
7934 MILLER CLERK
SQL> save q1.sql replace
Wrote file q1.sql
Only query gets saved, not its result:
SQL> $type q1.sql
select empno, ename, job sal
from emp
where deptno = 10
/
SQL>
As you already closed SQL*Plus, check v$sql. In order to be able to use it, sys should grant you (i.e. the user which will query it) privilege to do so:
SQL> connect sys/pwd as sysdba
Connected.
SQL> grant select on v_$sql to scott;
Grant succeeded.
SQL> connect scott/tiger
Connected.
You'd then spool result into a file:
SQL> spool q.sql
SQL> select sql_text
2 from v$sql
3 where to_date(first_load_time, 'yyyy-mm-dd hh24:mi:ss') >
4 to_date('30.05.2020 20:50', 'dd.mm.yyyy hh24:mi')
5 and parsing_schema_name = 'SCOTT';
SQL_TEXT
--------------------------------------------------------------------------------
select empno, ename, job sal from emp where deptno = 10
SQL> spool off
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
CREATE TABLE emp (
empno NUMBER (10) NOT NULL,
empname VARCHAR2 (50) NOT NULL,
mgr VARCHAR2 (10),
hiredate DATE,
sal NUMBER (10),
comm VARCHAR2 (10),
CONSTRAINT emp_pk PRIMARY KEY (empno)
) ;
DESC emp ;
INSERT ALL
INTO emp
(100, 'MARK', 'CXS', hire_date('1999-09-08', 'yyyy/mm/dd'), 8000, 'axw')
(200, 'peter', 'NULL', hire_date('1996-01-08', 'yyyy/mm/dd'), 9000)
(300, 'karl', 'NULL', hire_date('1995-05-08', 'yyyy/mm/dd'), 5000, 'AZQ')
(400, 'MAx', 'NULL', hire_date('1994-04-08', 'yyyy/mm/dd'), 10000, 'DES')
(500, 'Maggie', 'SAQ', hire_date('1998-06-08', 'yyyy/mm/dd'), 20000, 'QAS')
SELECT * FROM dual ;
Your insert all syntax is malformed, you need multiple into ... values ... pairs. At the moment it's trying to interpret 100 as a column name, hence the specific error you're seeing.
You also have hire_date(...) instead of to_date(...), and you're missing one of the comm values; assuming that is supposed to be null:
INSERT ALL
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (100, 'MARK', 'CXS', TO_DATE('1999-09-08', 'yyyy-mm-dd'), 8000, 'axw')
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (200, 'peter', NULL, TO_DATE('1996-01-08', 'yyyy-mm-dd'), 9000, null)
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (300, 'karl', NULL, TO_DATE('1995-05-08', 'yyyy-mm-dd'), 5000, 'AZQ')
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (400, 'MAx', NULL, TO_DATE('1994-04-08', 'yyyy-mm-dd'), 10000, 'DES')
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (500, 'Maggie', 'SAQ', TO_DATE('1998-06-08', 'yyyy-mm-dd'), 20000, 'QAS')
SELECT * FROM dual ;
5 rows inserted.
I've also changed the stirng literals 'NULL' to plain nulls, as it seems much more liekly that is what you really intended.
And I've changed the date format masks to use - rather than /, to match the values. But if you're using fixed values like that it's simpler to use date literals instead, e.g. instead of
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (100, 'MARK', 'CXS', TO_DATE('1999-09-08', 'yyyy-mm-dd'), 8000, 'axw')
use:
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (100, 'MARK', 'CXS', DATE '1999-09-08', 8000, 'axw')
The syntax for the INSERT ALL statement in Oracle/PLSQL is:
INSERT ALL
INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
SELECT * FROM dual;
So in your case you can use
INSERT ALL
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (100, 'MARK', 'CXS', TO_DATE('1999-09-08', 'yyyy-mm-dd'), 8000, 'axw')
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (200, 'peter', NULL, TO_DATE('1996-01-08', 'yyyy-mm-dd'), 9000, null)
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (300, 'karl', NULL, TO_DATE('1995-05-08', 'yyyy-mm-dd'), 5000, 'AZQ')
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (400, 'MAx', NULL, TO_DATE('1994-04-08', 'yyyy-mm-dd'), 10000, 'DES')
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (500, 'Maggie', 'SAQ', TO_DATE('1998-06-08', 'yyyy-mm-dd'), 20000, 'QAS')
SELECT * FROM dual ;
Also for any column you want blank/no value just put NULL if you include this as 'NULL' it will be considered as text NULL.
I want to return top 4 highest salaries from each dept along with deptno and dname in a stored procedure.
when deptno is not included there is no error but
When including deptno im getting an error invalid number.
ORA-01722: invalid number
Here is the code
create or replace procedure tpro2(dno in emp.deptno%type,dnum out dept.deptno%type, name out emp.ename%type, sal out emp.sal%type,dname out dept.dname%type, cur out sys_refcursor)
is begin
open cur for select ename , sal, dname, dept.deptno from (select * from emp order by sal desc)emp, dept where emp.deptno=dept.deptno and emp.deptno=dno and rownum<=4;
end tpro2;
/
declare
dnum dept.deptno%type;
name emp.ename%type;
sal emp.sal%type;
dname dept.dname%type;
cur sys_refcursor;
begin
tpro2(&dno,dnum,name,sal,dname,cur);
loop
fetch cur into dnum,name,sal,dname;
exit when cur%notfound;
dbms_output.put_line(dnum||' '||name||' '||sal||' '||dname);
end loop;
close cur;
end;
/
Please help!!!
open cur for select ename, sal, dname, dept.deptno
fetch cur into dnum, name, sal, dname;
Does you see nothing suspicious here? :)
I would use window functions to get the information you need without writing a stored procedure at all:
SELECT ename, sal, dname, deptno
RANK() OVER (PARTITION BY deptno ORDER BY sal DESC) "Rank"
FROM emp e inner join dept d using (deptno)
Can anyone please help me in solving this.
I need to write a pl/sql query which takes deptno from emp as input and returns ename, sal plus all the columns from dept table.(I don't want to declare the columns individually, instead I want to use %rowtype).
I have tried it in several ways. one of them is mentioned below.
Creation--
CREATE OR REPLACE PROCEDURE PROC01(
DNO EMP.DEPTNO%TYPE,
REC OUT DEPT%ROWTYPE,
NAME OUT EMP.ENAME%TYPE,
SAL OUT EMP.SAL%TYPE
, MY_CURSOR OUT SYS_REFCURSOR)
IS
BEGIN
OPEN MY_CURSOR FOR
SELECT D.*, ENAME, SAL
FROM EMP, DEPT D
WHERE EMP.DEPTNO = D.DEPTNO
AND D.DEPTNO = DNO;
END PROC01;
/
--Declare & Execution
DECLARE
REC DEPT%ROWTYPE;
NAME EMP.ENAME%TYPE;
SAL EMP.SAL%TYPE;
MY_CURSOR SYS_REFCURSOR;
BEGIN
PROC01(&DNO,REC, NAME, SAL, MY_CURSOR);
LOOP
FETCH MY_CURSOR INTO REC, NAME, SAL;
EXIT WHEN MY_CURSOR%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(REC.DNAME||' '||NAME||' '||SAL);
END LOOP;
CLOSE MY_CURSOR;
END;
/
ERROR :--
expression 'REC' in the INTO list is of wrong type
Thanks in advance...
The error is because of oracle can't fetch cursor in both rec type and normal type together.
I changed your query and it's working NOW!
Procedure :
CREATE OR REPLACE PROCEDURE PROC01(DNO IN emp.deptno%TYPE,
/*REC OUT DEPT%ROWTYPE,
NAME OUT EMP.ENAME%TYPE,
SAL OUT EMP.SAL%TYPE,*/
MY_CURSOR OUT SYS_REFCURSOR) IS
BEGIN
OPEN MY_CURSOR FOR
SELECT D.*, ENAME, SAL
FROM EMP, DEPT D
WHERE EMP.DEPTNO = D.DEPTNO
AND D.DEPTNO = DNO;
END PROC01;
Test code :
DECLARE
REC DEPT%ROWTYPE;
DEPTNO DEPT.deptno%TYPE;
DNAME DEPT.dname%TYPE;
LOC DEPT.loc%TYPE;
NAME EMP.ENAME%TYPE;
SAL EMP.SAL%TYPE;
MY_CURSOR SYS_REFCURSOR;
BEGIN
PROC01(&DNO, /*REC, NAME, SAL,*/ MY_CURSOR);
LOOP
FETCH MY_CURSOR
INTO /*REC*/ DEPTNO, DNAME, LOC, NAME, SAL;
EXIT WHEN MY_CURSOR%NOTFOUND;
DBMS_OUTPUT.PUT_LINE( /*REC.*/ DNAME || ' ' || NAME || ' ' || SAL);
END LOOP;
CLOSE MY_CURSOR;
END;