Item in where query source - sql

Hi I'm a newbie to the oracle apex and I'm trying to create a dynamic page that let the user (the logged one) see only "his" record I tried in the source query (P101_USERNAME is the username item on the login page)
select * from user u where u.username=v('P101_USERNAME')
And this
Select * from user u where u.username=:P101_USERNAME
But I got the no data found error I think I'm doing the things the wrong way.. So is there a way to create a page that let the user see only the record linked to his username(or primary key) and hide the other?

That username field is only relevant for the life of the login process.
Throughout the application you should refer to :APP_USER
See list of available substitution strings
https://docs.oracle.com/cd/E59726_01/doc.50/e39147/concept_sub.htm#BEIHCJBG

If you’re using APEX 5, you can now get the User from the APEX$SESSION application context. here
You also can use function APEX_APPLICATION.g_user here

Related

SQL select by field acting weird

I am writing this post because I have encountered something truly weird with an SQL statement I am trying to make.
Context:
I am developing an app which uses JPA in the backend to persist / retrieve objects to/from a postgres database.
Problem:
During some tests I have noticed that when a particular user adds entries in the database and later I try to fetch them by his facebook id, the result is an empty list, even though the entries are there in the database. Doing a select statement on the database returns no rows. This does not happen with other users.
I have noticed that the mentioned user's facebook id is slightly longer then others. I do not know if and how this affects this situation.
Interesting part:
When during debugging I created an entry not programmatically, but manually with a SQL INSERT statement directly on the database (marked red on the 1st screenshot), I could fetch the data by facebook id both in my app and with a select statement.
Do you have any ideas what is going on here?
Please check the screenshots:
result of select * from table:
result of select * from table where user_facebook_id = 10215905779020408 :
Please help,
Thanks

error while using the EXCEPT identifier in sql query

i have a user table with one attribute as habits that has valus like shopping,sports etc. Now when i log in to my application i get the username from the FORM tag and this is used in javascript for further use. I need a query that displays all the user table contents where habits=shopping but it shouldnt display the details of the currently logged in user. The query i used for this is,
select * from user where habits='shopping' except select * from user where username='niranjan';
But this line is generating an error stating that the EXCEPT identifier is not a valid input at this point.
pls correct my error or provide an alternative code for my issue.
select * from user where habits='shopping' and username!='niranjan';
No need for except here. Just add a condition to your where caluse:
And username <> 'niranjan'
The problem may be that user is a reserved word for SQL Server. I would suggest that you rename the table to users to get around this problem.
In the meantime, you can use square braces for the query:
select * from [user] where habits = 'shopping'
except
select * from [user] where username = 'niranjan';
However, it is bad form to use reserved words for table and column names.

Oracle Apex, when a report with sql is created, how do i get it return after entering in to a text box?

I want to use the wildcard character within the where clause for a report based on a query.
The user will enter the criteria through a textbox and here is the query I have developed.
select JOID,
JOBNAME,
JOBTYPE,
MACHINE,
JOB_BOX,
JOBDOC,
from CYCLE_JOB_VIEW
where JOB_NAME LIKE :P1_SEARCHTEXTBOX
When I run the report I get the error below:
ERR-1777: Page 1 provided no page to branch to. Please report this
error to your application administrator.
I am using Apex version 3.2
When the user enters some search criteria and hits Enter (or clicks a button), their browser generally submits the page to the server and Apex directs them to the appropriate page as defined.
In your case, you are getting ERR-1777 because your page doesn't specify what page to branch to. You probably just need to add a branch back to page 1, so that the search term is applied to the report on the same page.
I don't have a installation of Apex 3.2 and the following was developed on 4.2.x using the wizard but I believe it should work for you.
First here is the report without any criteria:
Now here is report after some criteria has been entered and the button "Go" pressed:
This functionality is obtained by using the following query (which has been created by Apex):
select *
from (select "JOB_ID",
"JOB_TITLE",
"MIN_SALARY",
"MAX_SALARY"
from #OWNER#.OEHR_JOBS)
where (instr(upper("JOB_TITLE"),upper(nvl(:P2_REPORT_SEARCH,"JOB_TITLE"))) > 0)
The branch error you are seeing, probably means that you need to either create a branch back to your page or the existing branch is pointing to an invalid location.

Login different to Login Name

I am currently working with SQL Server 2005 and I had the question arising whether you can have a Login with a different Loginname. I came to ask the question as the query
SELECT * FROM master.sys.syslogins
throws up, amongst others, the two columns "name" and "loginname" both displaying the same values.
So I asked myself if it was possible to have a Login called "XTest" where the user can actually log on with the Username "Test"...
No, it is not possible! Both columns have always the save value. You should not use sys.syslogins (in any database) at all in any current SQL Server version. This table is still provided for backward compatibility, use sys.server_principals and sys.sql_logins instead.

Help with instructions for a login system

I've been working with my last project from my 3 programming course, and right now I think I'm doing pretty well, basically all I gotta do is interact with Access tables, save, edit, create, etc...
That has been working out pretty well, but right now I'm stuck with my login system, I've created some methods where I encrypt the password, and then I send the password to a table called "security". The fields in the table are: username, password, email, type of account.
I can successfully insert all the respective data in it. Right now I am stuck with the validation. I need to create a system that will let me verify if the username exist (I did it successfully trying to insert the username again and if the username exists it will return an exception), but I don't know how to verify the password that is in the same line.
I was wondering if there is any instruction with which I can extract the information of each field from the username that I verified? please help me...
idk if I explain myself.. ?
ok thank your very much but do u know how can I retrieve it into a variable I have something like this "select contra from Seguridad where usuaruio = #CLAVE"
You are going to want o read a record from the table where the username field is the value of the user name to be tested. If no record found then insert the record. If a record found then do other things.
How to do this in VB.Net I don't know.
The query created in code would like something like
"SELECT * from UserTable where UserNameField = "' & varUserName & "'"