Item value as column name in select
Hi,
I have a problem with selecting the columns in the query using items. For example: I have a query:
select column_a from table; or select column_b from table;
and I want to do something like this:
- any item in which I choose the column name
- query: select column_from_item from tale
Is it possible?
My apex version: 4.0.2.00.07
My oracle db version: oracle 11g
Unfortunately, it does not work. For example:
I have a table book (title, themes ...), which is eight rows. When I create a static list of items containing the column names (display name and returns the name) and a report based on select according to your design(select :P5_select from table;), you get eight records in the name of the column.
item: select list -> static list -> display value: Title, return value: Title, name: P1_title
select :P1_title from books;
result which i get:
Title
Title
Title
Title
Similar Messages
-
How to remove column name in select clause
Hello Guys,
I just want to remove a column name in select clause. Because, I don't want to write all column names. I hope I express myself.
In other words, I want the following.
Select * - unwanted_column from table;
instead of this
Select col1, col2, col3, col4, ........ col 10000 from table;Hi,
Sorry, there's nothing in SQL that means "all columns *except* ...". As the others have said, the only way to get those results in SQL is to list all the columns you do want.
Your front end may have some feature that allows you to hide a specific column. For example, in SQL*Plus, you can use <tt> COLUMN ... NOPRINT </tt> , like this:
COLUMN dname NOPRINT
SELECT *
FROM scott.dept
ORDER BY dname
;Output:
` DEPTNO LOC
10 NEW YORK
40 BOSTON
20 DALLAS
30 CHICAGOThere is a column called dname in the scott.dept table; the query above actually uses it. But, because of the COLUMN command, SQL*Plus won't display that column.
Edited by: Frank Kulash on Feb 26, 2013 10:10 AM
Changed scott.dept example. -
Concat to retrieve column name in select
This is basically what I am trying to do:
SELECT 'LY_'| |to_char(sysdate,'MON')| |'SALES' FROM TERR_ACCT_SUM
Except, instead of returning "LY_OCTSALES", I would like to select the rows in the column LY_OCTSALES. How can I "create" the column name to select?Not sure if your question was meant using SQL*PLUS or java code.
If you want to use JDBC you could create SQL statements in a String variable and pass it to the executeQuery() method in the Statement object .
If you are using BC4J if you want you could create Dynamic View Objects based on SQL statments created at the run time.
raghu -
Change column names when selecting from a collection
Anyone know how to change C001,C002...etc to readable column names when selecting from a collection? Aliases don't work!
Paul PlattPaul,
Edit the report attributes and change the column headings by selecting the "Custom" radio button first.
Sergio -
Need to use Select List value as column name
I want to have a WHERE ? IS BETWEEN ? AND ? clause.
I am using the PL/SQL Query returning a SQL Query as a report. This uses bind variables for items I had set on my form..... If I hardcode something like:
'WHERE STARTDATE IS BETWEEN '||
'TO_DATE(:P1_START,''dd-MON-YYYY HH24:MI'') AND '||
'TO_DATE(:P2_END,''dd-MON-YYYY HH24:MI'')';
I have no problem, but I have 2 date columns, STARTDATE and ENDDATE, and would like to use the value in a select list and not have to hardcode "STARTDATE" in there. I have not been able to do this, does anyone know how to use a bind variable as a column name? From reading some posts I think it might not be possible.Heather,
You're on the right track, just glue in the column name so that it becomes part of the returned query string from the function (...'WHERE '||:COLNAME||' IS BETWEEN '|| ...).
Note that the bind variable is not part of the returned query string, but the column name obtained from the bind variable when the function executes does become part of the query string.
Scott -
Using select list value as column name in SQL
Folks,
Thanks in advance for any help with this
I have a select list with two values (Instance and Username) created by
STATIC2:Username;USERNAME,Instance;INSTANCE
I am trying to pass the value of this (:P2_SELECT) and use it as a column name in a SQL query as below
select USERNAME,
INSTANCE
from table_name
where :P2_SELECT like '%'||:P2_TEXTSEARCH||'%'
When I substitue the :P2_SELECT for one of the values (either instance or username) this works fine
I suspect it is due to how Application Express interprets the value of :P2_SELECT
Any help would be much appreciated!
GarethThanks Munky that worked a treat!
The next hurdle I have now is that because I have changed the region type to "PL/SQL Function(returning SQL Query)" there is no longer the option to add sorting to the columns as I have had to change the Source option to "Use Generic Column Names (parse query at runtime only)"
I will have a scout around and see how I can get around this
Gareth -
Passing parameters to table valued functions and using parameters as column name on select
I am creating a function where I want to pass it parameters and then use those parameters in a select statement. When I do that it selects the variable name as a literal not a column. How do I switch that context.
Query:
ALTER FUNCTION [dbo].[ufn_Banner_Orion_Employee_Comparison_parser_v2]
@BANNER_COLUMN AS VARCHAR(MAX),
@ORION_COLUMN AS VARCHAR(MAX)
RETURNS @Banner_Orion_Employee_Comparison TABLE
LAST_NAME nvarchar(max),
EMPNO int,
BannerColumnName nvarchar(max),
BANNER nvarchar(max),
ORION nvarchar(max)
AS
BEGIN
INSERT INTO @Banner_Orion_Employee_Comparison
(LAST_NAME, BANNER, ORION)
SELECT
a.LAST_NAME, @BANNER_COLUMN, @ORION_COLUMN
FROM OPENQUERY(ORCLPROD_APDORACLE, 'select LAST_NAME, BANNER_RANK, BADGE, EMP_STATUS from XTRACT_VIEW') AS a
inner join IWM_Stage.dbo.ViewPersonnel AS b
on a.BADGE = b.badge
WHERE a.EMP_STATUS = 'A'
and a.BANNER_RANK <> b.[rank]
RETURN;
END;
GO
Output
I execute this:
select * from ufn_Banner_Orion_Employee_Comparison_parser_v2 ('a.BANNER_RANK' , 'b.[rank]')
and get:
Cerecerez NULL
NULL a.BANNER_RANK
b.[rank]
George,
You could go for using a CASE statement as earlier mentioned by Erland. This would look like below: (Downside is that you need to be mentioning all possible values in the CASE)
ALTER FUNCTION [dbo].[ufn_Banner_Orion_Employee_Comparison_parser_v2]
@BANNER_COLUMN AS VARCHAR(MAX),
@ORION_COLUMN AS VARCHAR(MAX)
RETURNS @Banner_Orion_Employee_Comparison TABLE
LAST_NAME nvarchar(max),
EMPNO int,
BannerColumnName nvarchar(max),
BANNER nvarchar(max),
ORION nvarchar(max)
AS
BEGIN
INSERT INTO @Banner_Orion_Employee_Comparison(LAST_NAME, BANNER, ORION)
SELECT
a.LAST_NAME
, CASE @BANNER_COLUMN WHEN 'a.BANNER_RANK' THEN a.BANNER_RANK WHEN 'a.BADGE' THEN a.BADGE END --put values as required
, CASE @ORION_COLUMN WHEN 'b.[rank]' THEN b.[rank] END --put values as required
FROM OPENQUERY(ORCLPROD_APDORACLE, 'select LAST_NAME, BANNER_RANK, BADGE, EMP_STATUS from XTRACT_VIEW') AS a
inner join IWM_Stage.dbo.ViewPersonnel AS b
on a.BADGE = b.badge
WHERE a.EMP_STATUS = 'A'
and a.BANNER_RANK <> b.[rank]
RETURN;
END;
GO
Another method that I would suggest is to get all values from the function, then build a dynamic query to obtain results from it .. Something like:
ALTER FUNCTION [dbo].[ufn_Banner_Orion_Employee_Comparison_parser_v2]()
RETURNS @Banner_Orion_Employee_Comparison TABLE
LAST_NAME nvarchar(max),
EMPNO int,
BannerColumnName nvarchar(max),
BANNER nvarchar(max),
ORION nvarchar(max)
AS
BEGIN
INSERT INTO @Banner_Orion_Employee_Comparison(LAST_NAME, BANNER, ORION)
SELECT
* --Returns all the columns
FROM OPENQUERY(ORCLPROD_APDORACLE, 'select LAST_NAME, BANNER_RANK, BADGE, EMP_STATUS from XTRACT_VIEW') AS a
inner join IWM_Stage.dbo.ViewPersonnel AS b
on a.BADGE = b.badge
WHERE a.EMP_STATUS = 'A'
and a.BANNER_RANK <> b.[rank]
RETURN;
END;
GO
--Execution
DECLARE @BANNER_COLUMN AS VARCHAR(MAX), @ORION_COLUMN AS VARCHAR(MAX),@SQL NVARCHAR(MAX)
SET @BANNER_COLUMN='BANNER_RANK'
SET @ORION_COLUMN='[rank]'
SET @SQL='
select LAST_NAME,'+@BANNER_COLUMN+','+@ORION_COLUMN+' from ufn_Banner_Orion_Employee_Comparison_parser_v2 ()'
PRINT @SQL
EXEC @SQL
You just need to make sure that the column names returned by the function are UNIQUE (Using proper alias names) so that you don't have a problem referring to them from the outside..
Thanks,
Jay
<If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'> -
How to use bind variable value for table name in select statement.
Hi everyone,
I am having tough time to use value of bind variable for table name in select statement. I tried &p37_table_name. ,
:p37_table_name or v('p37_table_name) but none worked.
Following is the sql for interactive report:
select * from v('p37_table_name') where key_loc = :P37_KEY_LOC and
to_char(inspection_dte,'mm/dd/yyyy') = :P37_INSP_DT AND :p37_column_name is not null ;
I am setting value of p37_table_name in previous page which is atm_state_day_insp.
Following is error msg:
"Query cannot be parsed, please check the syntax of your query. (ORA-00933: SQL command not properly ended) "
Any help would be higly appreciated.
RajInterestingly enough I always had the same impression that you had to use a function to do this but found out from someone else that all you need to do is change the radio button from Use Query-Specific Column Names and Validate Query to Use Generic Column Names (parse query at runtime only). Apex will substitute your bind variable for you at run-time (something you can't normally do in pl/sql without using dynamic sql)
-
Invalid Column Name on select from materialized view?
Hey all, I have created this materialized view for my java to select from. For some reason when I try to select from it, I get invalid column name. Here is my mat view statement in its simplest form:
create materialized view mv_pgridtcevcluster_property as
select distinct clustername_ as "OBJECT_ID", CLUSTERNAME_, LICENSEMODE_
from p_gridtcevcluster p
order by clustername_;
Now when I run my select statement from jdbc:
SQL: select object_id from MV_PGRIDTCEVCLUSTER_PROPERTY
java.sql.SQLException: Invalid column name
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.jdbc.driver.OracleStatement.getColumnIndex(OracleStatement.java:3319)
at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1926)
at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:1515)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.getString(NewProxyResultSet.java:3342)
at historian.objects.mgmt.udrManagerTest.gatherObjects(udrManagerTest.java:73)
Anyone have issues with this before? It seems to throw the error sporatically, any help would be much appreciated!
Regards,
TimS
Edited by: TimS on Mar 30, 2009 1:54 PM
Nevermind, figured it out. Was using wrong column name identifier when picking values from resultset.Since you have "OBJECT_ID" in quotes, Oracle stores the column name literally and case sensitively, and the column name must be capitalized when referenced.
From a regular sql*plus window, try
select object_id from mv_pgridtcevcluster_property;
select OBJECT_ID from mv_pgridtcevcluster_property;
select "OBJECT_ID" from mv_pgridtcevcluster_property;What is the result from each of them? -
Display column value as column name
Hi,
I have a requirement to display column names as column values and vice versa. Pls suggest how to do this.
Test data
create table oratest as select 'saurabh' "name",23 "age" from dual;
SQL> select * from oratest;
name age
saurabh 23Expected output
saurabh 23
name ageOk, I've only got 10g here at the minute, so this is what I'd do...
SQL> ed
Wrote file afiedt.buf
1 DECLARE
2 v_v_val VARCHAR2(4000);
3 v_n_val NUMBER;
4 v_d_val DATE;
5 v_ret NUMBER;
6 c NUMBER;
7 d NUMBER;
8 col_cnt INTEGER;
9 f BOOLEAN;
10 rec_tab DBMS_SQL.DESC_TAB;
11 col_num NUMBER;
12 v_rowcount NUMBER := 0;
13 v_name VARCHAR2(20);
14 v_age NUMBER;
15 v_sql VARCHAR2(4000);
16 v_str VARCHAR2(250);
17 v_und VARCHAR2(250);
18 BEGIN
19 select "name", "age"
20 into v_name, v_age
21 from oratest;
22 v_sql := 'SELECT ''name'' as "'||v_name||'", ''age'' as "'||v_age||'" from dual';
23 c := DBMS_SQL.OPEN_CURSOR;
24 DBMS_SQL.PARSE(c, v_sql, DBMS_SQL.NATIVE);
25 d := DBMS_SQL.EXECUTE(c);
26 DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
27 --
28 -- Bind local return variables to the various columns based on their types
29 FOR j in 1..col_cnt
30 LOOP
31 CASE rec_tab(j).col_type
32 WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000); -- Varchar2
33 WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val); -- Number
34 WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val); -- Date
35 ELSE
36 DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000); -- Any other type return as varchar2
37 END CASE;
38 END LOOP;
39 -- Display the header
40 FOR j in 1..col_cnt
41 LOOP
42 v_str := v_str || rpad(rec_tab(j).col_name,30,' ')||' ';
43 v_und := v_und || rpad('-',30,'-')||' ';
44 END LOOP;
45 v_str := rtrim(v_str);
46 v_und := rtrim(v_und);
47 DBMS_OUTPUT.PUT_LINE(v_str);
48 DBMS_OUTPUT.PUT_LINE(v_und);
49 --
50 -- This part outputs the DATA
51 v_str := '';
52 LOOP
53 v_ret := DBMS_SQL.FETCH_ROWS(c);
54 EXIT WHEN v_ret = 0;
55 v_rowcount := v_rowcount + 1;
56 FOR j in 1..col_cnt
57 LOOP
58 CASE rec_tab(j).col_type
59 WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
60 v_str := v_str||rpad(v_v_val,30,' ')||' ';
61 WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
62 v_str := v_str||lpad(to_char(v_n_val,'fm999999999999'),30,' ')||' ';
63 WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
64 v_str := v_str||rpad(to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),30,' ')||' ';
65 ELSE
66 DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
67 v_str := v_str||rpad(v_v_val,30,' ')||' ';
68 END CASE;
69 END LOOP;
70 v_str := rtrim(v_str);
71 dbms_output.put_line(v_str);
72 END LOOP;
73 DBMS_SQL.CLOSE_CURSOR(c);
74* END;
SQL> /
saurabh 23
name age
PL/SQL procedure successfully completed.
SQL>Now, with 11g you can actuall create the DBMS_SQL cursor from the top part of the code...
18 BEGIN
19 select "name", "age"
20 into v_name, v_age
21 from oratest;
22 v_sql := 'SELECT ''name'' as "'||v_name||'", ''age'' as "'||v_age||'" from dual';
23 c := DBMS_SQL.OPEN_CURSOR;
24 DBMS_SQL.PARSE(c, v_sql, DBMS_SQL.NATIVE);And using the new function in 11g's DBMS_SQL package called dbms_sql.to_refcursor and convert the DBMS_SQL cursor to a REF CURSOR which you can then use in your applications (if that's the way you need to go)...
http://www.oracle.com/technology/oramag/oracle/07-nov/o67asktom.html
Whatever route you take though, you won't do this simply in SQL as the column names of a query are required to be known before any data is retrieved when a query (cursor) executes. You can see that when you use the DBMS_SQL package, where the query has to be parsed and the column names and descriptions are determined before any fetching of data. -
Supplying row value as column name
Hi all,
I have two tables in which row value in one table is column name of other. How do i relate it to retreive the data...
Table 1: control (contains 3 columns in it)
table_name - parametername - parametervalue
MI - UNPROCESSED_FLAG - N
MI - PROCESSED_FLAG - Y
MI - FROM_DATE - 01-JAN-2008
MI - TO_DATE - 31-DEC-2010
EMP - DEPTNO - 30
EMP - JOB - SALESMAN
EMP - FROM_DATE - 01-JAN-1982
EMP - TO_DATE - 31-DEC-1995
Table 2: emp (contains the columns: empno,ename,deptno,job,hiredate)
I want to display all details from emp table according to the parameter given in control table. I have already written a query using subquery
select *
from emp
where
deptno = (select parameter_value from job_control where parameter_name = 'DEPTNO')
and
job = (select parameter_value from job_control where parameter_name = 'JOB')
and
hiredate between (select parameter_value from job_control where parameter_name = 'FROM_DATE' and table_name = 'EMP') and (select parameter_value from job_control where parameter_name = 'TO_DATE' and table_name = 'EMP');
But i want to write ot using joins. Plz help me out.....
ThanksHi,
Welcome to the forum!
Whenever you have a question, please post CREATE TABLE and INSERT statements for your sample data, so that the people who want to help you can re-create the problem and test their ideas. (There's no need to post commonly available tables. like those in the scott schema, but make it clear which such tables you're using.) Since this is your first post, I'll do it for you:
CREATE TABLE control_table
table_name VARCHAR2 (20)
, parametername VARCHAR2 (20)
, parametervalue VARCHAR2 (20)
INSERT INTO control_table (table_name, parametername, parametervalue) VALUES ('EMP', 'DEPTNO', '30');
INSERT INTO control_table (table_name, parametername, parametervalue) VALUES ('EMP', 'JOB', 'SALESMAN');
INSERT INTO control_table (table_name, parametername, parametervalue) VALUES ('EMP', 'FROM_DATE', '01-SEP-1981');
INSERT INTO control_table (table_name, parametername, parametervalue) VALUES ('EMP', 'TO_DATE', '31-DEC-1995');
INSERT INTO control_table (table_name, parametername, parametervalue) VALUES ('MI', 'FROM_DATE', '01-JAN-2008');
;Also post the exact results you want from that sample data. The query below produces these results from the control_table above and the standard scott.emp table:
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30Always say which version of Oracle you're using. The query below works in Oracle 9.1 and up.
One thing you can do is pivot the appropriate parameters into a one-row result set, and treat it as a table, like this:
WITH got_params AS
SELECT TO_NUMBER (MIN (CASE WHEN parametername = 'DEPTNO' THEN parametervalue END)) AS deptno
, MIN (CASE WHEN parametername = 'JOB' THEN parametervalue END) AS job
, TO_DATE (MIN (CASE WHEN parametername = 'FROM_DATE' THEN parametervalue END), 'DD-MON-YYYY') AS fromdate
, TO_DATE (MIN (CASE WHEN parametername = 'TO_DATE' THEN parametervalue END), 'DD-MON-YYYY') AS todate
FROM control_table
WHERE table_name = 'EMP'
SELECT e.*
FROM emp e
JOIN got_params p ON e.deptno = p.deptno
AND e.job = p.job
AND e.hiredate BETWEEN p.fromdate
AND p.todate
;This assumes that the combination (table_name, parametername) is unique in the control_table. -
How to use a value as column name in Triggers?
Hello All!!!!!
How can i use a column value instead of field name in triggers? e.g. table X has one column and having following data.
COL1*
Id
Name
Contact No.
now in triggers i want to use "Id" instead of :new.id, is it possible?
Any solution?actually i am trying to write a trigger on lets say Table2 and i dont want to specify the column name in the trigger.
CREATE OR REPLACE TRIGGER TR_AIUDR_002
AFTER UPDATE
ON mytable
FOR EACH ROW
DECLARE
CURSOR C IS
SELECT * FROM t_table_columns;
BEGIN
IF UPDATING then
FOR I IN C LOOP
IF *:new.column_name <> :OLD.column_name* THEN
insert into....
END IF;
END LOOP;
END IF;
END TR_AIUDR_002;
instead of :new.column_name <> :old.column_name i want to compare on the base of loop column
Edited by: rha2 on Jan 31, 2009 7:04 PM -
ORA-00904: invalid column name in select query by using abstract datatype
Hi,
I had created abstract datatype as PERSON_TY and ADDRESS_TY ,
after inserting the record . i'm tryng to select the column but i got the error , even i refferd all those thing. they are given that same please look this finde me a result.
SQL> DESC PERSON_TY
Name Null? Type
NAME VARCHAR2(25)
ADDRESS ADDRESS_TY
SQL> DESC ADDRESS_TY
Name Null? Type
STREET VARCHAR2(30)
CITY VARCHAR2(25)
STATE CHAR(2)
COUNTRY VARCHAR2(15)
SQL> SELECT * FROM EMPLOYE
2 ;
EMP_CODE
PERSON(NAME, ADDRESS(STREET, CITY, STATE, COUNTRY))
10
PERSON_TY('VENKAT', ADDRESS_TY('112: BLUE MOUNT', 'CHENNAI', 'TN', 'INDIA'))
20
PERSON_TY('SRINI', ADDRESS_TY('144: GREEN GARDEN', 'THAMBARAM', 'TN', 'INDIA'))
SQL> SELECT PERSON.NAME FROM EMPLOYE
2 ;
SELECT PERSON.NAME FROM EMPLOYE
ERROR at line 1:
ORA-00904: invalid column name
regards
venkiSELECT PERSON.NAME FROM EMPLOYEIf you look in the documentation, you will see that we need to alias the table in order to make this work:
select e.person.name from employees e
/Cheers, APC
Blog : http://radiofreetooting.blogspot.com -
Dynamic column name with SELECT INTO
I am trying to build a function that derives a pay amount from a set of business rules. There are about 40 columns that hold various pay amounts and their column names are variations of 4 indicators (day shift, vs night shift, etc.) that I have to dynamically look up, ie here is the ID number and a timecard, now figure out which of the 40 fields to look up to get the pay amount.
I can determine from the timecard and employee ID which field to look at, but I'm getting hung up with the syntax needed to construct and execute the statement inside the PL/SQL block. I need to RETURN the pay I extract using the function, and I can create the correct SQL statement, but the EXECUTE IMMEDIATE won't accept the SELECT INTO syntax.
Can someone please suggest a solution? Here is the function:
create or replace FUNCTION FN_GET_PAYRATE(tc in NUMBER, e in NUMBER, pc in VARCHAR2)
RETURN NUMBER
IS
e_id NUMBER;
tc_id NUMBER;
pl_cd VARCHAR2(7);
shft VARCHAR2(2);
lvl VARCHAR2(2);
typ VARCHAR2(2);
e_typ VARCHAR2(4);
proj NUMBER;
hrly VARCHAR2(4);
payrt NUMBER;
var_col VARCHAR2(10);
sql_select VARCHAR2(200);
sql_from VARCHAR2(200);
sql_where VARCHAR2(200);
sql_and1 VARCHAR2(200);
sql_and2 VARCHAR2(200);
sql_and3 VARCHAR2(200);
sql_orderby VARCHAR2(200);
var_sql VARCHAR2(2000);
BEGIN
e_id := e;
tc_id := tc;
pl_cd := pc;
SELECT NVL(SHIFT,'D') INTO shft
FROM TS_TIMECARD_MAIN
WHERE TIMECARD_ID = tc_id;
--DBMS_OUTPUT.PUT_LINE('SHIFT= ' || shft);
SELECT NVL(PAY_LVL, 1), NVL(PAY_TYPE, 'B'), NVL(RTRIM(EMP_TYPE), 'LHD'), NVL(PROJECT, 001)
INTO lvl, typ, e_typ, proj
FROM TS_EMPLOYEES
WHERE EMP_ID = e_id;
--DBMS_OUTPUT.PUT_LINE('Level= ' || lvl);
--DBMS_OUTPUT.PUT_LINE('PAY_TYPE= ' || typ);
--DBMS_OUTPUT.PUT_LINE('EMP_TYPE= ' || e_typ);
--DBMS_OUTPUT.PUT_LINE('PROJECT= ' || proj);
IF e_typ <> 'LHD' THEN
hrly := 'H';
ELSE
hrly := '';
END IF;
IF proj <> 001 THEN
var_col := shft || lvl || typ || hrly;
--DBMS_OUTPUT.PUT_LINE('RATE COLUMN= ' || var_col);
sql_select := 'SELECT NVL(' || var_col || ', .01) INTO payrt';
sql_from := ' FROM TS_PAYRATES';
sql_where := ' WHERE PROJECT_ID = ' || proj;
sql_and1 := ' AND ACTIVE = 1';
sql_and2 := ' AND JOB_TYPE = ' || CHR(39) || e_typ || CHR(39);
sql_and3 := ' AND PILE_ID = ' || CHR(39) || pl_cd || CHR(39);
var_sql := sql_select || sql_from || sql_where || sql_and1 || sql_and2 || sql_and3 || sql_orderby;
DBMS_OUTPUT.PUT_LINE('SQL: ' || var_sql);
EXECUTE IMMEDIATE var_sql;
DBMS_OUTPUT.PUT_LINE('RATE= ' || payrt);
RETURN payrt;
ELSE
DBMS_OUTPUT.PUT_LINE('ERROR');
RETURN 1;
END IF;
END;
I have alternately tried this:
SELECT NVL(var_col,.01) into payrt
FROM TS_PAYRATES
WHERE PROJECT_ID = proj AND ACTIVE = 1
AND JOB_TYPE = CHR(39) || e_typ || CHR(39)
AND PILE_ID = CHR(39) || pl_cd || CHR(39);
as a substitute for the EXECUTE IMMEDIATE block, but I can't seem to use a dynamic substitution for the column name.
Any help would be greatly appreciated.That's the most difficult part - the error messages seem to indicate a problem with the SQL statement in its execution context, because I can take the SQL string by itself and it executes perfectly.
Here are three variations:
SELECT INTO
select fn_get_payrate(21555, 30162, 15) from dual
ERROR at line 1:
ORA-00905: missing keyword
ORA-06512: at "PEOPLENETIF.FN_GET_PAYRATE", line 60
SQL: SELECT NVL(N4P , .01) INTO payrt FROM TS_PAYRATES WHERE PROJECT_ID = 701 AND ACTIVE = 1 AND JOB_TYPE = 'LHD' AND PILE_ID = '15'
Without SELECT INTO (returns NULL)
SQL> select fn_get_payrate(21555, 30162, 15) from dual;
FN_GET_PAYRATE(21555,30162,15)
SQL: SELECT NVL(N4P , .01) FROM TS_PAYRATES WHERE PROJECT_ID = 701 AND ACTIVE = 1 AND JOB_TYPE = 'LHD' AND PILE_ID = '15'
RATE=
EXECUTE IMMEDIATE USING
SQL> select fn_get_payrate(21555, 30162, 15) from dual;
select fn_get_payrate(21555, 30162, 15) from dual
ERROR at line 1:
ORA-01006: bind variable does not exist
ORA-06512: at "PEOPLENETIF.FN_GET_PAYRATE", line 61
SQL: SELECT NVL(N4P , .01) FROM TS_PAYRATES WHERE PROJECT_ID = 701 AND ACTIVE = 1 AND JOB_TYPE = 'LHD' AND PILE_ID = '15' -
Item value on column link is not posted in 3.0
Hi,
I've on page 120 a column link to page 122 with 3 items: P120_X, P120_Y, P120_Z with the values set #P120_X#, #P120_Y#, #P120_Z# . If the value of P120_Z = # , then only P120_X und P120_Y are available at Page 122. P120_Z is NULL. My Version is Apex 3.0 now. This was working in Apex 2.0. Any idea how to solve this issue.
Thanks and Regards
JuergenJuergen,
I don't know why it worked in 2.0 but if you pass # as the item value in a URL without encoding it it will look like the start of a named anchor reference.
Just another reason not to pass arbitrary character data in URLs; stick with numeric primary keys as much as possible.
Scott
Maybe you are looking for
-
Error while configuring SSL in OID 11g - LDAP 50 Insufficient Access rights
HI, I am trying to configure SSL in OID 11g.As per the doc http://download.oracle.com/docs/cd/E12839_01/oid.1111/e10029/ssl.htm#CBHGBGAF ,i tried creating a Self-Signed Wallte using Fusion Middleware control,But i am getting an error LDAP 50: Insuffi
-
Hi, I have a question on ASCP (11.5.10)funtionality. We create SO for ATO Model, configure it to create * Item (configured item). We collect data and run unconstrained plan. Checking the workbench we can see that ASCP recommends to create a Discrete
-
After iPhone goes sleep, can't connect to wifi unless I turn it off and on
I'm having an odd issue. I've had my iPhone for about 1 month after owning an iPod touch. Both my gf and I have purchased iPhones and hers does not have this problem. When the phone hasn't been used for a while (ie in my pocket) once I try using it a
-
Here's my problem. I receive notices from something called Disqus. When I post a comment on the CNN website and someone replies to it I get an email with a link back to the story and comments. These used to show up properly in my inbox, but now they
-
Bug in Applet properties.
I have found what seems like a bug in the JDK1.6+ getProperties when running as an Applet java_home property returned as an application. E:\Program Files\Java\jre1.6.0_02 But as an Applet it is Wrong... E:\PROGRA~1\Java\JRE16~2.0_0 If you rely on thi